All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
plotClonesPyRoot.py
Go to the documentation of this file.
1 from ROOT import *
2 import sys
3 import re
4 
5 """
6 Prepare the clones plot.
7 Parses the end of the output file, printed by the destructors of the CPUCruncher.
8 A line with the pattern "Summary: name=" is looked for.
9 The number of Events in flight is parsed as well.
10 """
11 
12 # configure
13 Color=kBlue
14 MarkerStyle=kFullStar
15 MarkerSize=3.8
16 
17 NEventsInFlight=0
18 NThreads=-1
19 
20 
21 def parseLog(logfilename):
22  global NEventsInFlight
23  global NThreads
24  ifile = open(logfilename,"r")
25  lines = ifile.readlines()
26  vals=[]
27  for line in lines:
28  if "Summary: name=" in line:
29  runtime_nclones = map(float,
30  re.match(".* avg_runtime= ([0-9]*.[0-9]*|[0-9]*.[0-9]*e-[0-9]*) n_clones= ([0-9]).*",line).groups())
31  vals.append(runtime_nclones)
32  elif "Running with" in line:
33  NEventsInFlight,NThreads=map( int, re.match(".* Running with ([0-9]*) parallel events.*algorithms, ([0-9]*) threads",line).groups())
34 
35  return vals
36 
37 def createGraph(vals):
38  graph = TGraph(len(vals))
39  counter=0
40  for runtime,nclones in vals:
41  graph.SetPoint(counter, runtime, nclones)
42  counter+=1
43 
44  graph.SetMarkerStyle(MarkerStyle)
45  graph.SetMarkerSize(MarkerSize)
46  graph.SetMarkerColor(Color)
47  graph.SetTitle("GaudiHive Speedup (Brunel, 100 evts);Algorithm Runtime [s];Number of Clones")
48  return graph
49 
50 def getText(x,y,text,scale,angle,colour,font,NDC=False):
51  lat = TLatex(float(x),float(y),
52  "#scale[%s]{#color[%s]{#font[%s]{%s}}}"%(scale,colour,font,text))
53 
54  lat.SetNDC(NDC)
55  if angle!=0.:
56  lat.SetTextAngle(angle)
57  return lat
58 
59 def getCountLatexes(vals,xmax):
60  #print vals
61  def getNclones(runtime_nclones):
62  return runtime_nclones[1]
63  max_nclones = int(max(vals,key=getNclones)[1])
64 
65 
66  latexes=[]
67  for i in xrange(1,max_nclones+1):
68  n_algos = len( filter(lambda runtime_nclones:runtime_nclones[1]== i ,vals) )
69  latexes.append(getText(xmax*1.01,
70  i,
71  n_algos,
72  .7,
73  0,
74  600,
75  12))
76 
77 
78  label = getText(.95,
79  .55,
80  "Total",
81  .8,
82  270,
83  600,
84  12,
85  True)
86 
87  latexes.append(label)
88 
89  return latexes
90 
91 def doPlot(logfilename):
92  global NEventsInFlight
93  global NThreads
94  vals = parseLog(logfilename)
95  graph = createGraph(vals)
96  nalgorithms = len(vals)
97 
98  canvas = TCanvas("Clones","Clones",1024,768)
99  canvas.cd()
100  canvas.SetGrid()
101  graph.Draw("AP")
102 
103  # Latex
104 
105  countLatexes=getCountLatexes(vals,graph.GetXaxis().GetXmax())
106  map(lambda latex:latex.Draw(),countLatexes)
107  evtsIf = getText(.6,.365,
108  "#splitline{#splitline{%s Simultaneous Events}{%s Threads}}{%s Algorithms}"%(NEventsInFlight,NThreads,nalgorithms),
109  .8,0,2,12,True)
110  evtsIf.Draw()
111 
112 
113  a= raw_input("press enter to continue")
114  canvas.Print("PlotClones.png")
115 
116 
117 
118 if __name__ == "__main__":
119  argc=len(sys.argv)
120  if argc!=2:
121  print "Usage: plotClonesPyRoot.py logfilename"
122  sys.exit(1)
123  doPlot(sys.argv[1])
def getText(x, y, text, scale, angle, colour, font, NDC=False)
def parseLog(logfilename)
def getCountLatexes(vals, xmax)
def doPlot(logfilename)
struct GAUDI_API map
Parametrisation class for map-like implementation.