76def plot(data, showThreads=True, batch=False, nevtcolors=10, width=1200, height=500):
77 import ROOT
78
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
85
86 c = ROOT.TCanvas("timeline", "Timeline", width, height)
87 c.SetLeftMargin(0.05)
88 c.SetRightMargin(0.2)
89 c.SetTopMargin(0.1)
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()
98
99 c.Draw()
100 c.coord.Draw()
101
102 c.lines = []
103 colors = {}
104 setPalette(ymax, nevtcolors)
105 mycolors = algcolors
106 for d in data:
107 y = threadid[d.thread] if showThreads else d.slot
108 alg = d.algorithm
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")
113
114 if alg in colors:
115 t0 = d.start - tmin
116 t1 = d.end - tmin
117
118
119 l = ROOT.TBox(t0, y + 0.1, t1, y + 0.8)
120 l.SetFillColor(colors[alg])
121
122
123 l2 = ROOT.TBox(t0, y + 0.8, t1, y + 0.9)
124 l2.SetFillColor(evtcolors[d.event % nevtcolors])
125 c.lines += [l, l2]
126
127 l2.Draw()
128 l.Draw()
129
130
131 tevt, nbslots = findEvents(data)
132 bheight = 0.1
133 for k, v in tevt.items():
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])
137 c.lines += [l]
138 l.Draw()
139
140
141 c.leg = ROOT.TLegend(0.8, 0.4, 0.98, 0.9)
142 for alg, cl in sorted(colors.items(), key=operator.itemgetter(1)):
143 e = c.leg.AddEntry("", alg, "F")
144 e.SetLineColor(cl)
145 e.SetFillColor(cl)
146 e.SetFillStyle(1001)
147
148
149 bwidth = 0.18 / nevtcolors
150 for cl in range(nevtcolors):
151 l = ROOT.TLine()
152 c.lines.append(l)
153 l.SetLineWidth(10)
154 l.SetLineColor(evtcolors[cl])
155 l.DrawLineNDC(0.807 + bwidth * cl, 0.37, 0.807 + bwidth * (cl + 1), 0.37)
156
157 c.t1 = ROOT.TText(0.807, 0.314, "Events")
158 c.t1.SetNDC()
159 c.t1.SetTextFont(42)
160 c.t1.SetTextSize(0.04)
161 c.t1.Draw()
162
163 c.t2 = ROOT.TText(0.02, 0.92, "Event")
164 c.t2.SetNDC()
165 c.t2.SetTextFont(42)
166 c.t2.SetTextSize(0.03)
167 c.t2.SetTextAngle(90)
168 c.t2.Draw()
169 c.t3 = ROOT.TText(0.03, 0.922, "Slots")
170 c.t3.SetNDC()
171 c.t3.SetTextFont(42)
172 c.t3.SetTextSize(0.03)
173 c.t3.SetTextAngle(90)
174 c.t3.Draw()
175
176 c.leg.Draw()
177 c.Update()
178 if not batch:
179 eval(input())
180 return c
181
182