Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cwb_condor_benchmark.C
Go to the documentation of this file.
1 // draw benchmark plots of computational load : used by the cwb_condor command
2 
3 #include <vector>
4 
5 #define NSTAGE 7
6 
7 TCanvas* canvas;
8 TH1F* hplot;
9 TGraph* gplot;
10 TH2F* h2plot;
11 
13 
14  TString STAGE[NSTAGE] = {"FULL","INIT","STRAIN","CSTRAIN","COHERENCE","SUPERCLUSTER","LIKELIHOOD"};
15 
17 
18  TB.checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
19  TB.checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
20  TB.checkFile(gSystem->Getenv("CWB_UPARAMETERS_FILE"));
21 
22  // get benchmark options
23  TString cwb_jstage_name = "FULL";
24  TString cwb_fstage_name = "FULL";
25  TString cwb_plot_type = "HIST";
26  TString cwb_plot_save = "";
27  TString cwb_bench_name = "JET"; // JET/SET/MEM/SET
28  double cwb_bench_min = -1; // min bench value
29  double cwb_bench_max = -1; // max bench value
30  int cwb_bench_res = -1; // res bench value (disabled)
31  int cwb_bench_factor= -1; // factor bench value (disabled)
32  TString cwb_bench_opts=TString(gSystem->Getenv("CWB_BENCH_OPTS"));
33  if(cwb_bench_opts!="") {
34  int bstage=false;
35  TString option="";
36  // get fstage
37  option = TB.getParameter(cwb_bench_opts,"--fstage");
38  if(option!="") {
39  cwb_fstage_name = option;
40  cwb_fstage_name.ToUpper();
41  bstage=false;
42  for(int i=0;i<NSTAGE;i++) if(cwb_fstage_name==STAGE[i]) bstage=true;
43  if(!bstage) {
44  cout << "cwb_condor_benchmark.C : fstage "
45  << cwb_fstage_name.Data() << " not correct" << endl;
46  cout << "select : " << endl;
47  for(int i=0;i<NSTAGE;i++) cout << STAGE[i] << endl;
48  gSystem->Exit(1);
49  }
50  }
51  // get jstage
52  option = TB.getParameter(cwb_bench_opts,"--jstage");
53  if(option!="") {
54  cwb_jstage_name = option;
55  cwb_jstage_name.ToUpper();
56  bstage=false;
57  for(int i=0;i<NSTAGE;i++) if(cwb_jstage_name==STAGE[i]) bstage=true;
58  if(!bstage) {
59  cout << "cwb_condor_benchmark.C : jstage "
60  << cwb_jstage_name.Data() << " not correct" << endl;
61  cout << "select : " << endl;
62  for(int i=0;i<NSTAGE;i++) cout << STAGE[i] << endl;
63  gSystem->Exit(1);
64  }
65  }
66  // get res
67  option = TB.getParameter(cwb_bench_opts,"--res");
68  if(option!="") cwb_bench_res = option.Atoi();
69  // get factor
70  option = TB.getParameter(cwb_bench_opts,"--factor");
71  if(option!="") cwb_bench_factor = option.Atoi();
72  // get bench
73  option = TB.getParameter(cwb_bench_opts,"--bench");
74  if(option!="") {
75  cwb_bench_name=option;
76  cwb_bench_name.ToUpper();
77  if((cwb_bench_name!="MEM") && (cwb_bench_name!="JET") &&
78  (cwb_bench_name!="JFS") && (cwb_bench_name!="SET") &&
79  (cwb_bench_name!="PSIZE") && (cwb_bench_name!="CSIZE") &&
80  (cwb_bench_name!="THR") && (cwb_bench_name!="GT")) {
81  cout << "cwb_condor_benchmark.C : Error - "
82  << "currently only JET/MEM/JFS/SET/THR/PSIZE/CSIZE/GT is implemented" << endl;
83  gSystem->Exit(1);
84  }
85  }
86  if((cwb_bench_res>=0) &&
87  (cwb_bench_name!="THR")&&(cwb_bench_name!="PSIZE")&&(cwb_bench_name!="CSIZE")) {
88  cout << "cwb_condor_benchmark.C : Error - "
89  << "'--res' parm must declared only with bench=THR/PSIZE/CSIZE" << endl;
90  gSystem->Exit(1);
91  }
92  if(((cwb_bench_name=="THR") &&(cwb_bench_res<0)) ||
93  ((cwb_bench_name=="PSIZE")&&(cwb_bench_res<0)) ||
94  ((cwb_bench_name=="CSIZE")&&(cwb_bench_res<0))) {
95  cout << "cwb_condor_benchmark.C : Error - "
96  << "when bench=THR/PSIZE/CSIZE the '--res' parm must be > 0" << endl;
97  gSystem->Exit(1);
98  }
99  if(((cwb_bench_name=="THR") &&(cwb_jstage_name!="COHERENCE")) ||
100  ((cwb_bench_name=="PSIZE")&&(cwb_jstage_name!="COHERENCE")) ||
101  ((cwb_bench_name=="GT") &&(cwb_jstage_name!="COHERENCE")) ||
102  ((cwb_bench_name=="CSIZE")&&(cwb_jstage_name!="COHERENCE"))) {
103  cout << "cwb_condor_benchmark.C : Error - "
104  << "bench=THR/PSIZE/CSIZE/GT is available only in COHERENCE stage" << endl;
105  gSystem->Exit(1);
106  }
107  // get plot type
108  option = TB.getParameter(cwb_bench_opts,"--plot");
109  if(option!="") {
110  cwb_plot_type=option;
111  cwb_plot_type.ToUpper();
112  if((cwb_plot_type!="HIST")&&(cwb_plot_type!="GRAPH")&&(cwb_plot_type!="HIST2")) {
113  cout << "cwb_condor_benchmark.C : currently only HIST/GRAPH/HIST2 is implemented" << endl;
114  gSystem->Exit(1);
115  }
116  }
117  // get plot save
118  option = TB.getParameter(cwb_bench_opts,"--save");
119  if(option!="") {
120  cwb_plot_save=option;
121  if(option.EndsWith(".png")) { // if ends with .png then it is a file
122  // get directory
123  if(option.Contains("/")) {
124  option.Remove(option.Last('/')); // strip file name
125  } else option=".";
126  }
127  CWB::Toolbox::checkFile(option); // check if dir exist
128  }
129 
130  // get min
131  option = TB.getParameter(cwb_bench_opts,"--min");
132  if(option!="") cwb_bench_min = option.Atof();
133  // get max
134  option = TB.getParameter(cwb_bench_opts,"--max");
135  if(option!="") cwb_bench_max = option.Atof();
136  if(cwb_bench_min==0) cwb_bench_min=-1;
137  if(cwb_bench_max==0) cwb_bench_max=-1;
138  if(cwb_bench_min>0 && cwb_bench_max>0 && cwb_bench_min>=cwb_bench_max) {
139  cout << "cwb_condor_benchmark.C : Error min must be < max " << endl;
140  gSystem->Exit(1);
141  }
142  }
143 
144  // if bench = JET/SET/JFS/MEM the values of the current stage are reported in the next stage
145  bool uns = false; // uns : use next stage
146  if(cwb_bench_name=="JET") uns = true;
147  if(cwb_bench_name=="SET") uns = true;
148  if(cwb_bench_name=="JFS") uns = true;
149  if(cwb_bench_name=="MEM") uns = true;
150 
151  CWB_STAGE jstage=CWB_STAGE_FINISH;
152  if(cwb_jstage_name=="INIT") jstage = uns ? CWB_STAGE_STRAIN : CWB_STAGE_INIT;
153  if(cwb_jstage_name=="STRAIN") jstage = uns ? CWB_STAGE_CSTRAIN : CWB_STAGE_STRAIN;
154  if(cwb_jstage_name=="CSTRAIN") jstage = uns ? CWB_STAGE_COHERENCE : CWB_STAGE_CSTRAIN;
155  if(cwb_jstage_name=="COHERENCE") jstage = uns ? CWB_STAGE_SUPERCLUSTER: CWB_STAGE_COHERENCE;
156  if(cwb_jstage_name=="SUPERCLUSTER") jstage = uns ? CWB_STAGE_LIKELIHOOD : CWB_STAGE_SUPERCLUSTER;
157  if(cwb_jstage_name=="LIKELIHOOD") jstage = uns ? CWB_STAGE_SAVE : CWB_STAGE_LIKELIHOOD;
158  if(cwb_jstage_name=="FULL") { jstage = CWB_STAGE_FINISH;
159  if(cwb_bench_name=="SET") cwb_bench_name = "JET";}
160 
161  TString fstage="wave_";
162  if(cwb_fstage_name=="INIT") fstage = "init_";
163  if(cwb_fstage_name=="STRAIN") fstage = "strain_";
164  if(cwb_fstage_name=="CSTRAIN") fstage = "cstrain_";
165  if(cwb_fstage_name=="COHERENCE") fstage = "coherence_";
166  if(cwb_fstage_name=="SUPERCLUSTER") fstage = "supercluster_";
167  if(cwb_fstage_name=="LIKELIHOOD") fstage = "wave_";
168  if(cwb_fstage_name=="FULL") fstage = "wave_";
169 
170  if(cwb_jstage_name==cwb_fstage_name) jstage = CWB_STAGE_FINISH;
171 
172  if(nfactor<=0) nfactor=1; // fix nfactor when nfactor is not defined
173  // get the number of job submit by condor
174  char full_condor_dir[512];
175  sprintf(full_condor_dir,"%s/%s",work_dir,condor_dir);
176  char condor_dag_file[256];
177  sprintf(condor_dag_file,"%s/%s%s.dag",full_condor_dir,data_label,"");
178  Long_t id,size=0,flags,mt;
179  int estat = gSystem->GetPathInfo(condor_dag_file,&id,&size,&flags,&mt);
180  vector<int> jobList;
181  if (estat==0) jobList=TB.getCondorJobList(full_condor_dir, data_label);
182  else {
183  cout << endl << "cwb_condor_benchmark.C : error - dag file not exist !!!"
184  << endl << condor_dag_file << endl << endl;
185  if (!online) gSystem->Exit(1);
186  }
187  int ncondor_jobs = jobList.size();
188  int max_jobid=0;
189  for(int i=0;i<ncondor_jobs;i++) if(jobList[i]>max_jobid) max_jobid=jobList[i];
190 
191  // factor label
192  char sfactor[32]="";
193  if(simulation) {
194  double factor=factors[nfactor-1];
195  if(simulation==3) {
196  if(factor<0) sprintf(sfactor,"_n%g_",fabs(factor));
197  if(factor==0) sprintf(sfactor,"_z%g_",factor);
198  if(factor>0) sprintf(sfactor,"_p%g_",factor);
199  } else if(simulation==4) {
200  int ioffset = int(factors[0])<=0 ? 1 : int(factors[0]);
201  //ioffset+=nfactor-1;
202  sprintf(sfactor,"_%i_",ioffset);
203  } else sprintf(sfactor,"_%g_",factor);
204  }
205  char job_label[512];
206  if(fstage=="wave_") sprintf(job_label,"%s%s",data_label,sfactor);
207  else sprintf(job_label,"%s",data_label);
208 
209  cout << "Starting reading output directory ..." << endl;
210  vector<TString> fileList = TB.getFileListFromDir(output_dir,".root",fstage,job_label,true);
211  if (online) fileList = TB.getFileListFromDir(output_dir,".root",fstage,"",true);
212  int nfile = fileList.size();
213  float* jobId = new float[nfile];
214  float* istat = new float[nfile];
215  for(int n=0;n<nfile;n++) {jobId[n]=n;istat[n]=0;}
216  for(int n=0;n<nfile;n++) {
217  //cout << n << " " << fileList[n].Data()<< endl;
218 
219  if (n%100==0) cout << "cwb_condor benchmark - " << n << "/" << fileList.size() << " files" << endl;
220 
221  vector<float> bench = CWB::Toolbox::getJobBenchmark(fileList[n],jstage,
222  cwb_bench_res,cwb_bench_factor,cwb_bench_name);
223  jobId[n]=bench[0];
224  istat[n]=bench[1];
225  }
226 
227  //for(int n=0;n<nfile;n++) {if(istat[n]>0) cout << jobId[n] << " " << istat[n] << endl;}
228 
229  if(cwb_plot_save!="") gROOT->SetBatch(true);
230 
231  canvas = new TCanvas("cwb_condor_benchmark", "LVC experiment", 300,40, 800, 600);
232  canvas->Clear();
233  canvas->ToggleEventStatus();
234  canvas->SetGridx(true);
235  canvas->SetGridy(true);
236  canvas->SetFillColor(kWhite);
237 
238  gStyle->SetTitleH(0.050);
239  gStyle->SetTitleW(0.98);
240  gStyle->SetTitleY(0.98);
241  gStyle->SetTitleFont(72);
242 // gStyle->SetLineColor(kWhite);
243  gStyle->SetTitleFillColor(kWhite);
244  gStyle->SetNumberContours(256);
245  gStyle->SetMarkerStyle(7);
246  gStyle->SetMarkerSize(2);
247  gStyle->SetPalette(1,0);
248 
249  if((cwb_bench_name=="JET")||(cwb_bench_name=="SET")) {
250  for(int n=0;n<nfile;n++) istat[n]/=3600.; // sec -> hour
251  }
252  if(cwb_bench_name=="JFS") {
253  for(int n=0;n<nfile;n++) istat[n]/=(1024.*1024.); // bytes -> MB
254  }
255  if((cwb_bench_name=="THR")&&(cwb_bench_max<=0)) {
256  for(int n=0;n<nfile;n++) if(istat[n]>50) istat[n]=50;
257  }
258 
259  // compute istat min/max
260  double istat_min=100000;
261  double istat_max=0;
262  for(int n=0;n<nfile;n++) {
263  if(istat[n]>0 && istat[n]<istat_min) istat_min=istat[n];
264  if(istat[n]>0 && istat[n]>istat_max) istat_max=istat[n];
265  }
266  if(cwb_bench_max>0) istat_max=cwb_bench_max;
267 
268  //for(int n=0;n<nfile;n++) {if(istat[n]>0) cout << jobId[n] << " " << istat[n] << endl;}
269 
270  TString ptitle;
271  if(cwb_bench_name=="SET") ptitle="SET - Elapsed Time in Stage "+cwb_jstage_name;
272  if(cwb_bench_name=="JET") ptitle="JET - Job Elapsed Time at the end of Stage "+cwb_jstage_name;
273  if(cwb_bench_name=="JFS") ptitle="JFS - Job File Size at the end of Stage "+cwb_jstage_name;
274  if(cwb_bench_name=="MEM") ptitle="MEM - Virtual Memory used at the end of Stage "+cwb_jstage_name;
275  if(cwb_bench_name=="THR") {ptitle=cwb_jstage_name+" - Threshold @ ResolutionID : ";
276  ptitle+=cwb_bench_res;ptitle+=" & FactorID : ";
277  ptitle+=cwb_bench_factor;}
278  if(cwb_bench_name=="GT") {ptitle=cwb_jstage_name+" - Gating Time @ FactorID : ";
279  ptitle+=cwb_bench_factor;}
280  if(cwb_bench_name=="PSIZE") {ptitle=cwb_jstage_name+" - Number of pixels per lag @ ResolutionID : ";
281  ptitle+=cwb_bench_res;ptitle+=" & FactorID : ";
282  ptitle+=cwb_bench_factor;}
283  if(cwb_bench_name=="CSIZE") {ptitle=cwb_jstage_name+" - Number of clusters per lag @ ResolutionID : ";
284  ptitle+=cwb_bench_res;ptitle+=" & FactorID : ";
285  ptitle+=cwb_bench_factor;}
286  TString ytitle;
287  if(cwb_bench_name=="SET") ytitle="hour";
288  if(cwb_bench_name=="JET") ytitle="hour";
289  if(cwb_bench_name=="JFS") ytitle="MB";
290  if(cwb_bench_name=="MEM") ytitle="MB";
291  if(cwb_bench_name=="THR") ytitle="energy";
292  if(cwb_bench_name=="GT") ytitle="sec";
293  if(cwb_bench_name=="PSIZE") ytitle="count";
294  if(cwb_bench_name=="CSIZE") ytitle="count";
295 
296  char ofile_name[1024]="";
297  if(cwb_plot_save!="") {
298  if(cwb_plot_save.EndsWith(".png")) { // user defined file name
299  sprintf(ofile_name,"%s",cwb_plot_save.Data());
300  } else { // user define directory
301  TString extraLabel="";
302  if(cwb_bench_res>=0) {extraLabel+="_RESID_";extraLabel+=cwb_bench_res;}
303  if(cwb_bench_factor>=0) {extraLabel+="_FACTORID_";extraLabel+=cwb_bench_factor;}
304  // file name is provided by macro
305  sprintf(ofile_name,"%s/benchmark_%s_%s_%s_%s%s.png",cwb_plot_save.Data(),data_label,
306  cwb_bench_name.Data(),cwb_jstage_name.Data(),cwb_plot_type.Data(),extraLabel.Data());
307  }
308  }
309 
310  if(cwb_plot_type=="GRAPH") {
311  // sort data
312  float* x = new float[max_jobid+1];
313  float* y = new float[max_jobid+1];
314  for(int n=0;n<=max_jobid;n++) {x[n]=n;y[n]=0;}
315  for(int n=0;n<nfile;n++) {
316  if(istat[n]>0) y[int(jobId[n])]=istat[n];
317  }
318  int N=0;
319  for(int n=0;n<=max_jobid;n++) {
320  if(cwb_bench_name=="GT") {x[N]=x[n];y[N]=y[n];N++;}
321  else if(y[n]>0) {x[N]=x[n];y[N]=y[n];N++;}
322  }
323 
324  gplot = new TGraph(N,x,y);
325  gplot->SetName("benchmark");
326  gplot->SetTitle("graph");
327  gplot->SetLineColor(kRed);
328  gplot->SetMarkerColor(kRed);
329  gplot->Draw("APL");
330  gplot->GetHistogram()->SetXTitle("Job id");
331  gplot->GetHistogram()->SetYTitle(ytitle);
332  gplot->SetTitle(ptitle);
333  if(cwb_plot_save!="") {
334  cout << "cwb_condor_benchmark.C : dump -> " << ofile_name << endl;
335  canvas->Print(ofile_name);
336  exit(0);
337  }
338  }
339 
340  if(cwb_plot_type=="HIST") {
341  if((cwb_bench_name=="THR")||(cwb_bench_name=="PSIZE")||(cwb_bench_name=="CSIZE")||(cwb_bench_name=="GT")) {
342  canvas->SetLogy(true);
343  istat_max+=1;
344  }
345  hplot = new TH1F("benchmark","hist",100,istat_min,istat_max);
346  for(int n=0;n<nfile;n++) {
347  if(cwb_bench_name=="GT") hplot->Fill(istat[n]);
348  else if(istat[n]>0) hplot->Fill(istat[n]);
349  }
350  hplot->Draw();
351  hplot->SetXTitle(ytitle);
352  hplot->SetYTitle("#counts");
353  hplot->SetTitle(ptitle);
354  hplot->SetLineColor(kRed);
355  hplot->SetFillColor(kRed);
356  hplot->GetYaxis()->SetTitleOffset(1.3);
357  if(cwb_plot_save!="") {
358  cout << "cwb_condor_benchmark.C : dump -> " << ofile_name << endl;
359  canvas->Print(ofile_name);
360  exit(0);
361  }
362  }
363 
364  if(cwb_plot_type=="HIST2") {
365 
366  int NX = sqrt(max_jobid); NX=NX-NX%10; if(NX==0) NX=max_jobid;
367  int NY = max_jobid/NX; if(max_jobid%NX) NY+=1;
368 
369  h2plot = new TH2F("benchmark","hist2",NX,0,NX,NY,0,NX*NY);
370  for(int n=0;n<nfile;n++) {
371  int job = jobId[n]-1;
372  int nx = job%NX;
373  int ny = job;
374  double z = istat[n];
375  if(cwb_bench_max>0) if(istat[n]>cwb_bench_max) z=cwb_bench_max;
376  //cout << job << " " << nx << " " << ny << " " << istat[n] << " " << endl;
377  if(istat[n]) h2plot->Fill(nx,ny,z);
378  }
379  canvas->SetLogz(false);
380  h2plot->Draw("colz");
381  char h2title[256];sprintf(h2title," : condor jobs = %d/%d",nfile,ncondor_jobs);
382  h2plot->SetTitle(ptitle+h2title);
383  h2plot->SetStats(kFALSE);
384  h2plot->SetXTitle("");
385  h2plot->SetYTitle("job#");
386  h2plot->SetZTitle(ytitle);
387  h2plot->SetLineColor(kRed);
388  h2plot->SetFillColor(kRed);
389  h2plot->GetYaxis()->SetTitleOffset(1.3);
390  h2plot->GetZaxis()->SetTitleOffset(0.5);
391  h2plot->GetZaxis()->SetRangeUser(0,int(istat_max)+1);
392  //h2plot->GetZaxis()->SetNdivisions(-309);
393  h2plot->GetYaxis()->CenterTitle(true);
394  h2plot->GetZaxis()->CenterTitle(true);
395  if(cwb_plot_save!="") {
396  cout << "cwb_condor_benchmark.C : dump -> " << ofile_name << endl;
397  canvas->Print(ofile_name);
398  exit(0);
399  }
400  }
401 }
bool online
static vector< TString > getFileListFromDir(TString dir_name, TString endString="", TString beginString="", TString containString="", bool fast=false)
Definition: Toolbox.cc:4333
void cwb_condor_benchmark()
int n
Definition: cwb_net.C:10
wavearray< double > z
Definition: Test10.C:32
TString("c")
cout<< endl;cout<< "ts size = "<< ts.size()<< " ts rate = "<< ts.rate()<< endl;tf.Forward(ts, wdm);int levels=tf.getLevel();cout<< "tf size = "<< tf.size()<< endl;double dF=tf.resolution();double dT=1./(2 *dF);cout<< "rate(hz) : "<< RATE<< "\t layers : "<< nLAYERS<< "\t dF(hz) : "<< dF<< "\t dT(ms) : "<< dT *1000.<< endl;int itime=TIME_PIXEL_INDEX;int ifreq=FREQ_PIXEL_INDEX;int index=(levels+1)*itime+ifreq;double time=itime *dT;double freq=(ifreq >0)?ifreq *dF:dF/4;cout<< endl;cout<< "PIXEL TIME = "<< time<< " sec "<< endl;cout<< "PIXEL FREQ = "<< freq<< " Hz "<< endl;cout<< endl;wavearray< double > x
Long_t flags
Long_t size
#define NSTAGE
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:3956
#define N
CWB::Toolbox TB
Definition: ComputeSNR.C:5
TCanvas * canvas
char condor_dag_file[256]
static vector< float > getJobBenchmark(TString ifName, int stageID, TString bench)
Definition: Toolbox.cc:1425
char data_label[512]
Definition: test_config1.C:160
double factor
vector< int > jobList
i() int(T_cor *100))
char job_label[512]
TH1F * hplot
double factors[100]
Definition: test_config1.C:84
static vector< int > getCondorJobList(TString condor_dir, TString label)
Definition: Toolbox.cc:1378
static TString getParameter(TString options, TString param="")
Definition: Toolbox.cc:5943
TH2F * h2plot
cout<< "Starting reading output directory ..."<< endl;vector< TString > fileList
double fabs(const Complex &x)
Definition: numpy.cc:37
int estat
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
nfactor[0]
Definition: cwb_eced.C:10
Long_t mt
int jobId
Long_t id
char condor_dir[512]
Definition: test_config1.C:148
char work_dir[512]
Definition: test_config1.C:143
TGraph * gplot
simulation
Definition: cwb_eced.C:9
char output_dir[512]
Definition: test_config1.C:146
wavearray< double > y
Definition: Test10.C:31
char full_condor_dir[512]
CWB_STAGE
Definition: cwb.hh:102
exit(0)