diff --git a/Trigger/TrigSteer/DecisionHandling/src/ViewCreatorExtraPrefetchROITool.cxx b/Trigger/TrigSteer/DecisionHandling/src/ViewCreatorExtraPrefetchROITool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..5aefdd66af4189472fbc996acafb4a00e881fee4 --- /dev/null +++ b/Trigger/TrigSteer/DecisionHandling/src/ViewCreatorExtraPrefetchROITool.cxx @@ -0,0 +1,52 @@ +/* + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration +*/ +#include "ViewCreatorExtraPrefetchROITool.h" + +ViewCreatorExtraPrefetchROITool::ViewCreatorExtraPrefetchROITool(const std::string& type, const std::string& name, const IInterface* parent) +: base_class(type, name, parent) {} + +StatusCode ViewCreatorExtraPrefetchROITool::initialize() { + ATH_CHECK(m_extraRoiWHK.initialize()); + ATH_CHECK(m_roiCreator.retrieve()); + ATH_CHECK(m_roiUpdater.retrieve()); + return StatusCode::SUCCESS; +} + +StatusCode ViewCreatorExtraPrefetchROITool::attachROILinks(TrigCompositeUtils::DecisionContainer& decisions, const EventContext& eventContext) const { + using namespace TrigCompositeUtils; + + // Call the main RoI creator tool + ATH_CHECK(m_roiCreator->attachROILinks(decisions, eventContext)); + + // Record the updated RoI container + SG::WriteHandle<TrigRoiDescriptorCollection> outputRois = createAndStoreNoAux(m_extraRoiWHK, eventContext); + + // Loop over all decisions and create updated RoI for each RoI linked by the main tool + for (Decision* decision : decisions) { + // Get the original RoI from the main tool + const ElementLink<TrigRoiDescriptorCollection> roiEL = decision->objectLink<TrigRoiDescriptorCollection>(roiString()); + ATH_CHECK(roiEL.isValid()); + const TrigRoiDescriptor* originalRoi = *roiEL; + + // Execute the updater tool + std::unique_ptr<TrigRoiDescriptor> updatedRoi = m_roiUpdater->execute(originalRoi, eventContext); + + // Add the updated (and merged if requested) RoI to the output container + if (m_mergeWithOriginal.value()) { + outputRois->push_back(std::make_unique<TrigRoiDescriptor>()); + outputRois->back()->setComposite(true); + outputRois->back()->manageConstituents(true); // take ownership of the two objects added below + outputRois->back()->push_back(new TrigRoiDescriptor(*originalRoi)); + outputRois->back()->push_back(updatedRoi.release()); + } else { + outputRois->push_back(std::move(updatedRoi)); + } + + // Link the last element of the output container to the current decision object + const ElementLink<TrigRoiDescriptorCollection> newRoiEL{*outputRois, outputRois->size()-1, eventContext}; + decision->setObjectLink(m_extraRoiLinkName, newRoiEL); + } + + return StatusCode::SUCCESS; +} diff --git a/Trigger/TrigSteer/DecisionHandling/src/ViewCreatorExtraPrefetchROITool.h b/Trigger/TrigSteer/DecisionHandling/src/ViewCreatorExtraPrefetchROITool.h new file mode 100644 index 0000000000000000000000000000000000000000..00810934973bda0493dd344ab7117231d73beaaf --- /dev/null +++ b/Trigger/TrigSteer/DecisionHandling/src/ViewCreatorExtraPrefetchROITool.h @@ -0,0 +1,39 @@ +/* + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration +*/ +#ifndef DECISIONHANDLING_VIEWCREATOREXTRAPREFETCHROITOOL_H +#define DECISIONHANDLING_VIEWCREATOREXTRAPREFETCHROITOOL_H + +#include "DecisionHandling/IViewCreatorROITool.h" +#include "HLTSeeding/IRoiUpdaterTool.h" + +#include "AthenaBaseComps/AthAlgTool.h" +#include "StoreGate/WriteHandleKey.h" +#include "TrigSteeringEvent/TrigRoiDescriptorCollection.h" + +/** + * @class ViewCreatorExtraPrefetchROITool + * RoI provider wrapper tool which calls another RoI provider tool first, and then uses its output RoI + * to create a new RoI using the RoiUpdaterTool. This new RoI is saved in a different output container + * and can be used to prefetch ROBs instead of the original one. This solution was invented to prefetch + * ROBs for the second Tau reco step already during the first Tau reco step, see ATR-26419. + **/ +class ViewCreatorExtraPrefetchROITool : public extends<AthAlgTool, IViewCreatorROITool> { +public: + ViewCreatorExtraPrefetchROITool(const std::string& type, const std::string& name, const IInterface* parent); + virtual StatusCode initialize() override; + virtual StatusCode attachROILinks(TrigCompositeUtils::DecisionContainer& decisions, const EventContext& eventContext) const override; + +private: + SG::WriteHandleKey<TrigRoiDescriptorCollection> m_extraRoiWHK{ + this, "ExtraPrefetchRoIsKey", "", "Name of the extra RoI collection to be used for prefetching"}; + Gaudi::Property<std::string> m_extraRoiLinkName{ + this, "PrefetchRoIsLinkName", "prefetchRoI", "Name of the link from a decision object to the RoI for prefetching"}; + Gaudi::Property<bool> m_mergeWithOriginal{ + this, "MergeWithOriginal", true, "Make the output RoI be a super-RoI combining the original and updated ones"}; + + ToolHandle<IViewCreatorROITool> m_roiCreator { this, "RoiCreator", "", "The main RoI creator tool" }; + ToolHandle<IRoiUpdaterTool> m_roiUpdater { this, "RoiUpdater", "", "RoI Updater" }; +}; + +#endif // DECISIONHANDLING_VIEWCREATOREXTRAPREFETCHROITOOL_H diff --git a/Trigger/TrigSteer/DecisionHandling/src/components/DecisionHandling_entries.cxx b/Trigger/TrigSteer/DecisionHandling/src/components/DecisionHandling_entries.cxx index 8130bc9c9e23f5f48b44f852dfcfdb73d2c0dbed..23939e5922077e86646ecaaf0d8f93d2d029e316 100644 --- a/Trigger/TrigSteer/DecisionHandling/src/components/DecisionHandling_entries.cxx +++ b/Trigger/TrigSteer/DecisionHandling/src/components/DecisionHandling_entries.cxx @@ -12,6 +12,7 @@ #include "../ViewCreatorPreviousROITool.h" #include "../ViewCreatorNamedROITool.h" #include "../ViewCreatorFSROITool.h" +#include "../ViewCreatorExtraPrefetchROITool.h" #include "../ViewCreatorFetchFromViewROITool.h" #include "../ViewCreatorCentredOnIParticleROITool.h" #include "../ViewCreatorCentredOnClusterROITool.h" @@ -44,6 +45,7 @@ DECLARE_COMPONENT( ViewCreatorInitialROITool ) DECLARE_COMPONENT( ViewCreatorPreviousROITool ) DECLARE_COMPONENT( ViewCreatorNamedROITool ) DECLARE_COMPONENT( ViewCreatorFSROITool ) +DECLARE_COMPONENT( ViewCreatorExtraPrefetchROITool ) DECLARE_COMPONENT( ViewCreatorFetchFromViewROITool ) DECLARE_COMPONENT( ViewCreatorCentredOnIParticleROITool ) DECLARE_COMPONENT( ViewCreatorCentredOnClusterROITool ) diff --git a/Trigger/TriggerCommon/TriggerJobOpts/python/TriggerConfigFlags.py b/Trigger/TriggerCommon/TriggerJobOpts/python/TriggerConfigFlags.py index 6b5462364fdede2e5ec8f0e281a940b9f3a86183..eee21c9ddf610cb4bb2d5b49ca77e99b2e353af9 100644 --- a/Trigger/TriggerCommon/TriggerJobOpts/python/TriggerConfigFlags.py +++ b/Trigger/TriggerCommon/TriggerJobOpts/python/TriggerConfigFlags.py @@ -14,6 +14,8 @@ class ROBPrefetching(FlagEnum): StepRoI = 'StepRoI' # Enable mapping chains' first step to pre-HLT prefetching rules based on initial RoIs InitialRoI = 'InitialRoI' + # Enable using larger RoI in TauCore step to speculatively prefetch ROBs for the subsequent TauIso step (ATR-26419) + TauCoreLargeRoI = 'TauCoreLargeRoI' def createTriggerFlags(doTriggerRecoFlags): flags = AthConfigFlags() @@ -91,7 +93,7 @@ def createTriggerFlags(doTriggerRecoFlags): flags.addFlag('Trigger.doRuntimeNaviVal', False) # Select ROBPrefetching options, out of ROBPrefetching enum, empty list means no prefetching - flags.addFlag('Trigger.ROBPrefetchingOptions', [ROBPrefetching.InitialRoI, ROBPrefetching.StepRoI]) + flags.addFlag('Trigger.ROBPrefetchingOptions', [ROBPrefetching.InitialRoI, ROBPrefetching.StepRoI, ROBPrefetching.TauCoreLargeRoI]) # if 1, Run1 decoding version is set; if 2, Run2; if 3, Run 3 def EDMVersion(flags): diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLT/Config/MenuComponents.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLT/Config/MenuComponents.py index 0721fd31840d4c9e2f7b390e18f638b6b127974c..6b93d02821c4c0c34d11d8de4ee228d019f06a5e 100644 --- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLT/Config/MenuComponents.py +++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLT/Config/MenuComponents.py @@ -461,8 +461,13 @@ class MenuSequence(object): probeIM.Views = baseIM.Views.Path + "_probe" probeIM.RoITool = baseIM.RoITool probeIM.InputCachedViews = baseIM.InputMakerOutputDecisions - if hasattr(baseIM.RoITool,"RoisWriteHandleKey") and baseIM.RoITool.RoisWriteHandleKey.Path!="StoreGateSvc+": - probeIM.RoITool.RoisWriteHandleKey = baseIM.RoITool.RoisWriteHandleKey.Path + "_probe" + def updateHandle(baseTool, probeTool, handleName): + if hasattr(baseTool, handleName) and getattr(baseTool, handleName).Path!="StoreGateSvc+": + setattr(probeTool, handleName, getattr(baseTool, handleName).Path + "_probe") + updateHandle(baseIM.RoITool, probeIM.RoITool, "RoisWriteHandleKey") + if hasattr(baseIM.RoITool, "RoiCreator"): + updateHandle(baseIM.RoITool, probeIM.RoITool, "ExtraPrefetchRoIsKey") + updateHandle(baseIM.RoITool.RoiCreator, probeIM.RoITool.RoiCreator, "RoisWriteHandleKey") else: raise TypeError(f"Probe leg input maker may not be of type '{baseIM.__class__}'.") diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLT/Tau/TauRecoSequences.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLT/Tau/TauRecoSequences.py index ca97f4ea406ddf042c721b8199c98699166f635e..a833da700d0d93febfbd16d484dcaf871706b1e0 100644 --- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLT/Tau/TauRecoSequences.py +++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLT/Tau/TauRecoSequences.py @@ -4,12 +4,14 @@ from AthenaCommon.CFElements import parOR, seqAND from AthenaCommon.GlobalFlags import globalflags +from AthenaConfiguration.ComponentFactory import CompFactory from ViewAlgs.ViewAlgsConf import EventViewCreatorAlgorithm from DecisionHandling.DecisionHandlingConf import ViewCreatorInitialROITool, ViewCreatorFetchFromViewROITool, ViewCreatorPreviousROITool from TrigT2CaloCommon.CaloDef import HLTLCTopoRecoSequence from TrigEDMConfig.TriggerEDMRun3 import recordable from TriggerMenuMT.HLT.Config.MenuComponents import RecoFragmentsPool, algorithmCAToGlobalWrapper from TrigGenericAlgs.TrigGenericAlgsConfig import ROBPrefetchingAlgCfg_Si, ROBPrefetchingAlgCfg_Calo +from TriggerJobOpts.TriggerConfigFlags import ROBPrefetching import AthenaCommon.CfgMgr as CfgMgr @@ -299,9 +301,27 @@ def tauFTFCoreSequence(flags): newRoITool.RoisWriteHandleKey = recordable("HLT_Roi_TauCore") #RoI collection recorded to EDM newRoITool.InViewRoIs = "UpdatedCaloRoI" #input RoIs from calo only step + extraPrefetching = ROBPrefetching.TauCoreLargeRoI in flags.Trigger.ROBPrefetchingOptions + if extraPrefetching: + # Add extra RoI to prefetch ROBs for the subsequent tauIso step together with ROBs for tauCore + from TrigInDetConfig.ConfigSettings import getInDetTrigConfig + tauIsoConfig = getInDetTrigConfig("tauIso") + prefetchRoIUpdater = CompFactory.RoiUpdaterTool() + prefetchRoIUpdater.useBeamSpot = True + prefetchRoIUpdater.NSigma = 1.5 + prefetchRoIUpdater.EtaWidth = tauIsoConfig.etaHalfWidth + prefetchRoIUpdater.PhiWidth = tauIsoConfig.phiHalfWidth + prefetchRoIUpdater.ZedWidth = tauIsoConfig.zedHalfWidth + prefetchRoITool = CompFactory.ViewCreatorExtraPrefetchROITool() + prefetchRoITool.RoiCreator = newRoITool + prefetchRoITool.RoiUpdater = prefetchRoIUpdater + prefetchRoITool.ExtraPrefetchRoIsKey = str(newRoITool.RoisWriteHandleKey) + "_forPrefetching" + prefetchRoITool.PrefetchRoIsLinkName = "prefetchRoI" + prefetchRoITool.MergeWithOriginal = True + ftfCoreViewsMaker = EventViewCreatorAlgorithm("IMFTFCore") ftfCoreViewsMaker.mergeUsingFeature = True - ftfCoreViewsMaker.RoITool = newRoITool + ftfCoreViewsMaker.RoITool = prefetchRoITool if extraPrefetching else newRoITool ftfCoreViewsMaker.InViewRoIs = "RoiForTauCore" ftfCoreViewsMaker.Views = "TAUFTFCoreViews" ftfCoreViewsMaker.ViewFallThrough = True @@ -309,6 +329,8 @@ def tauFTFCoreSequence(flags): ftfCoreViewsMaker.ViewNodeName = RecoSequenceName robPrefetchAlg = algorithmCAToGlobalWrapper(ROBPrefetchingAlgCfg_Si, flags, nameSuffix=ftfCoreViewsMaker.name())[0] + if extraPrefetching: + robPrefetchAlg.RoILinkName = str(prefetchRoITool.PrefetchRoIsLinkName) (tauFTFCoreInViewSequence, sequenceOut) = tauFTFSequence( ftfCoreViewsMaker.InViewRoIs, RecoSequenceName)