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