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