00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 import os, glob
00021 import os.path
00022 import operator
00023 import subprocess
00024 import sys, getopt
00025 sys.argv.append('-b')
00026 from ROOT import *
00027 import cStringIO
00028
00029
00030 gROOT.SetStyle("Plain")
00031 gStyle.SetOptStat(111111)
00032 gStyle.SetHistFillColor(kBlue)
00033
00034
00035 def usage():
00036
00037 print "\nThis is the usage function\n"
00038 print 'Usage: '+sys.argv[0]+' -i <file1> [option]'
00039 print 'e.g.: '+sys.argv[0]+' -i outputTiming.root -t'
00040 print 'e.g.: '+sys.argv[0]+' -i outputTiming.root -s HLT_Jet300_v5\n'
00041
00042 print '\n-----Options-----'
00043 print ' -i Input File'
00044 print ' -o Output File (optional)'
00045 print ' -t For only main time info per event. It will take less than 1 min.'
00046 print ' -p For path time info. It will take approx 25 min.'
00047 print ' -m For module time info. It will take approx 25 min.'
00048 print ' -s Path_Name (For an specific path). Ti will take less than 1 min.'
00049 print '\n For -p or -m option, the process needs like 200 Mb in disk space,'
00050 print ' but please dont be afraid. Before the process ends, all the temporal files'
00051 print ' will be erased.'
00052
00053
00054
00055 def maininfo(infile, outfile):
00056 ''' Creates main info tex file'''
00057
00058 texpreamble = ['\documentclass[10pt,a5paper,landscape]{report}\n',
00059 '\usepackage{graphicx}\n',
00060 '\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n',
00061 '\usepackage[linktocpage]{hyperref}\n',
00062 '\hypersetup{backref, colorlinks=true}\n',
00063 '\\title{ \\textbf{\Huge{HLT Timing Summary}} \\footnote{\large{Documentation at \url{https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHLTTimingSummary}}} \\\\ Main Info }\n',
00064 '\\author{\Large{CMS Experiment}}\n',
00065 '\date{\\today}\n',
00066 '\\begin{document}\n',
00067 '\maketitle\n',
00068 '\\newpage\n',
00069 '\clearpage\n'
00070 '\\tableofcontents\n',
00071 '\\newpage\n',
00072 '\\newpage \chapter{Total time for all modules per event} \\newpage \centering \includegraphics[scale=0.6]{totalTimetemp.png}\n']
00073
00074 names1 = {}
00075 names4 = {}
00076 specific = {}
00077 file1 = TFile(infile,'read')
00078 for k in file1.GetListOfKeys():
00079 allnames = k.ReadObj().GetName()
00080 if 'pathTime_' in allnames:
00081 pathname = '_'.join(allnames.split('_')[1:])
00082 if not pathname in names1:
00083 names1[pathname] = k.ReadObj().GetMean()
00084 elif 'incPathTime_' in allnames:
00085 pathname = '_'.join(allnames.split('_')[1:])
00086 if not pathname in names4:
00087 names4[pathname] = k.ReadObj().GetMean()
00088
00089 names2 = dict(sorted(names1.iteritems(), key=operator.itemgetter(1),reverse=True)[:10])
00090 names3 = sorted(names2, key=names2.get, reverse=True)
00091 names5 = dict(sorted(names4.iteritems(), key=operator.itemgetter(1),reverse=True)[:10])
00092 names6 = sorted(names5, key=names5.get, reverse=True)
00093
00094 texfile = open(outfile+'-main.tex', 'w')
00095 texfile.writelines(texpreamble)
00096 if os.path.exists(infile.replace('.root','')+'-summary.txt'):
00097 excludefile = open(infile.replace('.root','')+'-summary.txt', 'r')
00098 texfile.write('\\newpage \section{Summary} \n \\begin{verbatim} \n')
00099 for line in excludefile.readlines():
00100 texfile.write(line+'\n')
00101 excludefile.close()
00102 texfile.write('\end{verbatim}')
00103 texfile.write('\\newpage \\chapter{10 Slowest Paths}\n')
00104 texfile.write('\section{Average module (in path) time}\n')
00105 for path in names3:
00106 texfile.write('\\newpage \subsection{'+ path.replace('_','\_') +'} \centering \includegraphics[scale=0.35]{moduleInPathTimeSummary'+ path.replace('_','') +'temp.png}\n')
00107 get_plot2(infile,'moduleInPathTimeSummary_'+path)
00108 texfile.write('\section{Average module (in path) running time}\n')
00109 for path in names3:
00110 texfile.write('\\newpage \subsection{'+ path.replace('_','\_') +'} \centering \includegraphics[scale=0.35]{moduleInPathScaledTimeSummary'+ path.replace('_','') +'temp.png}\n')
00111 get_plot2(infile,'moduleInPathScaledTimeSummary_'+path)
00112 texfile.write('\section{Per event time for path}\n')
00113 for path in names3:
00114 texfile.write('\\newpage \subsection{'+ path.replace('_','\_') +'} \centering \includegraphics[scale=0.6]{pathTime'+ path.replace('_','') +'temp.png}\n')
00115 get_plot1(infile,'pathTime_'+path)
00116 texfile.write('\section{Per event incremental time for path}\n')
00117 for path in names6:
00118 texfile.write('\\newpage \subsection{'+ path.replace('_','\_') +'} \centering \includegraphics[scale=0.6]{incPathTime'+ path.replace('_','') +'temp.png}\n')
00119 get_plot1(infile,'incPathTime_'+path)
00120 texfile.write('\end{document}')
00121 texfile.close()
00122
00123 texfile.close()
00124
00125 get_plot1(infile,'totalTime')
00126
00127
00128
00129
00130 def pathsinfo(infile,outfile):
00131 '''Create the paths info tex file'''
00132
00133
00134 texpreamble = ['\documentclass[10pt,a5paper,landscape]{book}\n',
00135 '\usepackage{graphicx}\n',
00136 '\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n',
00137 '\usepackage[linktocpage]{hyperref}\n',
00138 '\usepackage[titles]{tocloft}\n'
00139 '\hypersetup{backref, colorlinks=true}\n',
00140 '\setlength{\cftsecnumwidth}{4em}\n'
00141 '\\title{ \\textbf{\Huge{HLT Timing Summary}} \\footnote{\large{Documentation at \url{https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHLTTimingSummary}}} \\\\ Paths Info }\n',
00142 '\\author{\Large{CMS Experiment}}\n',
00143 '\date{\\today}\n',
00144 '\\begin{document}\n',
00145 '\maketitle\n',
00146 '\\newpage\n',
00147 '\\tableofcontents\n',
00148 '\\newpage\n']
00149
00150 names1 = {}
00151 file = TFile(infile,'read')
00152 for k in file.GetListOfKeys():
00153 allnames= k.ReadObj().GetName()
00154 mean = 1
00155 if 'moduleInPathScaledTime_' in allnames:
00156 pathname = '_'.join(allnames.split('_')[1:-1])
00157 if not pathname in names1:
00158 names1[pathname] = mean
00159 names = names1.keys()
00160 names.sort()
00161
00162 texfile = open(outfile+'-paths.tex', 'w')
00163 texfile.writelines(texpreamble)
00164
00165 texfile.write('\\chapter{Average module (in path) time}\n')
00166 for path in names:
00167 texfile.write('\\newpage \section{'+ path.replace('_','\_') +'} \centering \includegraphics[scale=0.35]{moduleInPathTimeSummary'+ path.replace('_','') +'temp.png}\n')
00168 get_plot2(infile,'moduleInPathTimeSummary_'+path)
00169 texfile.write('\\chapter{Average module (in path) running time}\n')
00170 for path in names:
00171 texfile.write('\\newpage \section{'+ path.replace('_','\_') +'} \centering \includegraphics[scale=0.35]{moduleInPathScaledTimeSummary'+ path.replace('_','') +'temp.png}\n')
00172 get_plot2(infile,'moduleInPathScaledTimeSummary_'+path)
00173 texfile.write('\\chapter{Failing module (by path)}')
00174 for path in names:
00175 texfile.write('\\newpage \section{'+ path.replace('_','\_') +'} \centering \includegraphics[scale=0.35]{failedModule'+ path.replace('_','') +'temp.png}\n')
00176 get_plot2(infile,'failedModule_'+path)
00177 texfile.write('\\chapter{Per event time for path}\n')
00178 for path in names:
00179 texfile.write('\\newpage \section{'+ path.replace('_','\_') +'} \centering \includegraphics[scale=0.6]{pathTime'+ path.replace('_','') +'temp.png}\n')
00180 get_plot1(infile,'pathTime_'+path)
00181 texfile.write('\\chapter{Per event incremental time for path}\n')
00182 for path in names:
00183 texfile.write('\\newpage \section{'+ path.replace('_','\_') +'} \centering \includegraphics[scale=0.6]{incPathTime'+ path.replace('_','') +'temp.png}\n')
00184 get_plot1(infile,'incPathTime_'+path)
00185
00186 texfile.write('\end{document}')
00187 texfile.close()
00188
00189
00190
00191 def moduleinfo(infile,outfile):
00192 '''Create the paths info tex file'''
00193
00194
00195 texpreamble = ['\documentclass[10pt,a5paper,landscape]{report}\n',
00196 '\usepackage{graphicx}\n',
00197 '\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n',
00198 '\usepackage[linktocpage]{hyperref}\n',
00199 '\hypersetup{backref, colorlinks=true}\n',
00200 '\usepackage[titles]{tocloft}\n'
00201 '\setlength{\cftsecnumwidth}{4em}\n'
00202 '\\title{ \\textbf{\Huge{HLT Timing Summary}} \\footnote{\large{Documentation at \url{https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHLTTimingSummary}}} \\\\ Modules Info }\n',
00203 '\\author{\Large{CMS Experiment}}\n',
00204 '\date{\\today}\n',
00205 '\\begin{document}\n',
00206 '\maketitle\n',
00207 '\\newpage\n',
00208 '\\tableofcontents\n',
00209 '\\newpage\n']
00210
00211 names1 = {}
00212 file = TFile(infile,'read')
00213 for k in file.GetListOfKeys():
00214 allnames = k.ReadObj().GetName()
00215 mean = 1
00216 if 'moduleTime_' in allnames:
00217 modname = ''.join(allnames.split('_')[1:])
00218 if not (('!' in modname) or ('-' in modname)):
00219 if not modname in names1:
00220 names1[modname] = mean
00221 names = names1.keys()
00222 names.sort()
00223
00224 texfile1 = open(outfile+'-modules.tex', 'w')
00225 texfile1.writelines(texpreamble)
00226
00227 texfile1.write('\\chapter{Time per event for module} \n \\newpage')
00228 for modules in names:
00229 texfile1.write('\section{'+modules+'}')
00230 texfile1.write('\centering \includegraphics[scale=0.4]{moduleTime'+ modules +'temp.png}\n')
00231 get_plot1(infile,'moduleTime_'+modules)
00232 texfile1.write('\end{document}')
00233 texfile1.close()
00234
00235 texfile2 = open(outfile+'-runningModules.tex', 'w')
00236 texfile2.writelines(texpreamble)
00237 texfile2.write('\\chapter{Running Time per event for module} \n \\newpage')
00238 for modules in names:
00239 texfile2.write('\section{'+modules+'}')
00240 texfile2.write('\centering \includegraphics[scale=0.45]{moduleScaledTime'+modules+'temp.png}\n')
00241 get_plot1(infile,'moduleScaledTime_'+ modules)
00242
00243 texfile2.write('\end{document}')
00244 texfile2.close()
00245
00246
00247 def specificpathinfo(infile, outfile, path):
00248 ''' Creates an specific path info tex file'''
00249
00250 texpreamble = ['\documentclass[10pt,a5paper,landscape]{report}\n',
00251 '\usepackage{graphicx}\n',
00252 '\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n',
00253 '\usepackage[linktocpage]{hyperref}\n',
00254 '\usepackage[titles]{tocloft}\n'
00255 '\hypersetup{backref, colorlinks=true}\n',
00256 '\setlength{\cftsubsecnumwidth}{4em}\n'
00257 '\\title{ \\textbf{\Huge{HLT Timing Summary}} \\footnote{\large{Documentation at \url{https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHLTTimingSummary}}} \\\\ Main Info + ' + path.replace('_','\_') +' info }\n',
00258 '\\author{\Large{CMS Experiment}}\n',
00259 '\date{\\today}\n',
00260 '\\begin{document}\n',
00261 '\maketitle\n',
00262 '\\tableofcontents \n'
00263 '\\newpage\n \\chapter{Main Info} \n',
00264 '\\newpage \centering \section{Total time for all modules per event} \includegraphics[scale=0.6]{totalTimetemp.png}\n']
00265
00266 texfile = open(outfile+'-'+path+'.tex', 'w')
00267 texfile.writelines(texpreamble)
00268 get_plot1(infile,'totalTime')
00269
00270 names = {}
00271 file1 = TFile(infile,'read')
00272 for k in file1.GetListOfKeys():
00273 allnames = k.ReadObj().GetName()
00274 if 'moduleInPathScaledTime_' in allnames:
00275 pathname = '_'.join(allnames.split('_')[1:-1])
00276 if not pathname in names:
00277 names[pathname] = {}
00278 for pathnames in names.keys():
00279 histo = file1.Get('moduleInPathTimeSummary_'+pathnames)
00280 for bin in range(histo.GetNbinsX()):
00281 label = histo.GetXaxis().GetBinLabel(bin+1)
00282 names[pathnames][bin+1] = label
00283
00284 for pathname in names:
00285 if path in pathname:
00286 texfile.write('\chapter{' + path.replace('_','\_')+ ' Info} \n')
00287 texfile.write('\\newpage \section{Average module in '+ path.replace('_','\_') +' time} \centering \includegraphics[scale=0.35]{moduleInPathTimeSummary'+ path.replace('_','') +'temp.png}\n')
00288 get_plot2(infile,'moduleInPathTimeSummary_'+path)
00289 texfile.write('\\newpage \section{Average module in '+ path.replace('_','\_') +' running time} \centering \includegraphics[scale=0.35]{moduleInPathScaledTimeSummary'+ path.replace('_','') +'temp.png}\n')
00290 get_plot2(infile,'moduleInPathScaledTimeSummary_'+path)
00291 texfile.write('\\newpage \section{Per event time for '+ path.replace('_','\_') +'} \centering \includegraphics[scale=0.6]{pathTime'+ path.replace('_','') +'temp.png}\n')
00292 get_plot1(infile,'pathTime_'+path)
00293 texfile.write('\\newpage \section{Per event incremental time for '+ path.replace('_','\_') +'} \centering \includegraphics[scale=0.6]{incPathTime'+ path.replace('_','') +'temp.png}\n')
00294 get_plot1(infile,'incPathTime_'+path)
00295 texfile.write('\section{Running time per event for '+path.replace('_','\_')+'}')
00296 for modules in names[path].values():
00297 texfile.write('\subsection{'+ modules +'} \centering \includegraphics[scale=0.6]{moduleInPathScaledTime'+ path.replace('_','') + modules +'temp.png}\n')
00298 get_plot1(infile,'moduleInPathScaledTime_'+ path +'_'+ modules)
00299 texfile.write('\\end{document}')
00300 texfile.close()
00301
00302
00303
00304
00305
00306 def get_plot1(file,allnames):
00307 ''' Function to create the plot and save it as.png file '''
00308
00309 file = TFile(file,'read')
00310 histo = file.Get(allnames)
00311 can = TCanvas('can', '', 800,600)
00312 can.cd()
00313 histo.UseCurrentStyle()
00314 histo.Draw()
00315 can.SetBorderMode(0)
00316 can.SetFillColor(kWhite)
00317 can.SaveAs(allnames.replace('_','')+'temp.png')
00318 del can
00319
00320
00321
00322
00323 def get_plot2(infile,allnames):
00324 ''' Function to create the plot and save it as.png file '''
00325
00326 file1 = TFile(infile,'read')
00327 histo = file1.Get(allnames)
00328 can = TCanvas('can', '', 1600,1000)
00329 can.cd()
00330 histo.UseCurrentStyle()
00331 histo.Draw()
00332 if histo.GetNbinsX() > 50:
00333 histo.GetXaxis().SetLabelSize(0.02)
00334 else:
00335 histo.GetXaxis().SetLabelSize(0.03)
00336 can.SetBorderMode(0)
00337 can.SetBorderSize(0)
00338 can.SetFillColor(kWhite)
00339 can.SetBottomMargin(0.4)
00340 can.SaveAs(allnames.replace('_','')+'temp.png')
00341 del can
00342
00343
00344 def main(argv):
00345
00346 print "\nPython script that creates Timing Summary pdf files"
00347 print "For more info, please contact Alejandro Gomez"
00348 print "email: alejandro.gomez@cern.ch\n"
00349
00350 infile = None
00351 outfile = None
00352 path = None
00353 call_maininfo = False
00354 call_pathsinfo = False
00355 call_modulesinfo = False
00356 call_specificinfo = False
00357 try:
00358 opts, args = getopt.getopt(argv, 'hi:o:tbpms:', ['help', 'input=', 'output='])
00359 if not opts:
00360 print 'No options supplied'
00361 usage()
00362 except getopt.GetoptError,e:
00363 print e
00364 usage()
00365 sys.exit(2)
00366 for opt, arg in opts:
00367 if opt in ('h', '--help'):
00368 usage()
00369 sys.exit(2)
00370 elif opt == '-b':
00371 print 'Running in batch mode'
00372 elif opt in ('-i', '--input'):
00373 infile = arg
00374 outfile = infile.replace('.root','')
00375 elif opt in ('-o', '--output'):
00376 outfile = arg
00377 elif opt == '-t':
00378 call_maininfo = True
00379 elif opt == '-p':
00380 call_pathsinfo = True
00381 elif opt == '-m':
00382 call_modulesinfo = True
00383 elif opt == '-s':
00384 path = arg
00385 call_specificinfo = True
00386 else:
00387 usage()
00388 sys.exit(2)
00389
00390
00391 if call_maininfo:
00392 print 'Creating the Main Info Timing Summary pdf'
00393 print 'Creating plots...'
00394 maininfo(infile,outfile)
00395 print 'Compiling tex file......'
00396 subprocess.call(['pdflatex', '-interaction=batchmode', outfile+'-main.tex'])
00397 print 'Verifing......'
00398 subprocess.call(['pdflatex', '-interaction=batchmode', outfile+'-main.tex'])
00399 print 'Removing temp files.........'
00400 os.remove(outfile+'-main.aux')
00401 os.remove(outfile+'-main.log')
00402 os.remove(outfile+'-main.out')
00403 os.remove(outfile+'-main.tex')
00404 os.remove(outfile+'-main.toc')
00405 for filename in glob.glob('*temp.png'):
00406 os.remove(filename)
00407 print '{0}-main.pdf is done'.format(outfile)
00408
00409 if call_pathsinfo:
00410 print 'Creating the Paths Info Timing Summary pdf'
00411 print 'This process takes awhile... please be patient'
00412 print 'Creating plots...'
00413 pathsinfo(infile,outfile)
00414 print 'Compiling tex file......'
00415 subprocess.call(['pdflatex', '-interaction=batchmode', outfile+'-paths.tex'])
00416 print 'Verifing......'
00417 subprocess.call(['pdflatex', '-interaction=batchmode', outfile+'-paths.tex'])
00418 print 'Removing temp files.........'
00419 os.remove(outfile+'-paths.aux')
00420 os.remove(outfile+'-paths.log')
00421 os.remove(outfile+'-paths.out')
00422 os.remove(outfile+'-paths.tex')
00423 os.remove(outfile+'-paths.toc')
00424 for filename in glob.glob('*temp.png'):
00425 os.remove(filename)
00426 print '{0}-paths.pdf is done'.format(outfile)
00427
00428 if call_modulesinfo:
00429 print 'Creating the Modules Info Timing Summary pdf'
00430 print 'This process takes awhile... please be patient'
00431 print 'Creating plots...'
00432 moduleinfo(infile,outfile)
00433 print 'Compiling tex file......'
00434 subprocess.call(['pdflatex', '-interaction=batchmode', outfile+'-modules.tex'])
00435 subprocess.call(['pdflatex', '-interaction=batchmode', outfile+'-runningModules.tex'])
00436 print 'Verifing......'
00437 subprocess.call(['pdflatex', '-interaction=batchmode', outfile+'-modules.tex'])
00438 subprocess.call(['pdflatex', '-interaction=batchmode', outfile+'-runningModules.tex'])
00439 print 'Removing temp files.........'
00440 os.remove(outfile+'-modules.aux')
00441 os.remove(outfile+'-runningModules.aux')
00442 os.remove(outfile+'-modules.log')
00443 os.remove(outfile+'-runningModules.log')
00444 os.remove(outfile+'-modules.out')
00445 os.remove(outfile+'-runningModules.out')
00446 os.remove(outfile+'-modules.tex')
00447 os.remove(outfile+'-runningModules.tex')
00448 os.remove(outfile+'-modules.toc')
00449 os.remove(outfile+'-runningModules.toc')
00450 for filename in glob.glob('*temp.png'):
00451 os.remove(filename)
00452 print '{0}-modules.pdf is done'.format(outfile)
00453 print '{0}-runningModules.pdf is done'.format(outfile)
00454
00455 if call_specificinfo:
00456 print 'Creating the Main Info + '+ path +' Timing Summary pdf'
00457 print 'This process takes awhile... please be patient'
00458 print 'Creating plots...'
00459 specificpathinfo(infile,outfile,path)
00460 print 'Compiling tex file......'
00461 subprocess.call(['pdflatex', '-interaction=batchmode', outfile+'-'+path+'.tex'])
00462 print 'Verifing......'
00463 subprocess.call(['pdflatex', '-interaction=batchmode', outfile+'-'+path+'.tex'])
00464 print 'Removing temp files.........'
00465 os.remove(outfile+'-'+path+'.aux')
00466 os.remove(outfile+'-'+path+'.log')
00467 os.remove(outfile+'-'+path+'.out')
00468 os.remove(outfile+'-'+path+'.tex')
00469 os.remove(outfile+'-'+path+'.toc')
00470 for filename in glob.glob('*temp.png'):
00471 os.remove(filename)
00472 print '{0}-'.format(outfile)+path+'.pdf is done'
00473
00474
00475
00476 if __name__ =='__main__':
00477
00478 main(sys.argv[1:])