2 """Plot timeline from TimelineSvc""" 4 __author__ =
"Frank Winklmeier" 10 from collections
import defaultdict
22 def read(f, regex='.*', skipevents=0):
24 regex = re.compile(regex)
25 for l
in open(f,
'r'): 27 names = l.lstrip(
'#').split()
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:
38 """Find event start/stop times""" 40 t = defaultdict(
lambda: [sys.maxint, 0, -1])
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]:
55 global algcolors, evtcolors
57 from ROOT
import TColor
58 algcolors =
range(2, 10) + [20, 28, 29, 30, 33, 38, 40] +
range(41, 50)
60 TColor.GetColor(0, 255 - g, g)
61 for g
in range(20, 255, (255 - 20) / nevtcolors)
73 tmin =
min(f.start
for f
in data)
74 tmax =
max(f.end
for f
in data)
75 slots = 1 +
max(f.slot
for f
in data)
76 threads = sorted(list(set(f.thread
for f
in data)))
77 threadid = dict((k, v)
for v, k
in enumerate(threads))
78 ymax = len(threads)
if showThreads
else slots
80 c = ROOT.TCanvas(
'timeline',
'Timeline', width, height)
84 c.SetBottomMargin(0.1)
85 c.coord = ROOT.TH2I(
'coord',
';Time (ns)', 100, 0, tmax - tmin, ymax, 0,
87 c.coord.GetYaxis().SetTitle((
'Thread' if showThreads
else 'Slot'))
88 c.coord.GetYaxis().SetTitleOffset(0.5)
89 c.coord.GetYaxis().CenterTitle()
90 c.coord.SetStats(
False)
91 c.coord.GetYaxis().SetNdivisions(ymax)
92 c.coord.GetXaxis().CenterTitle()
102 y = (threadid[d.thread]
if showThreads
else d.slot)
104 if alg
not in colors
and len(mycolors) > 0:
105 colors[alg] = mycolors.pop(0)
106 if len(mycolors) == 0:
107 print "Too many algorithm to show" 114 l = ROOT.TBox(t0, y + .1, t1, y + .8)
115 l.SetFillColor(colors[alg])
118 l2 = ROOT.TBox(t0, y + .8, t1, y + .9)
119 l2.SetFillColor(evtcolors[d.event % nevtcolors])
128 for k, v
in tevt.iteritems():
129 y = ymax + bheight * v[2]
130 l = ROOT.TBox(v[0] - tmin, y + 0.2 * bheight, v[1] - tmin, y + bheight)
131 l.SetFillColor(evtcolors[k % nevtcolors])
136 c.leg = ROOT.TLegend(0.8, 0.4, 0.98, 0.9)
137 for alg, cl
in sorted(colors.iteritems(), key=operator.itemgetter(1)):
138 e = c.leg.AddEntry(
'', alg,
'F')
144 bwidth = 0.18 / nevtcolors
145 for cl
in range(nevtcolors):
149 l.SetLineColor(evtcolors[cl])
150 l.DrawLineNDC(0.807 + bwidth * cl, 0.37, 0.807 + bwidth * (cl + 1),
153 c.t1 = ROOT.TText(0.807, 0.314,
'Events')
156 c.t1.SetTextSize(0.04)
159 c.t2 = ROOT.TText(0.02, 0.92,
'Event')
162 c.t2.SetTextSize(0.03)
163 c.t2.SetTextAngle(90)
165 c.t3 = ROOT.TText(0.03, 0.922,
'Slots')
168 c.t3.SetTextSize(0.03)
169 c.t3.SetTextAngle(90)
180 parser = argparse.ArgumentParser(description=__doc__)
182 parser.add_argument(
'timeline', nargs=1, help=
'timeline file')
188 help=
'Regular expression to filter algorithms')
195 help=
'Do not wait for user input')
201 help=
'Show slots instead of threads (leads to overlaps!)')
208 const=
'timeline.png',
209 help=
'Save to FILE [%(const)s]')
216 help=
'Number of colors used for events (10 is default)')
223 help=
'Number of events to skip at the start')
230 help=
'width of the output picture')
237 help=
'height of the output picture')
239 args = parser.parse_args()
241 data =
read(args.timeline[0], args.select, args.skipevents)
242 c =
plot(data,
not args.slots, args.batch, args.nevtcolors, args.width,
245 c.SaveAs(args.outfile)
250 if __name__ ==
'__main__':
EventIDBase min(const EventIDBase &lhs, const EventIDBase &rhs)
def read(f, regex='.*', skipevents=0)
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
def plot(data, showThreads=True, batch=False, nevtcolors=10, width=1200, height=500)
decltype(auto) range(Args &&...args)
Zips multiple containers together to form a single range.
def setPalette(nevts, nevtcolors)