ATLAS Offline Software
ChainConfigurationBase.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 
4 from AthenaCommon.Logging import logging
5 log = logging.getLogger(__name__)
6 
7 import abc
8 import inspect
9 import functools
10 from TriggerMenuMT.HLT.Config.MenuComponents import Chain, ChainStep
11 from DecisionHandling.DecisionHandlingConfig import ComboHypoCfg
12 from HLTSeeding.HLTSeedingConfig import mapThresholdToL1DecisionCollection
13 
14 
15 #----------------------------------------------------------------
16 # Base class to configure chain
17 #----------------------------------------------------------------
18 class 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  # Be carefull: custom ComboHpos are passed as partial functions, others no
58  # TODO: make uniform way to pass ComboHypo to the step (all partial functions)
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, stepID, stepPartName):
66  stepName = 'Step%s'%str(stepID) + '_' + stepPartName
67  log.debug("Configuring empty step %s", stepName)
68  return ChainStep(stepName, chainDicts=[self.dict], isEmpty = True)
69 
70  def buildChain(self, chainSteps):
71 
72  alignmentGroups = []
73  if isinstance(self.chainPart, dict):
74  alignmentGroups = [self.chainPart['alignmentGroup']]
75  elif isinstance(self.chainPart, list):
76 
77  alignmentGroups = [cp['alignmentGroup'] for cp in self.chainPart]
78  testAlignGrps = list(set(alignmentGroups))
79  if not(len(testAlignGrps) == 1 and testAlignGrps[0] == 'JetMET'):
80  log.error("ChainConfigurationBase.buildChain(): number of chainParts does not correspond chainSteps")
81  log.error('ChainConfigurationBase.buildChain() chainPart: %s',self.chainPart)
82  log.error("ChainConfigurationBase.buildChain() alignmentGroups: %s", alignmentGroups)
83  log.error("ChainConfigurationBase.buildChain() chainName: %s", self.chainName)
84  log.error("ChainConfigurationBase.buildChain() chainSteps: %s", chainSteps)
85  else:
86  alignmentGroups = testAlignGrps
87 
88  else:
89  log.error("ChainConfigurationBase.buildChain(): chainPart is not a list or dict, not sure what to do here! %s ", self.chainPart)
90 
92  myChain = Chain(name = self.chainName,
93  ChainSteps = chainSteps,
94  L1decisions = [L1decision],
95  nSteps = [len(chainSteps)], # not true for combined chains
96  alignmentGroups = alignmentGroups
97  )
98 
99  return myChain
100 
101  @abc.abstractmethod
102  def assembleChainImpl(self, flags):
103  return
104 
105  def assembleChain(self, flags):
106  return self.assembleChainImpl(flags)
ChainConfigurationBase.ChainConfigurationBase.L1Threshold
L1Threshold
Definition: ChainConfigurationBase.py:37
ChainConfigurationBase.ChainConfigurationBase.dict
dict
Definition: ChainConfigurationBase.py:26
ChainConfigurationBase.ChainConfigurationBase.buildChain
def buildChain(self, chainSteps)
Definition: ChainConfigurationBase.py:70
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ChainConfigurationBase.ChainConfigurationBase.mult
mult
Definition: ChainConfigurationBase.py:38
Cut::all
@ all
Definition: SUSYToolsAlg.cxx:67
ChainConfigurationBase.ChainConfigurationBase.getEmptyStep
def getEmptyStep(self, stepID, stepPartName)
Definition: ChainConfigurationBase.py:65
ChainConfigurationBase.ChainConfigurationBase.chainName
chainName
Definition: ChainConfigurationBase.py:29
ChainConfigurationBase.ChainConfigurationBase.chainPartNameNoMult
chainPartNameNoMult
Definition: ChainConfigurationBase.py:40
ChainConfigurationBase.ChainConfigurationBase.chainPart
chainPart
Definition: ChainConfigurationBase.py:36
ChainConfigurationBase.ChainConfigurationBase.assembleChainImpl
def assembleChainImpl(self, flags)
Definition: ChainConfigurationBase.py:102
ChainConfigurationBase.ChainConfigurationBase.chainL1Item
chainL1Item
Definition: ChainConfigurationBase.py:30
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
ChainConfigurationBase.ChainConfigurationBase.chainPartNameNoMultwL1
chainPartNameNoMultwL1
Definition: ChainConfigurationBase.py:41
ChainConfigurationBase.ChainConfigurationBase.assembleChain
def assembleChain(self, flags)
Definition: ChainConfigurationBase.py:105
ChainConfigurationBase.ChainConfigurationBase
Definition: ChainConfigurationBase.py:18
str
Definition: BTagTrackIpAccessor.cxx:11
ChainConfigurationBase.ChainConfigurationBase.__init__
def __init__(self, chainDict)
Definition: ChainConfigurationBase.py:20
HLTSeedingConfig.mapThresholdToL1DecisionCollection
def mapThresholdToL1DecisionCollection(threshold)
Definition: HLTSeedingConfig.py:79
ChainConfigurationBase.ChainConfigurationBase.chainPartName
chainPartName
Definition: ChainConfigurationBase.py:39
WriteBchToCool.update
update
Definition: WriteBchToCool.py:67
ChainConfigurationBase.ChainConfigurationBase.getStep
def getStep(self, flags, stepName, sequenceCfgArray, comboHypoCfg=ComboHypoCfg, comboTools=[], **stepArgs)
Definition: ChainConfigurationBase.py:46