13 from __future__
import division, print_function
16 from functools
import reduce
17 import xml.etree.cElementTree
as et
19 from PyCool
import cool
20 dbSvc = cool.DatabaseSvcFactory.databaseService()
22 from CoolRunQuery.AtlRunQuerySelectorBase
import DataKey
24 THIRTYTWOMASK=
int(2**32-1)
25 SERVER=
'http://atlasdqm.cern.ch:8080'
27 FLAGS_WE_CARE_ABOUT = [
'PIXB',
'PIX0',
'PIXEA',
'PIXEC',
28 'SCTB',
'SCTEA',
'SCTEC',
29 'TRTB',
'TRTEA',
'TRTEC',
'TRTTR'
31 'EMBA',
'EMBC',
'EMECA',
'EMECC',
'HECA',
'HECC',
33 'TILBA',
'TILBC',
'TIEBA',
'TIEBC',
35 'MDTBA',
'MDTBC',
'MDTEA',
'MDTEC',
53 'PIX': [
'PIXB',
'PIX0',
'PIXEA',
'PIXEC'],
54 'SCT': [
'SCTB',
'SCTEA',
'SCTEC'],
55 'TRT': [
'TRTB',
'TRTEA',
'TRTEC',
'TRTTR'],
56 'LAR': [
'EMBA',
'EMBC',
'EMECA',
'EMECC',
57 'HECA',
'HECC',
'FCALA',
'FCALC'],
58 'EM': [
'EMBA',
'EMBC',
'EMECA',
'EMECC'],
59 'HEC': [
'HECA',
'HECC'],
60 'FCAL': [
'FCALA',
'FCALC'],
61 'TILE': [
'TILBA',
'TILBC',
'TIEBA',
'TIEBC'],
62 'MDT': [
'MDTBA',
'MDTBC',
'MDTEA',
'MDTEC'],
63 'RPC': [
'RPCBA',
'RPCBC'],
64 'TGC': [
'TGCEA',
'TGCEC'],
65 'CSC': [
'CSCEA',
'CSCEC'],
66 'MBTS': [
'MBTSA',
'MBTSC'],
72 return (
max(1, lbr[0]), lbr[1]
if lbr[1] != -1
else THIRTYTWOMASK)
75 rv = (
max(tlbr1[0],tlbr2[0]),
min(tlbr1[1],tlbr2[1]))
84 if tuple(lbr)
in lumicache:
85 return lumicache[tuple(lbr)]
87 lblbdb = dbSvc.openDatabase(
'COOLONL_TRIGGER/CONDBR2',
True)
88 lblb = lblbdb.getFolder(
'/TRIGGER/LUMI/LBLB')
89 lblestonl = lblbdb.getFolder(
'/TRIGGER/LUMI/LBLESTONL')
91 lbs = lblb.browseObjects((run<<32)+lbr[0],
93 cool.ChannelSelection(0))
98 inf[(run, obj.since() & 0xFFFFFFFF)] = (lbpy[
'EndTime']-lbpy[
'StartTime'])/1e9
99 if obj.since() & 0xFFFFFFFF == lbr[1]:
100 print (
'Oops: this should not happen, appears to be off-by-one error')
101 lbls = lblestonl = lblestonl.browseObjects((run<<32)+lbr[0],
103 cool.ChannelSelection(0))
106 lblpy = obj.payload()
107 infl[(run, obj.since() & 0xFFFFFFFF)] = lblpy[
'LBAvInstLumi']
113 totlum += inf[lb]*infl[lb]
115 print (
'Missing run %d, LB %d' % lb)
116 lumicache[tuple(lbr)] = totlum
122 for runnum
in rundict.keys():
125 s = xmlrpc.client.ServerProxy(SERVER)
126 flaginfo = s.get_dqmf_summary_flags_lb({
'run_list':
list(runset)}, FLAGS_WE_CARE_ABOUT,
'SHIFTOFL')
129 for flag
in FLAGS_WE_CARE_ABOUT:
132 if str(run)
not in flaginfo:
133 print (
'%s not in flaginfo' % run)
136 for sublb
in rundict[run]:
137 for flag, periods
in flaginfo[
str(run)].
items():
138 for period
in periods:
143 record[flag].
append((ip[1]-ip[0], period[2],
lumi(run, ip)))
148 for pair
in rundict[run]:
149 totallum +=
lumi(run, pair)
150 print (
'Total lumi:', totallum)
154 for flag
in FLAGS_WE_CARE_ABOUT:
157 cols =
set([x[1]
for x
in lr])
160 llum =
sum([x[2]
for x
in lr
if x[1] == col])
162 print (flag, col, llum,
'%.2f%%' % (llum/totallum*100))
163 flagsum[flag][col] = (llum/totallum*100)
164 if abs(accounted-totallum) > 1e-8:
165 print (flag,
'n.a.', totallum-accounted,
'%.2f%%' % ((1-accounted/totallum)*100))
166 flagsum[flag][
'n.a.'] = ((1-accounted/totallum)*100)
170 for key
in set(d1.keys() + d2.keys()):
171 rv[key] = d1.get(key, 0) + d2.get(key, 0)
175 for flagtop, flaggroup
in FLAGGROUPS.items():
176 vals =
reduce(_sum, [flagsum[f]
for f
in flaggroup], {})
179 print (
' %s: %.2f%%' % (typ, vals[typ]/len(flaggroup)))
186 runs = dic[DataKey(
'Run')]
187 times = dic[DataKey(
'Start and endtime')]
192 s =
'<table style="color: #777777; font-size: 85%; margin-left: 14px" cellpadding="0" cellspacing="3">\n'
194 s +=
'<tr><td><i>Number of runs selected:</i></td><td> %g</td><td></td></tr>\n' % (len(runs))
195 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)))
196 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)))
202 s +=
'<table style="margin-left: 14px">\n'
203 s +=
'<tr><td><b>Run / Event Summary</b></td></tr>\n'
208 if __name__ ==
'__main__':
210 p = et.parse(sys.argv[1])
213 for lbc
in p.getiterator(
'LumiBlockCollection'):
214 runnum =
int(lbc.find(
'Run').text)
217 for lbr
in lbc.findall(
'LBRange'):
218 rundict[runnum].
append([
int(lbr.get(
'Start')),
219 int(lbr.get(
'End'))+1])