ATLAS Offline Software
Loading...
Searching...
No Matches
ChainConfigurationBase.py
Go to the documentation of this file.
1# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3
4from AthenaCommon.Logging import logging
5log = logging.getLogger(__name__)
6
7import abc
8import inspect
9import functools
10from TriggerMenuMT.HLT.Config.MenuComponents import Chain, ChainStep
11from DecisionHandling.DecisionHandlingConfig import ComboHypoCfg
12from HLTSeeding.HLTSeedingConfig import mapThresholdToL1DecisionCollection
13
14
15#----------------------------------------------------------------
16# Base class to configure chain
17#----------------------------------------------------------------
18class ChainConfigurationBase(metaclass=abc.ABCMeta):
19
20 def __init__(self, chainDict):
21
22 # Consider using translation from dict["chainName"] to dict.chainName (less typing),
23 # though need to be able to access list of dictionaries as value of chainPart as well
24 # dict = type("dict", (object,), dict)
25
26 self.dict = {}
27 self.dict.update(chainDict)
28
29 self.chainName = self.dict['chainName']
30 self.chainL1Item = self.dict['L1item']
31
32 # check dictionary contains only one chain part
33 if len( self.dict['chainParts'] ) != 1:
34 raise RuntimeError( "Passed chain dictionary with %i chainParts to ChainConfigurationBase, but this constructor only supports chains with a single part" % len( self.dict['chainParts'] ) )
35
36 self.chainPart = self.dict['chainParts'][0]
37 self.L1Threshold = self.chainPart['L1threshold'] # now threshold is always there
38 self.mult = int(self.chainPart['multiplicity'])
39 self.chainPartName = self.chainPart['chainPartName']
42
43 self.chainPartNameNoMult = self.chainPartName[1:] if self.mult > 1 else self.chainPartName
44 self.chainPartNameNoMultwL1 += "_"+self.chainL1Item
45
46 def getStep(self, flags, stepName, sequenceCfgArray, comboHypoCfg=ComboHypoCfg, comboTools=[], **stepArgs):
47 log.debug("Configuring step %s with %d chainParts", stepName, len(self.dict['chainParts']))
48
49 # do not generate Menu Sequences, just store the functions that can do that
50 seqArray = [functools.partial(gen, flags, **stepArgs) for gen in sequenceCfgArray]
51
52 if (len(seqArray)>0):
53 # Bind flags to comboHypo generator if needed
54 if 'flags' in inspect.signature(comboHypoCfg).parameters:
55 comboHypoCfg = functools.partial(comboHypoCfg, flags)
56 else:
57 comboHypoCfg = functools.partial(comboHypoCfg)
58 return ChainStep(stepName, seqArray,
59 [self.dict], comboHypoCfg = comboHypoCfg, comboToolConfs = comboTools)
60
61 # if not returned any step
62 raise RuntimeError("[getStep] No sequences generated for step %s!", stepName)
63
64 def getEmptyStep(self, stepName):
65 log.debug('Configuring empty step %s', stepName)
66 return ChainStep(stepName, chainDicts=[self.dict], isEmpty=True)
67
68 def buildChain(self, chainSteps):
69
70 alignmentGroups = []
71 if isinstance(self.chainPart, dict):
72 alignmentGroups = [self.chainPart['alignmentGroup']]
73 elif isinstance(self.chainPart, list):
74
75 alignmentGroups = [cp['alignmentGroup'] for cp in self.chainPart]
76 testAlignGrps = list(set(alignmentGroups))
77 if not(len(testAlignGrps) == 1 and testAlignGrps[0] == 'JetMET'):
78 log.error("ChainConfigurationBase.buildChain(): number of chainParts does not correspond chainSteps")
79 log.error('ChainConfigurationBase.buildChain() chainPart: %s',self.chainPart)
80 log.error("ChainConfigurationBase.buildChain() alignmentGroups: %s", alignmentGroups)
81 log.error("ChainConfigurationBase.buildChain() chainName: %s", self.chainName)
82 log.error("ChainConfigurationBase.buildChain() chainSteps: %s", chainSteps)
83 else:
84 alignmentGroups = testAlignGrps
85
86 else:
87 log.error("ChainConfigurationBase.buildChain(): chainPart is not a list or dict, not sure what to do here! %s ", self.chainPart)
88
89 L1decision = mapThresholdToL1DecisionCollection(self.L1Threshold)
90 myChain = Chain(name = self.chainName,
91 ChainSteps = chainSteps,
92 L1decisions = [L1decision],
93 nSteps = [len(chainSteps)], # not true for combined chains
94 alignmentGroups = alignmentGroups
95 )
96
97 return myChain
98
99 @abc.abstractmethod
100 def assembleChainImpl(self, flags):
101 return
102
103 def assembleChain(self, flags):
104 return self.assembleChainImpl(flags)
getStep(self, flags, stepName, sequenceCfgArray, comboHypoCfg=ComboHypoCfg, comboTools=[], **stepArgs)
STL class.