30 gROOT.SetStyle(
"Plain")
31 gStyle.SetOptStat(111111)
32 gStyle.SetHistFillColor(kBlue)
37 print "\nThis is the usage function\n" 38 print 'Usage: '+sys.argv[0]+
' -i <file1> [option]' 39 print 'e.g.: '+sys.argv[0]+
' -i outputTiming.root -t' 40 print 'e.g.: '+sys.argv[0]+
' -i outputTiming.root -s HLT_Jet300_v5\n' 42 print '\n-----Options-----' 43 print ' -i Input File' 44 print ' -o Output File (optional)' 45 print ' -t For only main time info per event. It will take less than 1 min.' 46 print ' -p For path time info. It will take approx 25 min.' 47 print ' -m For module time info. It will take approx 25 min.' 48 print ' -s Path_Name (For an specific path). Ti will take less than 1 min.' 49 print '\n For -p or -m option, the process needs like 200 Mb in disk space,' 50 print ' but please dont be afraid. Before the process ends, all the temporal files' 51 print ' will be erased.' 56 ''' Creates main info tex file''' 58 texpreamble = [
'\documentclass[10pt,a5paper,landscape]{report}\n',
59 '\usepackage{graphicx}\n',
60 '\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n',
61 '\usepackage[linktocpage]{hyperref}\n',
62 '\hypersetup{backref, colorlinks=true}\n',
63 '\\title{ \\textbf{\Huge{HLT Timing Summary}} \\footnote{\large{Documentation at \url{https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHLTTimingSummary}}} \\\\ Main Info }\n',
64 '\\author{\Large{CMS Experiment}}\n',
66 '\\begin{document}\n',
70 '\\tableofcontents\n',
72 '\\newpage \chapter{Total time for all modules per event} \\newpage \centering \includegraphics[scale=0.6]{totalTimetemp.png}\n']
77 file1 = TFile(infile,
'read')
78 for k
in file1.GetListOfKeys():
79 allnames = k.ReadObj().GetName()
80 if 'pathTime_' in allnames:
81 pathname =
'_'.
join(allnames.split(
'_')[1:])
82 if not pathname
in names1:
83 names1[pathname] = k.ReadObj().GetMean()
84 elif 'incPathTime_' in allnames:
85 pathname =
'_'.
join(allnames.split(
'_')[1:])
86 if not pathname
in names4:
87 names4[pathname] = k.ReadObj().GetMean()
89 names2 =
dict(sorted(names1.iteritems(), key=operator.itemgetter(1),reverse=
True)[:10])
90 names3 = sorted(names2, key=names2.get, reverse=
True)
91 names5 =
dict(sorted(names4.iteritems(), key=operator.itemgetter(1),reverse=
True)[:10])
92 names6 = sorted(names5, key=names5.get, reverse=
True)
94 texfile = open(outfile+
'-main.tex',
'w')
95 texfile.writelines(texpreamble)
96 if os.path.exists(infile.replace(
'.root',
'')+
'-summary.txt'):
97 excludefile = open(infile.replace(
'.root',
'')+
'-summary.txt',
'r') 98 texfile.write('\\newpage \section{Summary} \n \\begin{verbatim} \n')
99 for line
in excludefile.readlines():
100 texfile.write(line+
'\n')
102 texfile.write(
'\end{verbatim}')
103 texfile.write(
'\\newpage \\chapter{10 Slowest Paths}\n')
104 texfile.write(
'\section{Average module (in path) time}\n')
106 texfile.write(
'\\newpage \subsection{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.35]{moduleInPathTimeSummary'+ path.replace(
'_',
'') +
'temp.png}\n')
107 get_plot2(infile,
'moduleInPathTimeSummary_'+path)
108 texfile.write(
'\section{Average module (in path) running time}\n')
110 texfile.write(
'\\newpage \subsection{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.35]{moduleInPathScaledTimeSummary'+ path.replace(
'_',
'') +
'temp.png}\n')
111 get_plot2(infile,
'moduleInPathScaledTimeSummary_'+path)
112 texfile.write(
'\section{Per event time for path}\n')
114 texfile.write(
'\\newpage \subsection{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.6]{pathTime'+ path.replace(
'_',
'') +
'temp.png}\n')
116 texfile.write(
'\section{Per event incremental time for path}\n')
118 texfile.write(
'\\newpage \subsection{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.6]{incPathTime'+ path.replace(
'_',
'') +
'temp.png}\n')
120 texfile.write(
'\end{document}')
131 '''Create the paths info tex file''' 134 texpreamble = [
'\documentclass[10pt,a5paper,landscape]{book}\n',
135 '\usepackage{graphicx}\n',
136 '\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n',
137 '\usepackage[linktocpage]{hyperref}\n',
138 '\usepackage[titles]{tocloft}\n' 139 '\hypersetup{backref, colorlinks=true}\n',
140 '\setlength{\cftsecnumwidth}{4em}\n' 141 '\\title{ \\textbf{\Huge{HLT Timing Summary}} \\footnote{\large{Documentation at \url{https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHLTTimingSummary}}} \\\\ Paths Info }\n',
142 '\\author{\Large{CMS Experiment}}\n',
144 '\\begin{document}\n',
147 '\\tableofcontents\n',
151 file = TFile(infile,
'read')
152 for k
in file.GetListOfKeys():
153 allnames= k.ReadObj().GetName()
155 if 'moduleInPathScaledTime_' in allnames:
156 pathname =
'_'.
join(allnames.split(
'_')[1:-1])
157 if not pathname
in names1:
158 names1[pathname] = mean
159 names = names1.keys()
162 texfile = open(outfile+
'-paths.tex',
'w')
163 texfile.writelines(texpreamble)
165 texfile.write(
'\\chapter{Average module (in path) time}\n')
167 texfile.write(
'\\newpage \section{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.35]{moduleInPathTimeSummary'+ path.replace(
'_',
'') +
'temp.png}\n')
168 get_plot2(infile,
'moduleInPathTimeSummary_'+path)
169 texfile.write(
'\\chapter{Average module (in path) running time}\n')
171 texfile.write(
'\\newpage \section{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.35]{moduleInPathScaledTimeSummary'+ path.replace(
'_',
'') +
'temp.png}\n')
172 get_plot2(infile,
'moduleInPathScaledTimeSummary_'+path)
173 texfile.write(
'\\chapter{Failing module (by path)}')
175 texfile.write(
'\\newpage \section{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.35]{failedModule'+ path.replace(
'_',
'') +
'temp.png}\n')
177 texfile.write(
'\\chapter{Per event time for path}\n')
179 texfile.write(
'\\newpage \section{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.6]{pathTime'+ path.replace(
'_',
'') +
'temp.png}\n')
181 texfile.write(
'\\chapter{Per event incremental time for path}\n')
183 texfile.write(
'\\newpage \section{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.6]{incPathTime'+ path.replace(
'_',
'') +
'temp.png}\n')
186 texfile.write(
'\end{document}')
192 '''Create the paths info tex file''' 195 texpreamble = [
'\documentclass[10pt,a5paper,landscape]{report}\n',
196 '\usepackage{graphicx}\n',
197 '\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n',
198 '\usepackage[linktocpage]{hyperref}\n',
199 '\hypersetup{backref, colorlinks=true}\n',
200 '\usepackage[titles]{tocloft}\n' 201 '\setlength{\cftsecnumwidth}{4em}\n' 202 '\\title{ \\textbf{\Huge{HLT Timing Summary}} \\footnote{\large{Documentation at \url{https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHLTTimingSummary}}} \\\\ Modules Info }\n',
203 '\\author{\Large{CMS Experiment}}\n',
205 '\\begin{document}\n',
208 '\\tableofcontents\n',
212 file = TFile(infile,
'read')
213 for k
in file.GetListOfKeys():
214 allnames = k.ReadObj().GetName()
216 if 'moduleTime_' in allnames:
217 modname =
''.
join(allnames.split(
'_')[1:])
218 if not ((
'!' in modname)
or (
'-' in modname)):
219 if not modname
in names1:
220 names1[modname] = mean
221 names = names1.keys()
224 texfile1 = open(outfile+
'-modules.tex',
'w')
225 texfile1.writelines(texpreamble)
227 texfile1.write(
'\\chapter{Time per event for module} \n \\newpage')
228 for modules
in names:
229 texfile1.write(
'\section{'+modules+
'}')
230 texfile1.write(
'\centering \includegraphics[scale=0.4]{moduleTime'+ modules +
'temp.png}\n')
232 texfile1.write(
'\end{document}')
235 texfile2 = open(outfile+
'-runningModules.tex',
'w')
236 texfile2.writelines(texpreamble)
237 texfile2.write(
'\\chapter{Running Time per event for module} \n \\newpage')
238 for modules
in names:
239 texfile2.write(
'\section{'+modules+
'}')
240 texfile2.write(
'\centering \includegraphics[scale=0.45]{moduleScaledTime'+modules+
'temp.png}\n')
241 get_plot1(infile,
'moduleScaledTime_'+ modules)
243 texfile2.write(
'\end{document}')
248 ''' Creates an specific path info tex file''' 250 texpreamble = [
'\documentclass[10pt,a5paper,landscape]{report}\n',
251 '\usepackage{graphicx}\n',
252 '\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n',
253 '\usepackage[linktocpage]{hyperref}\n',
254 '\usepackage[titles]{tocloft}\n' 255 '\hypersetup{backref, colorlinks=true}\n',
256 '\setlength{\cftsubsecnumwidth}{4em}\n' 257 '\\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',
258 '\\author{\Large{CMS Experiment}}\n',
260 '\\begin{document}\n',
262 '\\tableofcontents \n' 263 '\\newpage\n \\chapter{Main Info} \n',
264 '\\newpage \centering \section{Total time for all modules per event} \includegraphics[scale=0.6]{totalTimetemp.png}\n']
266 texfile = open(outfile+
'-'+path+
'.tex',
'w')
267 texfile.writelines(texpreamble)
271 file1 = TFile(infile,
'read')
272 for k
in file1.GetListOfKeys():
273 allnames = k.ReadObj().GetName()
274 if 'moduleInPathScaledTime_' in allnames:
275 pathname =
'_'.
join(allnames.split(
'_')[1:-1])
276 if not pathname
in names:
278 for pathnames
in names.keys():
279 histo = file1.Get(
'moduleInPathTimeSummary_'+pathnames)
280 for bin
in range(histo.GetNbinsX()):
281 label = histo.GetXaxis().GetBinLabel(bin+1)
282 names[pathnames][bin+1] = label
284 for pathname
in names:
286 texfile.write(
'\chapter{' + path.replace(
'_',
'\_')+
' Info} \n')
287 texfile.write(
'\\newpage \section{Average module in '+ path.replace(
'_',
'\_') +
' time} \centering \includegraphics[scale=0.35]{moduleInPathTimeSummary'+ path.replace(
'_',
'') +
'temp.png}\n')
288 get_plot2(infile,
'moduleInPathTimeSummary_'+path)
289 texfile.write(
'\\newpage \section{Average module in '+ path.replace(
'_',
'\_') +
' running time} \centering \includegraphics[scale=0.35]{moduleInPathScaledTimeSummary'+ path.replace(
'_',
'') +
'temp.png}\n')
290 get_plot2(infile,
'moduleInPathScaledTimeSummary_'+path)
291 texfile.write(
'\\newpage \section{Per event time for '+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.6]{pathTime'+ path.replace(
'_',
'') +
'temp.png}\n')
293 texfile.write(
'\\newpage \section{Per event incremental time for '+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.6]{incPathTime'+ path.replace(
'_',
'') +
'temp.png}\n')
295 texfile.write(
'\section{Running time per event for '+path.replace(
'_',
'\_')+
'}')
296 for modules
in names[path].
values():
297 texfile.write(
'\subsection{'+ modules +
'} \centering \includegraphics[scale=0.6]{moduleInPathScaledTime'+ path.replace(
'_',
'') + modules +
'temp.png}\n')
298 get_plot1(infile,
'moduleInPathScaledTime_'+ path +
'_'+ modules)
299 texfile.write(
'\\end{document}')
307 ''' Function to create the plot and save it as.png file ''' 309 file = TFile(file,
'read')
310 histo = file.Get(allnames)
311 can = TCanvas(
'can',
'', 800,600)
313 histo.UseCurrentStyle()
316 can.SetFillColor(kWhite)
317 can.SaveAs(allnames.replace(
'_',
'')+
'temp.png')
324 ''' Function to create the plot and save it as.png file ''' 326 file1 = TFile(infile,
'read')
327 histo = file1.Get(allnames)
328 can = TCanvas(
'can',
'', 1600,1000)
330 histo.UseCurrentStyle()
332 if histo.GetNbinsX() > 50:
333 histo.GetXaxis().SetLabelSize(0.02)
335 histo.GetXaxis().SetLabelSize(0.03)
338 can.SetFillColor(kWhite)
339 can.SetBottomMargin(0.4)
340 can.SaveAs(allnames.replace(
'_',
'')+
'temp.png')
346 print "\nPython script that creates Timing Summary pdf files" 347 print "For more info, please contact Alejandro Gomez" 348 print "email: alejandro.gomez@cern.ch\n" 353 call_maininfo =
False 354 call_pathsinfo =
False 355 call_modulesinfo =
False 356 call_specificinfo =
False 358 opts, args = getopt.getopt(argv,
'hi:o:tbpms:', [
'help',
'input=',
'output='])
360 print 'No options supplied' 362 except getopt.GetoptError
as e:
366 for opt, arg
in opts:
367 if opt
in (
'h',
'--help'):
371 print 'Running in batch mode' 372 elif opt
in (
'-i',
'--input'):
374 outfile = infile.replace(
'.root',
'')
375 elif opt
in (
'-o',
'--output'):
380 call_pathsinfo =
True 382 call_modulesinfo =
True 385 call_specificinfo =
True 392 print 'Creating the Main Info Timing Summary pdf' 393 print 'Creating plots...' 395 print 'Compiling tex file......' 396 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-main.tex'])
397 print 'Verifing......' 398 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-main.tex'])
399 print 'Removing temp files.........' 400 os.remove(outfile+
'-main.aux')
401 os.remove(outfile+
'-main.log')
402 os.remove(outfile+
'-main.out')
403 os.remove(outfile+
'-main.tex')
404 os.remove(outfile+
'-main.toc')
405 for filename
in glob.glob(
'*temp.png'):
407 print '{0}-main.pdf is done'.
format(outfile)
410 print 'Creating the Paths Info Timing Summary pdf' 411 print 'This process takes awhile... please be patient' 412 print 'Creating plots...' 414 print 'Compiling tex file......' 415 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-paths.tex'])
416 print 'Verifing......' 417 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-paths.tex'])
418 print 'Removing temp files.........' 419 os.remove(outfile+
'-paths.aux')
420 os.remove(outfile+
'-paths.log')
421 os.remove(outfile+
'-paths.out')
422 os.remove(outfile+
'-paths.tex')
423 os.remove(outfile+
'-paths.toc')
424 for filename
in glob.glob(
'*temp.png'):
426 print '{0}-paths.pdf is done'.
format(outfile)
429 print 'Creating the Modules Info Timing Summary pdf' 430 print 'This process takes awhile... please be patient' 431 print 'Creating plots...' 433 print 'Compiling tex file......' 434 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-modules.tex'])
435 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-runningModules.tex'])
436 print 'Verifing......' 437 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-modules.tex'])
438 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-runningModules.tex'])
439 print 'Removing temp files.........' 440 os.remove(outfile+
'-modules.aux')
441 os.remove(outfile+
'-runningModules.aux')
442 os.remove(outfile+
'-modules.log')
443 os.remove(outfile+
'-runningModules.log')
444 os.remove(outfile+
'-modules.out')
445 os.remove(outfile+
'-runningModules.out')
446 os.remove(outfile+
'-modules.tex')
447 os.remove(outfile+
'-runningModules.tex')
448 os.remove(outfile+
'-modules.toc')
449 os.remove(outfile+
'-runningModules.toc')
450 for filename
in glob.glob(
'*temp.png'):
452 print '{0}-modules.pdf is done'.
format(outfile)
453 print '{0}-runningModules.pdf is done'.
format(outfile)
455 if call_specificinfo:
456 print 'Creating the Main Info + '+ path +
' Timing Summary pdf' 457 print 'This process takes awhile... please be patient' 458 print 'Creating plots...' 460 print 'Compiling tex file......' 461 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-'+path+
'.tex'])
462 print 'Verifing......' 463 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-'+path+
'.tex'])
464 print 'Removing temp files.........' 465 os.remove(outfile+
'-'+path+
'.aux')
466 os.remove(outfile+
'-'+path+
'.log')
467 os.remove(outfile+
'-'+path+
'.out')
468 os.remove(outfile+
'-'+path+
'.tex')
469 os.remove(outfile+
'-'+path+
'.toc')
470 for filename
in glob.glob(
'*temp.png'):
472 print '{0}-'.
format(outfile)+path+
'.pdf is done' 476 if __name__ ==
'__main__':
def pathsinfo(infile, outfile)
def specificpathinfo(infile, outfile, path)
def moduleinfo(infile, outfile)
def get_plot2(infile, allnames)
def get_plot1(file, allnames)
def maininfo(infile, outfile)
static std::string join(char **cmd)