ATLAS Offline Software
Loading...
Searching...
No Matches
ChainConfigurationBase.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 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 if inspect.signature(comboHypoCfg).parameters and all(inspect.signature(comboTool).parameters for comboTool in comboTools):
54 # Bind flags to comboHypo generator if needed
55 if 'flags' in inspect.signature(comboHypoCfg).parameters:
56 comboHypoCfg = functools.partial(comboHypoCfg, flags)
57 else:
58 comboHypoCfg = functools.partial(comboHypoCfg)
59 return ChainStep(stepName, seqArray,
60 [self.dict], comboHypoCfg = comboHypoCfg, comboToolConfs = comboTools)
61
62 # if not returned any step
63 raise RuntimeError("[getStep] No sequences generated for step %s!", stepName)
64
65 def getEmptyStep(self, stepName):
66 log.debug('Configuring empty step %s', stepName)
67 return ChainStep(stepName, chainDicts=[self.dict], isEmpty=True)
68
69 def buildChain(self, chainSteps):
70
71 alignmentGroups = []
72 if isinstance(self.chainPart, dict):
73 alignmentGroups = [self.chainPart['alignmentGroup']]
74 elif isinstance(self.chainPart, list):
75
76 alignmentGroups = [cp['alignmentGroup'] for cp in self.chainPart]
77 testAlignGrps = list(set(alignmentGroups))
78 if not(len(testAlignGrps) == 1 and testAlignGrps[0] == 'JetMET'):
79 log.error("ChainConfigurationBase.buildChain(): number of chainParts does not correspond chainSteps")
80 log.error('ChainConfigurationBase.buildChain() chainPart: %s',self.chainPart)
81 log.error("ChainConfigurationBase.buildChain() alignmentGroups: %s", alignmentGroups)
82 log.error("ChainConfigurationBase.buildChain() chainName: %s", self.chainName)
83 log.error("ChainConfigurationBase.buildChain() chainSteps: %s", chainSteps)
84 else:
85 alignmentGroups = testAlignGrps
86
87 else:
88 log.error("ChainConfigurationBase.buildChain(): chainPart is not a list or dict, not sure what to do here! %s ", self.chainPart)
89
90 L1decision = mapThresholdToL1DecisionCollection(self.L1Threshold)
91 myChain = Chain(name = self.chainName,
92 ChainSteps = chainSteps,
93 L1decisions = [L1decision],
94 nSteps = [len(chainSteps)], # not true for combined chains
95 alignmentGroups = alignmentGroups
96 )
97
98 return myChain
99
100 @abc.abstractmethod
101 def assembleChainImpl(self, flags):
102 return
103
104 def assembleChain(self, flags):
105 return self.assembleChainImpl(flags)
getStep(self, flags, stepName, sequenceCfgArray, comboHypoCfg=ComboHypoCfg, comboTools=[], **stepArgs)
STL class.