diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/CommonSequences/EventBuildingSequenceSetup.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/CommonSequences/EventBuildingSequenceSetup.py index ba9d34e8bd225a65c8de6b68d7e9abab0e36c427..4bf4949af6622fa30afa41b1a92736a758c75027 100644 --- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/CommonSequences/EventBuildingSequenceSetup.py +++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/CommonSequences/EventBuildingSequenceSetup.py @@ -128,3 +128,38 @@ def pebSequence(eventBuildType, inputMaker): if findAlgorithm(seq, inputMaker.name()) != inputMaker: seq += inputMaker return seq + + +def findEventBuildingStep(chainConfig): + pebSteps = [s for s in chainConfig.steps if 'PEBInfoWriter' in s.name and 'EmptyPEBAlign' not in s.name] + if len(pebSteps) == 0: + return None + elif len(pebSteps) > 1: + raise RuntimeError('Multiple Event Building steps in one chain are not supported but found in chain ' + chainConfig.name) + return pebSteps[0] + + +def alignEventBuildingSteps(all_chains): + def is_peb(chainData): + return len(chainData[0]['eventBuildType']) > 0 + all_peb_chains = list(filter(is_peb, all_chains)) + maxPebStepPosition = {} # {eventBuildType: N} + def getPebStepPosition(chainConfig): + pebStep = findEventBuildingStep(chainConfig) + return chainConfig.steps.index(pebStep) + 1 + + # First loop to find the maximal PEB step positions to which we need to align + for chainDict, chainConfig, lengthOfChainConfigs in all_peb_chains: + pebStepPosition = getPebStepPosition(chainConfig) + ebt = chainDict['eventBuildType'] + if ebt not in maxPebStepPosition or pebStepPosition > maxPebStepPosition[ebt]: + maxPebStepPosition[ebt] = pebStepPosition + + # Second loop to insert empty steps before the PEB steps where needed + for chainDict, chainConfig, lengthOfChainConfigs in all_peb_chains: + pebStepPosition = getPebStepPosition(chainConfig) + ebt = chainDict['eventBuildType'] + if pebStepPosition < maxPebStepPosition[ebt]: + numStepsNeeded = maxPebStepPosition[ebt] - pebStepPosition + log.debug('Aligning PEB step for chain %s by adding %d empty steps', chainDict['chainName'], numStepsNeeded) + chainConfig.insertEmptySteps(chainDict,'EmptyPEBAlign', numStepsNeeded, pebStepPosition-1) diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/GenerateMenuMT.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/GenerateMenuMT.py index 8b6283e8a729cfa87a75997cb491ab84ffc42c23..fd6cedfbc4a87b37f260bd87b975ce8747e2e052 100755 --- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/GenerateMenuMT.py +++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/GenerateMenuMT.py @@ -17,6 +17,7 @@ from TriggerMenuMT.HLTMenuConfig.Menu.ChainDictTools import splitInterSignatureC from TriggerMenuMT.HLTMenuConfig.Menu.MenuPrescaleConfig import MenuPrescaleConfig, applyHLTPrescale from TriggerMenuMT.HLTMenuConfig.Menu.ChainMerging import mergeChainDefs from TriggerMenuMT.HLTMenuConfig.Menu.MenuAlignmentTools import analyseCombinations, groupSignatures, setChainSignatures +from TriggerMenuMT.HLTMenuConfig.CommonSequences import EventBuildingSequenceSetup from AthenaCommon.Logging import logging log = logging.getLogger( __name__ ) @@ -201,6 +202,9 @@ class GenerateMenuMT(object): for sig in list(set(chainDict['signatures'])): signatures_to_align.update([sig]) + # align event building sequences + EventBuildingSequenceSetup.alignEventBuildingSteps(all_chains) + #will likely always be true, but the grouping could be redefined groupPeskySignatures = True @@ -497,8 +501,7 @@ class GenerateMenuMT(object): eventBuildType = mainChainDict['eventBuildType'] if eventBuildType: log.debug('Configuring event building sequence %s for chain %s', eventBuildType, mainChainDict['chainName']) - from TriggerMenuMT.HLTMenuConfig.CommonSequences.EventBuildingSequenceSetup import addEventBuildingSequence - addEventBuildingSequence(theChainConfig, eventBuildType) + EventBuildingSequenceSetup.addEventBuildingSequence(theChainConfig, eventBuildType) log.debug('ChainConfigs %s ', theChainConfig) return theChainConfig,lengthOfChainConfigs