The Gaudi Framework  v32r2 (46d42edc)
plotClonesPyRoot.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from ROOT import *
3 import sys
4 import re
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(
30  float,
31  re.match(
32  ".* avg_runtime= ([0-9]*.[0-9]*|[0-9]*.[0-9]*e-[0-9]*) n_clones= ([0-9]).*",
33  line).groups())
34  vals.append(runtime_nclones)
35  elif "Running with" in line:
36  NEventsInFlight, NThreads = map(
37  int,
38  re.match(
39  ".* Running with ([0-9]*) parallel events.*algorithms, ([0-9]*) threads",
40  line).groups())
41 
42  return vals
43 
44 
45 def createGraph(vals):
46  graph = TGraph(len(vals))
47  counter = 0
48  for runtime, nclones in vals:
49  graph.SetPoint(counter, runtime, nclones)
50  counter += 1
51 
52  graph.SetMarkerStyle(MarkerStyle)
53  graph.SetMarkerSize(MarkerSize)
54  graph.SetMarkerColor(Color)
55  graph.SetTitle(
56  "GaudiHive Speedup (Brunel, 100 evts);Algorithm Runtime [s];Number of Clones"
57  )
58  return graph
59 
60 
61 def getText(x, y, text, scale, angle, colour, font, NDC=False):
62  lat = TLatex(
63  float(x), float(y),
64  "#scale[%s]{#color[%s]{#font[%s]{%s}}}" % (scale, colour, font, text))
65 
66  lat.SetNDC(NDC)
67  if angle != 0.:
68  lat.SetTextAngle(angle)
69  return lat
70 
71 
72 def getCountLatexes(vals, xmax):
73  # print vals
74  def getNclones(runtime_nclones):
75  return runtime_nclones[1]
76 
77  max_nclones = int(max(vals, key=getNclones)[1])
78 
79  latexes = []
80  for i in range(1, max_nclones + 1):
81  n_algos = len(
82  filter(lambda runtime_nclones: runtime_nclones[1] == i, vals))
83  latexes.append(getText(xmax * 1.01, i, n_algos, .7, 0, 600, 12))
84 
85  label = getText(.95, .55, "Total", .8, 270, 600, 12, True)
86 
87  latexes.append(label)
88 
89  return latexes
90 
91 
92 def doPlot(logfilename):
93  global NEventsInFlight
94  global NThreads
95  vals = parseLog(logfilename)
96  graph = createGraph(vals)
97  nalgorithms = len(vals)
98 
99  canvas = TCanvas("Clones", "Clones", 1024, 768)
100  canvas.cd()
101  canvas.SetGrid()
102  graph.Draw("AP")
103 
104  # Latex
105 
106  countLatexes = getCountLatexes(vals, graph.GetXaxis().GetXmax())
107  map(lambda latex: latex.Draw(), countLatexes)
108  evtsIf = getText(
109  .6, .365,
110  "#splitline{#splitline{%s Simultaneous Events}{%s Threads}}{%s Algorithms}"
111  % (NEventsInFlight, NThreads, nalgorithms), .8, 0, 2, 12, True)
112  evtsIf.Draw()
113 
114  a = raw_input("press enter to continue")
115  canvas.Print("PlotClones.png")
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)
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:215
def getCountLatexes(vals, xmax)
def doPlot(logfilename)
struct GAUDI_API map
Parametrisation class for map-like implementation.
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.