ATLAS Offline Software
TLABuildingSequences.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 #
4 import functools
5 from TriggerMenuMT.HLT.Config.MenuComponents import ChainStep
6 from AthenaCommon.Logging import logging
7 from ..Jet.JetChainConfiguration import JetChainConfiguration
8 from ..Photon.PrecisionPhotonTLAMenuSequenceConfig import PhotonTLAMenuSequenceGenCfg
9 from ..Jet.JetTLASequenceConfig import JetTLAMenuSequenceGenCfg
10 from ..Muon.MuonTLASequenceConfig import MuonTLAMenuSequenceGenCfg
11 from ..Config.MenuComponents import EmptyMenuSequence
12 log = logging.getLogger(__name__)
13 
14 
15 def addTLAStep(flags, chain, chainDict):
16  '''
17  Add one extra chain step for TLA Activities
18  '''
19 
20  tlaSequencesList = []
21  log.debug("addTLAStep: processing chain: %s", chainDict['chainName'])
22 
23 
24  for cPart in chainDict['chainParts']:
25  log.debug("addTLAStep: processing signature: %s", cPart['signature'] )
26  # call the sequence from their respective signatures
27  tlaSequencesList.append(functools.partial(getTLASignatureSequenceGenCfg, flags, chainDict=chainDict, chainPart=cPart))
28 
29  log.debug("addTLAStep: About to add a step with: %d parallel sequences.", len(tlaSequencesList))
30 
31  # we add one step per TLA chain, with sequences matching the list of signatures
32  # and multiplicities matching those of the previous step of the chain (already merged if combined)
33  prevStep = chain.steps[-1]
34  stepName = 'TLAStep_{:s}'.format(prevStep.name)
35  step = ChainStep(name = stepName,
36  SequenceGens = tlaSequencesList,
37  chainDicts = prevStep.stepDicts)
38 
39  log.debug("addTLAStep: About to add step %s ", stepName)
40  chain.steps.append(step)
41 
42 
43 
44 def getTLASignatureSequenceGenCfg(flags, chainDict, chainPart):
45  # Here we simply retrieve the TLA sequence from the existing signature code
46  signature= chainPart['signature']
47 
48  if signature == 'Photon':
49  photonOutCollectionName = "HLT_egamma_Photons"
50  return PhotonTLAMenuSequenceGenCfg(flags, photonsIn=photonOutCollectionName)
51 
52  elif signature == 'Muon':
53  return MuonTLAMenuSequenceGenCfg(flags, muChainPart=chainPart)
54 
55  elif signature == 'Jet':
56  # Use the jet reco machinery to define the jet collection
57  jetChainConfig = JetChainConfiguration(chainDict)
58  jetChainConfig.prepareDataDependencies(flags)
59  jetInputCollectionName = jetChainConfig.jetName
60  log.debug(f"TLA jet input collection = {jetInputCollectionName}")
61  return JetTLAMenuSequenceGenCfg(flags, jetsIn=jetInputCollectionName)
62  elif signature == 'MET':
63  return EmptyMenuSequence("EmptyMETTLA")
64 
65  else:
66  raise ValueError(f"Unsupported TLA signature: No TLA sequence specified for signature {signature}.")
67 
68 
69 def findTLAStep(chainConfig):
70  tlaSteps = [s for s in chainConfig.steps if 'TLAStep' in s.name and 'EmptyPEBAlign' not in s.name and 'EmptyTLAAlign' not in s.name and 'PEBInfoWriter' not in s.name]
71  if len(tlaSteps) == 0:
72  return None
73  elif len(tlaSteps) > 1:
74  raise RuntimeError('Multiple TLA steps in one chain are not supported. ', len(tlaSteps), ' were found in chain ' + chainConfig.name)
75  return tlaSteps[0]
76 
77 
78 def alignTLASteps(chain_configs, chain_dicts):
79 
80  TLAEventBuildTypes = ('PhysicsTLA', 'FTagPEBTLA', 'EgammaPEBTLA', 'DarkJetPEBTLA')
81  all_tla_chain_configs = [ch for ch in chain_configs if any(ebtype in chain_dicts[ch.name]['eventBuildType'] for ebtype in TLAEventBuildTypes)]
82 
83  def getTLAStepPosition(chainConfig):
84  tlaStep = findTLAStep(chainConfig)
85  log.debug('getTLAStepPosition found step %s and return %d',tlaStep,chainConfig.steps.index(tlaStep) + 1)
86  return chainConfig.steps.index(tlaStep) + 1
87 
88  # First loop to find the maximal TLA step positions to which we need to align
89  maxTLAStepPosition = 0 # {eventBuildType: N}
90  for chain in all_tla_chain_configs:
91  tlaStepPosition = getTLAStepPosition(chain)
92  if tlaStepPosition > maxTLAStepPosition:
93  maxTLAStepPosition = tlaStepPosition
94 
95  log.debug('maxTLAStepPosition=%d',maxTLAStepPosition)
96 
97  # Second loop to insert empty steps before the TLA steps where needed
98  for chain in all_tla_chain_configs:
99  tlaStepPosition = getTLAStepPosition(chain)
100  log.debug('Aligning TLA step at step %d for chain %s ', tlaStepPosition, chain.name)
101  if tlaStepPosition < maxTLAStepPosition:
102  numStepsNeeded = maxTLAStepPosition - tlaStepPosition
103  log.debug('Aligning TLA step for chain %s by adding %d empty steps', chain.name, numStepsNeeded)
104  chain.insertEmptySteps('EmptyTLAAlign', numStepsNeeded, tlaStepPosition-1)
105  chain.numberAllSteps()
vtune_athena.format
format
Definition: vtune_athena.py:14
PrecisionPhotonTLAMenuSequenceConfig.PhotonTLAMenuSequenceGenCfg
def PhotonTLAMenuSequenceGenCfg(flags, photonsIn)
Definition: PrecisionPhotonTLAMenuSequenceConfig.py:26
python.HLT.CommonSequences.TLABuildingSequences.addTLAStep
def addTLAStep(flags, chain, chainDict)
Definition: TLABuildingSequences.py:15
python.HLT.Jet.JetChainConfiguration.JetChainConfiguration
Definition: JetChainConfiguration.py:32
python.HLT.Jet.JetTLASequenceConfig.JetTLAMenuSequenceGenCfg
def JetTLAMenuSequenceGenCfg(flags, jetsIn)
Definition: JetTLASequenceConfig.py:32
python.HLT.CommonSequences.TLABuildingSequences.getTLASignatureSequenceGenCfg
def getTLASignatureSequenceGenCfg(flags, chainDict, chainPart)
Definition: TLABuildingSequences.py:44
python.HLT.CommonSequences.TLABuildingSequences.alignTLASteps
def alignTLASteps(chain_configs, chain_dicts)
Definition: TLABuildingSequences.py:78
python.HLT.CommonSequences.TLABuildingSequences.findTLAStep
def findTLAStep(chainConfig)
Definition: TLABuildingSequences.py:69
python.HLT.Muon.MuonTLASequenceConfig.MuonTLAMenuSequenceGenCfg
def MuonTLAMenuSequenceGenCfg(flags, muChainPart)
Definition: MuonTLASequenceConfig.py:40