The Gaudi Framework  v29r0 (ff2e7097)
hivetimeline Namespace Reference

Classes

class  Data
 

Functions

def read (f, regex='.*', skipevents=0)
 
def findEvents (data)
 
def setPalette (nevts, nevtcolors)
 
def plot (data, showThreads=True, batch=False, nevtcolors=10, width=1200, height=500)
 
def main ()
 

Variables

string __author__ = "Frank Winklmeier"
 
list algcolors = []
 
list evtcolors = []
 

Detailed Description

Plot timeline from TimelineSvc

Function Documentation

def hivetimeline.findEvents (   data)
Find event start/stop times

Definition at line 37 of file hivetimeline.py.

37 def findEvents(data):
38  """Find event start/stop times"""
39 
40  t = defaultdict(lambda: [sys.maxint, 0, -1]) # start,stop,slot
41  nbslots = 0
42  for d in data:
43  if d.start < t[d.event][0]:
44  t[d.event][0] = d.start
45  t[d.event][2] = d.slot
46  if d.end > t[d.event][1]:
47  t[d.event][1] = d.end
48  if d.slot > nbslots:
49  nbslots = d.slot
50 
51  return t, nbslots
52 
53 
def findEvents(data)
Definition: hivetimeline.py:37
def hivetimeline.main ( )

Definition at line 172 of file hivetimeline.py.

172 def main():
173  parser = argparse.ArgumentParser(description=__doc__)
174 
175  parser.add_argument('timeline', nargs=1,
176  help='timeline file')
177 
178  parser.add_argument('-s', '--select', default='.*',
179  help='Regular expression to filter algorithms')
180 
181  parser.add_argument('-b', '--batch', action='store_true', default=False,
182  help='Do not wait for user input')
183 
184  parser.add_argument('--slots', action='store_true', default=False,
185  help='Show slots instead of threads (leads to overlaps!)')
186 
187  parser.add_argument('-p', '--print', dest='outfile', nargs='?',
188  const='timeline.png',
189  help='Save to FILE [%(const)s]')
190 
191  parser.add_argument('-n', '--nevtcolors', default=10, type=int,
192  help='Number of colors used for events (10 is default)')
193 
194  parser.add_argument('-e', '--skipevents', default=0, type=int,
195  help='Number of events to skip at the start')
196 
197  parser.add_argument('-x', '--width', default=1200, type=int,
198  help='width of the output picture')
199 
200  parser.add_argument('-y', '--height', default=500, type=int,
201  help='height of the output picture')
202 
203  args = parser.parse_args()
204 
205  data = read(args.timeline[0], args.select, args.skipevents)
206  c = plot(data, not args.slots, args.batch,
207  args.nevtcolors, args.width, args.height)
208  if args.outfile:
209  c.SaveAs(args.outfile)
210 
211  return 0
212 
213 
def read(f, regex='.*', skipevents=0)
Definition: hivetimeline.py:22
def plot(data, showThreads=True, batch=False, nevtcolors=10, width=1200, height=500)
Definition: hivetimeline.py:63
def hivetimeline.plot (   data,
  showThreads = True,
  batch = False,
  nevtcolors = 10,
  width = 1200,
  height = 500 
)

Definition at line 63 of file hivetimeline.py.

63 def plot(data, showThreads=True, batch=False, nevtcolors=10, width=1200, height=500):
64  import ROOT
65 
66  tmin = min(f.start for f in data)
67  tmax = max(f.end for f in data)
68  slots = 1 + max(f.slot for f in data)
69  threads = sorted(list(set(f.thread for f in data)))
70  threadid = dict((k, v) for v, k in enumerate(threads)) # map thread : id
71  ymax = len(threads) if showThreads else slots
72 
73  c = ROOT.TCanvas('timeline', 'Timeline', width, height)
74  c.SetLeftMargin(0.05)
75  c.SetRightMargin(0.2)
76  c.SetTopMargin(0.1)
77  c.SetBottomMargin(0.1)
78  c.coord = ROOT.TH2I('coord', ';Time (ns)', 100,
79  0, tmax - tmin, ymax, 0, ymax)
80  c.coord.GetYaxis().SetTitle(('Thread' if showThreads else 'Slot'))
81  c.coord.GetYaxis().SetTitleOffset(0.5)
82  c.coord.GetYaxis().CenterTitle()
83  c.coord.SetStats(False)
84  c.coord.GetYaxis().SetNdivisions(ymax)
85  c.coord.GetXaxis().CenterTitle()
86 
87  c.Draw()
88  c.coord.Draw()
89 
90  c.lines = []
91  colors = {}
92  setPalette(ymax, nevtcolors)
93  mycolors = algcolors
94  for d in data:
95  y = (threadid[d.thread] if showThreads else d.slot)
96  alg = d.algorithm
97  if alg not in colors and len(mycolors) > 0:
98  colors[alg] = mycolors.pop(0)
99  if len(mycolors) == 0:
100  print "Too many algorithm to show"
101 
102  if alg in colors:
103  t0 = d.start - tmin
104  t1 = d.end - tmin
105 
106  # Alg
107  l = ROOT.TBox(t0, y + .1, t1, y + .8)
108  l.SetFillColor(colors[alg])
109 
110  # Event
111  l2 = ROOT.TBox(t0, y + .8, t1, y + .9)
112  l2.SetFillColor(evtcolors[d.event % nevtcolors])
113  c.lines += [l, l2]
114 
115  l2.Draw()
116  l.Draw()
117 
118  # Global event timeline
119  tevt, nbslots = findEvents(data)
120  bheight = 0.1
121  for k, v in tevt.iteritems():
122  y = ymax + bheight * v[2]
123  l = ROOT.TBox(v[0] - tmin, y + 0.2 * bheight, v[1] - tmin, y + bheight)
124  l.SetFillColor(evtcolors[k % nevtcolors])
125  c.lines += [l]
126  l.Draw()
127 
128  # Alg legend
129  c.leg = ROOT.TLegend(0.8, 0.4, 0.98, 0.9)
130  for alg, cl in sorted(colors.iteritems(), key=operator.itemgetter(1)):
131  e = c.leg.AddEntry('', alg, 'F')
132  e.SetLineColor(cl)
133  e.SetFillColor(cl)
134  e.SetFillStyle(1001)
135 
136  # Event legend
137  bwidth = 0.18 / nevtcolors
138  for cl in range(nevtcolors):
139  l = ROOT.TLine()
140  c.lines.append(l)
141  l.SetLineWidth(10)
142  l.SetLineColor(evtcolors[cl])
143  l.DrawLineNDC(0.807 + bwidth * cl, 0.37,
144  0.807 + bwidth * (cl + 1), 0.37)
145 
146  c.t1 = ROOT.TText(0.807, 0.314, 'Events')
147  c.t1.SetNDC()
148  c.t1.SetTextFont(42)
149  c.t1.SetTextSize(0.04)
150  c.t1.Draw()
151 
152  c.t2 = ROOT.TText(0.02, 0.92, 'Event')
153  c.t2.SetNDC()
154  c.t2.SetTextFont(42)
155  c.t2.SetTextSize(0.03)
156  c.t2.SetTextAngle(90)
157  c.t2.Draw()
158  c.t3 = ROOT.TText(0.03, 0.922, 'Slots')
159  c.t3.SetNDC()
160  c.t3.SetTextFont(42)
161  c.t3.SetTextSize(0.03)
162  c.t3.SetTextAngle(90)
163  c.t3.Draw()
164 
165  c.leg.Draw()
166  c.Update()
167  if not batch:
168  raw_input()
169  return c
170 
171 
def plot(data, showThreads=True, batch=False, nevtcolors=10, width=1200, height=500)
Definition: hivetimeline.py:63
decltype(auto) range(Args &&...args)
Zips multiple containers together to form a single range.
def setPalette(nevts, nevtcolors)
Definition: hivetimeline.py:54
def findEvents(data)
Definition: hivetimeline.py:37
def hivetimeline.read (   f,
  regex = '.*',
  skipevents = 0 
)

Definition at line 22 of file hivetimeline.py.

22 def read(f, regex='.*', skipevents=0):
23  data = []
24  regex = re.compile(regex)
25  for l in open(f, 'r'):
26  if l.startswith('#'): # e.g. #start end algorithm thread slot event
27  names = l.lstrip('#').split()
28  continue
29  d = Data()
30  for i, f in enumerate(l.split()):
31  setattr(d, names[i], int(f) if f.isdigit() else f)
32  if d.event >= skipevents:
33  data.append(d)
34  return data
35 
36 
def read(f, regex='.*', skipevents=0)
Definition: hivetimeline.py:22
def hivetimeline.setPalette (   nevts,
  nevtcolors 
)

Definition at line 54 of file hivetimeline.py.

54 def setPalette(nevts, nevtcolors):
55  global algcolors, evtcolors
56 
57  from ROOT import TColor
58  algcolors = range(2, 10) + [20, 28, 29, 30, 33, 38, 40] + range(41, 50)
59  evtcolors = [TColor.GetColor(0, 255 - g, g)
60  for g in range(20, 255, (255 - 20) / nevtcolors)]
61 
62 
decltype(auto) range(Args &&...args)
Zips multiple containers together to form a single range.
def setPalette(nevts, nevtcolors)
Definition: hivetimeline.py:54

Variable Documentation

string hivetimeline.__author__ = "Frank Winklmeier"
private

Definition at line 4 of file hivetimeline.py.

list hivetimeline.algcolors = []

Definition at line 12 of file hivetimeline.py.

list hivetimeline.evtcolors = []

Definition at line 13 of file hivetimeline.py.