91int main(
int argc,
char** argv) {
93 if (argc < 4) {
return usage(argv[0], -1); }
95 std::string output_dir =
"";
99 gStyle->SetPadRightMargin(0.05);
100 gStyle->SetPadTopMargin(0.05);
102 gStyle->SetPadLeftMargin(0.14);
103 gStyle->SetPadBottomMargin(0.14);
111 bool atlasstyle =
false;
112 bool atlaslabel =
false;
116 bool autochains =
false;
118 std::string autopattern =
"";
120 std::vector<std::string> taglabels;
122 std::string directory =
"TIMERS";
125 TDirectory* tdir = gDirectory;
131 std::string frefname =
"";
133 double xoffset = 0.17;
135 bool show_directory =
true;
137 bool norm_width =
true;
141 bool withlumiblock =
false;
143 bool withfractional =
false;
145 std::vector<std::string> replace_list;
148 std::vector<std::string> algorithms;
149 for(
int argnum = 1; argnum < argc; argnum++){
150 std::string arg = argv[argnum];
152 if (arg ==
"-h" || arg ==
"--help") {
153 return usage(argv[0], 0);
155 else if (arg ==
"-o" || arg ==
"--outputfolder") {
156 if (++argnum < argc) { output_dir = argv[argnum]; }
157 else {
return usage(argv[0], -1); }
159 else if (arg ==
"-x" || arg ==
"--xoffset") {
160 if (++argnum < argc) { xoffset = std::atof(argv[argnum]); }
161 else {
return usage(argv[0], -1); }
163 else if (arg ==
"-t" || arg ==
"--tag") {
164 if (++argnum < argc) { tag = std::string(
"-") + argv[argnum]; }
165 else {
return usage(argv[0], -1); }
167 else if (arg ==
"-k" || arg ==
"--key") {
168 if (++argnum < argc) { key = argv[argnum] + std::string(
"-"); }
169 else {
return usage(argv[0], -1); }
171 else if (arg ==
"-r" || arg ==
"--replace") {
172 if (++argnum < argc) replace_list.push_back( argv[argnum] );
173 else {
return usage(argv[0], -1); }
174 if (++argnum < argc) replace_list.push_back( argv[argnum] );
175 else {
return usage(argv[0], -1); }
177 else if ( arg ==
"--logx") {
180 else if (arg ==
"-np" || arg ==
"--nopng") {
183 else if (arg ==
"-f" || arg ==
"--frac" ) {
184 withfractional =
true;
186 else if (arg ==
"-a" || arg ==
"--auto") {
189 else if (arg ==
"--nodir") {
190 show_directory =
false;
192 else if (arg ==
"-v" || arg ==
"--verbose") {
195 else if (arg ==
"-lb" ) {
196 withlumiblock =
true;
198 else if (arg ==
"-nr" || arg ==
"--noref") {
201 else if (arg ==
"-w" || arg ==
"--binwidth") {
204 else if (arg ==
"-as" || arg ==
"--atlasstyle") {
207 else if (arg ==
"-al" || arg ==
"--atlaslabel") {
210 else if (arg ==
"-ap" || arg ==
"--autopattern") {
211 if (++argnum < argc) autopattern = argv[argnum];
212 else return usage(argv[0], -1);
214 else if (arg ==
"-d" || arg ==
"--directory") {
215 if (++argnum < argc) directory = argv[argnum];
216 else return usage(argv[0], -1);
218 else if (arg ==
"-p" || arg ==
"--pattern") {
219 if (++argnum < argc)
patterns.push_back(argv[argnum]);
220 else return usage(argv[0], -1);
226 ftest =
new TFile(
file.c_str() );
229 std::cerr <<
"main(): test file " << arg <<
" does not exist" << std::endl;
233 else if ( frefname==
"" ) frefname = std::move(arg);
235 algorithms.push_back(std::move(arg));
243 if (ftest == 0 || ( noref==
false && frefname==
"" ) ) {
244 return usage(argv[0], -4);
247 if ( fref == 0 && !noref ) {
250 fref =
new TFile(
file.c_str() );
253 std::cerr <<
"main(): ref file " << frefname <<
" does not exist" << std::endl;
260 gStyle->SetErrorX(0);
262 if ( noref ) fref = ftest;
266 if ( ftest && autochains ) {
270 std::vector<std::string>
dirs;
274 if ( autopattern==
"" ) {
275 for (
unsigned j=0 ; j<
dirs.size() ; j++ ) {
276 if (
verbose ) std::cout <<
"\talgorithm " <<
dirs[j] << std::endl;
277 algorithms.push_back(
dirs[j] );
281 std::cout <<
"autopattern : " << autopattern << std::endl;
282 for (
unsigned j=0 ; j<
dirs.size() ; j++ ) {
283 if (
dirs[j].
find(autopattern)!=std::string::npos ) {
284 algorithms.push_back(
dirs[j] );
285 std::cout <<
"adding " << algorithms.back() << std::endl;
295 if ( output_dir !=
"" ) {
296 if ( mkdir( output_dir.c_str(), 0777 ) ) {
297 if (
exists(output_dir) ) std::cerr <<
"main() directory " << output_dir <<
" aleady exists" << std::endl;
298 else std::cerr <<
"main() could not create directory " << output_dir << std::endl;
306 TDirectory* testtimers = 0;
308 if ( directory!=
"" ) ftest->GetObject( directory.c_str(), testtimers );
309 else testtimers = ftest;
311 if (testtimers == 0 ) {
312 std::cerr <<
"main(): can not find timers in test file" << std::endl;
317 TDirectory* reftimers = 0;
319 if ( directory!=
"" ) fref->GetObject( directory.c_str(), reftimers );
320 else reftimers = fref;
322 if (reftimers == 0 ) {
323 std::cerr <<
"main(): can not find timers in ref file" << std::endl;
328 TFile fcck(
"fcck.root",
"recreate" );
331 std::vector<histoinfo> histograms;
332 histograms.push_back(
histoinfo(
"_TotalTime",
"Total time") );
343 std::cout <<
"\nhistogram " << histograms.at(
histogram) <<
" : with " << algorithms.size() <<
" algorithms" << std::endl;
346 std::string xaxis = histograms.at(
histogram).dname +
" [ms]";
347 std::string yaxis =
"Entries";
354 if ( !withlumiblock && algorithms[
algorithm].
find(
"LumiBlock")!=std::string::npos )
continue;
356 if ( !withfractional && algorithms[
algorithm].
find(
"Fractional")!=std::string::npos )
continue;
358 std::cout <<
"\nmain() processing algorithm : " << algorithms[
algorithm] << std::endl;
360 TCanvas* c1 =
new TCanvas(
label(
"canvas-%d",
int(
histogram)).c_str(),
"histogram", 800, 600 );
364 double x2 = xoffset+0.25;
372 Legend legend(x1, x2, y1, y2);
375 std::string histname = algorithms[
algorithm];
377 std::string xaxis_tmp = xaxis;
378 bool fractional =
contains( histname,
"Fractional" );
379 if ( fractional ) xaxis_tmp =
"Fraction of " + histograms.at(
histogram).dname;
387 TH1F* testhist = (TH1F*)ftest->Get(histname.c_str());
389 if (testhist == 0 ) {
390 std::cerr <<
"main(): can not find hist " << histname <<
" in test file" << std::endl;
394 std::cout <<
"mean time: " << testhist->GetMean() <<
"\t:: " << testhist->GetName() << std::endl;
396 if ( norm_width )
binwidth( testhist );
399 if ( std::string(testhist->ClassName()).find(
"TH1")==std::string::npos )
continue;
401 testhist->SetName(
tail(algorithms[
algorithm],
"/").c_str() );
406 std::string refhistname = std::move(histname);
409 TH1F* refhist = (TH1F*)fref->Get(refhistname.c_str());
415 if ( refhist==0 && replace_list.size()>=2 ) {
417 for (
size_t ir=0 ;
ir<replace_list.size()-1 ;
ir+=2 ) {
419 size_t pos = refhistname.find(replace_list[
ir]);
420 if ( pos != std::string::npos ) {
422 while( pos!=std::string::npos ) {
423 refhistname.replace( pos, replace_list[
ir].size(),
"XXXX" );
424 pos = refhistname.find(replace_list[
ir]);
427 pos = refhistname.find(
"XXXX");
428 while( pos!=std::string::npos ) {
429 refhistname.replace( pos, 4, replace_list[
ir+1] );
430 pos = refhistname.find(
"XXXX");
436 refhist = (TH1F*)fref->Get(refhistname.c_str());
441 std::cerr <<
"main(): can not find hist " << refhistname <<
" in ref file" << std::endl;
445 if ( norm_width )
binwidth( refhist );
447 testhist->GetYaxis()->SetTitle(yaxis.c_str());
448 testhist->GetYaxis()->SetTitleOffset(1.5);
450 refhist->GetYaxis()->SetTitle(yaxis.c_str());
451 refhist->GetYaxis()->SetTitleOffset(1.5);
453 testhist->GetXaxis()->SetTitle(xaxis_tmp.c_str());
454 testhist->GetXaxis()->SetTitleOffset(1.5);
456 refhist->GetXaxis()->SetTitle(xaxis_tmp.c_str());
457 refhist->GetXaxis()->SetTitleOffset(1.5);
464 std::string algpname = algorithms[
algorithm];
467 if ( algname.find(
"h_")==0 ) algname.erase(0, 2);
472 plots.push_back(
Plotter( testhist, refhist,
" "+algname ) );
474 std::string plotname = key + algpname + tag;
476 std::string stub = directory;
478 size_t pos = stub.find(
'/');
479 while ( pos!=std::string::npos ) { stub.erase( pos, 1 ); pos = stub.find(
'/'); }
481 while ( plotname.find(stub)!=std::string::npos ) {
482 plotname.erase( 0, plotname.find(stub)+stub.size() );
485 while ( plotname.find(
'_')==0 ) plotname.erase( 0, 1 );
487 plotname = output_dir + plotname;
489 std::cout <<
"output dir " << output_dir <<
"\tkey " << key <<
"\talgname " << algname <<
"\ttag " << tag << std::endl;
494 std::vector<std::string> chains;
495 chains.push_back( algname + tag );
500 double Nent_ref =
plotable( refhist );
502 if ( fractional ) ylogt =
false;
504 if ( Nent==0 || Nent_ref==0 ) {
506 std::cerr <<
"histograms empty: " << testhist->GetName() << std::endl;
511 testhist->SetTitle(
"");
512 refhist->SetTitle(
"");
515 plots.SetLogy(ylogt);
517 if ( logx ) plots.SetLogx(
true);
519 double rmin = plots.realmin();
520 double rmax = plots.realmax();
522 if ( rmin == rmax ) rmin = 0;
525 if ( rmin == 0 ) rmin = rmax*0.0001;
526 double delta = std::log10(rmax)-std::log10(rmin);
527 if ( atlasstyle ) plots.Max( rmax*std::pow(10,delta*0.15*2*(chains.size()+taglabels.size()+1.5)) );
528 else plots.Max( rmax*std::pow(10,delta*0.15*2*(chains.size()+taglabels.size()+1.0)) );
529 plots.Min( rmin*std::pow(10,-delta*0.1) );
532 double delta = rmax-rmin;
533 plots.Max( rmax+delta*0.1*2*chains.size() );
535 double pmin = rmin-delta*0.1;
536 if ( pmin>0 ) plots.Min( pmin );
541 std::vector<double> range = plots.findxrange();
543 double lower = range[0];
544 double upper = range[1];
546 if ( lower<0 ) lower = 0;
548 plots.SetRangeUser( lower,
upper );
550 plots.Draw( legend,
true );
552 std::string dirtitle = std::move(
dirname);
553 if ( dirtitle.find(
"HLT_")==0 && dirtitle.find(
"__")!=std::string::npos ) dirtitle.erase( dirtitle.find(
"__"), dirtitle.size() );
555 if ( show_directory )
DrawLabel( x1+0.02, y2+0.02, dirtitle, kBlack, legend.TextSize(), legend.TextFont() );
557 if ( atlasstyle && atlaslabel )
ATLASLabel(0.68, 0.88,
"Internal");
562 if ( logx ) gPad->SetLogx(
true);
564 plots.back().Print( (plotname+
".pdf").c_str() );
565 if ( !nopng ) plots.back().Print( (plotname+
".png").c_str() );
569 std::cout <<
"done algorithm " <<
algorithm <<
" " << algorithms[
algorithm] << std::endl;
572 std::cout <<
"done hist " <<
histogram <<
" " << histograms.at(
histogram).dname <<
" " << std::endl;
581#ifdef USE_SLOW_ROOT_FILE_DELETION
583 std::cout <<
"deleting ftest" << std::endl;
590 std::cout <<
"deleting fref" << std::endl;
601 std::cout <<
"done" << std::endl;