13 from __future__
import print_function
15 from CoolRunQuery.utils.AtlRunQueryUtils
import prettyNumber, durationInSeconds, filesize, importroot
16 from CoolRunQuery.utils.AtlRunQueryLookup
import DQChannelDict, DQSuperGroupsDict, DQGroupDict, DQChannels
17 from CoolRunQuery.output.AtlRunQueryRoot
import SetStyle, MakeHtml
18 from CoolRunQuery.selector.AtlRunQuerySelectorBase
import DataKey
20 from ROOT
import TCanvas, gPad, gStyle, TGraph, TColor, TGaxis, gROOT, TH1F, TLegend, TText, Double
23 c_White = TColor.GetColor(
"#ffffff" )
24 c_NovelBlue = TColor.GetColor(
"#2244a5" )
25 c_DarkOrange = TColor.GetColor(
"#ff6600" )
26 c_NovelRed = TColor.GetColor(
"#dd0033" )
27 c_DarkGreen = TColor.GetColor(
"#116600" )
28 c_Violet = TColor.GetColor(
"#aa11aa" )
29 c_LightBlue = TColor.GetColor(
"#66aaff" )
30 c_VDarkYellow = TColor.GetColor(
"#ffa500" )
31 c_Gray = TColor.GetColor(
"#888888" )
32 c_VLightGray = TColor.GetColor(
"#eeeeee" )
33 c_VDarkGray = TColor.GetColor(
"#333333" )
41 s =
'<table class="resulttable" width="%i" style="margin-left: 14px">\n' % tablewidth
45 s +=
' <th style="text-align:left">%s</th> ' % cornerstr
47 s +=
' <th class="emptycorner">−</th>'
48 for ic
in range(0,ncol):
49 s +=
'<th>%s</th>' % colstr[ic]
51 for ir
in range(0,nrow):
56 if 'debug_' in rowkeys[ir][1]:
57 s +=
'<tr class="outRed%s">\n' % color
59 s +=
'<tr class="out%s">\n' % color
60 s +=
' <th class="rowsum" style="text-align:left">%s </th> ' % rowkeys[ir][1]
61 for ic
in range(ncol):
62 if ic
in rowkeys[ir][4]:
64 s +=
'<td style="text-align:center">−</td'
66 s +=
'<td style="text-align:right">'
67 if isinstance(table[ir][ic],str):
68 s +=
"%s" % table[ir][ic]
69 elif rowkeys[ir][3] ==
'pretty-int':
72 s += (rowkeys[ir][3] % table[ir][ic])
73 s +=
'%s</td>' % rowkeys[ir][2]
90 dw_call =
'<script type="text/javascript">\n'
91 dw_call +=
"""if(dw_Tooltip.content_vars==undefined) {dw_Tooltip.content_vars = {}; };\n"""
92 for ir
in range(0,nrow):
93 for ic
in range(0,ncol):
94 if dic[colchans[ic]][rowstr[ir]][0] > 0:
95 var =
'var_%i_%i' % (ir,ic+labeloffset)
96 dw_call +=
'dw_Tooltip.content_vars["%s"] = {' % var
97 dw_call +=
"content: '<strong><b>Corresponding run(s) [# = %i]:</b></strong><br> " % dic[colchans[ic]][rowstr[ir]][0]
99 for r
in dic[colchans[ic]][rowstr[ir]][1]:
100 dw_call +=
'%s, ' % r
104 if dw_call[-1-3:] ==
'<br>':
105 dw_call = dw_call[0:-1-3]
107 dw_call = dw_call[0:-1-1]
108 dw_call +=
""" ' };\n"""
109 dw_call +=
'</script>\n\n'
111 s =
'<table class="resulttable" width="auto" style="margin-left: 14px">\n'
115 s +=
' <th class="rowsum" style="text-align:left" rowspan="2">%s</th> ' % cornerstr
117 s +=
' <th class="emptycorner" rowspan="2">−</th>'
118 s +=
'<th class="colsumL" colspan="%i">%s</th></tr><tr>' % (ncol, title)
119 for ic
in range(0,ncol):
120 s +=
'<th class="colsum">%s</th>' % colstr[ic]
122 for ir
in range(0,nrow):
127 s +=
'<tr class="out%s">\n' % color
128 s +=
' <th class="rowsum" style="text-align:left">%s</th> ' % rowstrNames[ir]
129 for ic
in range(0,ncol):
134 s +=
'<td class="td%s" style="text-align:center">' % dqk_tdtype
135 if dic[colchans[ic]][rowstr[ir]][0] > 0:
136 s +=
'<div class="showTip var_%i_%i" style="display:inline;cursor:pointer">' % (ir,ic+labeloffset)
137 if dic[colchans[ic]][dqk][0]>0:
138 s +=
'%i' % (dic[colchans[ic]][dqk][0])
139 if dic[colchans[ic]][rowstr[ir]][0] > 0:
160 mean =
float(tot)/len(vlist)
161 return [tot,mean,mn,mx,len(vlist)]
164 if 'Duration' == tpe:
166 elif 'STR:physics_*' == tpe:
169 print (
'Big troubles... in function "AtlRunQuerySummary::DecodeStr": invalid length for "%s"' % tpe)
174 return float(s[1])/s[0]/1.0e6
177 return int(s[0].value)
180 drawNumber=False, unit='M', text=TText() ):
181 hist = graph.GetHistogram()
182 hist.SetLineColor( col )
183 graph.SetLineColor( col )
184 hist.SetLineWidth( width )
185 graph.SetLineWidth( width )
186 hist.SetLineStyle( style )
187 graph.SetLineStyle( style )
189 legend.AddEntry( hist, title,
"L" )
200 graph.GetPoint( 0, minunit_, minnev_ )
201 graph.GetPoint( N-1, maxunit_, maxnev_ )
202 dist = maxunit_ - minunit_
203 graph.GetPoint( N-1,x,y )
205 text.SetTextAlign( 12 )
206 text.SetTextSize( 0.030 )
207 text.SetTextColor( c_NovelBlue )
212 text.DrawText( x+0.015*dist, y,
'%s %s' % (yt, unit) )
216 c_VLightGray = TColor.GetColor(
"#eeeeee" )
217 c_VDarkGray = TColor.GetColor(
"#333333" )
219 frame.SetLabelOffset( 0.012,
"X" )
220 frame.SetLabelOffset( 0.012,
"Y" )
221 frame.GetXaxis().SetTitleOffset( 1.25 )
222 frame.GetYaxis().SetTitleOffset( 0.94 )
223 frame.GetXaxis().SetTitleSize( 0.045*scale )
224 frame.GetYaxis().SetTitleSize( 0.045*scale )
225 labelSize = 0.04*scale
226 frame.GetXaxis().SetLabelSize( labelSize )
227 frame.GetYaxis().SetLabelSize( labelSize )
229 gPad.SetBottomMargin( 0.120*scale )
230 gStyle.SetTitleFillColor( c_VLightGray )
231 gStyle.SetTitleTextColor( c_VDarkGray )
232 gStyle.SetTitleBorderSize( 1 )
233 gStyle.SetTitleH( 0.06 )
234 gStyle.SetTitleX( gPad.GetLeftMargin() )
235 gStyle.SetTitleY( 1 - gPad.GetTopMargin() + gStyle.GetTitleH() )
236 gStyle.SetTitleW( 1 - gPad.GetLeftMargin() - gPad.GetRightMargin() )
240 title =
"ATLAS integrated numnber of events in run range %i - %i" % (runmin, runmax)
241 c = TCanvas(
"c", title, 0, 0, 800, 550 )
242 c.GetPad(0).SetRightMargin(0.08)
243 c.GetPad(0).SetLeftMargin(0.10)
244 c.GetPad(0).SetTopMargin(0.07)
245 htitle =
"Events recorded by ATLAS between %s and %s" % (time.strftime(
'%b %d',tminS),
246 time.strftime(
'%b %d, %Y',tmaxS))
248 frame =
TH1F(
"frame", htitle.strip(), 10000, runmin, runmax )
251 TGaxis.SetMaxDigits(6)
252 frame.GetYaxis().SetTitleOffset( 1.0 )
253 frame.SetMinimum( 0 )
254 frame.SetMaximum( maxnev*1.1 )
255 frame.SetYTitle(
"Number of events (in %s)" % unit )
256 frame.SetXTitle(
"Run number" )
262 legend = TLegend( c.GetLeftMargin() + dx, 1 - c.GetTopMargin() + dy,
263 c.GetLeftMargin() + 0.48 + dx, 1 - c.GetTopMargin() - 0.38 + dy)
264 legend.SetFillStyle( 1001 )
265 legend.SetFillColor( c_VLightGray )
266 legend.SetBorderSize(1)
267 legend.SetMargin( 0.2 )
268 legend.SetTextColor( c_VDarkGray )
271 return c, frame, legend
281 colours = [ c_NovelRed, 4, c_DarkOrange, c_DarkGreen, c_Violet, c_LightBlue, 3, c_VDarkYellow, c_Gray,
282 1, 2, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 ]
285 run_and_time =
sorted(rootstreamdic[DataKey(
'Start and endtime')])
286 runs = [x[0]
for x
in run_and_time]
290 tmin =
min([x[1][0]
for x
in run_and_time])
291 tmax =
max([x[1][1]
for x
in run_and_time])
294 tminS = time.gmtime(tmin)
295 tmaxS = time.gmtime(tmax)
303 maxnev = {
'all_':-1,
'debug_':-1,
'calibration_':-1 }
304 for key, content
in rootstreamdic.iteritems():
305 if type(key)==DataKey:
307 if 'Start and endtime' not in key:
308 graphs.append( TGraph( len(content) ) )
309 graphs[-1].SetName( key.strip().
replace(
' ',
'_') )
310 graphs[-1].SetTitle( key.strip() )
312 for i
in range(len(content)):
317 cumulsum += content[j][1]/scale
318 graphs[-1].SetPoint( i, content[j][0], cumulsum )
319 for stype
in maxnev.keys():
321 if cumulsum > maxnev[stype]:
322 maxnev[stype] = cumulsum
323 if 'debug_' not in key
and cumulsum > maxnev[
'all_']:
324 maxnev[
'all_'] = cumulsum
325 sortdic[len(graphs)-1] = cumulsum
328 sortedlist =
sorted(sortdic, key=sortdic.__getitem__, reverse=
True)
335 if 'physics_' in name
or 'express_' in name:
338 g.GetPoint( g.GetN()-1, x, y )
340 legend.SetX2( legend.GetX2() - 0.2 )
341 legend.SetY1( legend.GetY2() - 0.05 )
342 DrawGraph( g, colours[ic], 2, 1, legend, name.replace(
'physics_',
'').
replace(
'express_',
'').
replace(
'express',
'Express'),
True,
'M', TText() )
346 frame.Draw(
"sameaxis")
350 fname =
'%s/atlrunquery_%s.png' % (datapath, name)
355 htmlstr.append(
MakeHtml( [
'Events in streams %s versus run' % name], [fname],
True, 60, 5 ) )
358 c, frame, legend =
CreateCanvasAndFrame( runmin, runmax, tminS, tmaxS, maxnev[
'all_'],
'',
'million' )
363 if '#Events (streamed)' in name:
364 DrawGraph( g, c_NovelBlue, 2, 2, legend,
"Total number of streamed events" )
365 elif '#Events' == name:
366 DrawGraph( g, c_NovelBlue, 5, 1, legend,
"Total number of triggered events (excl. calib)",
True,
'M', TText() )
367 elif 'physics_' in name
or 'express_' in name:
368 DrawGraph( g, colours[ic], 2, 1, legend, name.replace(
'physics_',
'').
replace(
'express_',
'').
replace(
'express',
'Express') )
372 frame.Draw(
"sameaxis")
376 fname =
'%s/atlrunquery_physicsstreams.png' % datapath
381 htmlstr.append(
MakeHtml( [
'Events in physics streams versus run'], [fname],
True, 60, 5 ) )
385 plottypes = {
'debug_' : [
'Debug',
'thousand',
'k' ],
386 'calibration_' : [
'Calibration',
'million',
'M' ] }
389 for key, cprop
in plottypes.iteritems():
391 c, frame, legend =
CreateCanvasAndFrame( runmin, runmax, tminS, tmaxS, maxnev[key], cprop[0], cprop[1] )
392 legend.SetY1( legend.GetY1() + 0.15 )
393 legend.SetX2( legend.GetX2() - 0.15 )
399 DrawGraph( g, colours[ic], 2, 1, legend, name, ic == 0, cprop[2], TText() )
403 frame.Draw(
"sameaxis")
407 fname =
'%s/atlrunquery_%sstreams.png' % (datapath, cprop[0].lower())
412 htmlstr.append(
MakeHtml( [
'Events in %s streams versus run' % cprop[0].lower()], [fname],
True, 60, 5 ) )
415 retstr =
'<table width="900" style="margin-left: 14px; background-color: #f0f0f0; border: 2px white solid; border-collapse: collapse;"><tr>'
416 for i,s
in enumerate(htmlstr):
417 retstr +=
'<td style="padding: 4px">%s</td>' % s
419 retstr +=
'</tr><tr>'
420 retstr +=
'</tr></table>'
426 runs = dic[DataKey(
'Run')]
428 times = dic[DataKey(
'Start and endtime')]
433 s =
'<table style="color: #777777; font-size: 85%; margin-left: 14px" cellpadding="0" cellspacing="3">\n'
435 s +=
'<tr><td><i>Number of runs selected:</i></td><td> %g</td><td></td></tr>\n' % (len(runs))
436 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)))
437 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)))
443 s +=
'<table style="margin-left: 14px">\n'
444 s +=
'<tr><td><b>Run / Event Summary</b></td></tr>\n'
449 keys = [ [
'Duration',
'Run duration',
' h',
'%.2f', [] ],
450 [
'#Events',
'#Events (excl.)',
'',
'pretty-int', [] ],
451 [
'#Events (streamed)',
'#Events (incl.)',
'',
'pretty-int', [] ],
452 [
'STR:physics_*',
'Event size <font size="-2">(RAW)</font>',
' MB',
'%.2f', [0] ]
456 for dk, c
in dic.iteritems():
458 if (
'*' in k[0]
and k[0].
replace(
'*',
'')
in dk.ResultKey)
or (
'*' not in k[0]
and k[0] == dk.ResultKey):
477 s +=
'<table style="margin-left: 14px">\n'
478 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'
487 for dk, c
in dic.iteritems():
489 if '#Events' in dk.ResultKey:
490 rootstreamdic[dk] = []
491 for run,dataentries
in zip(runs,c):
494 data = dataentries[0].value
496 rootstreamdic[dk].
append([run,
int(data)])
499 rootstreamdic[dk].
append([run, data])
501 if 'Start and endtime' in dk.ResultKey:
502 rootstreamdic[dk] = []
503 for run,data
in zip(runs,c):
505 rootstreamdic[dk].
append([
int(run), map(float,data.split(
','))])
508 if 'STR:' in dk.ResultKey:
510 sname = dk.ResultKey.replace(
'STR:',
'')
511 streamdic[sname] = []
512 streamsizedic[sname] = 0
513 streamfracdic[sname] = []
514 streamratedic[sname] = []
515 rootstreamdic[sname] = []
517 for run,t,dataentries
in zip(runs,times,c):
519 data = dataentries[0].value
520 if not isinstance(data, str):
521 streamdic[sname].
append(data[0])
522 streamfracdic[sname].
append(data[0])
523 tmin_ =
float(t.partition(
',')[0])
524 tmax_ =
float(t.partition(
',')[2])
525 deltat = tmax_ - tmin_
527 streamratedic[sname].
append(data[0]/deltat)
529 streamratedic[sname].
append(-1)
530 streamsizedic[sname] += data[1]
532 rootstreamdic[sname].
append([run, data[0]])
536 streamfracdic[sname].
append(
'na')
539 streamtypes = [
'physics',
'express',
'debug',
'calibration']
541 for stype
in streamtypes:
543 for key, c
in streamdic.iteritems():
546 sortedstreams +=
sorted(keys, key=keys.__getitem__, reverse=
True)
551 for stream
in sortedstreams:
553 table.append( stats[0:4] )
556 if 'calibration_' not in stream:
558 for i, evrun
in enumerate(streamfracdic[stream]):
561 for stream2
in sortedstreams:
562 if 'calibration_' not in stream2:
563 if streamfracdic[stream2][i] !=
'na':
564 evsum += streamfracdic[stream2][i]
566 v.append(
float(evrun)/evsum*100 )
570 table[-1] += [
'&minus']
573 table[-1] += [
'%.3g' %
ComputeStats( streamratedic[stream] )[1]]
576 table[-1] += [stats[4]]
580 table[-1] += [
filesize(streamsizedic[stream]),
583 table[-1] += [
filesize(streamsizedic[stream]),
'&minus']
586 if 'debug' in stream:
587 prettystr =
'<font color="#C11B17">' + stream +
'</font>'
589 keys.append( [stream, prettystr,
'',
'pretty-int', []] )
592 [
'Total',
'Average',
'Min',
'Max',
593 'Average<br>fraction (%)',
594 'Average<br>rate (Hz)',
595 '#Runs<br><font size="-2">(out of %i)</font>' % nruns,
596 'Total file<br>size <font size="-2">(RAW)</font>',
597 'Average event<br>size <font size="-2">(RAW)</font>'], keys, table, 900 )
610 s +=
'<table style="margin-left: 14px">\n'
611 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'
614 dqflags = [
'G',
'Y',
'R',
'B',
'U',
'n.a.']
615 dqflagsNames = [
'Green',
'Yellow',
'Red',
'Black',
'Unknown',
'Not assigned ']
624 for chan, dqgroup
in DQGroupDict.items():
626 for dqflag
in dqflags:
627 ndq[chan][dqflag] = 0
629 for chan, dqchan
in dqitems:
631 grchan =
int(chan/10)*10
634 for dqflag
in dic[dqchan]:
635 ndq[grchan][dqflag] += 1
639 for chan, dqgroup
in DQChannelDict.items():
640 colstr.append( dqgroup )
641 colchans.append( chan )
647 for chan, dqchan
in dqitems:
648 dqchan =
"SHIFTOFL_%s" % (dqchan)
649 colstr.append( dqchan )
650 colchans.append( chan )
653 for dqflag
in dqflags:
654 ndq[chan][dqflag] = [0, []]
657 for i, dqflag
in enumerate(dic[dqchan]):
658 ndq[chan][dqflag][0] += 1
659 ndq[chan][dqflag][1].
append(runs[i])
667 for i
in range(len(colchans)):
673 colstr_.append(colstr[i])
674 colchans_.append(colchans[i])
678 for dqgroup, content
in DQSuperGroupsDict.iteritems():
682 for dqchan
in content[1]:
683 colstr_.append(dqchan)
684 colchans_.append(DQChannelDict[dqchan])
685 s +=
MakeDQSummaryTableHtml(
'', title, colstr_, colchans_, dqflags, dqflagsNames, ndq, nruns, labeloffset )