ATLAS Offline Software
Loading...
Searching...
No Matches
CTPUnpackingTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4#include "CTPUnpackingTool.h"
6#include "TrigT1Result/CTPResult.h" // TODO: Deprecate in favour of using new xAOD::CTPResult class
8
10
11#include <boost/algorithm/string.hpp>
12
13using namespace HLT;
14
15
17 const std::string& name,
18 const IInterface* parent )
19 : CTPUnpackingToolBase(type, name, parent) {}
20
21
23 ATH_CHECK( m_L1MenuKey.initialize() );
24 ATH_CHECK( m_HLTMenuKey.initialize() );
25 ATH_CHECK( m_ctpResultKey.initialize( m_useEDMxAOD ) );
26
27
29
30 return StatusCode::SUCCESS;
31}
32
33
35 ATH_MSG_INFO( "Updating CTP bits decoding configuration");
36
37 // iterate over all items and obtain the CPT ID for each item. Then, package that in the map: name -> CTP ID
38 ATH_MSG_INFO( "start(): use new L1 trigger menu" );
39 // Cleanup in case there was a stop/start transition
41 m_ctpToChain.clear();
42
43 auto l1menu = SG::makeHandle( m_L1MenuKey );
44 if( l1menu.isValid() ) {
45 for ( const TrigConf::L1Item & item: *l1menu ) {
46 m_itemNametoCTPIDMap[item.name()] = item.ctpId();
47 }
48 } else {
49 ATH_MSG_ERROR( "TrigConf::L1Menu does not exist" );
50 }
51
52 auto addIfItemExists = [&]( const std::string& itemName, HLT::Identifier id, bool warningOnly = false ) -> StatusCode {
53 if ( m_itemNametoCTPIDMap.find( itemName ) != m_itemNametoCTPIDMap.end() ) {
54 m_ctpToChain[ m_itemNametoCTPIDMap[itemName] ].push_back( id );
55 return StatusCode::SUCCESS;
56 }
57 if( warningOnly ) {
58 // this code should be removed after the L1 menu is migrated to the new json version
59 ATH_MSG_WARNING(itemName << " used to seed the chain " << id <<" not in the configuration ");
60 return StatusCode::SUCCESS;
61 }
62 ATH_MSG_ERROR(itemName << " used to seed the chain " << id <<" not in the configuration ");
63 return StatusCode::FAILURE;
64 };
65
67 ATH_CHECK( hltMenuHandle.isValid() );
68 for ( const TrigConf::Chain& chain: *hltMenuHandle ) {
69 HLT::Identifier chainID{ chain.name() };
70 if ( chain.l1item().empty() ) { // unseeded chain
71 m_ctpToChain[ s_CTPIDForUnseededChains ].push_back( chainID );
72 } else if ( chain.l1item().find(',') != std::string::npos ) { // OR seeds
73
74 std::vector<std::string> items;
75 boost::split(items, chain.l1item(), [](char c){return c == ',';});
76 for ( const std::string& i: items ) {
77 ATH_CHECK( addIfItemExists( i, chainID, true ) );
78 }
79 } else { // regular chain
80 ATH_CHECK( addIfItemExists( chain.l1item(), chainID ) );
81 }
82 }
83
84 for ( const auto& ctpIDtoChain: m_ctpToChain ) {
85 for ( auto chain: ctpIDtoChain.second ) {
86 ATH_MSG_DEBUG( "CTP seed of " << ctpIDtoChain.first << " enables chains " << chain );
87 }
88 }
89
90 return StatusCode::SUCCESS;
91}
92
93
94StatusCode CTPUnpackingTool::decode( const EventContext& ctx, const ROIB::RoIBResult& roib, HLT::IDVec& enabledChains ) const {
95 auto nItems = Monitored::Scalar( "Items", 0 );
96 auto nChains = Monitored::Scalar( "Chains", 0 );
97
98 std::vector<uint32_t> ctpBits;
99 if (m_useEDMxAOD) { // Need to make sure you can pick up the correct CTPResult in StoreGate
100
101 // Retrieve xAOD::CTPResult object
103 if (!ctpRes.isValid()) {
104 ATH_MSG_ERROR("Failed to retrieve CTPResult with key " << m_ctpResultKey.key());
105 return StatusCode::FAILURE;
106 };
107
108 // Get the appropriate trigger bits for L1A bunch
109 ctpBits = m_useTBPBit ? ctpRes->getTBPWords() : ctpRes->getTAVWords();
110
111 }
112 else {
113
114 // Get appropriate trigger bits from ROIB::CTPResult object in RoIBResult object
115 auto rois = m_useTBPBit ? roib.cTPResult().TBP() : roib.cTPResult().TAV();
116 ctpBits.reserve(rois.size());
117
118 // Trigger bits stored in vector of ROIB::CTPRoI objects (which are just uint32_t), need to convert to a vector of type uint32_t
119 std::transform(rois.begin(), rois.end(), std::back_inserter(ctpBits), [](const ROIB::CTPRoI& roi){ return roi.roIWord(); });
120
121 }
122 const size_t bitsSize = ctpBits.size();
123 constexpr static size_t wordSize{32};
124
125 for ( size_t wordCounter = 0; wordCounter < bitsSize; ++wordCounter ) {
126 for ( size_t bitCounter = 0; bitCounter < wordSize; ++bitCounter ) {
127 const size_t ctpIndex = wordSize*wordCounter + bitCounter;
128 const bool decision = ( ctpBits[wordCounter] & ((uint32_t)1 << bitCounter) ) > 0;
129
130 if ( decision or m_forceEnable ) {
131 if ( decision ) {
132 nItems = nItems + 1;
133 ATH_MSG_DEBUG("L1 item " << ctpIndex << " active, enabling chains "
134 << (m_forceEnable ? " due to the forceEnable flag" : " due to the seed"));
135 }
136
137 auto itr = m_ctpToChain.find( ctpIndex );
138 if ( itr != m_ctpToChain.end() ) {
139 enabledChains.insert( enabledChains.end(), itr->second.begin(), itr->second.end() );
140 }
141 }
142 }
143 }
144 // the unseeded chains are always enabled at this stage
145 const auto itr = m_ctpToChain.find( s_CTPIDForUnseededChains );
146 if ( itr != m_ctpToChain.cend() ) {
147 enabledChains.insert( enabledChains.end(), itr->second.begin(), itr->second.end());
148 }
149
150 nChains = enabledChains.size();
151 for ( auto chain: enabledChains ) {
152 ATH_MSG_DEBUG( "Enabling chain: " << chain );
153 }
154 if ( nItems == 0 ) {
155 ATH_MSG_ERROR( "All CTP bits were disabled, this event should not have shown here" );
156 return StatusCode::FAILURE;
157 }
158 Monitored::Group( m_monTool, nItems, nChains );
159 return StatusCode::SUCCESS;
160}
161
162
164 const std::vector<std::string>& l1ItemNames,
165 bool& pass) const {
166
167 pass = false;
168
169 const auto ctpBits = roib->cTPResult().TBP();
170
171 for (const std::string& l1name : l1ItemNames) {
172 try {
173 // Retrieve before prescale decision
174 const size_t ctpId = m_itemNametoCTPIDMap.at(l1name);
175 const size_t bitCounter = ctpId % 32;
176 const size_t wordCounter = ctpId / 32;
177
178 const bool decision = (ctpBits[wordCounter].roIWord() & ((uint32_t)1 << bitCounter)) > 0;
179
180 pass = (pass || decision);
181 }
182 catch (const std::exception& e) {
183 ATH_MSG_ERROR ( l1name << " is not part of L1Menu!" );
184 return StatusCode::FAILURE;
185 }
186 }
187
188 return StatusCode::SUCCESS;
189}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Header file to be included by clients of the Monitored infrastructure.
CTPUnpackingToolBase(const std::string &type, const std::string &name, const IInterface *parent)
ToolHandle< GenericMonitoringTool > m_monTool
std::unordered_map< int, HLT::IDVec > m_ctpToChain
virtual StatusCode initialize() override
static constexpr int s_CTPIDForUnseededChains
Gaudi::Property< bool > m_forceEnable
SG::ReadHandleKey< xAOD::CTPResult > m_ctpResultKey
SG::ReadHandleKey< TrigConf::HLTMenu > m_HLTMenuKey
virtual StatusCode passBeforePrescaleSelection(const ROIB::RoIBResult *roib, const std::vector< std::string > &l1ItemNames, bool &pass) const override
CTPUnpackingTool(const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode start() override
SG::ReadHandleKey< TrigConf::L1Menu > m_L1MenuKey
virtual StatusCode initialize() override
Gaudi::Property< bool > m_useTBPBit
std::map< std::string, size_t > m_itemNametoCTPIDMap
Gaudi::Property< bool > m_useEDMxAOD
virtual StatusCode decode(const EventContext &ctx, const ROIB::RoIBResult &roib, HLT::IDVec &enabledChains) const override
Fills the list of chains that should be activated in a given event (note HLT prescaling happens at a ...
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
const std::vector< CTPRoI > TBP() const
get trigger result before prescale
const std::vector< CTPRoI > TAV() const
get trigger result after veto
ROIB::CTPRoI contains a RoI delivered by the CTP.
Definition CTPRoI.h:28
Class holding the LVL1 RoIB result build by the RoIBuilder.
Definition RoIBResult.h:47
const CTPResult & cTPResult() const
Gets the CTP part of the L1 RDO.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
L1 threshold configuration.
Definition L1Item.h:18
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
std::vector< HLT::Identifier > IDVec
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())