Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
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 Prepare the clones plot.
6 Parses the end of the output file, printed by the destructors of the CPUCruncher.
7 A line with the pattern "Summary: name=" is looked for.
8 The number of Events in flight is parsed as well.
9 """
10 
11 # configure
12 Color = kBlue
13 MarkerStyle = kFullStar
14 MarkerSize = 3.8
15 
16 NEventsInFlight = 0
17 NThreads = -1
18 
19 
20 def parseLog(logfilename):
21  global NEventsInFlight
22  global NThreads
23  ifile = open(logfilename, "r")
24  lines = ifile.readlines()
25  vals = []
26  for line in lines:
27  if "Summary: name=" in line:
28  runtime_nclones = map(
29  float,
30  re.match(
31  ".* avg_runtime= ([0-9]*.[0-9]*|[0-9]*.[0-9]*e-[0-9]*) n_clones= ([0-9]).*",
32  line).groups())
33  vals.append(runtime_nclones)
34  elif "Running with" in line:
35  NEventsInFlight, NThreads = map(
36  int,
37  re.match(
38  ".* Running with ([0-9]*) parallel events.*algorithms, ([0-9]*) threads",
39  line).groups())
40 
41  return vals
42 
43 
44 def createGraph(vals):
45  graph = TGraph(len(vals))
46  counter = 0
47  for runtime, nclones in vals:
48  graph.SetPoint(counter, runtime, nclones)
49  counter += 1
50 
51  graph.SetMarkerStyle(MarkerStyle)
52  graph.SetMarkerSize(MarkerSize)
53  graph.SetMarkerColor(Color)
54  graph.SetTitle(
55  "GaudiHive Speedup (Brunel, 100 evts);Algorithm Runtime [s];Number of Clones"
56  )
57  return graph
58 
59 
60 def getText(x, y, text, scale, angle, colour, font, NDC=False):
61  lat = TLatex(
62  float(x), float(y),
63  "#scale[%s]{#color[%s]{#font[%s]{%s}}}" % (scale, colour, font, text))
64 
65  lat.SetNDC(NDC)
66  if angle != 0.:
67  lat.SetTextAngle(angle)
68  return lat
69 
70 
71 def getCountLatexes(vals, xmax):
72  # print vals
73  def getNclones(runtime_nclones):
74  return runtime_nclones[1]
75 
76  max_nclones = int(max(vals, key=getNclones)[1])
77 
78  latexes = []
79  for i in xrange(1, max_nclones + 1):
80  n_algos = len(
81  filter(lambda runtime_nclones: runtime_nclones[1] == i, vals))
82  latexes.append(getText(xmax * 1.01, i, n_algos, .7, 0, 600, 12))
83 
84  label = getText(.95, .55, "Total", .8, 270, 600, 12, True)
85 
86  latexes.append(label)
87 
88  return latexes
89 
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(
108  .6, .365,
109  "#splitline{#splitline{%s Simultaneous Events}{%s Threads}}{%s Algorithms}"
110  % (NEventsInFlight, NThreads, nalgorithms), .8, 0, 2, 12, True)
111  evtsIf.Draw()
112 
113  a = raw_input("press enter to continue")
114  canvas.Print("PlotClones.png")
115 
116 
117 if __name__ == "__main__":
118  argc = len(sys.argv)
119  if argc != 2:
120  print "Usage: plotClonesPyRoot.py logfilename"
121  sys.exit(1)
122  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.