8 from PyCool
import cool
9 from CoolConvUtilities.AtlCoolLib
import indirectOpen
12 """Helper to iterate through runlist. The format is:
13 runlist: [[run1,run2], [run3,run4], ... ]
14 In addition each "run" can be a tuple of format (run,LB)
17 """Create (Run,Lumi) tuple"""
18 return rl
if isinstance(rl,tuple)
else (rl,0)
21 (r1,l1) = makeRunLumi(a)
22 (r2,l2) = makeRunLumi(b)
24 limmin = (r1 << 32) + l1
25 if isinstance(b,tuple):
26 limmax = (r2 << 32) + l2
28 limmax = ((r2+1) << 32) - 1
30 yield (limmin, limmax)
38 m =
match(
r".*?([^/.]+)\.db",dbconn)
39 if dbconn
in [
"CONDBR2",
"COMP200",
"OFLP200"]:
40 connection = f
'COOLONL_TRIGGER/{dbconn}'
42 dbname=m.group(1).
upper()
43 connection =
"sqlite://;schema=%s;dbname=%s;" % (dbconn,dbname)
45 raise RuntimeError (
"Can't connect to COOL db %s" % dbconn)
47 openConn =
indirectOpen(connection,readOnly=
True,debug=(verbosity>0))
58 db = TriggerCoolUtil.getDBConnectionForRun(run)
59 configs = TriggerCoolUtil.getHLTConfigKeys(db, [(run, run)])
60 return configs.get(run,
None)
65 f = db.getFolder(
"/TRIGGER/HLT/HltConfigKeys" )
67 objs = f.browseObjects( limmin, limmax, cool.ChannelSelection(0))
68 while objs.goToNext():
70 runNr = obj.since()>>32
71 if runNr>1e9:
continue
73 smk = payload[
'MasterConfigurationKey']
74 hltpsk = payload[
'HltPrescaleConfigurationKey']
80 confsrc = payload[
'ConfigSource'].
split(
';')
81 if len(confsrc)>2: release = confsrc[2].
split()[0]
83 confsrc = payload[
'ConfigSource'].
split(
',', maxsplit=1)
84 if len(confsrc)>1: release = confsrc[1]
87 configKeys[runNr] = {
"REL" : release,
94 def _getKeys(db, runlist, folder, in_name, out_name):
95 """Helper to retrieve run/LB-index configuration keys
96 returns empty dict if not iov is found
100 f = db.getFolder( folder )
102 objs = f.browseObjects( limmin, limmax, cool.ChannelSelection(0))
103 while objs.goToNext():
104 obj=objs.currentRef()
105 runNr = obj.since()>>32
106 if runNr>1e9:
continue
107 payload = obj.payload()
108 key = payload[in_name]
109 firstLB = obj.since() & lbmask
110 until = (obj.until() & lbmask)
111 lastLB = until-1
if until>0
else lbmask
112 configKeys.setdefault(runNr,{}).setdefault( out_name, [] ).
append((key,firstLB,lastLB))
118 return TriggerCoolUtil._getKeys(db, runlist,
"/TRIGGER/HLT/PrescaleKey",
119 "HltPrescaleKey",
"HLTPSK2")
124 db = TriggerCoolUtil.getDBConnectionForRun(run)
125 prescales = TriggerCoolUtil.getHLTPrescaleKeys(db, [(run, run)])
126 if(run
not in prescales):
128 for (hltpsk, firstlb, lastlb)
in prescales[run][
'HLTPSK2']:
129 if firstlb<=lb
and lb<=lastlb:
135 return TriggerCoolUtil._getKeys(db, runlist,
"/TRIGGER/LVL1/Lvl1ConfigKey",
136 "Lvl1PrescaleConfigurationKey",
"LVL1PSK")
141 db = TriggerCoolUtil.getDBConnectionForRun(run)
142 prescales = TriggerCoolUtil.getL1ConfigKeys(db, [(run, run)])
143 if(run
not in prescales):
145 for (l1psk, firstlb, lastlb)
in prescales[run][
'LVL1PSK']:
146 if firstlb<=lb
and lb<=lastlb:
152 return TriggerCoolUtil._getKeys(db, runlist,
"/TRIGGER/LVL1/BunchGroupKey",
153 "Lvl1BunchGroupConfigurationKey",
"BGKey")
158 db = TriggerCoolUtil.getDBConnectionForRun(run)
159 bunches = TriggerCoolUtil.getBunchGroupKey(db, [(run, run)])
160 if(run
not in bunches):
162 for (bgsk, firstlb, lastlb)
in bunches[run][
'BGKey']:
163 if firstlb<=lb
and lb<=lastlb:
169 return TriggerCoolUtil.GetConnection(
'CONDBR2' if runNumber > 230000
else 'COMP200')
173 db = TriggerCoolUtil.getDBConnectionForRun(runNumber)
174 bgkey = TriggerCoolUtil.getBunchGroupKeyForRunLB(runNumber, lumiBlock, db)
175 l1pskey = TriggerCoolUtil.getL1PrescaleKey(runNumber, lumiBlock, db)
176 hltpskey = TriggerCoolUtil.getHLTPrescaleKey(runNumber, lumiBlock, db)
177 menucfg = TriggerCoolUtil.getMenuConfigKey(runNumber, db)
179 "SMK": menucfg[
'SMK']
if menucfg
else None,
180 "DB": menucfg[
'DB']
if menucfg
else None,
190 f = db.getFolder(
"/TRIGGER/LUMI/LBLB" )
192 limmin=(rr[0] << 32)+0
193 limmax=((rr[1]+1) << 32)+0
194 objs = f.browseObjects( limmin, limmax, cool.ChannelSelection(0) )
195 while objs.goToNext():
196 obj=objs.currentRef()
197 runNr = obj.since()>>32
198 if runNr==latestRunNr:
continue
200 if runNr
not in runs:
continue
201 payload=obj.payload()
202 starttime = payload[
'StartTime']
203 startTime[runNr] = {
"STARTTIME" : ctime(starttime/1E9).
replace(
' ',
'_') }
212 printPrescales = verbosity>0
213 printDisabled = verbosity>1
215 f = db.getFolder(
"/TRIGGER/LVL1/Menu" )
216 chansel=cool.ChannelSelection.all()
217 objs = f.browseObjects( limmin,limmax,chansel)
218 fps = db.getFolder(
"/TRIGGER/LVL1/Prescales" )
219 objsps = fps.browseObjects( limmin,limmax,chansel)
223 while objs.goToNext():
224 obj=objs.currentRef()
225 channel = obj.channelId()
226 payload=obj.payload()
227 itemname = payload[
'ItemName']
228 itemName[channel] = itemname
229 longestName=
max(longestName,len(itemname))
230 while objsps.goToNext():
231 objps=objsps.currentRef()
232 channel = objps.channelId()
233 payloadps=objps.payload()
234 ps = payloadps[
'Lvl1Prescale']
235 if channel
in itemPrescale:
236 itemPrescale[channel] += [ ps ]
238 itemPrescale[channel] = [ ps ]
239 for channel
in itemName:
241 for x
in itemPrescale[channel]:
242 if x>0
or printDisabled: doPrint =
True
243 if not doPrint:
continue
245 print (
"%4i: %-*s PS " % (channel, longestName, itemName[channel]), itemPrescale[channel])
247 print (
"%4i: %s" % (channel, itemName[channel]))
253 limmax=((run+1)<<32)-1
255 f = db.getFolder(
"/TRIGGER/HLT/Menu" )
256 chansel=cool.ChannelSelection.all()
257 objs = f.browseObjects( limmin,limmax,chansel)
265 while objs.goToNext():
266 obj=objs.currentRef()
267 payload=obj.payload()
268 level = payload[
'TriggerLevel']
269 if level==
'L2' and not printL2:
continue
270 if level==
'EF' and not printEF:
continue
271 name = payload[
'ChainName']
272 sizeName=
max(sizeName,len(name))
273 counter = payload[
'ChainCounter']
274 chainNames[(level,counter)] = name
276 version = payload[
'ChainVersion']
277 prescale = payload[
'Prescale']
278 passthr = payload[
'PassThrough']
279 stream = payload[
'StreamInfo']
280 lower = payload[
'LowerChainName']
281 sizePS=
max(sizePS,prescale)
282 sizePT=
max(sizePT,passthr)
283 sizeStr=
max(sizeStr,len(stream))
284 sizeLow=
max(sizeLow,len(lower))
285 chainExtraInfo[(name,level)] = (version, prescale, passthr, stream, lower)
286 sizePS = len(
"%i"%sizePS)
287 sizePT = len(
"%i"%sizePT)
288 for c
in sorted(chainNames):
290 print (
"%s %4i: %-*s" % (c[0], c[1], sizeName, name),)
292 (version, prescale, passthr, stream, lower) = chainExtraInfo[(name,c[0])]
293 print (
"[V %1s, PS %*i, PT %*i, by %-*s , => %-*s ]" %
294 (version, sizePS, prescale, sizePT, passthr, sizeLow, lower, sizeStr, stream), end=
'')
300 limmax=((run+1)<<32)-1
301 print (
"Used Streams:")
302 f = db.getFolder(
"/TRIGGER/HLT/Menu" )
303 chansel=cool.ChannelSelection.all()
304 objs = f.browseObjects( limmin,limmax,chansel)
306 while objs.goToNext():
307 obj=objs.currentRef()
308 payload=obj.payload()
309 streamsOfChain = payload[
'StreamInfo']
310 for streamprescale
in streamsOfChain.split(
';'):
311 streamname = streamprescale.split(
',')[0]
312 streams.add(streamname)
318 if __name__ ==
"__main__":
319 from pprint
import pprint
321 db = TriggerCoolUtil.GetConnection(
'CONDBR2')
325 for run
in [run2, run3]:
327 pprint(TriggerCoolUtil.getHLTConfigKeys(db, [[run,run]]))
328 pprint(TriggerCoolUtil.getHLTPrescaleKeys(db, [[run,run]]))
329 pprint(TriggerCoolUtil.getL1ConfigKeys(db, [[run,run]]))
330 pprint(TriggerCoolUtil.getBunchGroupKey(db, [[run,run]]))
333 print(
"\nLB range within run:")
334 pprint(TriggerCoolUtil.getHLTPrescaleKeys(db, [[(run3,266),(run3,400)]]))
336 print(
"\nRun range:")
337 pprint(TriggerCoolUtil.getHLTPrescaleKeys(db, [[run3,435349]]))
339 print(
"\nMultiple run ranges:")
340 pprint(TriggerCoolUtil.getHLTPrescaleKeys(db, [[run3,435349],[435831,435927]]))
342 print(
"\nMultiple run/LB ranges:")
343 pprint(TriggerCoolUtil.getHLTPrescaleKeys(db, [[(run3,266),(435349,10)],
344 [(435831,466),435927]]))