5 from functools
import cache
6 from TrigConfigSvc.TrigConfigSvcCfg
import getHLTMenuFileName
7 from AthenaCommon.CFElements
import getSequenceChildren
8 from AthenaCommon.Logging
import logging
9 __log = logging.getLogger( __name__ )
13 pattern = re.compile(
r'_v\d+|DC14')
14 patternPos = pattern.search(menuName)
16 menuName=menuName[:patternPos.end()]
18 __log.info(
'Can\'t find pattern to shorten menu name, either non-existent in name or not implemented.')
22 """ Generates a list where the index corresponds to a Step number and the stored object is a list of Sequencers making up the Step
25 if HLTAllSteps
is not None:
26 for HLTStep
in HLTAllSteps.Members:
27 if "_reco" not in HLTStep.getName():
31 if "_reco" in Reco.getName()
and HLTStep.getName()
not in stepsData:
32 stepsData.append( HLTStep.Members )
36 stepsData.append( HLTStep.Members )
38 __log.warn(
"No HLTAllSteps sequencer, will not export per-Step data for chains.")
43 if hasattr(filterAlg,
"Chains"):
45 return set(ch[7:]
if ch.startswith(
'leg')
else ch
for ch
in filterAlg.Chains)
50 """ Finds the Filter which is responsible for this Chain in each Step.
51 Return a list of the per-Step name() of the Sequencer which is unlocked by the Chain's Filter in the Step.
54 for counter, step
in enumerate(stepsData, 1):
56 for sequencer
in step:
58 sequencerFilter = sequencer.Members[0]
59 except (AttributeError, IndexError):
62 if mySequencer
is not None:
63 __log.error(
"Multiple Filters found (corresponding Sequencers %s, %s) for %s in Step %i!",
64 mySequencer.getName(), sequencer.getName(), chainName, counter)
65 mySequencer = sequencer
67 sequencers.append(mySequencer.getName()
if mySequencer
else "")
69 while len(sequencers) != 0
and sequencers[-1] ==
"":
74 """ For each Sequencer in each Step, return a flat list of the full name of all Algorithms under the Sequencer
76 from AthenaCommon.CFElements
import findAllAlgorithms
78 for step
in stepsData:
79 for sequencer
in step:
80 sequencerAlgs[ sequencer.getName() ] =
list(map(
lambda x: x.getFullJobOptName(),
findAllAlgorithms(sequencer)))
81 return sorted(sequencerAlgs.items(), key=
lambda t: t[0])
84 """ Generates JSON given the ChainProps and sequences
87 menuDict = {
"filetype":
"hltmenu",
95 from TriggerMenuMT.HLT.Menu
import StreamInfo
96 for chain
in chainDicts:
99 for streamName
in chain[
"stream"]:
100 streamTag = StreamInfo.getStreamTag(streamName)
102 if streamTag
is None:
103 __log.error(
'Stream %s does not have StreamTags defined excluding from JSON', streamName)
106 chainStreamTags.append(streamName)
108 if streamName
not in menuDict[
"streams"]:
109 menuDict[
"streams"][streamName] = {
111 "type": streamTag.type(),
112 "obeyLB": streamTag.obeysLumiBlock(),
113 "forceFullEventBuilding": streamTag.forceFullEventBuilding()
119 [ l1Thresholds.append(p[
'L1threshold'])
for p
in chain[
'chainParts'] ]
122 chainName = chain[
"chainName"]
123 menuDict[
"chains"][chainName] = {
124 "counter": chain[
"chainCounter"],
125 "nameHash": chain[
"chainNameHash"],
126 "legMultiplicities": chain[
"chainMultiplicities"],
127 "l1item": chain[
"L1item"],
128 "l1thresholds": l1Thresholds,
129 "groups": chain[
"groups"],
130 "streams": chainStreamTags,
141 __log.info(
"Writing HLT Menu JSON to %s", fileName )
142 with open( fileName,
'w' )
as fp:
143 json.dump( menuDict, fp, indent=4, sort_keys=
False )
147 """ Runs some validation checks which may pick up on issues with the menu
153 """ Check that global algs only go into one Step
157 from AthenaConfiguration.ComponentFactory
import CompFactory
159 for seqName, seqeuncer
in menuDict[
"sequencers"].
items():
160 stepNumber =
int(re.search(
r'\d+', seqName).
group())
161 fullEventMode =
False
162 for alg
in seqeuncer:
163 if isinstance(alg, CompFactory.EventViewCreatorAlgorithm):
164 fullEventMode =
False
165 elif isinstance(alg, CompFactory.InputMakerForRoI):
167 if not fullEventMode:
169 if alg
in algToStep
and algToStep[alg] != stepNumber:
170 __log.error(
"{} is a full-event context alg, it should only be running in one Step, however it is in both Steps {} and {}".
format(alg, stepNumber, algToStep[alg]))
173 algToStep[alg] = stepNumber
175 raise Exception(
"[validateJSON] Problems detected in validateGlobalAlgs().")