14 from CoolRunQuery.utils.AtlRunQueryUtils
import prettyNumber, durationInSeconds, filesize, importroot
15 from CoolRunQuery.utils.AtlRunQueryLookup
import DQChannelDict, DQSuperGroupsDict, DQGroupDict, DQChannels
16 from CoolRunQuery.output.AtlRunQueryRoot
import SetStyle, MakeHtml
17 from CoolRunQuery.selector.AtlRunQuerySelectorBase
import DataKey
19 from ROOT
import TCanvas, gPad, gStyle, TGraph, TColor, TGaxis, gROOT, TH1F, TLegend, TText, Double
22 c_White = TColor.GetColor(
"#ffffff" )
23 c_NovelBlue = TColor.GetColor(
"#2244a5" )
24 c_DarkOrange = TColor.GetColor(
"#ff6600" )
25 c_NovelRed = TColor.GetColor(
"#dd0033" )
26 c_DarkGreen = TColor.GetColor(
"#116600" )
27 c_Violet = TColor.GetColor(
"#aa11aa" )
28 c_LightBlue = TColor.GetColor(
"#66aaff" )
29 c_VDarkYellow = TColor.GetColor(
"#ffa500" )
30 c_Gray = TColor.GetColor(
"#888888" )
31 c_VLightGray = TColor.GetColor(
"#eeeeee" )
32 c_VDarkGray = TColor.GetColor(
"#333333" )
40 s =
'<table class="resulttable" width="%i" style="margin-left: 14px">\n' % tablewidth
44 s +=
' <th style="text-align:left">%s</th> ' % cornerstr
46 s +=
' <th class="emptycorner">−</th>'
47 for ic
in range(0,ncol):
48 s +=
'<th>%s</th>' % colstr[ic]
50 for ir
in range(0,nrow):
55 if 'debug_' in rowkeys[ir][1]:
56 s +=
'<tr class="outRed%s">\n' % color
58 s +=
'<tr class="out%s">\n' % color
59 s +=
' <th class="rowsum" style="text-align:left">%s </th> ' % rowkeys[ir][1]
60 for ic
in range(ncol):
61 if ic
in rowkeys[ir][4]:
63 s +=
'<td style="text-align:center">−</td'
65 s +=
'<td style="text-align:right">'
66 if isinstance(table[ir][ic],str):
67 s +=
"%s" % table[ir][ic]
68 elif rowkeys[ir][3] ==
'pretty-int':
71 s += (rowkeys[ir][3] % table[ir][ic])
72 s +=
'%s</td>' % rowkeys[ir][2]
89 dw_call =
'<script type="text/javascript">\n'
90 dw_call +=
"""if(dw_Tooltip.content_vars==undefined) {dw_Tooltip.content_vars = {}; };\n"""
91 for ir
in range(0,nrow):
92 for ic
in range(0,ncol):
93 if dic[colchans[ic]][rowstr[ir]][0] > 0:
94 var =
'var_%i_%i' % (ir,ic+labeloffset)
95 dw_call +=
'dw_Tooltip.content_vars["%s"] = {' % var
96 dw_call +=
"content: '<strong><b>Corresponding run(s) [# = %i]:</b></strong><br> " % dic[colchans[ic]][rowstr[ir]][0]
98 for r
in dic[colchans[ic]][rowstr[ir]][1]:
103 if dw_call[-1-3:] ==
'<br>':
104 dw_call = dw_call[0:-1-3]
106 dw_call = dw_call[0:-1-1]
107 dw_call +=
""" ' };\n"""
108 dw_call +=
'</script>\n\n'
110 s =
'<table class="resulttable" width="auto" style="margin-left: 14px">\n'
114 s +=
' <th class="rowsum" style="text-align:left" rowspan="2">%s</th> ' % cornerstr
116 s +=
' <th class="emptycorner" rowspan="2">−</th>'
117 s +=
'<th class="colsumL" colspan="%i">%s</th></tr><tr>' % (ncol, title)
118 for ic
in range(0,ncol):
119 s +=
'<th class="colsum">%s</th>' % colstr[ic]
121 for ir
in range(0,nrow):
126 s +=
'<tr class="out%s">\n' % color
127 s +=
' <th class="rowsum" style="text-align:left">%s</th> ' % rowstrNames[ir]
128 for ic
in range(0,ncol):
133 s +=
'<td class="td%s" style="text-align:center">' % dqk_tdtype
134 if dic[colchans[ic]][rowstr[ir]][0] > 0:
135 s +=
'<div class="showTip var_%i_%i" style="display:inline;cursor:pointer">' % (ir,ic+labeloffset)
136 if dic[colchans[ic]][dqk][0]>0:
137 s +=
'%i' % (dic[colchans[ic]][dqk][0])
138 if dic[colchans[ic]][rowstr[ir]][0] > 0:
159 mean =
float(tot)/len(vlist)
160 return [tot,mean,mn,mx,len(vlist)]
163 if 'Duration' == tpe:
165 elif 'STR:physics_*' == tpe:
168 print (
'Big troubles... in function "AtlRunQuerySummary::DecodeStr": invalid length for "%s"' % tpe)
173 return float(s[1])/s[0]/1.0e6
176 return int(s[0].value)
179 drawNumber=False, unit='M', text=TText() ):
180 hist = graph.GetHistogram()
181 hist.SetLineColor( col )
182 graph.SetLineColor( col )
183 hist.SetLineWidth( width )
184 graph.SetLineWidth( width )
185 hist.SetLineStyle( style )
186 graph.SetLineStyle( style )
188 legend.AddEntry( hist, title,
"L" )
199 graph.GetPoint( 0, minunit_, minnev_ )
200 graph.GetPoint( N-1, maxunit_, maxnev_ )
201 dist = maxunit_ - minunit_
202 graph.GetPoint( N-1,x,y )
204 text.SetTextAlign( 12 )
205 text.SetTextSize( 0.030 )
206 text.SetTextColor( c_NovelBlue )
211 text.DrawText( x+0.015*dist, y,
'%s %s' % (yt, unit) )
215 c_VLightGray = TColor.GetColor(
"#eeeeee" )
216 c_VDarkGray = TColor.GetColor(
"#333333" )
218 frame.SetLabelOffset( 0.012,
"X" )
219 frame.SetLabelOffset( 0.012,
"Y" )
220 frame.GetXaxis().SetTitleOffset( 1.25 )
221 frame.GetYaxis().SetTitleOffset( 0.94 )
222 frame.GetXaxis().SetTitleSize( 0.045*scale )
223 frame.GetYaxis().SetTitleSize( 0.045*scale )
224 labelSize = 0.04*scale
225 frame.GetXaxis().SetLabelSize( labelSize )
226 frame.GetYaxis().SetLabelSize( labelSize )
228 gPad.SetBottomMargin( 0.120*scale )
229 gStyle.SetTitleFillColor( c_VLightGray )
230 gStyle.SetTitleTextColor( c_VDarkGray )
231 gStyle.SetTitleBorderSize( 1 )
232 gStyle.SetTitleH( 0.06 )
233 gStyle.SetTitleX( gPad.GetLeftMargin() )
234 gStyle.SetTitleY( 1 - gPad.GetTopMargin() + gStyle.GetTitleH() )
235 gStyle.SetTitleW( 1 - gPad.GetLeftMargin() - gPad.GetRightMargin() )
239 title =
"ATLAS integrated numnber of events in run range %i - %i" % (runmin, runmax)
240 c = TCanvas(
"c", title, 0, 0, 800, 550 )
241 c.GetPad(0).SetRightMargin(0.08)
242 c.GetPad(0).SetLeftMargin(0.10)
243 c.GetPad(0).SetTopMargin(0.07)
244 htitle =
"Events recorded by ATLAS between %s and %s" % (time.strftime(
'%b %d',tminS),
245 time.strftime(
'%b %d, %Y',tmaxS))
247 frame =
TH1F(
"frame", htitle.strip(), 10000, runmin, runmax )
250 TGaxis.SetMaxDigits(6)
251 frame.GetYaxis().SetTitleOffset( 1.0 )
252 frame.SetMinimum( 0 )
253 frame.SetMaximum( maxnev*1.1 )
254 frame.SetYTitle(
"Number of events (in %s)" % unit )
255 frame.SetXTitle(
"Run number" )
261 legend = TLegend( c.GetLeftMargin() + dx, 1 - c.GetTopMargin() + dy,
262 c.GetLeftMargin() + 0.48 + dx, 1 - c.GetTopMargin() - 0.38 + dy)
263 legend.SetFillStyle( 1001 )
264 legend.SetFillColor( c_VLightGray )
265 legend.SetBorderSize(1)
266 legend.SetMargin( 0.2 )
267 legend.SetTextColor( c_VDarkGray )
270 return c, frame, legend
280 colours = [ c_NovelRed, 4, c_DarkOrange, c_DarkGreen, c_Violet, c_LightBlue, 3, c_VDarkYellow, c_Gray,
281 1, 2, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 ]
284 run_and_time =
sorted(rootstreamdic[DataKey(
'Start and endtime')])
285 runs = [x[0]
for x
in run_and_time]
289 tmin =
min([x[1][0]
for x
in run_and_time])
290 tmax =
max([x[1][1]
for x
in run_and_time])
293 tminS = time.gmtime(tmin)
294 tmaxS = time.gmtime(tmax)
302 maxnev = {
'all_':-1,
'debug_':-1,
'calibration_':-1 }
303 for key, content
in rootstreamdic.iteritems():
304 if type(key)==DataKey:
306 if 'Start and endtime' not in key:
307 graphs.append( TGraph( len(content) ) )
308 graphs[-1].SetName( key.strip().
replace(
' ',
'_') )
309 graphs[-1].SetTitle( key.strip() )
311 for i
in range(len(content)):
316 cumulsum += content[j][1]/scale
317 graphs[-1].SetPoint( i, content[j][0], cumulsum )
318 for stype
in maxnev.keys():
320 if cumulsum > maxnev[stype]:
321 maxnev[stype] = cumulsum
322 if 'debug_' not in key
and cumulsum > maxnev[
'all_']:
323 maxnev[
'all_'] = cumulsum
324 sortdic[len(graphs)-1] = cumulsum
327 sortedlist =
sorted(sortdic, key=sortdic.__getitem__, reverse=
True)
334 if 'physics_' in name
or 'express_' in name:
337 g.GetPoint( g.GetN()-1, x, y )
339 legend.SetX2( legend.GetX2() - 0.2 )
340 legend.SetY1( legend.GetY2() - 0.05 )
341 DrawGraph( g, colours[ic], 2, 1, legend, name.replace(
'physics_',
'').
replace(
'express_',
'').
replace(
'express',
'Express'),
True,
'M', TText() )
345 frame.Draw(
"sameaxis")
349 fname =
'%s/atlrunquery_%s.png' % (datapath, name)
354 htmlstr.append(
MakeHtml( [
'Events in streams %s versus run' % name], [fname],
True, 60, 5 ) )
357 c, frame, legend =
CreateCanvasAndFrame( runmin, runmax, tminS, tmaxS, maxnev[
'all_'],
'',
'million' )
362 if '#Events (streamed)' in name:
363 DrawGraph( g, c_NovelBlue, 2, 2, legend,
"Total number of streamed events" )
364 elif '#Events' == name:
365 DrawGraph( g, c_NovelBlue, 5, 1, legend,
"Total number of triggered events (excl. calib)",
True,
'M', TText() )
366 elif 'physics_' in name
or 'express_' in name:
367 DrawGraph( g, colours[ic], 2, 1, legend, name.replace(
'physics_',
'').
replace(
'express_',
'').
replace(
'express',
'Express') )
371 frame.Draw(
"sameaxis")
375 fname =
'%s/atlrunquery_physicsstreams.png' % datapath
380 htmlstr.append(
MakeHtml( [
'Events in physics streams versus run'], [fname],
True, 60, 5 ) )
384 plottypes = {
'debug_' : [
'Debug',
'thousand',
'k' ],
385 'calibration_' : [
'Calibration',
'million',
'M' ] }
388 for key, cprop
in plottypes.iteritems():
390 c, frame, legend =
CreateCanvasAndFrame( runmin, runmax, tminS, tmaxS, maxnev[key], cprop[0], cprop[1] )
391 legend.SetY1( legend.GetY1() + 0.15 )
392 legend.SetX2( legend.GetX2() - 0.15 )
398 DrawGraph( g, colours[ic], 2, 1, legend, name, ic == 0, cprop[2], TText() )
402 frame.Draw(
"sameaxis")
406 fname =
'%s/atlrunquery_%sstreams.png' % (datapath, cprop[0].lower())
411 htmlstr.append(
MakeHtml( [
'Events in %s streams versus run' % cprop[0].lower()], [fname],
True, 60, 5 ) )
414 retstr =
'<table width="900" style="margin-left: 14px; background-color: #f0f0f0; border: 2px white solid; border-collapse: collapse;"><tr>'
415 for i,s
in enumerate(htmlstr):
416 retstr +=
'<td style="padding: 4px">%s</td>' % s
418 retstr +=
'</tr><tr>'
419 retstr +=
'</tr></table>'
425 runs = dic[DataKey(
'Run')]
427 times = dic[DataKey(
'Start and endtime')]
432 s =
'<table style="color: #777777; font-size: 85%; margin-left: 14px" cellpadding="0" cellspacing="3">\n'
434 s +=
'<tr><td><i>Number of runs selected:</i></td><td> %g</td><td></td></tr>\n' % (len(runs))
435 s +=
'<tr><td><i>First run selected:</i></td><td> %s</td><td> (%s)</td></tr>\n' % (runs[-1], time.strftime(
"%a %b %d, %Y, %X",time.gmtime(starttime)))
436 s +=
'<tr><td><i>Last run selected:</i></td><td> %s</td><td> (%s)</td></tr>\n' % (runs[0], time.strftime(
"%a %b %d, %Y, %X",time.gmtime(endtime)))
442 s +=
'<table style="margin-left: 14px">\n'
443 s +=
'<tr><td><b>Run / Event Summary</b></td></tr>\n'
448 keys = [ [
'Duration',
'Run duration',
' h',
'%.2f', [] ],
449 [
'#Events',
'#Events (excl.)',
'',
'pretty-int', [] ],
450 [
'#Events (streamed)',
'#Events (incl.)',
'',
'pretty-int', [] ],
451 [
'STR:physics_*',
'Event size <font size="-2">(RAW)</font>',
' MB',
'%.2f', [0] ]
455 for dk, c
in dic.iteritems():
457 if (
'*' in k[0]
and k[0].
replace(
'*',
'')
in dk.ResultKey)
or (
'*' not in k[0]
and k[0] == dk.ResultKey):
476 s +=
'<table style="margin-left: 14px">\n'
477 s +=
'<tr><td><b>Streams / Events Summary</b> <font size=-2> [ Straight averages given, not weighted by number of events in run ]</font></td></tr>\n'
486 for dk, c
in dic.iteritems():
488 if '#Events' in dk.ResultKey:
489 rootstreamdic[dk] = []
490 for run,dataentries
in zip(runs,c):
493 data = dataentries[0].value
495 rootstreamdic[dk].
append([run,
int(data)])
498 rootstreamdic[dk].
append([run, data])
500 if 'Start and endtime' in dk.ResultKey:
501 rootstreamdic[dk] = []
502 for run,data
in zip(runs,c):
504 rootstreamdic[dk].
append([
int(run), map(float,data.split(
','))])
507 if 'STR:' in dk.ResultKey:
509 sname = dk.ResultKey.replace(
'STR:',
'')
510 streamdic[sname] = []
511 streamsizedic[sname] = 0
512 streamfracdic[sname] = []
513 streamratedic[sname] = []
514 rootstreamdic[sname] = []
516 for run,t,dataentries
in zip(runs,times,c):
518 data = dataentries[0].value
519 if not isinstance(data, str):
520 streamdic[sname].
append(data[0])
521 streamfracdic[sname].
append(data[0])
522 tmin_ =
float(t.partition(
',')[0])
523 tmax_ =
float(t.partition(
',')[2])
524 deltat = tmax_ - tmin_
526 streamratedic[sname].
append(data[0]/deltat)
528 streamratedic[sname].
append(-1)
529 streamsizedic[sname] += data[1]
531 rootstreamdic[sname].
append([run, data[0]])
535 streamfracdic[sname].
append(
'na')
538 streamtypes = [
'physics',
'express',
'debug',
'calibration']
540 for stype
in streamtypes:
542 for key, c
in streamdic.iteritems():
545 sortedstreams +=
sorted(keys, key=keys.__getitem__, reverse=
True)
550 for stream
in sortedstreams:
552 table.append( stats[0:4] )
555 if 'calibration_' not in stream:
557 for i, evrun
in enumerate(streamfracdic[stream]):
560 for stream2
in sortedstreams:
561 if 'calibration_' not in stream2:
562 if streamfracdic[stream2][i] !=
'na':
563 evsum += streamfracdic[stream2][i]
565 v.append(
float(evrun)/evsum*100 )
569 table[-1] += [
'&minus']
572 table[-1] += [
'%.3g' %
ComputeStats( streamratedic[stream] )[1]]
575 table[-1] += [stats[4]]
579 table[-1] += [
filesize(streamsizedic[stream]),
582 table[-1] += [
filesize(streamsizedic[stream]),
'&minus']
585 if 'debug' in stream:
586 prettystr =
'<font color="#C11B17">' + stream +
'</font>'
588 keys.append( [stream, prettystr,
'',
'pretty-int', []] )
591 [
'Total',
'Average',
'Min',
'Max',
592 'Average<br>fraction (%)',
593 'Average<br>rate (Hz)',
594 '#Runs<br><font size="-2">(out of %i)</font>' % nruns,
595 'Total file<br>size <font size="-2">(RAW)</font>',
596 'Average event<br>size <font size="-2">(RAW)</font>'], keys, table, 900 )
609 s +=
'<table style="margin-left: 14px">\n'
610 s +=
'<tr><td><b>Data Quality Summary - SHIFTOFL (number of runs)</b> <font size=-2> [ No number signifies zero. Move mouse over number to see corresponding runs. ]</font></td></tr>\n'
613 dqflags = [
'G',
'Y',
'R',
'B',
'U',
'n.a.']
614 dqflagsNames = [
'Green',
'Yellow',
'Red',
'Black',
'Unknown',
'Not assigned ']
623 for chan, dqgroup
in DQGroupDict.items():
625 for dqflag
in dqflags:
626 ndq[chan][dqflag] = 0
628 for chan, dqchan
in dqitems:
630 grchan =
int(chan/10)*10
633 for dqflag
in dic[dqchan]:
634 ndq[grchan][dqflag] += 1
638 for chan, dqgroup
in DQChannelDict.items():
639 colstr.append( dqgroup )
640 colchans.append( chan )
646 for chan, dqchan
in dqitems:
647 dqchan =
"SHIFTOFL_%s" % (dqchan)
648 colstr.append( dqchan )
649 colchans.append( chan )
652 for dqflag
in dqflags:
653 ndq[chan][dqflag] = [0, []]
656 for i, dqflag
in enumerate(dic[dqchan]):
657 ndq[chan][dqflag][0] += 1
658 ndq[chan][dqflag][1].
append(runs[i])
666 for i
in range(len(colchans)):
672 colstr_.append(colstr[i])
673 colchans_.append(colchans[i])
677 for dqgroup, content
in DQSuperGroupsDict.iteritems():
681 for dqchan
in content[1]:
682 colstr_.append(dqchan)
683 colchans_.append(DQChannelDict[dqchan])
684 s +=
MakeDQSummaryTableHtml(
'', title, colstr_, colchans_, dqflags, dqflagsNames, ndq, nruns, labeloffset )