The Gaudi Framework  v36r9p1 (5c15b2bb)
plotClonesPyRoot.py
Go to the documentation of this file.
1 
11 from __future__ import print_function
12 
13 import re
14 import sys
15 
16 from ROOT import *
17 
18 """
19 Prepare the clones plot.
20 Parses the end of the output file, printed by the destructors of the CPUCruncher.
21 A line with the pattern "Summary: name=" is looked for.
22 The number of Events in flight is parsed as well.
23 """
24 
25 # configure
26 Color = kBlue
27 MarkerStyle = kFullStar
28 MarkerSize = 3.8
29 
30 NEventsInFlight = 0
31 NThreads = -1
32 
33 
34 def parseLog(logfilename):
35  global NEventsInFlight
36  global NThreads
37  ifile = open(logfilename, "r")
38  lines = ifile.readlines()
39  vals = []
40  for line in lines:
41  if "Summary: name=" in line:
42  runtime_nclones = map(
43  float,
44  re.match(
45  ".* avg_runtime= ([0-9]*.[0-9]*|[0-9]*.[0-9]*e-[0-9]*) n_clones= ([0-9]).*",
46  line,
47  ).groups(),
48  )
49  vals.append(runtime_nclones)
50  elif "Running with" in line:
51  NEventsInFlight, NThreads = map(
52  int,
53  re.match(
54  ".* Running with ([0-9]*) parallel events.*algorithms, ([0-9]*) threads",
55  line,
56  ).groups(),
57  )
58 
59  return vals
60 
61 
62 def createGraph(vals):
63  graph = TGraph(len(vals))
64  counter = 0
65  for runtime, nclones in vals:
66  graph.SetPoint(counter, runtime, nclones)
67  counter += 1
68 
69  graph.SetMarkerStyle(MarkerStyle)
70  graph.SetMarkerSize(MarkerSize)
71  graph.SetMarkerColor(Color)
72  graph.SetTitle(
73  "GaudiHive Speedup (Brunel, 100 evts);Algorithm Runtime [s];Number of Clones"
74  )
75  return graph
76 
77 
78 def getText(x, y, text, scale, angle, colour, font, NDC=False):
79  lat = TLatex(
80  float(x),
81  float(y),
82  "#scale[%s]{#color[%s]{#font[%s]{%s}}}" % (scale, colour, font, text),
83  )
84 
85  lat.SetNDC(NDC)
86  if angle != 0.0:
87  lat.SetTextAngle(angle)
88  return lat
89 
90 
91 def getCountLatexes(vals, xmax):
92  # print vals
93  def getNclones(runtime_nclones):
94  return runtime_nclones[1]
95 
96  max_nclones = int(max(vals, key=getNclones)[1])
97 
98  latexes = []
99  for i in range(1, max_nclones + 1):
100  n_algos = len(filter(lambda runtime_nclones: runtime_nclones[1] == i, vals))
101  latexes.append(getText(xmax * 1.01, i, n_algos, 0.7, 0, 600, 12))
102 
103  label = getText(0.95, 0.55, "Total", 0.8, 270, 600, 12, True)
104 
105  latexes.append(label)
106 
107  return latexes
108 
109 
110 def doPlot(logfilename):
111  global NEventsInFlight
112  global NThreads
113  vals = parseLog(logfilename)
114  graph = createGraph(vals)
115  nalgorithms = len(vals)
116 
117  canvas = TCanvas("Clones", "Clones", 1024, 768)
118  canvas.cd()
119  canvas.SetGrid()
120  graph.Draw("AP")
121 
122  # Latex
123 
124  countLatexes = getCountLatexes(vals, graph.GetXaxis().GetXmax())
125  map(lambda latex: latex.Draw(), countLatexes)
126  evtsIf = getText(
127  0.6,
128  0.365,
129  "#splitline{#splitline{%s Simultaneous Events}{%s Threads}}{%s Algorithms}"
130  % (NEventsInFlight, NThreads, nalgorithms),
131  0.8,
132  0,
133  2,
134  12,
135  True,
136  )
137  evtsIf.Draw()
138 
139  a = raw_input("press enter to continue")
140  canvas.Print("PlotClones.png")
141 
142 
143 if __name__ == "__main__":
144  argc = len(sys.argv)
145  if argc != 2:
146  print("Usage: plotClonesPyRoot.py logfilename")
147  sys.exit(1)
148  doPlot(sys.argv[1])
plotClonesPyRoot.getText
def getText(x, y, text, scale, angle, colour, font, NDC=False)
Definition: plotClonesPyRoot.py:78
plotClonesPyRoot.createGraph
def createGraph(vals)
Definition: plotClonesPyRoot.py:62
plotClonesPyRoot.parseLog
def parseLog(logfilename)
Definition: plotClonesPyRoot.py:34
max
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:225
Containers::map
struct GAUDI_API map
Parametrisation class for map-like implementation.
Definition: KeyedObjectManager.h:35
plotClonesPyRoot.getCountLatexes
def getCountLatexes(vals, xmax)
Definition: plotClonesPyRoot.py:91
plotClonesPyRoot.doPlot
def doPlot(logfilename)
Definition: plotClonesPyRoot.py:110
Gaudi::Functional::details::zip::range
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
Definition: FunctionalDetails.h:102