From 098fb34b01c87db75aa8e26fd8747cb7b09b2af7 Mon Sep 17 00:00:00 2001 From: Teng Jian Khoo <teng.jian.khoo@cern.ch> Date: Mon, 29 Mar 2021 19:15:26 +0000 Subject: [PATCH] ATR-23011 -- Type-checking of "flags" argument to RecoFragmentsPool.retrieve --- .../Jet/JetRecConfig/python/JetDefinition.py | 2 +- .../python/TrigGenericAlgsConfig.py | 2 +- .../TrigT2CaloCommon/python/CaloDef.py | 18 ++--- .../HLTMenuConfig/Egamma/PrecisionCaloRec.py | 2 +- .../Jet/JetChainConfiguration.py | 2 +- .../HLTMenuConfig/Jet/JetTLASequences.py | 10 +-- .../HLTMenuConfig/MET/METRecoSequences.py | 69 ++++++++++++------- .../HLTMenuConfig/Menu/MenuComponents.py | 8 ++- .../HLTMenuConfig/Tau/TauRecoSequences.py | 4 +- 9 files changed, 72 insertions(+), 45 deletions(-) diff --git a/Reconstruction/Jet/JetRecConfig/python/JetDefinition.py b/Reconstruction/Jet/JetRecConfig/python/JetDefinition.py index b822f2737b9..416206121b7 100644 --- a/Reconstruction/Jet/JetRecConfig/python/JetDefinition.py +++ b/Reconstruction/Jet/JetRecConfig/python/JetDefinition.py @@ -110,7 +110,7 @@ class JetDefinition(object): def __hash__(self): - return hash((self.__radius,self.__inputdef,self.ptmin,str(self.ghostdefs),str(self.modifiers),str(self.extrainputs))) + return hash((self._radius,self._inputdef,self.ptmin,str(self.ghostdefs),str(self.modifiers),str(self.extrainputs))) def __eq__(self,rhs): return self.__hash__() == rhs.__hash__() diff --git a/Trigger/TrigAlgorithms/TrigGenericAlgs/python/TrigGenericAlgsConfig.py b/Trigger/TrigAlgorithms/TrigGenericAlgs/python/TrigGenericAlgsConfig.py index 60b1620367a..695fc6b536c 100644 --- a/Trigger/TrigAlgorithms/TrigGenericAlgs/python/TrigGenericAlgsConfig.py +++ b/Trigger/TrigAlgorithms/TrigGenericAlgs/python/TrigGenericAlgsConfig.py @@ -23,4 +23,4 @@ def TimeBurnerHypoToolGen(chainDict): def PassthroughComboHypoCfg(name): - return CompFactory.PassthroughComboHypo(name) \ No newline at end of file + return CompFactory.PassthroughComboHypo(name) diff --git a/Trigger/TrigAlgorithms/TrigT2CaloCommon/python/CaloDef.py b/Trigger/TrigAlgorithms/TrigT2CaloCommon/python/CaloDef.py index bbb4276fc8c..f7b39bbe7c0 100644 --- a/Trigger/TrigAlgorithms/TrigT2CaloCommon/python/CaloDef.py +++ b/Trigger/TrigAlgorithms/TrigT2CaloCommon/python/CaloDef.py @@ -112,36 +112,36 @@ def clusterFSInputMaker( ): return InputMakerAlg -def HLTCellMaker(RoIs=caloFSRoI, outputName="CaloCells", algSuffix=""): +def HLTCellMaker(ConfigFlags,RoIs=caloFSRoI, outputName="CaloCells", algSuffix=""): cellMakerAlgo = _algoHLTCaloCell(name="HLTCaloCellMaker"+algSuffix, inputEDM=RoIs, outputEDM=outputName, RoIMode=True) return cellMakerAlgo -def HLTFSCellMakerRecoSequence(RoIs=caloFSRoI): - cellMaker = HLTCellMaker(RoIs, outputName="CaloCellsFS", algSuffix="FS") +def HLTFSCellMakerRecoSequence(ConfigFlags,RoIs=caloFSRoI): + cellMaker = HLTCellMaker(ConfigFlags, RoIs, outputName="CaloCellsFS", algSuffix="FS") RecoSequence = parOR("ClusterRecoSequenceFS", [cellMaker]) return (RecoSequence, cellMaker.CellsName) -def HLTFSTopoRecoSequence(RoIs): - cellMaker = HLTCellMaker(RoIs, outputName="CaloCellsFS", algSuffix="FS") +def HLTFSTopoRecoSequence(ConfigFlags,RoIs): + cellMaker = HLTCellMaker(ConfigFlags, RoIs, outputName="CaloCellsFS", algSuffix="FS") topoClusterMaker = _algoHLTTopoCluster(inputEDM = cellMaker.CellsName, algSuffix="FS") RecoSequence = parOR("TopoClusterRecoSequenceFS", [cellMaker, topoClusterMaker]) return (RecoSequence, topoClusterMaker.CaloClusters) -def HLTRoITopoRecoSequence(RoIs): +def HLTRoITopoRecoSequence(ConfigFlags, RoIs): import AthenaCommon.CfgMgr as CfgMgr HLTRoITopoRecoSequenceVDV = CfgMgr.AthViews__ViewDataVerifier("HLTRoITopoRecoSequenceVDV") HLTRoITopoRecoSequenceVDV.DataObjects = [( 'TrigRoiDescriptorCollection' , 'StoreGateSvc+PrecisionCaloRoIs' ), ( 'CaloBCIDAverage' , 'StoreGateSvc+CaloBCIDAverage' )] - cellMaker = HLTCellMaker(RoIs, algSuffix="RoI") + cellMaker = HLTCellMaker(ConfigFlags, RoIs, algSuffix="RoI") topoClusterMaker = _algoHLTTopoCluster(inputEDM = cellMaker.CellsName, algSuffix="RoI") RecoSequence = parOR("RoITopoClusterRecoSequence", [HLTRoITopoRecoSequenceVDV, cellMaker, topoClusterMaker]) return (RecoSequence, topoClusterMaker.CaloClusters) -def HLTLCTopoRecoSequence(RoIs='InViewRoIs'): - cellMaker = HLTCellMaker(RoIs, outputName="CaloCellsLC", algSuffix="LC") +def HLTLCTopoRecoSequence(ConfigFlags, RoIs='InViewRoIs'): + cellMaker = HLTCellMaker(ConfigFlags, RoIs, outputName="CaloCellsLC", algSuffix="LC") topoClusterMaker = _algoHLTTopoClusterLC(inputEDM = cellMaker.CellsName, algSuffix="LC") RecoSequence = parOR("TopoClusterRecoSequenceLC",[cellMaker,topoClusterMaker]) return (RecoSequence, topoClusterMaker.CaloClusters) diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Egamma/PrecisionCaloRec.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Egamma/PrecisionCaloRec.py index ee2ecf9dd89..0b472891bf5 100644 --- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Egamma/PrecisionCaloRec.py +++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Egamma/PrecisionCaloRec.py @@ -26,7 +26,7 @@ def precisionCaloRecoSequence(DummyFlag, RoIs): doAdd = False ) from TrigT2CaloCommon.CaloDef import HLTRoITopoRecoSequence - (precisionRecoSequence, caloclusters) = RecoFragmentsPool.retrieve(HLTRoITopoRecoSequence, RoIs) + (precisionRecoSequence, caloclusters) = RecoFragmentsPool.retrieve(HLTRoITopoRecoSequence, None, RoIs=RoIs) algo = egammaTopoClusterCopier() algo.InputTopoCollection = caloclusters diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetChainConfiguration.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetChainConfiguration.py index c26084f8187..61bd0d291e5 100644 --- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetChainConfiguration.py +++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetChainConfiguration.py @@ -194,7 +194,7 @@ class JetChainConfiguration(ChainConfigurationBase): from TriggerMenuMT.HLTMenuConfig.Jet.JetTLASequences import jetTLAMenuSequence stepName = "TLAStep_"+jetCollectionName - jetSeq = RecoFragmentsPool.retrieve( jetTLAMenuSequence, jetCollectionName ) + jetSeq = RecoFragmentsPool.retrieve( jetTLAMenuSequence, None, jetsin=jetCollectionName ) from TrigGenericAlgs.TrigGenericAlgsConfig import PassthroughComboHypoCfg chainStep = ChainStep(stepName, [jetSeq], multiplicity=[1], chainDicts=[self.dict], comboHypoCfg=PassthroughComboHypoCfg) diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetTLASequences.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetTLASequences.py index 8ecf1caf2f8..951d05a8063 100644 --- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetTLASequences.py +++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Jet/JetTLASequences.py @@ -7,7 +7,7 @@ from AthenaCommon.CFElements import parOR, seqAND from GaudiKernel.Constants import WARNING #this can eventually become a TLA/PEB sequence, but let's start with TLA only -def jetTLASequence(jetsin): +def jetTLASequence(flags, jetsin): #make a new reco sequence, empty at this point now recoSeq = parOR("JetTLASeq_"+jetsin, []) @@ -22,24 +22,24 @@ def jetTLASequence(jetsin): return (recoSeq, sequenceOut) #Configure an AthSequence for jet TLA - will eventually also include PEB -def jetTLAAthSequence(jetsin): +def jetTLAAthSequence(flags, jetsin): from AthenaConfiguration.ComponentFactory import CompFactory InputMakerAlg = CompFactory.InputMakerForRoI( "IM_Jet_TLAStep" ) InputMakerAlg.RoITool = CompFactory.ViewCreatorInitialROITool() InputMakerAlg.mergeUsingFeature = True - (JetTLASequence, sequenceOut) = RecoFragmentsPool.retrieve( jetTLASequence, jetsin ) + (JetTLASequence, sequenceOut) = RecoFragmentsPool.retrieve( jetTLASequence, flags, jetsin=jetsin ) JetTLAAthSequence = seqAND("jetTLAAthSequence_"+jetsin,[InputMakerAlg, JetTLASequence ]) return (JetTLAAthSequence, InputMakerAlg, sequenceOut) -def jetTLAMenuSequence(jetsin): +def jetTLAMenuSequence(flags, jetsin): from TrigHLTJetHypo.TrigHLTJetHypoConf import TrigJetTLAHypoAlgMT from TrigHLTJetHypo.TrigJetHypoToolConfig import trigJetTLAHypoToolFromDict - (JetTLAAthSequence, InputMakerAlg, sequenceOut) = RecoFragmentsPool.retrieve(jetTLAAthSequence,jetsin) + (JetTLAAthSequence, InputMakerAlg, sequenceOut) = RecoFragmentsPool.retrieve(jetTLAAthSequence,flags,jetsin=jetsin) hypo = TrigJetTLAHypoAlgMT("TrigJetTLAHypoAlgMT_"+jetsin) hypo.Jets = sequenceOut diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/METRecoSequences.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/METRecoSequences.py index 446481da4cb..c9442641ff3 100644 --- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/METRecoSequences.py +++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/MET/METRecoSequences.py @@ -222,14 +222,19 @@ class MergedPFOInputConfig(AlgInputConfig): def dependencies(self, recoDict): return ["PFOPrefix", "cPFOs", "nPFOs"] + def create_sequence(self, inputs, RoIs, recoDict): + # Alg generator for RecoFragmentsPool + # Need to unpack dict as not hashable + def getPFOPrepAlg(_,**inputs): + return HLT__MET__PFOPrepAlg( + f"{inputs['PFOPrefix']}METTrigPFOPrepAlg", + InputNeutralKey=inputs["nPFOs"], + InputChargedKey=inputs["cPFOs"], + OutputKey=f"{inputs['PFOPrefix']}METTrigCombinedParticleFlowObjects", + OutputCategoryKey="PUClassification") prepAlg = RecoFragmentsPool.retrieve( - HLT__MET__PFOPrepAlg, - f"{inputs['PFOPrefix']}METTrigPFOPrepAlg", - InputNeutralKey=inputs["nPFOs"], - InputChargedKey=inputs["cPFOs"], - OutputKey=f"{inputs['PFOPrefix']}METTrigCombinedParticleFlowObjects", - OutputCategoryKey="PUClassification", + getPFOPrepAlg,None,**inputs ) return ( [prepAlg], @@ -252,26 +257,44 @@ class CVFClusterInputConfig(AlgInputConfig): def create_sequence(self, inputs, RoIs, recoDict): trkopt = "ftf" + # Alg generator for RecoFragmentsPool + # Need to unpack dict as not hashable + # We can only use ** once, so manually + # extract the inputs + def getCVFAlg(_,inputClusters,inputTracks,inputVertices,**recoDict): + return HLT__MET__CVFAlg( + f"{recoDict['calib']}{trkopt}ClusterCVFAlg", + InputClusterKey=inputClusters, + InputTrackKey=inputTracks, + InputVertexKey=inputVertices, + OutputCVFKey="CVF", + TrackSelectionTool=InDet__InDetTrackSelectionTool(CutLevel="TightPrimary"), + TVATool=CP__TrackVertexAssociationTool( + WorkingPoint="Custom", d0_cut=2.0, dzSinTheta_cut=2.0, + TrackContName = inputTracks, + ), + ExtensionTool=ApproximateTrackToLayerTool() + ) cvfAlg = RecoFragmentsPool.retrieve( - HLT__MET__CVFAlg, - f"{recoDict['calib']}{trkopt}ClusterCVFAlg", - InputClusterKey=inputs["Clusters"], - InputTrackKey=inputs["Tracks"], - InputVertexKey=inputs["Vertices"], - OutputCVFKey="CVF", - TrackSelectionTool=InDet__InDetTrackSelectionTool(CutLevel="TightPrimary"), - TVATool=CP__TrackVertexAssociationTool( - WorkingPoint="Custom", d0_cut=2.0, dzSinTheta_cut=2.0, - TrackContName = inputs["Tracks"], - ), - ExtensionTool=ApproximateTrackToLayerTool(), + getCVFAlg,None, + inputClusters=inputs["Clusters"], + inputTracks=inputs["Tracks"], + inputVertices=inputs["Vertices"], + **recoDict ) + + def getCVFPrepAlg(_,inputClusters,inputCVFKey,**recoDict): + return HLT__MET__CVFPrepAlg( + f"{recoDict['calib']}{trkopt}ClusterCVFPrepAlg", + InputClusterKey=inputClusters, + InputCVFKey=inputCVFKey, + OutputCategoryKey="PUClassification" + ) prepAlg = RecoFragmentsPool.retrieve( - HLT__MET__CVFPrepAlg, - f"{recoDict['calib']}{trkopt}ClusterCVFPrepAlg", - InputClusterKey=inputs["Clusters"], - InputCVFKey=cvfAlg.OutputCVFKey, - OutputCategoryKey="PUClassification", + getCVFPrepAlg,None, + inputClusters=inputs["Clusters"], + inputCVFKey=cvfAlg.OutputCVFKey, + **recoDict ) return ( [cvfAlg, prepAlg], diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/MenuComponents.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/MenuComponents.py index d4bf12d89a7..e11ea0024cc 100644 --- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/MenuComponents.py +++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/MenuComponents.py @@ -276,13 +276,13 @@ class ComboMaker(AlgNode): self.mult=list(multiplicity) self.legIds = list(legIds) self.comboHypoCfg = comboHypoCfg - Alg = RecoFragmentsPool.retrieve( self.create, name ) + Alg = self.create(name) log.debug("ComboMaker init: Alg %s", name) AlgNode.__init__(self, Alg, 'HypoInputDecisions', 'HypoOutputDecisions') def create (self, name): log.debug("ComboMaker.create %s",name) - return self.comboHypoCfg(name) + return self.comboHypoCfg(name=name) def addChain(self, chainDict): chainName = chainDict['chainName'] @@ -1017,6 +1017,10 @@ class RecoFragmentsPool(object): bound.apply_defaults() return dict(bound.arguments) + from AthenaConfiguration.AthConfigFlags import AthConfigFlags + if not(isinstance(flags,AthConfigFlags) or flags is None): + raise TypeError("RecoFragmentsPool: First argument for creator function passed to retrieve() must be of type ConfigFlags or None") + allargs = bind_callargs(creator, flags, **kwargs) # First arg is flags, which we don't want to depend on firstkey = list(allargs.keys())[0] diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Tau/TauRecoSequences.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Tau/TauRecoSequences.py index 8a088f6653c..525b236670b 100644 --- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Tau/TauRecoSequences.py +++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Tau/TauRecoSequences.py @@ -154,7 +154,7 @@ def _algoTauPrecisionMVA(inputRoIs, tracks, step): def tauCaloRecoSequence(InViewRoIs, SeqName): global TauCaloJetContainer # lc sequence - (lcTopoInViewSequence, lcCaloSequenceOut) = RecoFragmentsPool.retrieve(HLTLCTopoRecoSequence, InViewRoIs) + (lcTopoInViewSequence, lcCaloSequenceOut) = RecoFragmentsPool.retrieve(HLTLCTopoRecoSequence, None, RoIs=InViewRoIs) tauCaloRoiUpdaterAlg = _algoTauRoiUpdater(inputRoIs = InViewRoIs, clusters = lcCaloSequenceOut) updatedRoIs = tauCaloRoiUpdaterAlg.RoIOutputKey tauCaloOnlyAlg = _algoTauCaloOnly(L1RoIs = InViewRoIs,inputRoIs = updatedRoIs, clusters = lcCaloSequenceOut) @@ -164,7 +164,7 @@ def tauCaloRecoSequence(InViewRoIs, SeqName): def tauCaloMVARecoSequence(InViewRoIs, SeqName): global TauCaloJetContainer # lc sequence - (lcTopoInViewSequence, lcCaloSequenceOut) = RecoFragmentsPool.retrieve(HLTLCTopoRecoSequence, InViewRoIs) + (lcTopoInViewSequence, lcCaloSequenceOut) = RecoFragmentsPool.retrieve(HLTLCTopoRecoSequence, None, RoIs=InViewRoIs) tauCaloRoiUpdaterAlg = _algoTauRoiUpdater(inputRoIs = InViewRoIs, clusters = lcCaloSequenceOut) updatedRoIs = tauCaloRoiUpdaterAlg.RoIOutputKey tauCaloOnlyMVAAlg = _algoTauCaloOnlyMVA(L1RoIs = InViewRoIs,inputRoIs = updatedRoIs, clusters = lcCaloSequenceOut) -- GitLab