From 3a42b0bb924597c6ab5668ae7af5c4cd3e677ac6 Mon Sep 17 00:00:00 2001 From: Rafal Bielski <rafal.bielski@cern.ch> Date: Fri, 7 Oct 2022 23:18:58 +0200 Subject: [PATCH 1/2] Add new RoI creator tool for extra ROB prefetching in TauCore sequence --- .../src/ViewCreatorExtraPrefetchROITool.cxx | 52 +++++++++++++++++++ .../src/ViewCreatorExtraPrefetchROITool.h | 39 ++++++++++++++ .../components/DecisionHandling_entries.cxx | 2 + .../python/TriggerConfigFlags.py | 4 +- .../python/HLT/Config/MenuComponents.py | 9 +++- .../python/HLT/Tau/TauRecoSequences.py | 21 +++++++- 6 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 Trigger/TrigSteer/DecisionHandling/src/ViewCreatorExtraPrefetchROITool.cxx create mode 100644 Trigger/TrigSteer/DecisionHandling/src/ViewCreatorExtraPrefetchROITool.h diff --git a/Trigger/TrigSteer/DecisionHandling/src/ViewCreatorExtraPrefetchROITool.cxx b/Trigger/TrigSteer/DecisionHandling/src/ViewCreatorExtraPrefetchROITool.cxx new file mode 100644 index 000000000000..5aefdd66af41 --- /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 000000000000..00810934973b --- /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 8130bc9c9e23..23939e592207 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 6b5462364fde..eee21c9ddf61 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 0721fd31840d..6b93d02821c4 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 ca97f4ea406d..0dcf6853e14d 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,24 @@ 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: + prefetchRoIUpdater = CompFactory.RoiUpdaterTool() + prefetchRoIUpdater.useBeamSpot = True + prefetchRoIUpdater.NSigma = 1.5 + prefetchRoIUpdater.EtaWidth = 0.4 + prefetchRoIUpdater.PhiWidth = 0.4 + prefetchRoIUpdater.ZedWidth = 7 + 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 +326,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) -- GitLab From 8c36cdb4f9da650940509b98cc6eeba291c1d49c Mon Sep 17 00:00:00 2001 From: Rafal Bielski <rafal.bielski@cern.ch> Date: Tue, 11 Oct 2022 22:38:19 +0200 Subject: [PATCH 2/2] Use TrigInDetConfig to set prefetchRoIUpdater eta, phi, zed half-widths --- .../TriggerMenuMT/python/HLT/Tau/TauRecoSequences.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLT/Tau/TauRecoSequences.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLT/Tau/TauRecoSequences.py index 0dcf6853e14d..a833da700d0d 100644 --- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLT/Tau/TauRecoSequences.py +++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLT/Tau/TauRecoSequences.py @@ -303,12 +303,15 @@ def tauFTFCoreSequence(flags): 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 = 0.4 - prefetchRoIUpdater.PhiWidth = 0.4 - prefetchRoIUpdater.ZedWidth = 7 + prefetchRoIUpdater.EtaWidth = tauIsoConfig.etaHalfWidth + prefetchRoIUpdater.PhiWidth = tauIsoConfig.phiHalfWidth + prefetchRoIUpdater.ZedWidth = tauIsoConfig.zedHalfWidth prefetchRoITool = CompFactory.ViewCreatorExtraPrefetchROITool() prefetchRoITool.RoiCreator = newRoITool prefetchRoITool.RoiUpdater = prefetchRoIUpdater -- GitLab