14 #include <sys/types.h>
33 #include "TDirectory.h"
42 std::ostream&
s = std::cout;
43 s <<
"Usage: " <<
name <<
" [OPTIONS] expert-monitoring.root reference.root algorithm1 algorithm2 algorithm3 ...\n\n";
44 s <<
" TIDA \'" <<
name <<
"\' extracts timing histograms\n\n";
46 s <<
" -o, --outputfolder value\t puts output in folder 'value' making it if it doesn't exist, \n\n";
47 s <<
" -t, --tag value \t appends tag 'value' to the end of output plot names, \n";
48 s <<
" -k, --key value \t prepends key 'value' to the front of output plot names, \n\n";
49 s <<
" -a, --auto \t process all histograms that are in the file, \n";
50 s <<
" -r, --replace patt rep\t replace patt wiht rep in the file name\n";
51 s <<
" -d, --directory value \t if auto is set, search only in specifed directory, \n";
52 s <<
" --nodir \t do not print the directory name on the plot,\n";
53 s <<
" -p, --pattern value \t if auto is set, search for histograms containing this string, \n\n";
54 s <<
" -f, --frac \t explicitly include the fractional plots\n";
55 s <<
" -nr, --noref \t do not use the reference file, \n\n";
56 s <<
" -x, --xoffset value \t offset the key by value \n";
57 s <<
" --logx \t force logx \n";
58 s <<
" -w, --binwidth \t normalise by bin width\n";
59 s <<
" -as, --atlasstyle \t use the ATLAS style \n\n";
60 s <<
" -al, --atlaslabel \t show the ATLAS label \n\n";
61 s <<
" -v, --verbose \t verbose output\n\n";
62 s <<
" -h, --help \t this help\n";
77 return s <<
h.fname <<
" : " <<
h.dname;
82 for (
int i=0 ;
i<
h->GetNbinsX() ;
i++ ) {
83 double w =
h->GetBinLowEdge(
i+2)-
h->GetBinLowEdge(
i+1);
84 h->SetBinContent(
i+1,
h->GetBinContent(
i+1)/
w );
85 h->SetBinError(
i+1,
h->GetBinError(
i+1)/
w );
94 std::string output_dir =
"";
98 gStyle->SetPadRightMargin(0.05);
99 gStyle->SetPadTopMargin(0.05);
101 gStyle->SetPadLeftMargin(0.14);
102 gStyle->SetPadBottomMargin(0.14);
110 bool atlasstyle =
false;
111 bool atlaslabel =
false;
115 bool autochains =
false;
117 std::string autopattern =
"";
119 std::vector<std::string> taglabels;
130 std::string frefname =
"";
132 double xoffset = 0.17;
134 bool show_directory =
true;
136 bool norm_width =
true;
140 bool withlumiblock =
false;
142 bool withfractional =
false;
144 std::vector<std::string> replace_list;
147 std::vector<std::string> algorithms;
148 for(
int argnum = 1; argnum <
argc; argnum++){
149 std::string
arg =
argv[argnum];
151 if (
arg ==
"-h" ||
arg ==
"--help") {
154 else if (
arg ==
"-o" ||
arg ==
"--outputfolder") {
155 if (++argnum <
argc) { output_dir =
argv[argnum]; }
158 else if (
arg ==
"-x" ||
arg ==
"--xoffset") {
162 else if (
arg ==
"-t" ||
arg ==
"--tag") {
163 if (++argnum <
argc) {
tag = std::string(
"-") +
argv[argnum]; }
166 else if (
arg ==
"-k" ||
arg ==
"--key") {
167 if (++argnum <
argc) {
key =
argv[argnum] + std::string(
"-"); }
170 else if (
arg ==
"-r" ||
arg ==
"--replace") {
171 if (++argnum <
argc) replace_list.push_back(
argv[argnum] );
173 if (++argnum <
argc) replace_list.push_back(
argv[argnum] );
176 else if (
arg ==
"--logx") {
179 else if (
arg ==
"-np" ||
arg ==
"--nopng") {
182 else if (
arg ==
"-f" ||
arg ==
"--frac" ) {
183 withfractional =
true;
185 else if (
arg ==
"-a" ||
arg ==
"--auto") {
188 else if (
arg ==
"--nodir") {
189 show_directory =
false;
191 else if (
arg ==
"-v" ||
arg ==
"--verbose") {
194 else if (
arg ==
"-lb" ) {
195 withlumiblock =
true;
197 else if (
arg ==
"-nr" ||
arg ==
"--noref") {
200 else if (
arg ==
"-w" ||
arg ==
"--binwidth") {
203 else if (
arg ==
"-as" ||
arg ==
"--atlasstyle") {
206 else if (
arg ==
"-al" ||
arg ==
"--atlaslabel") {
209 else if (
arg ==
"-ap" ||
arg ==
"--autopattern") {
210 if (++argnum <
argc) autopattern =
argv[argnum];
213 else if (
arg ==
"-d" ||
arg ==
"--directory") {
217 else if (
arg ==
"-p" ||
arg ==
"--pattern") {
225 ftest =
new TFile(
file.c_str() );
228 std::cerr <<
"main(): test file " <<
arg <<
" does not exist" << std::endl;
232 else if ( frefname==
"" ) frefname =
arg;
234 algorithms.push_back(
arg);
242 if (ftest == 0 || ( noref==
false && frefname==
"" ) ) {
246 if ( fref == 0 && !noref ) {
249 fref =
new TFile(
file.c_str() );
252 std::cerr <<
"main(): ref file " << frefname <<
" does not exist" << std::endl;
259 gStyle->SetErrorX(0);
261 if ( noref ) fref = ftest;
265 if ( ftest && autochains ) {
269 std::vector<std::string>
dirs;
273 if ( autopattern==
"" ) {
274 for (
unsigned j=0 ; j<
dirs.size() ; j++ ) {
275 if (
verbose ) std::cout <<
"\talgorithm " <<
dirs[j] << std::endl;
276 algorithms.push_back(
dirs[j] );
280 std::cout <<
"autopattern : " << autopattern << std::endl;
281 for (
unsigned j=0 ; j<
dirs.size() ; j++ ) {
282 if (
dirs[j].
find(autopattern)!=std::string::npos ) {
283 algorithms.push_back(
dirs[j] );
284 std::cout <<
"adding " << algorithms.back() << std::endl;
294 if ( output_dir !=
"" ) {
295 if (
mkdir( output_dir.c_str(), 0777 ) ) {
296 if (
exists(output_dir) ) std::cerr <<
"main() directory " << output_dir <<
" aleady exists" << std::endl;
297 else std::cerr <<
"main() could not create directory " << output_dir << std::endl;
305 TDirectory* testtimers = 0;
308 else testtimers = ftest;
310 if (testtimers == 0 ) {
311 std::cerr <<
"main(): can not find timers in test file" << std::endl;
316 TDirectory* reftimers = 0;
319 else reftimers = fref;
321 if (reftimers == 0 ) {
322 std::cerr <<
"main(): can not find timers in ref file" << std::endl;
327 TFile fcck(
"fcck.root",
"recreate" );
342 std::cout <<
"\nhistogram " <<
histograms.at(
histogram) <<
" : with " << algorithms.size() <<
" algorithms" << std::endl;
346 std::string yaxis =
"Entries";
353 if ( !withlumiblock && algorithms[
algorithm].
find(
"LumiBlock")!=std::string::npos )
continue;
355 if ( !withfractional && algorithms[
algorithm].
find(
"Fractional")!=std::string::npos )
continue;
357 std::cout <<
"\nmain() processing algorithm : " << algorithms[
algorithm] << std::endl;
359 TCanvas*
c1 =
new TCanvas(
label(
"canvas-%d",
int(
histogram)).c_str(),
"histogram", 800, 600 );
363 double x2 = xoffset+0.25;
376 std::string xaxis_tmp = xaxis;
388 if (testhist == 0 ) {
389 std::cerr <<
"main(): can not find hist " <<
histname <<
" in test file" << std::endl;
393 std::cout <<
"mean time: " << testhist->GetMean() <<
"\t:: " << testhist->GetName() << std::endl;
395 if ( norm_width )
binwidth( testhist );
398 if ( std::string(testhist->ClassName()).find(
"TH1")==std::string::npos )
continue;
400 testhist->SetName(
tail(algorithms[
algorithm],
"/").c_str() );
408 TH1F* refhist = (
TH1F*)fref->Get(refhistname.c_str());
414 if ( refhist==0 && replace_list.size()>=2 ) {
416 for (
size_t ir=0 ;
ir<replace_list.size()-1 ;
ir+=2 ) {
418 size_t pos = refhistname.find(replace_list[
ir]);
419 if (
pos != std::string::npos ) {
421 while(
pos!=std::string::npos ) {
422 refhistname.replace(
pos, replace_list[
ir].
size(),
"XXXX" );
423 pos = refhistname.find(replace_list[
ir]);
426 pos = refhistname.find(
"XXXX");
427 while(
pos!=std::string::npos ) {
428 refhistname.replace(
pos, 4, replace_list[
ir+1] );
429 pos = refhistname.find(
"XXXX");
435 refhist = (
TH1F*)fref->Get(refhistname.c_str());
440 std::cerr <<
"main(): can not find hist " << refhistname <<
" in ref file" << std::endl;
444 if ( norm_width )
binwidth( refhist );
446 testhist->GetYaxis()->SetTitle(yaxis.c_str());
447 testhist->GetYaxis()->SetTitleOffset(1.5);
449 refhist->GetYaxis()->SetTitle(yaxis.c_str());
450 refhist->GetYaxis()->SetTitleOffset(1.5);
452 testhist->GetXaxis()->SetTitle(xaxis_tmp.c_str());
453 testhist->GetXaxis()->SetTitleOffset(1.5);
455 refhist->GetXaxis()->SetTitle(xaxis_tmp.c_str());
456 refhist->GetXaxis()->SetTitleOffset(1.5);
463 std::string algpname = algorithms[
algorithm];
473 std::string plotname =
key + algpname +
tag;
480 while ( plotname.find(
stub)!=std::string::npos ) {
481 plotname.erase( 0, plotname.find(
stub)+
stub.size() );
484 while ( plotname.find(
'_')==0 ) plotname.erase( 0, 1 );
486 plotname = output_dir + plotname;
488 std::cout <<
"output dir " << output_dir <<
"\tkey " <<
key <<
"\talgname " <<
algname <<
"\ttag " <<
tag << std::endl;
493 std::vector<std::string>
chains;
499 double Nent_ref =
plotable( refhist );
501 if ( fractional ) ylogt =
false;
503 if ( Nent==0 || Nent_ref==0 ) {
505 std::cerr <<
"histograms empty: " << testhist->GetName() << std::endl;
510 testhist->SetTitle(
"");
511 refhist->SetTitle(
"");
514 plots.SetLogy(ylogt);
516 if ( logx )
plots.SetLogx(
true);
518 double rmin =
plots.realmin();
519 double rmax =
plots.realmax();
521 if ( rmin == rmax ) rmin = 0;
524 if ( rmin == 0 ) rmin = rmax*0.0001;
525 double delta = std::log10(rmax)-std::log10(rmin);
526 if ( atlasstyle )
plots.Max( rmax*
std::pow(10,delta*0.15*2*(
chains.size()+taglabels.size()+1.5)) );
531 double delta = rmax-rmin;
534 double pmin = rmin-delta*0.1;
535 if ( pmin>0 )
plots.Min( pmin );
540 std::vector<double>
range =
plots.findxrange();
542 double lower =
range[0];
545 if ( lower<0 ) lower = 0;
551 std::string dirtitle =
dirname;
552 if ( dirtitle.find(
"HLT_")==0 && dirtitle.find(
"__")!=std::string::npos ) dirtitle.erase( dirtitle.find(
"__"), dirtitle.size() );
556 if ( atlasstyle && atlaslabel )
ATLASLabel(0.68, 0.88,
"Internal");
561 if ( logx ) gPad->SetLogx(
true);
563 plots.back().Print( (plotname+
".pdf").c_str() );
564 if ( !nopng )
plots.back().Print( (plotname+
".png").c_str() );
568 std::cout <<
"done algorithm " <<
algorithm <<
" " << algorithms[
algorithm] << std::endl;
580 #ifdef USE_SLOW_ROOT_FILE_DELETION
582 std::cout <<
"deleting ftest" << std::endl;
589 std::cout <<
"deleting fref" << std::endl;
600 std::cout <<
"done" << std::endl;