]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/sim/PlotSysInfo.C
Updates
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / sim / PlotSysInfo.C
1 /**
2  * @file   PlotSysInfo.C
3  * @author Christian Holm Christensen <cholm@nbi.dk>
4  * @date   Wed Oct 15 13:21:47 2014
5  * 
6  * @brief  A script to plot information from system watch files
7  */
8 /** 
9  * Make a canvas 
10  * 
11  * @param title Title on canvas 
12  * 
13  * @return The canvas 
14  */
15 TVirtualPad* MakeCanvas(const char* title="")
16 {
17   static Int_t cId = 0;
18   TCanvas* c = new TCanvas(Form("c%02d", ++cId), title);
19   c->SetTopMargin(0.02);
20   c->SetRightMargin(0.02);
21   c->cd();
22   return c;
23 }
24 /** 
25  * Summarize the usage 
26  * 
27  * @param tree tree to look in 
28  * @param exp  expression to draw 
29  * @param cut  Cut to use 
30  * @param draw Whether to draw or not 
31  * 
32  * @return The summed usage 
33  */
34 Double_t SumUsage(TTree*      tree, 
35                   const char* exp, 
36                   const char* cut, 
37                   bool        draw=false)
38 {
39   if (draw) MakeCanvas(Form("%s [%s]", exp, cut));
40   
41   Int_t  entries = tree->Draw(exp, cut, (draw ? "" : "goff"));
42   if (entries==0) return 0;
43
44   Double_t mean = TMath::Mean(entries, tree->GetV1());
45   return entries * mean;
46 }
47 /** 
48  * Return the most heavy load 
49  * 
50  * @param tree  tree to look in 
51  * @param exp   expression to draw 
52  * @param cut   Cut to use 
53  * @param order Off set
54  * 
55  * @return Most heavy usage 
56  */
57 Double_t TopUsage(TTree*      tree, 
58                   const char* exp, 
59                   const char* cut, 
60                   Int_t       order)
61 {
62   Int_t entries = tree->Draw(exp, cut, "goff");
63   if (entries <= 1 || !tree->GetV1()) return -10000;
64   
65   TArrayI index(entries);
66   TMath::Sort(entries, tree->GetV1(), index.fArray);
67
68   Int_t    oindex = TMath::Min(order, entries);
69   Double_t value  = tree->GetV1()[index[oindex-1]];
70   
71   return value;
72 }
73 /** 
74  * Extract a histogram from a resource spec 
75  * 
76  * @param tree    tree to look in 
77  * @param exp     expression to draw 
78  * @param cut     Cut to use 
79  * @param name    Name of histogram
80  * @param xtitle  X axis title
81  * @param ytitle  Y axis title 
82  * @param draw    If true, draw 
83  * 
84  * @return The extract histogram or null
85  */
86   
87 TH1* ExtractHist(TTree*      tree,
88                  const char* exp, 
89                  const char* cut,
90                  const char* name,
91                  const char* xtitle="", 
92                  const char* ytitle="",
93                  Bool_t      draw=false)
94 {
95   tree->Draw(Form("%s>>tmpa", exp), cut, "GOFF");
96   if (!tree->GetHistogram()) return 0;
97
98   TH1* ret = static_cast<TH1*>(tree->GetHistogram()->Clone(name));
99   delete tree->GetHistogram();
100   ret->SetXTitle(xtitle);
101   ret->SetYTitle(ytitle);
102   ret->SetMarkerStyle(22);
103   ret->SetMarkerSize(1);
104   if (draw) {
105     if (draw) MakeCanvas(name);
106     ret->Draw();
107   }
108   return ret;
109 }
110                  
111 /** 
112  * Print some information to output stream
113  *  
114  * @param o             Stream
115  * @param name          Step
116  * @param dT            Change in time
117  * @param dVM           Change in VM usage
118  * @param alldT         Sum of time
119  * @param alldVM        Sum of VM usage 
120  */              
121 void Print(std::ostream& o,
122            const char*   name, 
123            Double_t      dT, 
124            Double_t      dVM, 
125            Double_t      alldT, 
126            Double_t      alldVM)
127 {
128   o << name << "\t" 
129     << dT   << "\t" 
130     << dVM  << "\t" 
131     << 100*(alldT  > 0 ? dT  / alldT  : 0) << "\t" 
132     << 100*(alldVM > 0 ? dVM / alldVM : 0) << std::endl;
133 }
134 /**
135  * Detectors
136  * 
137  */
138 const char* dets[] = {"ITS", 
139                       "TPC", 
140                       "TRD", 
141                       "TOF", 
142                       "PHOS", 
143                       "HMPID", 
144                       "EMCAL", 
145                       "MUON", 
146                       "FMD", 
147                       "ZDC", 
148                       "PMD", 
149                       "T0", 
150                       "VZERO", 
151                       "ACORDE", 
152                       "HLT",
153                       0 };
154
155 /** 
156  * Plot information from one file 
157  * 
158  * @param file  File to plot from 
159  * @param draw  Drawing flags
160  */
161 void
162 Plot1SysInfo(const char* file, UShort_t draw=0x1)
163 {
164   // --- Create output file and tree ---------------------------------
165   TString rootOut(file); 
166   rootOut.ReplaceAll(".log", ".root");
167   rootOut.ReplaceAll(".foo", ".root");
168   Info("", "Writing to ROOT file %s", rootOut.Data());
169   TFile* out  = TFile::Open(rootOut, "RECREATE");
170   TTree* tree = AliSysInfo::MakeTree(file);
171   tree->SetName("T");
172   
173   
174   // --- Create ASCII output ------------------------------------------
175   TString sumOut(rootOut); 
176   sumOut.ReplaceAll(".root", ".sum");
177   Info("", "Writing to ASCII file %s", sumOut.Data());
178   std::ofstream ascii(sumOut.Data());
179   ascii << "Det/C:sumDt/F:sumDvm/F:fracDt/F:fracDvm/F" << std::endl;
180
181   // --- Get global stuff ---------------------------------------------
182   const char* all     = "id0>=0&&id2>=0";
183   Double_t sumdTAll   = SumUsage(tree, "deltaT",  all, draw & 0x1);
184   Double_t sumdVMAll  = SumUsage(tree, "deltaVM", all, draw & 0x1);
185   Double_t topdT      = TopUsage(tree, "deltaT",  "id2<3", 20);
186   Double_t topdVM     = TopUsage(tree, "deltaVM", "", 20);
187   TCut     cutT("cutDT", Form("deltaT > %f", topdT));
188   TCut     cutVM("cutVM", Form("deltaVM > %f", topdVM));
189   
190   ExtractHist(tree, "deltaVM:sname", "1"+cutVM,
191               "DVMvsName","","#DeltaVM [MB]", draw&0x4);
192   ExtractHist(tree, "VM:sname", "id2<3"+cutVM, 
193               "VMvsName", "", "VM [MB]", draw&0x4);
194   ExtractHist(tree, "VM:T", "deltaVM>1", 
195               "VMvsTime", "Time [sec]", "VM [MB]", draw&0x4);
196   ExtractHist(tree, "deltaT:sname","id2<3"+cutT,
197               "CPUvsName","","#DeltaT [sec]", draw&0x4);
198   
199
200
201   Print(ascii, "all", sumdTAll, sumdVMAll, sumdTAll, sumdVMAll);
202
203   
204
205   // --- Loop over detetors ------------------------------------------
206   const char** pdet = dets;
207   Int_t        idet = 0;
208   while (*pdet) { 
209     TString  cut    = Form("id0==%d && id2 >= 0", idet);
210     Double_t sumdT  = SumUsage(tree, "deltaT",  cut, draw & 0x2);
211     Double_t sumdVM = SumUsage(tree, "deltaVM", cut, draw & 0x2);
212     Print(ascii, *pdet, sumdT, sumdVM, sumdTAll, sumdVMAll);
213     
214 #if 0
215     TString cut2    = Form("id0==%d",idet);
216     ExtractHist(tree, "deltaVM:sname", cut2.Data()+cutVM,
217                 Form("DVMvsName_%02d", idet), "", "#DeltaVM [MB]", draw&0x8);
218     ExtractHist(tree, "VM:sname",      cut2.Data()+cutVM,
219                 Form("VMvsName_%02d", idet), "", "VM [MB]", draw&0x8);
220     ExtractHist(tree, "deltaT:sname",  cut2.Data()+cutT, 
221                 Form("CPUvsName_%02d", idet),"", "#DeltaT [sec]", draw&0x8);
222 #endif
223
224     pdet++;
225     idet++;
226   }
227   ascii.close();
228   tree->Write();
229   out->Write();
230   out->ls();
231   new TBrowser;
232 }
233
234 /** 
235  * Plot for one job both simulation and reconstruction usage 
236  * 
237  * @param pid Job identifier 
238  */
239 void
240 PlotSysInfo(ULong_t pid=431808952)
241 {
242   Plot1SysInfo(Form("%d_simwatch.log", pid));
243   Plot1SysInfo(Form("%d_recowatch.log", pid));
244 }
245 // 
246 // EOF
247 // 
248
249