4 """Provides Trigger related selectors:
6 TriggerSelector Trigger menu from TriggerDB
9 L1TrigKeySelector L1PSK
10 HLTTrigKeySelector HLTPSK
11 RatesSelector L1 rates from COOL
18 from collections
import defaultdict
20 from PyCool
import cool
22 from CoolRunQuery.selector.AtlRunQuerySelectorBase
import Selector, RunLBBasedCondition
23 from CoolRunQuery.utils.AtlRunQueryUtils
import coolDbConn, GetRanges
34 super(TrigKeySelector,self).
__init__(name=name,
35 dbfolderkey=
'COOLONL_TRIGGER::/TRIGGER/HLT/HltConfigKeys',
36 channelKeys = [(0,
'SMK',
'MasterConfigurationKey'),
37 (0,
'Release',
'ConfigSource')])
54 super(TrigKeySelector,self).setShowOutput(
'SMK')
57 super(TrigKeySelector,self).setShowOutput(
'Release')
61 major, minor, sub, patch = ([
int(x)
for x
in r.split(
'.')] + [0,0,0,0])[0:4]
64 return 1000000*major+10000*minor+100*sub+patch
69 return 'SELOUT Checking if SMK matches "%s" and release matches "%s"' % (self.
trigkeys,self.
release)
71 return 'SELOUT Checking if SMK matches "%s"' % self.
trigkeys
73 return 'SELOUT Checking if release matches "%s"' % (self.
release)
76 return "Retrieving SMK and release version"
78 return "Retrieving SMK"
80 return "Retrieving release version"
92 if val>=cr[0]
and val<=cr[1]:
107 if val>=cr[0]
and val<=cr[1]:
117 if key==
'Release' and value!=
"n.a." and ',' in value:
118 return value.split(
',')[1]
122 if key==
'Release' and ';' in condData:
123 [db,rel,relfull] = condData.split(
';')
124 return {
"db" : db,
"release" : rel,
"releaseFullName" : relfull}
130 return {
"value": smk}
134 from CoolRunQuery.utils.AtlRunQueryTriggerUtils
import getSmkNames, getRandom, triggerDBAlias
141 smkNamesByLHCRun = {}
145 smk =
int(run.result[
'SMK'])
146 except (ValueError, KeyError):
150 smksByLHCRun[run.lhcRun].
add(smk)
153 dbAlias = run.data[
'Release'][0][
"db"]
155 smk = run.data[
'SMK'][0].value
156 dbAlias =
"TRIGGERDB_RUN3" if smk>=3000
else "TRIGGERDBDEV1_I8"
157 smksByLHCRun[run.lhcRun][dbAlias].
add(smk)
161 smkNamesByLHCRun[3] = {}
162 for dbAlias
in smksByLHCRun[3]:
163 smkNamesByLHCRun[3].update(
getSmkNames(smksByLHCRun[3][dbAlias], dbAlias) )
167 smk =
int(run.result[
'SMK'])
168 except (ValueError, KeyError):
171 if smk
in smkNamesByLHCRun[run.lhcRun]:
172 info =
list(smkNamesByLHCRun[run.lhcRun][smk])
174 info = [
"Name unknown", 0,
"no comment"]
175 if info[2]==
"" or info[2]==
"~":
186 super(BGSKeySelector,self).
__init__(name=name,
187 dbfolderkey=
'COOLONL_TRIGGER::/TRIGGER/LVL1/BunchGroupKey',
188 channelKeys = [(0,
'BGS Key',
'Lvl1BunchGroupConfigurationKey')])
190 return "Retrieving Bunch group set key"
196 if not str.isdigit(value):
201 for k
in self.ResultKey():
203 run.stats[k] = {
"blocks" : [],
"first" : 0 }
204 entries = run.data[k]
208 for entry
in entries:
210 if len(blocks) > 0
and blocks[-1][0]==v
and blocks[-1][2]==entry.startlb:
211 blocks[-1][2] = entry.endlb
213 blocks += [ [v, entry.startlb, entry.endlb] ]
214 run.stats[k] = {
"blocks" : blocks,
"first" : entries[0].value }
220 super(L1TrigKeySelector,self).
__init__(name=name,
221 dbfolderkey=
'COOLONL_TRIGGER::/TRIGGER/LVL1/Lvl1ConfigKey',
222 channelKeys = [(0,
'L1 PSK',
'Lvl1PrescaleConfigurationKey')])
225 return "Retrieving L1 PSK"
231 return int(value)
if str.isdigit(value)
else None
234 for k
in self.ResultKey():
236 run.stats[k] = {
"blocks" : [],
"first" : 0 }
237 entries = run.data[k]
241 for entry
in entries:
245 if len(blocks) > 0
and blocks[-1][0]==v
and blocks[-1][2]==entry.startlb:
246 blocks[-1][2] = entry.endlb
248 blocks += [ [v, entry.startlb, entry.endlb] ]
249 run.stats[k] = {
"blocks" : blocks,
"first" : entries[0].value }
250 HLTTrigKeySelector.combineHltL1Keys(runlist)
256 if Selector.condDB() ==
'OFLP200':
257 super(HLTTrigKeySelector,self).
__init__(name=name,
258 dbfolderkey=
'COOLONL_TRIGGER::/TRIGGER/HLT/HltConfigKeys',
259 channelKeys = [(0,
'HLT PSK',
'HltPrescaleConfigurationKey')])
261 super(HLTTrigKeySelector,self).
__init__(name=name,
262 dbfolderkey=
'COOLONL_TRIGGER::/TRIGGER/HLT/PrescaleKey',
263 channelKeys = [(0,
'HLT PSK',
'HltPrescaleKey')])
266 return "Retrieving HLT PSK"
272 if not str.isdigit(value):
277 for k
in self.ResultKey():
281 for entry
in run.data[k]:
285 if len(blocks) > 0
and blocks[-1][0]==v
and blocks[-1][2]==entry.startlb:
286 blocks[-1][2] = entry.endlb
288 blocks += [ [v, entry.startlb, entry.endlb] ]
289 run.stats[k] = {
"blocks" : blocks,
"first" : run.data[k][0].value }
291 HLTTrigKeySelector.combineHltL1Keys(runlist)
295 from CoolRunQuery.utils.AtlRunQueryTriggerUtils
import isTriggerRun2
296 l1keysByDbAlias = defaultdict(set)
297 hltkeysByDbAlias = defaultdict(set)
306 dbAlias = run.data[
'Release'][0][
"db"]
308 smk = run.data[
'SMK'][0].value
309 dbAlias =
"TRIGGERDB_RUN3" if smk>=3000
else "TRIGGERDBDEV1_I8"
310 if 'L1 PSK' in run.stats:
311 l1keysByDbAlias[dbAlias].update( [x[0]
for x
in run.stats[
'L1 PSK'][
'blocks']] )
312 if 'HLT PSK' in run.stats:
313 hltkeysByDbAlias[dbAlias].update( [x[0]
for x
in run.stats[
'HLT PSK'][
'blocks']] )
315 if 'L1 PSK' in run.stats:
316 l1keysRun2.update( [x[0]
for x
in run.stats[
'L1 PSK'][
'blocks']] )
317 if 'HLT PSK' in run.stats:
318 hltkeysRun2.update( [x[0]
for x
in run.stats[
'HLT PSK'][
'blocks']] )
320 if 'L1 PSK' in run.stats:
321 l1keysRun1.update( [x[0]
for x
in run.stats[
'L1 PSK'][
'blocks']] )
322 if 'HLT PSK' in run.stats:
323 hltkeysRun1.update( [x[0]
for x
in run.stats[
'HLT PSK'][
'blocks']] )
326 if len(l1keysRun1)+len(l1keysRun2)+len(l1keysByDbAlias) == 0:
328 if len(hltkeysRun1)+len(hltkeysRun2)+len(hltkeysByDbAlias) == 0:
331 from CoolRunQuery.utils.AtlRunQueryTriggerUtils
import getL1PskNames, getHLTPskNames
336 l1NamesByDbAlias = {}
337 hltNamesByDbAlias = {}
338 for dbAlias
in l1keysByDbAlias:
339 l1NamesByDbAlias[dbAlias] =
getL1PskNames(l1keysByDbAlias[dbAlias], dbAlias = dbAlias)
340 for dbAlias
in hltkeysByDbAlias:
341 hltNamesByDbAlias[dbAlias] =
getHLTPskNames(hltkeysByDbAlias[dbAlias], dbAlias = dbAlias)
346 dbAlias = run.data[
'Release'][0][
"db"]
348 smk = run.data[
'SMK'][0].value
349 dbAlias =
"TRIGGERDB_RUN3" if smk>=3000
else "TRIGGERDBDEV1_I8"
350 l1names = l1NamesByDbAlias[dbAlias]
351 hltnames = hltNamesByDbAlias[dbAlias]
353 l1names = l1namesRun2
354 hltnames = hltnamesRun2
356 l1names = l1namesRun1
357 hltnames = hltnamesRun1
358 if not (
'L1 PSK' in run.stats
and 'HLT PSK' in run.stats):
362 for l1key, l1beg, l1end
in run.stats[
'L1 PSK' ][
'blocks']:
363 for hltkey, hltbeg, hltend
in run.stats[
'HLT PSK' ][
'blocks']:
364 lbmin =
max(ic,
min(l1beg,hltbeg))
365 lbmax =
min(l1end-1,hltend-1)
366 if lbmin > lbmax
or lbmin == 0
or lbmax == 0:
370 l1name = l1names[l1key]
if l1key
else ""
371 hltname = hltnames[hltkey]
if hltkey
else ""
372 elm = (lbmin, lbmax, l1key, hltkey, l1name, hltname)
374 run.stats[
'PSK' ] = {
'blocks' :
sorted(
list(blocks)) }
384 dbfolderkey=
'COOLONL_TRIGGER::/TRIGGER/LUMI/LVL1COUNTERS',
385 channelKeys = [(-1,
'TriggerRates',
'TriggerName')]
389 from CoolRunQuery.AtlRunQuerySelectorWorker
import SelectorWorker
390 self.
trigSel = SelectorWorker.getRetrieveSelector(
'trigger',
'TriggerSelector')
392 self.
trigSel.addShowTriggerPattern(
','.
join(trigger))
395 if pattern==
"" or pattern==
"L1":
396 pattern=
"L1_EM5,L1_TAU5,L1_XE10,L1_J5,L1_MBTS_4_4,L1_MU6"
397 self.
trigSel.addShowTriggerPattern(pattern)
398 self.
trigger += pattern.split(
',')
402 return "Retrieving trigger rates for %r" %
','.
join(self.
trigger)
409 fL1R = coolDbConn.GetDBConn(self.schema,db=Selector.condDB()).getFolder(self.folder)
412 menu = r.result[
'TriggerMenu']
414 namelookup = 256*[
'']
417 if not tr.name.startswith(
"L1_"):
420 namelookup[ch] = tr.name
421 channellist.append(ch)
423 if len(channellist)>50:
424 r.addResult(self.ResultKey()[0],
"Too many L1 triggers requested (%i), maximum is 50" % len(channellist))
427 if len(channellist)==0:
428 r.addResult(self.ResultKey()[0],
"No match")
433 chanselL1 = cool.ChannelSelection(ch,ch,cool.ChannelSelection.sinceBeforeChannel)
434 for ch
in channellist[1:]:
435 chanselL1.addChannel(ch)
437 iovmin=(r.runNr << 32)+0
438 iovmax=((r.runNr+1) << 32)-1
440 countsholder = defaultdict(list)
443 objs = fL1R.browseObjects( iovmin, iovmax, chanselL1)
444 while objs.goToNext():
445 obj=objs.currentRef()
447 countsholder[namelookup[ch]].
append((obj.since()&0xFFFFFFFF,
448 obj.payloadValue(
'BeforePrescale'),
449 obj.payloadValue(
'AfterPrescale'),
450 obj.payloadValue(
'L1Accept')))
452 r.addResult(self.ResultKey()[0], countsholder)
454 duration = time() - start
456 if self.applySelection:
457 print (
" ==> %i runs found (%.2f sec)" % (len(runlist),duration))
459 print (
" ==> Done (%g sec)" % duration)
471 from CoolRunQuery.AtlRunQuerySelectorWorker
import SelectorWorker
472 SelectorWorker.getRetrieveSelector(
'trigkey',
'TrigKeySelector')
473 SelectorWorker.getRetrieveSelector(
'l1trigkey',
'L1TrigKeySelector')
474 SelectorWorker.getRetrieveSelector(
'hlttrigkey',
'HLTTrigKeySelector')
476 super(TriggerSelector,self).
__init__(name=name,
477 dbfolderkey=
'COOLONL_TRIGGER::/TRIGGER/HLT/Menu',
478 channelKeys = [(-1,
'TriggerMenu',
'ChainName')])
492 if triggerpattern==
"":
498 return 'SELOUT Checking if the trigger name matches "%s"' % self.
triggers
505 runl1psks is a dict run -> [l1psk,...]
507 from CoolRunQuery.utils.AtlRunQueryTriggerUtils
import getL1Prescales
509 for run_number, pss
in runl1psks.items():
511 l1pscache[(run_number,l1psk)] =
getL1Prescales(l1psk,run_number = run_number)
516 runhltpsks is a dict run -> [hltpsk,...]
518 from CoolRunQuery.utils.AtlRunQueryTriggerUtils
import getHLTPrescales
521 for run_number, pss
in runhltpsks.items():
523 l2pscache[(run_number,psk)], efpscache[(run_number,psk)] =
getHLTPrescales(psk, run_number = run_number)
525 return l2pscache, efpscache
529 from CoolRunQuery.utils.AtlRunQueryTriggerUtils
import getL1Menu, getHLTMenu
532 l2menucache = defaultdict(dict)
533 efmenucache = defaultdict(dict)
536 for smk
in set(smks):
540 l1menucache[smk] = l1items
544 d2 = l2menucache[smk] = dict([(c.counter,c)
for c
in l2chains])
547 for chain
in efchains:
548 if chain.lowername==
"":
551 if (cc
in d2)
and (chain.lowername == d2[cc].name):
553 chain.lowercounter = cc
555 for l2ch
in l2chains:
556 if chain.lowername == l2ch.name:
558 chain.lowercounter = l2ch.counter
561 for chain
in l2chains:
562 if chain.lowername ==
"":
564 for l1item
in l1items:
565 if l1item
and chain.lowername == l1item.name:
567 chain.lowercounter = l1item.counter
571 for item
in l1items + l2chains + efchains:
577 for item
in l1items + l2chains + efchains:
581 return l1menucache, l2menucache, efmenucache
599 smks = [
int(r.result[
'SMK'])
for r
in runlist]
603 runl1psks[r.runNr] = [l1psk
for (l1psk,firstlb,lastlb)
in r.stats[
'L1 PSK'][
'blocks']]
604 runhltpsks[r.runNr] = [hltpsk
for (hltpsk,firstlb,lastlb)
in r.stats[
'HLT PSK'][
'blocks']]
614 smk =
int(run.result[
'SMK'])
615 psks = [(x[2],x[3])
for x
in run.stats[
'PSK'][
'blocks']]
617 l1items = [it
for it
in l1menucache[smk]
if it
and (it.forshow
or it.forselect)]
618 l2chains = [ch
for ch
in l2menucache[smk].
values()
if (ch.forshow
or ch.forselect)
and not ch.multiseeded]
619 efchains = [ch
for ch
in efmenucache[smk].
values()
if (ch.forshow
or ch.forselect)
and not ch.multiseeded
and ch.lower
and not ch.lower.multiseeded]
621 value = defaultdict(list)
624 for l1psk,hltpsk
in psks:
628 itemps = l1pscache[(run.runNr,l1psk)][item.counter]
629 value[item].
append(itemps
if itemps>=0
else -1)
631 for l2chain
in l2chains:
632 for l1psk,hltpsk
in psks:
633 if not l1psk
or not hltpsk:
634 value[l2chain].
append(
None)
636 chainps,chainpt = l2pscache[(smk,hltpsk)][l2chain.counter]
640 chainps *= l1pscache[(run.runNr,l1psk)][l2chain.lowercounter]
641 value[l2chain].
append(chainps
if chainps>=0
else -1)
643 for efchain
in efchains:
644 l2chain = efchain.lower
645 for l1psk,hltpsk
in psks:
646 if not l1psk
or not hltpsk:
647 value[efchain].
append(
None)
649 chainps,chainpt = efpscache[(smk,hltpsk)][efchain.counter]
653 l2chainps,l2chainpt = l2pscache[(smk,hltpsk)][l2chain.counter]
658 chainps *= l1pscache[(run.runNr,l1psk)][l2chain.lowercounter]
659 value[efchain].
append(chainps
if chainps>=0
else -1)
662 for tr,pslist
in value.items():
663 if not any([ps
is None or ps>=0
for ps
in pslist]):
668 newrunlist += [run.runNr]
670 run.addResult(self.ResultKey()[0], value)
672 runlist = [r
for r
in runlist
if r.runNr
in newrunlist]
674 duration = time() - start
677 print (
" ==> %i runs found (%.2f sec)" % (len(runlist),duration))
679 print (
" ==> Done (%g sec)" % duration)
697 form += [
"%s (%s)" % (v[0],
','.
join(v[1]))]
699 form += [
"%s (%s|%s)" % v]
700 return ', '.
join(form)
704 for chain
in triggers: