3 __author__ =
'Javier Montejo'
4 __version__=
"$Revision: 2.0 $"
5 __doc__=
"Interface to retrieve lists of unprescaled triggers according to types and periods"
8 from TriggerMenuMT.TriggerAPI.TriggerInfo
import TriggerInfo
9 from TriggerMenuMT.TriggerAPI.TriggerEnums
import TriggerPeriod, TriggerType
10 from TriggerMenuMT.TriggerAPI
import SerializeAPI
11 from AthenaCommon.Logging
import logging
14 log = logging.getLogger(__name__)
34 todel = [(p,grl)
for p,grl
in cls.
dbQueries if p & TriggerPeriod.future]
40 """Set ConfigFlags (only required for "future" periods)"""
46 if release
and re.match(
r'21\.1(\.[0-9]+)+$',release):
48 elif release==
"current":
51 cls.
log.warning(
"Release doesn't seem to be a well-formed 21.1 release, ignoring: "+release)
55 if TriggerInfo.testCustomGRL(grl):
58 cls.
log.warning(
"Couldn't set GRL: "+grl)
59 cls.
log.warning(
"Will use default GRL")
63 def getLowestUnprescaled(cls, period, triggerType=TriggerType.ALL, additionalTriggerType=TriggerType.UNDEFINED, matchPattern="", livefraction=1.0, reparse=False):
64 ''' Returns a list of the lowest-pt-threshold HLT chains that were always unprescaled in the given period.
65 period: see TriggerEnums.TriggerPeriod for all possibilities, recommeded TriggerPeriod.y2018
66 triggerType: see TriggerEnums.TriggerType for all possibilities, example TriggerType.el_single
67 additionalTriggerType: can request additional types to match, use TriggerType.ALL to show combined triggers of any kind
68 accepts also a list as input in that case all types have to match
69 matchPattern: provide additionally a regex-like expression to be applied
70 livefraction: accept items that are not unprescaled but have a live fraction above this threshold, example 0.95
71 The live fraction is only an approximation, weighting the number of lumiblocks by prescale.
74 return cls.
dbQueries[(period,cls.
customGRL)]._getLowestUnprescaled(triggerType, additionalTriggerType, matchPattern, livefraction)
77 def getLowestUnprescaledAnyPeriod(cls, period, triggerType=TriggerType.ALL, additionalTriggerType=TriggerType.UNDEFINED, matchPattern="", livefraction=1.0, reparse=False):
78 ''' Returns a list of the lowest-pt-threshold HLT chains that were unprescaled in at least one of
79 the subperiods within the given period. The lowest granularity can be seen in TriggerEnums.TriggerPeriod
80 See getLowestUnprescaled for a detailed description of the options
83 for i, ibin
in enumerate(reversed(
bin(period)[2:])):
88 subperiodset =
set( cls.
dbQueries[(subperiod,cls.
customGRL)]._getLowestUnprescaled(triggerType, additionalTriggerType, matchPattern, livefraction) )
89 lowset |= subperiodset
93 def getUnprescaled(cls, period, triggerType=TriggerType.ALL, additionalTriggerType=TriggerType.UNDEFINED, matchPattern="", livefraction=1.0, reparse=False):
94 ''' Returns a list of always-unprescaled HLT chains, including backup items with higher thresholds.
95 See getLowestUnprescaled for a detailed description of the options
97 return cls.
dbQueries[(period,cls.
customGRL)]._getUnprescaled(triggerType, additionalTriggerType, matchPattern, livefraction)
100 def getUnprescaledAnyPeriod(cls, period, triggerType=TriggerType.ALL, additionalTriggerType=TriggerType.UNDEFINED, matchPattern="", livefraction=1.0, reparse=False):
101 ''' Returns a list of HLT chains that were unprescaled in at least one of
102 the subperiods within the given period. The lowest granularity can be seen in TriggerEnums.TriggerPeriod
103 See getLowestUnprescaled for a detailed description of the options
106 for i, ibin
in enumerate(reversed(
bin(period)[2:])):
108 if not ibin:
continue
111 subperiodset =
set( cls.
dbQueries[(subperiod,cls.
customGRL)]._getUnprescaled(triggerType, additionalTriggerType, matchPattern, livefraction) )
112 lowset |= subperiodset
116 def getInactive(cls, period, triggerType=TriggerType.ALL, additionalTriggerType=TriggerType.UNDEFINED, matchPattern="", livefraction=1e-99, reparse=False):
117 ''' Returns a list of HLT chains that were fully inactive, excluding disabled chains in rerun.
118 See getLowestUnprescaled for a detailed description of the options
121 return cls.
dbQueries[(period,cls.
customGRL)]._getInactive(triggerType, additionalTriggerType, matchPattern, livefraction)
124 def getActive(cls, period, triggerType=TriggerType.ALL, additionalTriggerType=TriggerType.UNDEFINED, matchPattern="", livefraction=1e-99, reparse=False):
125 ''' Returns a list of HLT chains that were active at some point, including disabled chains in rerun.
126 See getLowestUnprescaled for a detailed description of the options
129 return cls.
dbQueries[(period,cls.
customGRL)]._getActive(triggerType, additionalTriggerType, matchPattern, livefraction)
132 def getAllHLT(cls, period, triggerType=TriggerType.ALL, additionalTriggerType=TriggerType.UNDEFINED, matchPattern="", livefraction=0, reparse=False):
133 ''' Returns a map of {HLT chains: average live fraction} for a given period.
134 The average live fraction is an approximation weighting the number of lumiblocks by prescale.
135 *** Don't use this number in analysis!!! ***
136 See getLowestUnprescaled for a detailed description of the options
139 return cls.
dbQueries[(period,cls.
customGRL)]._getAllHLT(triggerType, additionalTriggerType, matchPattern, livefraction)
142 def checkPeriodConsistency(cls, period=TriggerPeriod.future, triggerType=TriggerType.ALL, additionalTriggerType=TriggerType.UNDEFINED, matchPattern="", reparse=False):
143 ''' Returns a list of triggers that are tighter than the lowest unprescaled but are not flagged as primary
144 This only makes sense for future periods, the past is already consistent :)
145 See getLowestUnprescaled for a detailed description of the options
147 period &= TriggerPeriod.future
149 return cls.
dbQueries[(period,cls.
customGRL)]._checkPeriodConsistency(triggerType, additionalTriggerType, matchPattern)
153 if period != TriggerPeriod.customGRL
and not period & TriggerPeriod.future: cls.
init()
155 if TriggerPeriod.isRunNumber(period)
or (isinstance(period,TriggerPeriod)
and period.isBasePeriod()):
158 basePeriods = [tp
for tp
in TriggerPeriod.basePeriods()
if tp & period]
159 for bp
in basePeriods:
168 if TriggerPeriod.isRunNumber(period)
or (isinstance(period,TriggerPeriod)
and period.isBasePeriod()):
continue
175 ''' Run some tests or dump the full pickle/json for CalibPath '''
176 log = logging.getLogger(__name__)
179 for triggerPeriod
in TriggerPeriod:
180 unprescaled = TriggerAPI.getLowestUnprescaled(triggerPeriod,TriggerType.mu_single)
181 log.info(triggerPeriod)
182 log.info(
sorted(unprescaled))
184 unprescaled = TriggerAPI.getLowestUnprescaled(337833,TriggerType.mu_single)
186 log.info(
sorted(unprescaled))
187 TriggerAPI.dumpAPI(full=
True)
189 try: period =
int(sys.argv[1])
190 except Exception: period = TriggerPeriod.y2018
191 for triggerType
in TriggerType:
192 unprescaled = TriggerAPI.getLowestUnprescaled(period,triggerType)
193 log.info(triggerType)
194 log.info(
sorted(unprescaled))
196 if __name__ ==
"__main__":
197 dumpFullAPI = (
"dumpFullAPI" in sys.argv)
198 sys.exit(
main(dumpFullAPI))