ATLAS Offline Software
Loading...
Searching...
No Matches
HLTSeeding.cxx
Go to the documentation of this file.
1
2/*
3 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4*/
5
6#include "HLTSeeding.h"
10
12#include "GaudiKernel/EventContext.h"
13
15
16HLTSeeding::HLTSeeding(const std::string& name, ISvcLocator* pSvcLocator)
17 : AthReentrantAlgorithm(name, pSvcLocator) {}
18
19
21 ATH_MSG_INFO( "Reading RoIB information from: " << m_RoIBResultKey.objKey() << " : "
22 << m_RoIBResultKey.fullKey() << " : " << m_RoIBResultKey.key() );
23
24 if ( m_RoIBResultKey.empty() && m_l1TriggerResultKey.empty() ) {
25 ATH_MSG_INFO( "RoIBResult and L1TriggerResult keys both empty: assume we're running with CTP emulation" );
26 }
27
28 ATH_CHECK( m_RoIBResultKey.initialize(!m_RoIBResultKey.empty()) );
30
31 ATH_CHECK( m_summaryKey.initialize() );
32 ATH_CHECK( m_startStampKey.initialize() );
33
34 ATH_CHECK( m_ctpUnpacker.retrieve() );
35 ATH_CHECK( m_roiUnpackers_roib.retrieve() );
36 ATH_CHECK( m_roiUnpackers_xaod.retrieve() );
37 ATH_CHECK( m_prescaler.retrieve() );
38
39 if ( !m_keyWriterTool.empty() ) {
40 ATH_CHECK( m_keyWriterTool.retrieve() );
41 }
42
43 if ( !m_consistencyChecker.empty() ) {
44 ATH_CHECK( m_consistencyChecker.retrieve() );
45 }
46
48 ATH_CHECK( m_trigCostSvcHandle.retrieve() );
49 }
50
51 if ( m_roiZedWidthDefault!=0 ) {
52 ATH_MSG_INFO( "CHANGING THE DEFAULT ROI Z WIDTH: " << m_roiZedWidthDefault );
54 }
55
56 return StatusCode::SUCCESS;
57}
58
59
60StatusCode HLTSeeding::execute (const EventContext& ctx) const {
61 {
62 auto timeStampHandle = SG::makeHandle( m_startStampKey, ctx );
63 ATH_CHECK( timeStampHandle.record( std::make_unique<TrigTimeStamp>() ) );
64 }
65 using namespace TrigCompositeUtils;
66 const bool decodeRoIB = !m_RoIBResultKey.empty();
67 const bool decodexAOD = !m_l1TriggerResultKey.empty();
68
69 const ROIB::RoIBResult* roib = nullptr;
70 if (decodeRoIB) {
72 roib = roibH.cptr();
73 ATH_MSG_DEBUG( "Obtained RoIBResult" );
74 }
75
76 const xAOD::TrigComposite* l1TriggerResult = nullptr;
77 if (decodexAOD) {
78 auto l1TriggerResultCont = SG::makeHandle(m_l1TriggerResultKey, ctx);
79 if (!l1TriggerResultCont.isValid()) {
80 ATH_MSG_ERROR("Failed to retrieve L1TriggerResult with key " << m_l1TriggerResultKey.key());
81 return StatusCode::FAILURE;
82 }
83 if (l1TriggerResultCont->size() != 1) {
84 ATH_MSG_ERROR("Size of the L1TriggerResultContainer is " << l1TriggerResultCont->size() << " but 1 expected");
85 return StatusCode::FAILURE;
86 }
87 l1TriggerResult = l1TriggerResultCont->at(0);
88 if (msgLvl(MSG::DEBUG)) {
89 const std::vector<std::string>& linkNames = l1TriggerResult->linkColNames();
90 const std::vector<uint32_t>& linkClids = l1TriggerResult->linkColClids();
91 ATH_MSG_DEBUG("L1TriggerResult has " << linkNames.size() << " links:");
92 for (size_t i=0; i<linkNames.size(); ++i) {
93 ATH_MSG_DEBUG("--> " << linkNames.at(i) << " CLID: " << linkClids.at(i));
94 }
95 }
96 }
97
99 auto *chainsInfo = handle.ptr();
100
101 HLT::IDVec l1SeededChains;
102 if (decodeRoIB) {
103 ATH_CHECK( m_ctpUnpacker->decode( ctx, *roib, l1SeededChains ) );
104 } else if (m_ctpUnpacker->isEmulated()) {
105 ATH_CHECK( m_ctpUnpacker->decode( ctx, ROIB::RoIBResult{}, l1SeededChains ) );
106 }
107
108 // important: sorting of the list of seeded chains is needed so that the deduplication and following set difference are correct
109 std::sort( l1SeededChains.begin(), l1SeededChains.end() );
110
111 // Multiple items can seed some chains, remove duplicates from the sorted vector
112 HLT::IDVec::iterator removeFrom = std::unique(l1SeededChains.begin(), l1SeededChains.end());
113 l1SeededChains.erase(removeFrom, l1SeededChains.end());
114
115 HLT::IDVec activeChains; // Chains which are activated to run in the first pass (seeded and pass prescale)
116 HLT::IDVec prescaledChains; // Chains which are activated but do not run in the first pass (seeded but prescaled out)
117
118 ATH_CHECK( m_prescaler->prescaleChains( ctx, l1SeededChains, activeChains ) );
119
120 // important: sorting of the list of active chains is needed so that the set difference is correct
121 std::sort( activeChains.begin(), activeChains.end() );
122
123 std::set_difference(l1SeededChains.begin(), l1SeededChains.end(),
124 activeChains.begin(), activeChains.end(),
125 std::back_inserter(prescaledChains));
126
127 // Validation
128 for (const HLT::Identifier& id : prescaledChains) {
129 if (std::find(activeChains.begin(), activeChains.end(), id) != activeChains.end()) {
130 ATH_MSG_ERROR("Prescaled chain cannot also be an active chain (" << id << ")");
131 }
132 }
133
134 ATH_CHECK( saveChainsInfo( l1SeededChains, chainsInfo, "l1seeded" ) );
135 ATH_CHECK( saveChainsInfo( activeChains, chainsInfo, "unprescaled" ) );
136 ATH_CHECK( saveChainsInfo( prescaledChains, chainsInfo, "prescaled" ) );
137 // Note: 'prescaled' is deduced from 'l1seeded' and 'unprescaled'.
138
139 // Do cost monitoring, this utilises the HLT_costmonitor chain
140 if (m_doCostMonitoring) {
141 const static HLT::Identifier costMonitorChain(m_costMonitoringChain);
142 const auto activeCostMonIt = std::find(activeChains.begin(), activeChains.end(), costMonitorChain);
143 if (activeCostMonIt == activeChains.end()){
144 ATH_CHECK(m_trigCostSvcHandle->discardEvent(ctx));
145 }
146 }
147
148 ATH_MSG_DEBUG( "Unpacking RoIs" );
149 HLT::IDSet activeChainSet( activeChains.begin(), activeChains.end() );
150 if (decodeRoIB) {
151 for ( auto unpacker: m_roiUnpackers_roib ) {
152 ATH_CHECK( unpacker->unpack( ctx, *roib, activeChainSet ) );
153 }
154 } else if (m_ctpUnpacker->isEmulated()) {
155 ROIB::RoIBResult roib{};
156 for ( auto unpacker: m_roiUnpackers_roib ) {
157 ATH_CHECK( unpacker->unpack( ctx, roib, activeChainSet ) );
158 }
159 }
160 if (decodexAOD) {
161 for ( auto unpacker: m_roiUnpackers_xaod ) {
162 try {
163 ATH_CHECK( unpacker->unpack( ctx, *l1TriggerResult, activeChainSet ) );
164 } catch (const std::exception& ex) {
165 ATH_MSG_ERROR("Exception in " << unpacker->name() << "::unpack: " << ex.what());
166 return StatusCode::FAILURE;
167 }
168 }
169 }
170
171 if ( !m_keyWriterTool.empty() ) {
172 ATH_CHECK( m_keyWriterTool->writeKeys(ctx) );
173 }
174
175 if ( !m_consistencyChecker.empty() ) {
176 ATH_CHECK( m_consistencyChecker->consistencyCheck(l1SeededChains, ctx) );
177 }
178
179 return StatusCode::SUCCESS;
180}
181
182
183StatusCode HLTSeeding::saveChainsInfo(const HLT::IDVec& chains,
185 const std::string& type) {
186 using namespace TrigCompositeUtils;
187 Decision* d = newDecisionIn( storage, type );
188 for ( auto c: chains) {
189 addDecisionID(c.numeric(), d);
190 }
191 return StatusCode::SUCCESS;
192}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Decision * newDecisionIn(DecisionContainer *dc, const std::string &name="")
Helper method to create a Decision object, place it in the container and return a pointer to it.
Handle class for recording to StoreGate.
void addDecisionID(DecisionID id, Decision *d)
Appends the decision (given as ID) to the decision object.
bool msgLvl(const MSG::Level lvl) const
An algorithm that can be simultaneously executed in multiple threads.
virtual StatusCode execute(const EventContext &ctx) const override
ToolHandle< TrigConf::IKeyWriterTool > m_keyWriterTool
Definition HLTSeeding.h:89
ToolHandle< L1DataConsistencyChecker > m_consistencyChecker
Definition HLTSeeding.h:92
ServiceHandle< ITrigCostSvc > m_trigCostSvcHandle
Definition HLTSeeding.h:74
static StatusCode saveChainsInfo(const HLT::IDVec &chains, xAOD::TrigCompositeContainer *storage, const std::string &type)
ToolHandleArray< IRoIsUnpackingTool > m_roiUnpackers_xaod
Definition HLTSeeding.h:83
ToolHandle< ICTPUnpackingTool > m_ctpUnpacker
Definition HLTSeeding.h:77
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_l1TriggerResultKey
Level-1 result with RoIs from Run-3 hardware systems.
Definition HLTSeeding.h:49
SG::ReadHandleKey< ROIB::RoIBResult > m_RoIBResultKey
Definition HLTSeeding.h:45
Gaudi::Property< std::string > m_costMonitoringChain
Definition HLTSeeding.h:64
virtual StatusCode initialize() override
SG::WriteHandleKey< TrigCompositeUtils::DecisionContainer > m_summaryKey
Definition HLTSeeding.h:52
ToolHandleArray< IRoIsUnpackingTool > m_roiUnpackers_roib
Definition HLTSeeding.h:80
Gaudi::Property< float > m_roiZedWidthDefault
Definition HLTSeeding.h:69
HLTSeeding(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteHandleKey< TrigTimeStamp > m_startStampKey
Definition HLTSeeding.h:55
ToolHandle< IPrescalingTool > m_prescaler
Definition HLTSeeding.h:86
Gaudi::Property< bool > m_doCostMonitoring
Definition HLTSeeding.h:61
Class holding the LVL1 RoIB result build by the RoIBuilder.
Definition RoIBResult.h:47
static double zedWidthDefault()
const_pointer_type cptr()
Dereference the pointer.
pointer_type ptr()
Dereference the pointer.
const std::vector< std::string > & linkColNames() const
Raw access to the persistent link names.
const std::vector< uint32_t > & linkColClids() const
Raw access to the persistent link CLIDs.
std::vector< HLT::Identifier > IDVec
std::set< HLT::Identifier > IDSet
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
DataModel_detail::iterator< DVL > unique(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of unique for DataVector/List.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
TrigCompositeContainer_v1 TrigCompositeContainer
Declare the latest version of the container.
TrigComposite_v1 TrigComposite
Declare the latest version of the class.