7 from PyCool
import cool
8 from CoolConvUtilities.AtlCoolLib
import indirectOpen
11 """Helper to iterate through runlist. The format is:
12 runlist: [[run1,run2], [run3,run4], ... ]
13 In addition each "run" can be a tuple of format (run,LB)
16 """Create (Run,Lumi) tuple"""
17 return rl
if isinstance(rl,tuple)
else (rl,0)
20 (r1,l1) = makeRunLumi(a)
21 (r2,l2) = makeRunLumi(b)
23 limmin = (r1 << 32) + l1
24 if isinstance(b,tuple):
25 limmax = (r2 << 32) + l2
27 limmax = ((r2+1) << 32) - 1
29 yield (limmin, limmax)
37 m =
match(
r".*?([^/.]+)\.db",dbconn)
38 if dbconn
in [
"CONDBR2",
"COMP200",
"OFLP200"]:
39 connection = f
'COOLONL_TRIGGER/{dbconn}'
41 dbname=m.group(1).
upper()
42 connection =
"sqlite://;schema=%s;dbname=%s;" % (dbconn,dbname)
44 raise RuntimeError (
"Can't connect to COOL db %s" % dbconn)
46 openConn =
indirectOpen(connection,readOnly=
True,debug=(verbosity>0))
56 f = db.getFolder(
"/TRIGGER/HLT/HltConfigKeys" )
58 objs = f.browseObjects( limmin, limmax, cool.ChannelSelection(0))
59 while objs.goToNext():
61 runNr = obj.since()>>32
62 if runNr>1e9:
continue
64 smk = payload[
'MasterConfigurationKey']
65 hltpsk = payload[
'HltPrescaleConfigurationKey']
71 confsrc = payload[
'ConfigSource'].
split(
';')
72 if len(confsrc)>2: release = confsrc[2].
split()[0]
74 confsrc = payload[
'ConfigSource'].
split(
',', maxsplit=1)
75 if len(confsrc)>1: release = confsrc[1]
78 configKeys[runNr] = {
"REL" : release,
85 def _getKeys(db, runlist, folder, in_name, out_name):
86 """Helper to retrieve run/LB-index configuration keys"""
89 f = db.getFolder( folder )
91 objs = f.browseObjects( limmin, limmax, cool.ChannelSelection(0))
92 while objs.goToNext():
94 runNr = obj.since()>>32
95 if runNr>1e9:
continue
96 payload = obj.payload()
97 key = payload[in_name]
98 firstLB = obj.since() & lbmask
99 until = (obj.until() & lbmask)
100 lastLB = until-1
if until>0
else lbmask
101 configKeys.setdefault(runNr,{}).setdefault( out_name, [] ).
append((key,firstLB,lastLB))
107 return TriggerCoolUtil._getKeys(db, runlist,
"/TRIGGER/HLT/PrescaleKey",
108 "HltPrescaleKey",
"HLTPSK2")
112 return TriggerCoolUtil._getKeys(db, runlist,
"/TRIGGER/LVL1/Lvl1ConfigKey",
113 "Lvl1PrescaleConfigurationKey",
"LVL1PSK")
117 return TriggerCoolUtil._getKeys(db, runlist,
"/TRIGGER/LVL1/BunchGroupKey",
118 "Lvl1BunchGroupConfigurationKey",
"BGKey")
124 f = db.getFolder(
"/TRIGGER/LUMI/LBLB" )
126 limmin=(rr[0] << 32)+0
127 limmax=((rr[1]+1) << 32)+0
128 objs = f.browseObjects( limmin, limmax, cool.ChannelSelection(0) )
129 while objs.goToNext():
130 obj=objs.currentRef()
131 runNr = obj.since()>>32
132 if runNr==latestRunNr:
continue
134 if runNr
not in runs:
continue
135 payload=obj.payload()
136 starttime = payload[
'StartTime']
137 startTime[runNr] = {
"STARTTIME" : ctime(starttime/1E9).
replace(
' ',
'_') }
146 printPrescales = verbosity>0
147 printDisabled = verbosity>1
149 f = db.getFolder(
"/TRIGGER/LVL1/Menu" )
150 chansel=cool.ChannelSelection.all()
151 objs = f.browseObjects( limmin,limmax,chansel)
152 fps = db.getFolder(
"/TRIGGER/LVL1/Prescales" )
153 objsps = fps.browseObjects( limmin,limmax,chansel)
157 while objs.goToNext():
158 obj=objs.currentRef()
159 channel = obj.channelId()
160 payload=obj.payload()
161 itemname = payload[
'ItemName']
162 itemName[channel] = itemname
163 longestName=
max(longestName,len(itemname))
164 while objsps.goToNext():
165 objps=objsps.currentRef()
166 channel = objps.channelId()
167 payloadps=objps.payload()
168 ps = payloadps[
'Lvl1Prescale']
169 if channel
in itemPrescale:
170 itemPrescale[channel] += [ ps ]
172 itemPrescale[channel] = [ ps ]
173 for channel
in itemName:
175 for x
in itemPrescale[channel]:
176 if x>0
or printDisabled: doPrint =
True
177 if not doPrint:
continue
179 print (
"%4i: %-*s PS " % (channel, longestName, itemName[channel]), itemPrescale[channel])
181 print (
"%4i: %s" % (channel, itemName[channel]))
187 limmax=((run+1)<<32)-1
189 f = db.getFolder(
"/TRIGGER/HLT/Menu" )
190 chansel=cool.ChannelSelection.all()
191 objs = f.browseObjects( limmin,limmax,chansel)
199 while objs.goToNext():
200 obj=objs.currentRef()
201 payload=obj.payload()
202 level = payload[
'TriggerLevel']
203 if level==
'L2' and not printL2:
continue
204 if level==
'EF' and not printEF:
continue
205 name = payload[
'ChainName']
206 sizeName=
max(sizeName,len(name))
207 counter = payload[
'ChainCounter']
208 chainNames[(level,counter)] = name
210 version = payload[
'ChainVersion']
211 prescale = payload[
'Prescale']
212 passthr = payload[
'PassThrough']
213 stream = payload[
'StreamInfo']
214 lower = payload[
'LowerChainName']
215 sizePS=
max(sizePS,prescale)
216 sizePT=
max(sizePT,passthr)
217 sizeStr=
max(sizeStr,len(stream))
218 sizeLow=
max(sizeLow,len(lower))
219 chainExtraInfo[(name,level)] = (version, prescale, passthr, stream, lower)
220 sizePS = len(
"%i"%sizePS)
221 sizePT = len(
"%i"%sizePT)
222 counters = chainNames.keys()
226 print (
"%s %4i: %-*s" % (c[0], c[1], sizeName, name),)
228 (version, prescale, passthr, stream, lower) = chainExtraInfo[(name,c[0])]
229 print (
"[V %1s, PS %*i, PT %*i, by %-*s , => %-*s ]" %
230 (version, sizePS, prescale, sizePT, passthr, sizeLow, lower, sizeStr, stream), end=
'')
236 limmax=((run+1)<<32)-1
237 print (
"Used Streams:")
238 f = db.getFolder(
"/TRIGGER/HLT/Menu" )
239 chansel=cool.ChannelSelection.all()
240 objs = f.browseObjects( limmin,limmax,chansel)
242 while objs.goToNext():
243 obj=objs.currentRef()
244 payload=obj.payload()
245 streamsOfChain = payload[
'StreamInfo']
246 for streamprescale
in streamsOfChain.split(
';'):
247 streamname = streamprescale.split(
',')[0]
248 streams.add(streamname)
254 if __name__ ==
"__main__":
255 from pprint
import pprint
257 db = TriggerCoolUtil.GetConnection(
'CONDBR2')
261 for run
in [run2, run3]:
263 pprint(TriggerCoolUtil.getHLTConfigKeys(db, [[run,run]]))
264 pprint(TriggerCoolUtil.getHLTPrescaleKeys(db, [[run,run]]))
265 pprint(TriggerCoolUtil.getL1ConfigKeys(db, [[run,run]]))
266 pprint(TriggerCoolUtil.getBunchGroupKey(db, [[run,run]]))
269 print(
"\nLB range within run:")
270 pprint(TriggerCoolUtil.getHLTPrescaleKeys(db, [[(run3,266),(run3,400)]]))
272 print(
"\nRun range:")
273 pprint(TriggerCoolUtil.getHLTPrescaleKeys(db, [[run3,435349]]))
275 print(
"\nMultiple run ranges:")
276 pprint(TriggerCoolUtil.getHLTPrescaleKeys(db, [[run3,435349],[435831,435927]]))
278 print(
"\nMultiple run/LB ranges:")
279 pprint(TriggerCoolUtil.getHLTPrescaleKeys(db, [[(run3,266),(435349,10)],
280 [(435831,466),435927]]))