20 from __future__
import print_function
27 from ROOT
import gROOT, gStyle, TFile, TCanvas
31 gROOT.SetStyle(
"Plain")
32 gStyle.SetOptStat(111111)
33 gStyle.SetHistFillColor(kBlue)
38 print(
"\nThis is the usage function\n")
39 print(
'Usage: '+sys.argv[0]+
' -i <file1> [option]')
40 print(
'e.g.: '+sys.argv[0]+
' -i outputTiming.root -t')
41 print(
'e.g.: '+sys.argv[0]+
' -i outputTiming.root -s HLT_Jet300_v5\n')
43 print(
'\n-----Options-----')
44 print(
' -i Input File')
45 print(
' -o Output File (optional)')
46 print(
' -t For only main time info per event. It will take less than 1 min.')
47 print(
' -p For path time info. It will take approx 25 min.')
48 print(
' -m For module time info. It will take approx 25 min.')
49 print(
' -s Path_Name (For an specific path). Ti will take less than 1 min.')
50 print(
'\n For -p or -m option, the process needs like 200 Mb in disk space,')
51 print(
' but please dont be afraid. Before the process ends, all the temporal files')
52 print(
' will be erased.')
57 ''' Creates main info tex file''' 59 texpreamble = [
'\documentclass[10pt,a5paper,landscape]{report}\n',
60 '\\usepackage{graphicx}\n',
61 '\\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n',
62 '\\usepackage[linktocpage]{hyperref}\n',
63 '\hypersetup{backref, colorlinks=true}\n',
64 '\\title{ \\textbf{\Huge{HLT Timing Summary}} \\footnote{\large{Documentation at \\url{https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHLTTimingSummary}}} \\\\ Main Info }\n',
65 '\\author{\Large{CMS Experiment}}\n',
67 '\\begin{document}\n',
71 '\\tableofcontents\n',
73 '\\newpage \chapter{Total time for all modules per event} \\newpage \centering \includegraphics[scale=0.6]{totalTimetemp.png}\n']
78 file1 = TFile(infile,
'read')
79 for k
in file1.GetListOfKeys():
80 allnames = k.ReadObj().GetName()
81 if 'pathTime_' in allnames:
82 pathname =
'_'.
join(allnames.split(
'_')[1:])
83 if not pathname
in names1:
84 names1[pathname] = k.ReadObj().GetMean()
85 elif 'incPathTime_' in allnames:
86 pathname =
'_'.
join(allnames.split(
'_')[1:])
87 if not pathname
in names4:
88 names4[pathname] = k.ReadObj().GetMean()
90 names2 = dict(sorted(names1.items(), key=operator.itemgetter(1),reverse=
True)[:10])
91 names3 = sorted(names2, key=names2.get, reverse=
True)
92 names5 = dict(sorted(names4.items(), key=operator.itemgetter(1),reverse=
True)[:10])
93 names6 = sorted(names5, key=names5.get, reverse=
True)
95 texfile = open(outfile+
'-main.tex',
'w')
96 texfile.writelines(texpreamble)
97 if os.path.exists(infile.replace(
'.root',
'')+
'-summary.txt'):
98 excludefile = open(infile.replace(
'.root',
'')+
'-summary.txt',
'r') 99 texfile.write('\\newpage \section{Summary} \n \\begin{verbatim} \n')
100 for line
in excludefile.readlines():
101 texfile.write(line+
'\n')
103 texfile.write(
'\end{verbatim}')
104 texfile.write(
'\\newpage \\chapter{10 Slowest Paths}\n')
105 texfile.write(
'\section{Average module (in path) time}\n')
107 texfile.write(
'\\newpage \subsection{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.35]{moduleInPathTimeSummary'+ path.replace(
'_',
'') +
'temp.png}\n')
108 get_plot2(infile,
'moduleInPathTimeSummary_'+path)
109 texfile.write(
'\section{Average module (in path) running time}\n')
111 texfile.write(
'\\newpage \subsection{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.35]{moduleInPathScaledTimeSummary'+ path.replace(
'_',
'') +
'temp.png}\n')
112 get_plot2(infile,
'moduleInPathScaledTimeSummary_'+path)
113 texfile.write(
'\section{Per event time for path}\n')
115 texfile.write(
'\\newpage \subsection{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.6]{pathTime'+ path.replace(
'_',
'') +
'temp.png}\n')
117 texfile.write(
'\section{Per event incremental time for path}\n')
119 texfile.write(
'\\newpage \subsection{'+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.6]{incPathTime'+ path.replace(
'_',
'') +
'temp.png}\n')
121 texfile.write(
'\end{document}')
132 '''Create the paths info tex file''' 135 texpreamble = [
'\documentclass[10pt,a5paper,landscape]{book}\n',
136 '\\usepackage{graphicx}\n',
137 '\\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n',
138 '\\usepackage[linktocpage]{hyperref}\n',
139 '\\usepackage[titles]{tocloft}\n' 140 '\hypersetup{backref, colorlinks=true}\n',
141 '\setlength{\cftsecnumwidth}{4em}\n' 142 '\\title{ \\textbf{\Huge{HLT Timing Summary}} \\footnote{\large{Documentation at \\url{https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHLTTimingSummary}}} \\\\ Paths Info }\n',
143 '\\author{\Large{CMS Experiment}}\n',
145 '\\begin{document}\n',
148 '\\tableofcontents\n',
152 file = TFile(infile,
'read')
153 for k
in file.GetListOfKeys():
154 allnames= k.ReadObj().GetName()
156 if 'moduleInPathScaledTime_' in allnames:
157 pathname =
'_'.
join(allnames.split(
'_')[1:-1])
158 if not pathname
in names1:
159 names1[pathname] = mean
160 names = sorted(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 = sorted(names1.keys())
223 texfile1 = open(outfile+
'-modules.tex',
'w')
224 texfile1.writelines(texpreamble)
226 texfile1.write(
'\\chapter{Time per event for module} \n \\newpage')
227 for modules
in names:
228 texfile1.write(
'\section{'+modules+
'}')
229 texfile1.write(
'\centering \includegraphics[scale=0.4]{moduleTime'+ modules +
'temp.png}\n')
231 texfile1.write(
'\end{document}')
234 texfile2 = open(outfile+
'-runningModules.tex',
'w')
235 texfile2.writelines(texpreamble)
236 texfile2.write(
'\\chapter{Running Time per event for module} \n \\newpage')
237 for modules
in names:
238 texfile2.write(
'\section{'+modules+
'}')
239 texfile2.write(
'\centering \includegraphics[scale=0.45]{moduleScaledTime'+modules+
'temp.png}\n')
240 get_plot1(infile,
'moduleScaledTime_'+ modules)
242 texfile2.write(
'\end{document}')
247 ''' Creates an specific path info tex file''' 249 texpreamble = [
'\documentclass[10pt,a5paper,landscape]{report}\n',
250 '\\usepackage{graphicx}\n',
251 '\\usepackage[a5paper,vmargin={5mm,2mm},hmargin={5mm,5mm}]{geometry}\n',
252 '\\usepackage[linktocpage]{hyperref}\n',
253 '\\usepackage[titles]{tocloft}\n' 254 '\hypersetup{backref, colorlinks=true}\n',
255 '\setlength{\cftsubsecnumwidth}{4em}\n' 256 '\\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',
257 '\\author{\Large{CMS Experiment}}\n',
259 '\\begin{document}\n',
261 '\\tableofcontents \n' 262 '\\newpage\n \\chapter{Main Info} \n',
263 '\\newpage \centering \section{Total time for all modules per event} \includegraphics[scale=0.6]{totalTimetemp.png}\n']
265 texfile = open(outfile+
'-'+path+
'.tex',
'w')
266 texfile.writelines(texpreamble)
270 file1 = TFile(infile,
'read')
271 for k
in file1.GetListOfKeys():
272 allnames = k.ReadObj().GetName()
273 if 'moduleInPathScaledTime_' in allnames:
274 pathname =
'_'.
join(allnames.split(
'_')[1:-1])
275 if not pathname
in names:
277 for pathnames
in names.keys():
278 histo = file1.Get(
'moduleInPathTimeSummary_'+pathnames)
279 for bin
in range(histo.GetNbinsX()):
280 label = histo.GetXaxis().GetBinLabel(bin+1)
281 names[pathnames][bin+1] = label
283 for pathname
in names:
285 texfile.write(
'\chapter{' + path.replace(
'_',
'\_')+
' Info} \n')
286 texfile.write(
'\\newpage \section{Average module in '+ path.replace(
'_',
'\_') +
' time} \centering \includegraphics[scale=0.35]{moduleInPathTimeSummary'+ path.replace(
'_',
'') +
'temp.png}\n')
287 get_plot2(infile,
'moduleInPathTimeSummary_'+path)
288 texfile.write(
'\\newpage \section{Average module in '+ path.replace(
'_',
'\_') +
' running time} \centering \includegraphics[scale=0.35]{moduleInPathScaledTimeSummary'+ path.replace(
'_',
'') +
'temp.png}\n')
289 get_plot2(infile,
'moduleInPathScaledTimeSummary_'+path)
290 texfile.write(
'\\newpage \section{Per event time for '+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.6]{pathTime'+ path.replace(
'_',
'') +
'temp.png}\n')
292 texfile.write(
'\\newpage \section{Per event incremental time for '+ path.replace(
'_',
'\_') +
'} \centering \includegraphics[scale=0.6]{incPathTime'+ path.replace(
'_',
'') +
'temp.png}\n')
294 texfile.write(
'\section{Running time per event for '+path.replace(
'_',
'\_')+
'}')
295 for modules
in names[path].
values():
296 texfile.write(
'\subsection{'+ modules +
'} \centering \includegraphics[scale=0.6]{moduleInPathScaledTime'+ path.replace(
'_',
'') + modules +
'temp.png}\n')
297 get_plot1(infile,
'moduleInPathScaledTime_'+ path +
'_'+ modules)
298 texfile.write(
'\\end{document}')
306 ''' Function to create the plot and save it as.png file ''' 308 file = TFile(file,
'read')
309 histo = file.Get(allnames)
310 can = TCanvas(
'can',
'', 800,600)
312 histo.UseCurrentStyle()
315 can.SetFillColor(kWhite)
316 can.SaveAs(allnames.replace(
'_',
'')+
'temp.png')
323 ''' Function to create the plot and save it as.png file ''' 325 file1 = TFile(infile,
'read')
326 histo = file1.Get(allnames)
327 can = TCanvas(
'can',
'', 1600,1000)
329 histo.UseCurrentStyle()
331 if histo.GetNbinsX() > 50:
332 histo.GetXaxis().SetLabelSize(0.02)
334 histo.GetXaxis().SetLabelSize(0.03)
337 can.SetFillColor(kWhite)
338 can.SetBottomMargin(0.4)
339 can.SaveAs(allnames.replace(
'_',
'')+
'temp.png')
345 print(
"\nPython script that creates Timing Summary pdf files")
346 print(
"For more info, please contact Alejandro Gomez")
347 print(
"email: alejandro.gomez@cern.ch\n")
352 call_maininfo =
False 353 call_pathsinfo =
False 354 call_modulesinfo =
False 355 call_specificinfo =
False 357 opts, args = getopt.getopt(argv,
'hi:o:tbpms:', [
'help',
'input=',
'output='])
359 print(
'No options supplied')
361 except getopt.GetoptError
as e:
365 for opt, arg
in opts:
366 if opt
in (
'h',
'--help'):
370 print(
'Running in batch mode')
371 elif opt
in (
'-i',
'--input'):
373 outfile = infile.replace(
'.root',
'')
374 elif opt
in (
'-o',
'--output'):
379 call_pathsinfo =
True 381 call_modulesinfo =
True 384 call_specificinfo =
True 391 print(
'Creating the Main Info Timing Summary pdf')
392 print(
'Creating plots...')
394 print(
'Compiling tex file......')
395 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-main.tex'])
396 print(
'Verifing......')
397 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-main.tex'])
398 print(
'Removing temp files.........')
399 os.remove(outfile+
'-main.aux')
400 os.remove(outfile+
'-main.log')
401 os.remove(outfile+
'-main.out')
402 os.remove(outfile+
'-main.tex')
403 os.remove(outfile+
'-main.toc')
404 for filename
in glob.glob(
'*temp.png'):
409 print(
'Creating the Paths Info Timing Summary pdf')
410 print(
'This process takes awhile... please be patient')
411 print(
'Creating plots...')
413 print(
'Compiling tex file......')
414 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-paths.tex'])
415 print(
'Verifing......')
416 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-paths.tex'])
417 print(
'Removing temp files.........')
418 os.remove(outfile+
'-paths.aux')
419 os.remove(outfile+
'-paths.log')
420 os.remove(outfile+
'-paths.out')
421 os.remove(outfile+
'-paths.tex')
422 os.remove(outfile+
'-paths.toc')
423 for filename
in glob.glob(
'*temp.png'):
428 print(
'Creating the Modules Info Timing Summary pdf')
429 print(
'This process takes awhile... please be patient')
430 print(
'Creating plots...')
432 print(
'Compiling tex file......')
433 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-modules.tex'])
434 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-runningModules.tex'])
435 print(
'Verifing......')
436 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-modules.tex'])
437 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-runningModules.tex'])
438 print(
'Removing temp files.........')
439 os.remove(outfile+
'-modules.aux')
440 os.remove(outfile+
'-runningModules.aux')
441 os.remove(outfile+
'-modules.log')
442 os.remove(outfile+
'-runningModules.log')
443 os.remove(outfile+
'-modules.out')
444 os.remove(outfile+
'-runningModules.out')
445 os.remove(outfile+
'-modules.tex')
446 os.remove(outfile+
'-runningModules.tex')
447 os.remove(outfile+
'-modules.toc')
448 os.remove(outfile+
'-runningModules.toc')
449 for filename
in glob.glob(
'*temp.png'):
452 print(
'{0}-runningModules.pdf is done'.
format(outfile))
454 if call_specificinfo:
455 print(
'Creating the Main Info + '+ path +
' Timing Summary pdf')
456 print(
'This process takes awhile... please be patient')
457 print(
'Creating plots...')
459 print(
'Compiling tex file......')
460 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-'+path+
'.tex'])
461 print(
'Verifing......')
462 subprocess.call([
'pdflatex',
'-interaction=batchmode', outfile+
'-'+path+
'.tex'])
463 print(
'Removing temp files.........')
464 os.remove(outfile+
'-'+path+
'.aux')
465 os.remove(outfile+
'-'+path+
'.log')
466 os.remove(outfile+
'-'+path+
'.out')
467 os.remove(outfile+
'-'+path+
'.tex')
468 os.remove(outfile+
'-'+path+
'.toc')
469 for filename
in glob.glob(
'*temp.png'):
475 if __name__ ==
'__main__':
def pathsinfo(infile, outfile)
def specificpathinfo(infile, outfile, path)
def moduleinfo(infile, outfile)
def get_plot2(infile, allnames)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def get_plot1(file, allnames)
def maininfo(infile, outfile)
static std::string join(char **cmd)