00001
00002
00003
00004 def get_max(data,index=1):
00005 max_time=-1
00006 for el in data:
00007 sec=el[index]
00008 if max_time<sec:
00009 max_time=sec
00010 return max_time
00011
00012 def get_min(data,index=1):
00013 min_time=1e20
00014 for el in data:
00015 sec=el[index]
00016 if min_time>sec:
00017 min_time=sec
00018 return min_time
00019
00020 def manipulate_log(outdir,logfile_name,secsperbin):
00021
00022 import time
00023 import sys
00024 import ROOT
00025
00026
00027
00028 data=[]
00029
00030
00031 logfile=open(logfile_name,'r')
00032 logfile_lines=logfile.readlines()
00033 logfile.close()
00034
00035
00036 i=0
00037 while i < len(logfile_lines):
00038 line=logfile_lines[i]
00039 if 'TimeEvent>' in line:
00040 line=line[:-1]
00041 line_content_list=line.split(' ')
00042 event_number=int(line_content_list[1])
00043 seconds=float(line_content_list[3])
00044 data.append((event_number,seconds))
00045 i+=1
00046
00047
00048
00049
00050 __argv=sys.argv
00051 sys.argv=sys.argv[:1]
00052 ROOT.gROOT.SetStyle("Plain")
00053 sys.argv=__argv
00054
00055
00056
00057 ROOT.gROOT.SetBatch(1)
00058
00059
00060 rootfilename='%s/graphs.root' %outdir
00061 myfile=ROOT.TFile(rootfilename,'RECREATE')
00062
00063
00064
00065 min_val=get_min(data,1)
00066 max_val=get_max(data,1)
00067 interval=max_val-min_val
00068
00069 min_val=min_val-interval*0.2
00070 max_val=max_val+interval*0.2
00071 interval=max_val-min_val
00072
00073 nbins=int(interval/secsperbin)
00074
00075 print 'Minval=',min_val,' maxval=',max_val, ' interval=',interval
00076
00077 histo=ROOT.TH1F('Seconds per event','Seconds per event',nbins,min_val,max_val)
00078 histo.GetXaxis().SetTitle("s")
00079
00080 npoints=len(data)
00081
00082 graph=ROOT.TGraph(npoints)
00083 graph.SetMarkerStyle(8)
00084 graph.SetMarkerSize(.7)
00085 graph.SetMarkerColor(1)
00086 graph.SetLineWidth(3)
00087 graph.SetLineColor(2)
00088 graph.SetTitle('Seconds per event')
00089 graph.SetName('SecondsPerEvent')
00090 graph.GetXaxis().SetTitle("Event")
00091
00092 last_event=data[-1][0]
00093 print 'last event =',last_event
00094 graph.GetXaxis().SetLimits(0,last_event)
00095
00096 graph.GetYaxis().SetTitleOffset(1.3)
00097 graph.GetYaxis().SetTitle("s")
00098 graph.GetYaxis().SetRangeUser(0,max_val)
00099
00100
00101
00102
00103
00104 evt_counter=0
00105 total=0
00106 for evt_num,secs in data:
00107 graph.SetPoint(evt_counter,evt_num,secs)
00108 histo.Fill(secs)
00109 total+=secs
00110 evt_counter+=1
00111
00112 print 'Total Time=', total
00113
00114
00115 avg=histo.GetMean()
00116 avg_line=ROOT.TLine(1,avg,last_event,avg)
00117 avg_line.SetLineColor(4)
00118 avg_line.SetLineWidth(2)
00119
00120
00121 graph_canvas=ROOT.TCanvas('graph_canvas')
00122 graph_canvas.cd()
00123 graph.Draw("ALP")
00124 avg_line.Draw("Same")
00125
00126 graph_canvas.Print("%s/graph.gif" %outdir,"gif")
00127
00128
00129 graph.Write()
00130 graph_canvas.Write()
00131
00132 histo_canvas=ROOT.TCanvas('histo_canvas')
00133 histo_canvas.cd()
00134 histo.Draw('')
00135
00136 histo_canvas.Print("%s/histo.gif" %outdir,"gif")
00137
00138
00139 histo.Write()
00140 histo_canvas.Write()
00141
00142 myfile.Close()
00143
00144
00145
00146 titlestring='<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
00147 %(os.environ['CMSSW_VERSION'],time.asctime())
00148
00149 html_file_name='%s/%s.html' %(outdir,logfile_name[:-4])
00150 html_file=open(html_file_name,'w')
00151 html_file.write('<html>\n<body>\n'+\
00152 titlestring)
00153 html_file.write('<table>\n'+\
00154 '<tr><td><img src=graph.gif></img></td></tr>'+\
00155 '<tr><td><img src=histo.gif></img></td></tr>'+\
00156 '</table>\n')
00157 html_file.write('\n</body>\n</html>')
00158 html_file.close()
00159
00160
00161
00162
00163 if __name__ == '__main__':
00164
00165 import optparse
00166 import os
00167
00168
00169 usage='timing_parser.py <options>'
00170 parser = optparse.OptionParser(usage)
00171 parser.add_option('-i', '--in_ profile',
00172 help='The profile to manipulate' ,
00173 default='',
00174 dest='profile')
00175
00176 parser.add_option('-o', '--outdir',
00177 help='The directory of the output' ,
00178 default='',
00179 dest='outdir')
00180
00181 parser.add_option('-n',
00182 help='Number of secs per bin. Default is 1.' ,
00183 default='1',
00184 dest='startevt')
00185
00186 (options,args) = parser.parse_args()
00187
00188
00189 if options.profile=='' or\
00190 options.outdir=='':
00191 raise('Please select a profile and an output dir!')
00192
00193 if not os.path.exists(options.profile) or\
00194 not os.path.exists(options.outdir):
00195 raise ('Outdir or input profile not present!')
00196
00197 try:
00198 startevt=float(options.startevt)
00199 except ValueError:
00200 print 'Problems in convertng starting event value!'
00201
00202
00203
00204 manipulate_log(options.outdir,options.profile,startevt)
00205
00206