20 from __future__
import print_function
32 gROOT.SetStyle(
"Plain")
33 gStyle.SetOptStat(111111)
34 gStyle.SetHistFillColor(kBlue)
39 print(
"\nThis is the usage function\n")
40 print(
'Usage: '+sys.argv[0]+
' -i <file1> [option]')
41 print(
'e.g.: '+sys.argv[0]+
' -i outputTiming.root -t')
42 print(
'e.g.: '+sys.argv[0]+
' -i outputTiming.root -s HLT_Jet300_v5\n')
44 print(
'\n-----Options-----')
45 print(
' -i Input File')
46 print(
' -o Output File (optional)')
47 print(
' -t For only main time info per event. It will take less than 1 min.')
48 print(
' -p For path time info. It will take approx 25 min.')
49 print(
' -m For module time info. It will take approx 25 min.')
50 print(
' -s Path_Name (For an specific path). Ti will take less than 1 min.')
51 print(
'\n For -p or -m option, the process needs like 200 Mb in disk space,')
52 print(
' but please dont be afraid. Before the process ends, all the temporal files')
53 print(
' will be erased.')
58 ''' Creates main info tex file'''
60 texpreamble = [
'\documentclass[10pt,a5paper,landscape]{report}\n',
61 '\\usepackage{graphicx}\n',
62 '\\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n',
63 '\\usepackage[linktocpage]{hyperref}\n',
64 '\hypersetup{backref, colorlinks=true}\n',
65 '\\title{ \\textbf{\Huge{HLT Timing Summary}} \\footnote{\large{Documentation at \\url{https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHLTTimingSummary}}} \\\\ Main Info }\n',
66 '\\author{\Large{CMS Experiment}}\n',
68 '\\begin{document}\n',
72 '\\tableofcontents\n',
74 '\\newpage \chapter{Total time for all modules per event} \\newpage \centering \includegraphics[scale=0.6]{totalTimetemp.png}\n']
79 file1 = TFile(infile,
'read')
80 for k
in file1.GetListOfKeys():
81 allnames = k.ReadObj().GetName()
82 if 'pathTime_' in allnames:
83 pathname =
'_'.
join(allnames.split(
'_')[1:])
84 if not pathname
in names1:
85 names1[pathname] = k.ReadObj().GetMean()
86 elif 'incPathTime_' in allnames:
87 pathname =
'_'.
join(allnames.split(
'_')[1:])
88 if not pathname
in names4:
89 names4[pathname] = k.ReadObj().GetMean()
91 names2 = dict(sorted(six.iteritems(names1), key=operator.itemgetter(1),reverse=
True)[:10])
92 names3 = sorted(names2, key=names2.get, reverse=
True)
93 names5 = dict(sorted(six.iteritems(names4), key=operator.itemgetter(1),reverse=
True)[:10])
94 names6 = sorted(names5, key=names5.get, reverse=
True)
96 texfile = open(outfile+
'-main.tex',
'w')
97 texfile.writelines(texpreamble)
98 if os.path.exists(infile.replace(
'.root',
'')+
'-summary.txt'):
99 excludefile = open(infile.replace(
'.root',
'')+
'-summary.txt',
'r')
100 texfile.write(
'\\newpage \section{Summary} \n \\begin{verbatim} \n')
101 for line
in excludefile.readlines():
102 texfile.write(line+
'\n')
104 texfile.write(
'\end{verbatim}')
105 texfile.write(
'\\newpage \\chapter{10 Slowest Paths}\n')
106 texfile.write(
'\section{Average module (in path) time}\n')
108 texfile.write(
'\\newpage \subsection{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.35]{moduleInPathTimeSummary'+ path.replace(
'_',
'') +
'temp.png}\n')
109 get_plot2(infile,
'moduleInPathTimeSummary_'+path)
110 texfile.write(
'\section{Average module (in path) running time}\n')
112 texfile.write(
'\\newpage \subsection{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.35]{moduleInPathScaledTimeSummary'+ path.replace(
'_',
'') +
'temp.png}\n')
113 get_plot2(infile,
'moduleInPathScaledTimeSummary_'+path)
114 texfile.write(
'\section{Per event time for path}\n')
116 texfile.write(
'\\newpage \subsection{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.6]{pathTime'+ path.replace(
'_',
'') +
'temp.png}\n')
118 texfile.write(
'\section{Per event incremental time for path}\n')
120 texfile.write(
'\\newpage \subsection{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.6]{incPathTime'+ path.replace(
'_',
'') +
'temp.png}\n')
122 texfile.write(
'\end{document}')
133 '''Create the paths info tex file'''
136 texpreamble = [
'\documentclass[10pt,a5paper,landscape]{book}\n',
137 '\\usepackage{graphicx}\n',
138 '\\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n',
139 '\\usepackage[linktocpage]{hyperref}\n',
140 '\\usepackage[titles]{tocloft}\n'
141 '\hypersetup{backref, colorlinks=true}\n',
142 '\setlength{\cftsecnumwidth}{4em}\n'
143 '\\title{ \\textbf{\Huge{HLT Timing Summary}} \\footnote{\large{Documentation at \\url{https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHLTTimingSummary}}} \\\\ Paths Info }\n',
144 '\\author{\Large{CMS Experiment}}\n',
146 '\\begin{document}\n',
149 '\\tableofcontents\n',
153 file = TFile(infile,
'read')
154 for k
in file.GetListOfKeys():
155 allnames= k.ReadObj().GetName()
157 if 'moduleInPathScaledTime_' in allnames:
158 pathname =
'_'.
join(allnames.split(
'_')[1:-1])
159 if not pathname
in names1:
160 names1[pathname] = mean
161 names = sorted(names1.keys())
163 texfile = open(outfile+
'-paths.tex',
'w')
164 texfile.writelines(texpreamble)
166 texfile.write(
'\\chapter{Average module (in path) time}\n')
168 texfile.write(
'\\newpage \section{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.35]{moduleInPathTimeSummary'+ path.replace(
'_',
'') +
'temp.png}\n')
169 get_plot2(infile,
'moduleInPathTimeSummary_'+path)
170 texfile.write(
'\\chapter{Average module (in path) running time}\n')
172 texfile.write(
'\\newpage \section{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.35]{moduleInPathScaledTimeSummary'+ path.replace(
'_',
'') +
'temp.png}\n')
173 get_plot2(infile,
'moduleInPathScaledTimeSummary_'+path)
174 texfile.write(
'\\chapter{Failing module (by path)}')
176 texfile.write(
'\\newpage \section{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.35]{failedModule'+ path.replace(
'_',
'') +
'temp.png}\n')
178 texfile.write(
'\\chapter{Per event time for path}\n')
180 texfile.write(
'\\newpage \section{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.6]{pathTime'+ path.replace(
'_',
'') +
'temp.png}\n')
182 texfile.write(
'\\chapter{Per event incremental time for path}\n')
184 texfile.write(
'\\newpage \section{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.6]{incPathTime'+ path.replace(
'_',
'') +
'temp.png}\n')
187 texfile.write(
'\end{document}')
193 '''Create the paths info tex file'''
196 texpreamble = [
'\documentclass[10pt,a5paper,landscape]{report}\n',
197 '\\usepackage{graphicx}\n',
198 '\\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n',
199 '\\usepackage[linktocpage]{hyperref}\n',
200 '\hypersetup{backref, colorlinks=true}\n',
201 '\\usepackage[titles]{tocloft}\n'
202 '\setlength{\cftsecnumwidth}{4em}\n'
203 '\\title{ \\textbf{\Huge{HLT Timing Summary}} \\footnote{\large{Documentation at \\url{https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHLTTimingSummary}}} \\\\ Modules Info }\n',
204 '\\author{\Large{CMS Experiment}}\n',
206 '\\begin{document}\n',
209 '\\tableofcontents\n',
213 file = TFile(infile,
'read')
214 for k
in file.GetListOfKeys():
215 allnames = k.ReadObj().GetName()
217 if 'moduleTime_' in allnames:
218 modname =
''.
join(allnames.split(
'_')[1:])
219 if not ((
'!' in modname)
or (
'-' in modname)):
220 if not modname
in names1:
221 names1[modname] = mean
222 names = sorted(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'):
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'):
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'):
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'):
476 if __name__ ==
'__main__':