CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions | Variables
cmsTiming_parser Namespace Reference

Functions

def manipulate_log
 

Variables

string default = ''
 
string dest = 'profile'
 
string help = 'The profile to manipulate'
 
tuple parser = optparse.OptionParser(usage)
 
tuple startevt = float(options.startevt)
 
string usage = 'timing_parser.py <options>'
 

Function Documentation

def cmsTiming_parser.manipulate_log (   outdir,
  logfile_name,
  secsperbin 
)
Parses logfile_name and create an html report
    with information and plots, at the outdir path.
    Graphs' production is also done here.

Definition at line 12 of file cmsTiming_parser.py.

References SiStripPI.max, min(), GetRecoTauVFromDQM_MC_cff.next, print(), sistrip::SpyUtilities.range(), and mathSSE.sqrt().

12 
13 def manipulate_log(outdir, logfile_name, secsperbin):
14  """ Parses logfile_name and create an html report
15  with information and plots, at the outdir path.
16  Graphs' production is also done here.
17  """
18  ################################
19  #### Parse of the log file. ####
20  ################################
21  logfile = open(logfile_name,'r')
22  logfile_lines = iter(logfile.readlines())
23  logfile.close()
24  data = {}
25  report = ''
26  for line in logfile_lines:
27  # Retrieve cpu time of every event.
28  if 'TimeEvent>' in line:
29  line = line[:-1] #no \n!
30  content = line.split(' ')
31  event = int(content[1])
32  seconds = float(content[3])
33  data[event] = seconds
34  # Fill the time report.
35  elif 'TimeReport' in line:
36  if '[sec]' in line:
37  report += line.replace('TimeReport', '\n')
38  elif 'headings' in line:
39  continue
40  elif 'complete' in line:
41  report += line.replace('TimeReport', '\n')
42  for count in range(12):
43  line = next(logfile_lines)
44  report += line
45  break
46  else:
47  report += line.replace('TimeReport', '')
48 
49  ##############################
50  #### Graph and Histogram ####
51  ##############################
52  __argv = sys.argv # trick for a strange behaviour of the TApp..
53  sys.argv = sys.argv[:1]
54  ROOT.gROOT.SetStyle("Plain") # style paranoia
55  sys.argv = __argv
56  #Cannot use this option when the logfile includes
57  #a large number of events... PyRoot seg-faults.
58  #Set ROOT in batch mode to avoid canvases popping up!
59  ROOT.gROOT.SetBatch(1)
60 
61  # Save in file
62  rootfilename = '%s/graphs.root' %outdir
63  myfile = ROOT.TFile(rootfilename,'RECREATE')
64 
65  # Set limits
66  min_val = data[min(data, key=data.get)]
67  max_val = data[max(data, key=data.get)]
68  interval = max_val-min_val
69  min_val = min_val - (interval*0.2)
70  max_val = max_val + (interval*0.2)
71  interval = max_val - min_val
72  nbins = int(interval/secsperbin)
73 
74  # Initialize Histogram
75  histo = ROOT.TH1F('Seconds per event','Seconds per event', nbins, min_val, max_val)
76  histo.GetXaxis().SetTitle("s")
77  # Initialize Graph
78  npoints = len(data)
79  graph = ROOT.TGraph(npoints)
80  graph.SetMarkerStyle(8)
81  graph.SetMarkerSize(.7)
82  graph.SetMarkerColor(1)
83  graph.SetLineWidth(3)
84  graph.SetLineColor(2)
85  graph.SetTitle('Seconds per event')
86  graph.SetName('SecondsPerEvent')
87  graph.GetXaxis().SetTitle("Event")
88  last_event = max(data)
89  graph.GetXaxis().SetLimits(0, last_event)
90  graph.GetYaxis().SetTitleOffset(1.3)
91  graph.GetYaxis().SetTitle("s")
92  graph.GetYaxis().SetRangeUser(0, max_val)
93  # Fill them
94  total_time = 0
95  for event_num in data.keys():
96  seconds = data[event_num]
97  graph.SetPoint(event_num-1, event_num, seconds)
98  histo.Fill(seconds)
99  total_time += seconds
100  # A line which represents the average is drawn in the TGraph
101  avg = histo.GetMean()
102  avg_line = ROOT.TLine(1,avg,last_event, avg)
103  avg_line.SetLineColor(4)
104  avg_line.SetLineWidth(2)
105  # Draw and save!
106  graph_canvas = ROOT.TCanvas('graph_canvas')
107  graph_canvas.cd()
108  graph.Draw("ALP")
109  avg_line.Draw("Same")
110 
111 
112  # Write graph to file
113  graph_canvas.Print("%s/graph.png" %outdir,"png")
114  graph.Write()
115  graph_canvas.Write()
116  histo_canvas = ROOT.TCanvas('histo_canvas')
117  histo_canvas.cd()
118  histo.Draw('')
119 
120  # Write histogram to file
121  histo_canvas.Print("%s/histo.png" %outdir,"png")
122  histo.Write()
123  histo_canvas.Write()
124 
125  myfile.Close()
126 
127  ########################
128  #### The html page! ####
129  ########################
130  titlestring = '<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
131  %(os.environ['CMSSW_VERSION'], time.asctime())
132  html_file_name = '%s/%s_TimingReport.html' %(outdir, logfile_name[:-4])
133  html_file = open(html_file_name,'w')
134  html_file.write('<html>\n<body>\n'+\
135  titlestring)
136  html_file.write('<table>\n'+\
137  '<tr>\n<td><img src=graph.png></img></td>\n'+\
138  '<td><img src=histo.png></img></td>\n</tr>\n'+\
139  '</table>\n')
140  html_file.write('<hr>\n<h2>Time Report</h2>\n<pre>\n' + report + '</pre>\n')
141  html_file.write('</body>\n</html>')
142  html_file.close()
143 
144  ##########################
145  #### Print statistics ####
146  ##########################
147  total_events = max(data)
148  average_time = total_time / total_events
149  sum = 0.
150  for i in range(1, max(data)+1):
151  sum += (data[i]-average_time)**2
152  denominator = total_events**2 - total_events
153  uncertainty = sqrt(sum/denominator)
154  # Comment out next 2 line to round uncertainty to the most significant digit
155  #rounded_uncertainty=round(uncertainty, -int(floor(log10(uncertainty))))
156  #print 'Rounded uncertainty=' , rounded_uncertainty
157  print('------ Statistics ------')
158  print('last event = {}'.format(last_event))
159  print('Minval = {} maxval = {} interval = {}'.format(min_val, max_val, interval))
160  print('Total Time = {}'.format(total_time))
161  print('Average Time = {}'.format(average_time))
162  print('Uncertainty of Average Time = {} +/- {}'.format(average_time, uncertainty))
const uint16_t range(const Frame &aFrame)
T sqrt(T t)
Definition: SSEVec.h:19
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
T min(T a, T b)
Definition: MathUtil.h:58

Variable Documentation

string cmsTiming_parser.default = ''

Definition at line 172 of file cmsTiming_parser.py.

string cmsTiming_parser.dest = 'profile'

Definition at line 173 of file cmsTiming_parser.py.

string cmsTiming_parser.help = 'The profile to manipulate'

Definition at line 171 of file cmsTiming_parser.py.

tuple cmsTiming_parser.parser = optparse.OptionParser(usage)

Definition at line 169 of file cmsTiming_parser.py.

tuple cmsTiming_parser.startevt = float(options.startevt)

Definition at line 196 of file cmsTiming_parser.py.

string cmsTiming_parser.usage = 'timing_parser.py <options>'

Definition at line 168 of file cmsTiming_parser.py.