76 def plot(data, showThreads=True, batch=False, nevtcolors=10, width=1200, height=500):
79 tmin =
min(f.start
for f
in data)
80 tmax =
max(f.end
for f
in data)
81 slots = 1 +
max(f.slot
for f
in data)
82 threads = sorted(list(set(f.thread
for f
in data)))
83 threadid = dict((k, v)
for v, k
in enumerate(threads))
84 ymax = len(threads)
if showThreads
else slots
86 c = ROOT.TCanvas(
"timeline",
"Timeline", width, height)
90 c.SetBottomMargin(0.1)
91 c.coord = ROOT.TH2I(
"coord",
";Time (ns)", 100, 0, tmax - tmin, ymax, 0, ymax)
92 c.coord.GetYaxis().SetTitle((
"Thread" if showThreads
else "Slot"))
93 c.coord.GetYaxis().SetTitleOffset(0.5)
94 c.coord.GetYaxis().CenterTitle()
95 c.coord.SetStats(
False)
96 c.coord.GetYaxis().SetNdivisions(ymax)
97 c.coord.GetXaxis().CenterTitle()
107 y = threadid[d.thread]
if showThreads
else d.slot
109 if alg
not in colors
and len(mycolors) > 0:
110 colors[alg] = mycolors.pop(0)
111 if len(mycolors) == 0:
112 print(
"Too many algorithm to show")
119 l = ROOT.TBox(t0, y + 0.1, t1, y + 0.8)
120 l.SetFillColor(colors[alg])
123 l2 = ROOT.TBox(t0, y + 0.8, t1, y + 0.9)
124 l2.SetFillColor(evtcolors[d.event % nevtcolors])
133 for k, v
in tevt.iteritems():
134 y = ymax + bheight * v[2]
135 l = ROOT.TBox(v[0] - tmin, y + 0.2 * bheight, v[1] - tmin, y + bheight)
136 l.SetFillColor(evtcolors[k % nevtcolors])
141 c.leg = ROOT.TLegend(0.8, 0.4, 0.98, 0.9)
142 for alg, cl
in sorted(colors.iteritems(), key=operator.itemgetter(1)):
143 e = c.leg.AddEntry(
"", alg,
"F")
149 bwidth = 0.18 / nevtcolors
150 for cl
in range(nevtcolors):
154 l.SetLineColor(evtcolors[cl])
155 l.DrawLineNDC(0.807 + bwidth * cl, 0.37, 0.807 + bwidth * (cl + 1), 0.37)
157 c.t1 = ROOT.TText(0.807, 0.314,
"Events")
160 c.t1.SetTextSize(0.04)
163 c.t2 = ROOT.TText(0.02, 0.92,
"Event")
166 c.t2.SetTextSize(0.03)
167 c.t2.SetTextAngle(90)
169 c.t3 = ROOT.TText(0.03, 0.922,
"Slots")
172 c.t3.SetTextSize(0.03)
173 c.t3.SetTextAngle(90)