ATLAS Offline Software
Loading...
Searching...
No Matches
TrigDecisionCnvTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6// Gaudi/Athena include(s):
8
9// Trigger include(s):
14
15// Local include(s):
16#include "TrigDecisionCnvTool.h"
17
18namespace xAODMaker {
19
20 //
21 // This is a copy of the contents of TrigDecisionTool/Conditions.h until
22 // that header is moved to TrigDecisionInterface.
24 namespace TrigDefs {
25 // Conditions Mask elements
26 // -- we should do this with enum but there are issues with python
27 // so we'll code it as int for now.
28
29 const static unsigned int requireDecision = 0x1;
30 // ... otherwise ignore the decision
31 //const static unsigned int passedThrough = 0x1 << 1;
32 // ... otherwise ignore the passedThrough requirement
33 //const static unsigned int allowResurrectedDecision = 0x1 << 2;
34 // ... otherwise require that it wasn't resurrected
35 //
36 const static unsigned int enforceLogicalFlow = 0x1 << 5;
37 // ... otherwise we only care about this trigger level
38 //const static unsigned int eventAccepted = 0x1 << 6;
39 // ... an event was written out (useful for trigger rates)
40 //
41 //const static unsigned int ignoreIOV = 0x1 << 15;
42 //const static unsigned int alsoDeactivateTEs = 0x1 << 16;
43 //const static unsigned int ignoreFDR = 0x1 << 17;
44 //
45 const static unsigned int Physics = requireDecision | enforceLogicalFlow;
46 //const static unsigned int fullChain = enforceLogicalFlow;
47 // Bit location placeholders for isPassedBit()
48 const static unsigned int EF_passedRaw =0x1;
49 const static unsigned int EF_passThrough =0x1 << 1;
50 const static unsigned int EF_prescaled =0x1 << 2;
51 const static unsigned int EF_resurrected =0x1 << 3;
52 const static unsigned int L2_passedRaw =0x1 << 8;
53 const static unsigned int L2_passThrough =0x1 << 9;
54 const static unsigned int L2_prescaled =0x1 << 10;
55 const static unsigned int L2_resurrected =0x1 << 11;
56 //const static unsigned int L1_isPassedAfterPrescale = 0x1 << 16;
57 //const static unsigned int L1_isPassedBeforePrescale = 0x1 << 17;
58 //const static unsigned int L1_isPassedAfterVeto = 0x1 << 18;
59 //const static unsigned int EF_error = 0x1 << 19;
60 //const static unsigned int L2_error = 0x1 << 20;
61 }
62
64
68 static const uint32_t MAXIMUM_CHAIN_ID = 8192;
70 static const uint32_t BITSET_SIZE = MAXIMUM_CHAIN_ID / 32;
71
73 const std::string& name,
74 const IInterface* parent )
75 : AthAlgTool( type, name, parent ) {
76
77 // Declare the interface(s) provided by the tool:
78 declareInterface< ITrigDecisionCnvTool >( this );
79 }
80
81
84
85
87
88 ATH_MSG_INFO( "Using TrigConfigSvc: " << m_trigconf.typeAndName() );
89
90 // Retrieve the needed component(s):
91 CHECK( m_tdt.retrieve() );
92 CHECK( m_trigconf.retrieve() );
93
94 // Return gracefully:
95 return StatusCode::SUCCESS;
96 }
97
109 xAOD::TrigDecision* xaod, const TriggerInfo * triggerInfo) const {
110
111 ATH_MSG_DEBUG( "converting TrigDecision to xAOD::TrigDecision" );
112
113 // Copy the trigger configuration key:
114 xaod->setSMK( aod->masterKey() );
115
116 // Copy the LVL1 information:
117 xaod->setBGCode( aod->BGCode() );
118 ATH_MSG_DEBUG( "converting BGCode " << std::hex << (unsigned int) aod->BGCode() << " (size " << sizeof(aod->BGCode()) << "|" << sizeof(xaod->bgCode()) << ")" );
119
120 if( aod->getL1Result().isConfigured() ) {
121 ATH_MSG_DEBUG( "setting L1 info from old TrigDecision");
122 xaod->setTAV( aod->getL1Result().itemsAfterVeto() );
123 xaod->setTAP( aod->getL1Result().itemsAfterPrescale() );
124 xaod->setTBP( aod->getL1Result().itemsBeforePrescale() );
125 } else if( triggerInfo != nullptr ){
126 ATH_MSG_DEBUG( "setting L1 info from TriggerInfo (l1 size " << triggerInfo->level1TriggerInfo().size() << ")" );
127
128 uint32_t L1SIZE = triggerInfo->level1TriggerInfo().size()/3;
129 std::vector<uint32_t>::const_iterator begin, end;
130
131 begin = triggerInfo->level1TriggerInfo().begin();
132 end = begin;
133 std::advance(end,L1SIZE);
134 std::vector<uint32_t> tbp(begin,end);
135
136 begin = end;
137 std::advance(end,L1SIZE);
138 std::vector<uint32_t> tap(begin,end);
139
140 begin = end;
141 std::advance(end,L1SIZE);
142 std::vector<uint32_t> tav(begin,end);
143
144 xaod->setTAV( tav );
145 xaod->setTAP( tap );
146 xaod->setTBP( tbp );
147
148 ATH_MSG_DEBUG( "TBP size = " << xaod->tbp().size() );
149 ATH_MSG_DEBUG( "TAP size = " << xaod->tap().size() );
150 ATH_MSG_DEBUG( "TAV size = " << xaod->tav().size() );
151
152 } else {
153
154 ATH_MSG_DEBUG( "can not set L1 info as the old TrigDecision has no L1Result and there is no TriggerInfo available");
155
156 }
157
158 // Copy the basic HLT information:
159 xaod->setLVL2ErrorBits( aod->getL2Result().error_bits() );
160 xaod->setEFErrorBits ( aod->getEFResult().error_bits() );
163
164 //
165 // Construct the HLT decision bits using the TDT.
166 //
167
168 // The LVL2 bitsets:
169 std::vector< uint32_t > l2PassedPhysics( BITSET_SIZE, 0 );
170 std::vector< uint32_t > l2PassedRaw ( BITSET_SIZE, 0 );
171 std::vector< uint32_t > l2PassedThrough( BITSET_SIZE, 0 );
172 std::vector< uint32_t > l2Prescaled ( BITSET_SIZE, 0 );
173 std::vector< uint32_t > l2Resurrected ( BITSET_SIZE, 0 );
174
175 // The EF bitsets:
176 std::vector< uint32_t > efPassedPhysics( BITSET_SIZE, 0 );
177 std::vector< uint32_t > efPassedRaw ( BITSET_SIZE, 0 );
178 std::vector< uint32_t > efPassedThrough( BITSET_SIZE, 0 );
179 std::vector< uint32_t > efPrescaled ( BITSET_SIZE, 0 );
180 std::vector< uint32_t > efResurrected ( BITSET_SIZE, 0 );
181
182 // Get a list of all the HLT chains:
183 const TrigConf::HLTChainList& chains = m_trigconf->chains();
184
185 // Loop over all the chains:
186 TrigConf::HLTChainList::const_iterator chain_itr = chains.begin();
187 TrigConf::HLTChainList::const_iterator chain_end = chains.end();
188 for( ; chain_itr != chain_end; ++chain_itr ) {
189
190 // Decide whether to care about the chain or not:
191 if( static_cast< uint32_t >( ( *chain_itr )->chain_counter() )
192 >= MAXIMUM_CHAIN_ID ) {
193 continue;
194 }
195
196 // Create chain group (no regex parsing for speed)
197 const Trig::ChainGroup* group = m_tdt->getChainGroup( ( *chain_itr )->chain_name(),
199 // Get the decision for the chain:
200 const uint32_t bits = m_tdt->isPassedBits(group);
201
202 // Decide which level the chain is from:
203 if( ( *chain_itr )->level_enum() == TrigConf::L2 ) {
204 // Set the different decisions:
205 CHECK( setBit( l2PassedPhysics, ( *chain_itr )->chain_counter(),
206 m_tdt->isPassed( group, TrigDefs::Physics ) ) );
207 CHECK( setBit( l2PassedRaw, ( *chain_itr )->chain_counter(),
208 ( bits & TrigDefs::L2_passedRaw ) ) );
209 CHECK( setBit( l2PassedThrough, ( *chain_itr )->chain_counter(),
210 ( bits & TrigDefs::L2_passThrough ) ) );
211 CHECK( setBit( l2Prescaled, ( *chain_itr )->chain_counter(),
212 ( bits & TrigDefs::L2_prescaled ) ) );
213 CHECK( setBit( l2Resurrected, ( *chain_itr )->chain_counter(),
214 ( bits & TrigDefs::L2_resurrected ) ) );
215 }
216 // EF and HLT results are treated the same:
217 else {
218 // Set the different decisions:
219 CHECK( setBit( efPassedPhysics, ( *chain_itr )->chain_counter(),
220 m_tdt->isPassed( group, TrigDefs::Physics ) ) );
221 CHECK( setBit( efPassedRaw, ( *chain_itr )->chain_counter(),
222 ( bits & TrigDefs::EF_passedRaw ) ) );
223 CHECK( setBit( efPassedThrough, ( *chain_itr )->chain_counter(),
224 ( bits & TrigDefs::EF_passThrough ) ) );
225 CHECK( setBit( efPrescaled, ( *chain_itr )->chain_counter(),
226 ( bits & TrigDefs::EF_prescaled ) ) );
227 CHECK( setBit( efResurrected, ( *chain_itr )->chain_counter(),
228 ( bits & TrigDefs::EF_resurrected ) ) );
229 }
230 }
231
232 // Put the bit-patterns into the output object:
233 xaod->setLVL2PassedPhysics( l2PassedPhysics );
234 xaod->setLVL2PassedRaw ( l2PassedRaw );
235 xaod->setLVL2PassedThrough( l2PassedThrough );
236 xaod->setLVL2Prescaled ( l2Prescaled );
237 xaod->setLVL2Resurrected ( l2Resurrected );
238 xaod->setEFPassedPhysics( efPassedPhysics );
239 xaod->setEFPassedRaw ( efPassedRaw );
240 xaod->setEFPassedThrough( efPassedThrough );
241 xaod->setEFPrescaled ( efPrescaled );
242 xaod->setEFResurrected ( efResurrected );
243
244 // Return gracefully:
245 return StatusCode::SUCCESS;
246 }
247
248 StatusCode TrigDecisionCnvTool::setBit( std::vector< uint32_t >& bitset,
249 uint32_t chainId, bool value ) {
250
251 // Check if the operation will be successful:
252 if( ( chainId >= MAXIMUM_CHAIN_ID ) ||
253 ( bitset.size() < BITSET_SIZE ) ) {
254 return StatusCode::FAILURE;
255 }
256
257 // Decide which bit to modify exactly:
258 const size_t word = chainId / 32;
259 const size_t bit = chainId % 32;
260
261 if( value ) {
262 // Turn the bit on:
263 bitset[ word ] = bitset[ word ] | ( 0x1 << bit );
264 } else {
265 // Turn the bit off:
266 bitset[ word ] = bitset[ word ] & ( ~ ( 0x1 << bit ) );
267 }
268
269 // Everything went fine:
270 return StatusCode::SUCCESS;
271 }
272
273} // namespace xAODMaker
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
virtual uint32_t error_bits() const
bit flags to explain problems during processing
bool isHLTResultTruncated() const
is serialized HLTResult truncated
Definition HLTResult.h:242
bool isConfigured() const
is LVL1 configured ?
Definition Lvl1Result.h:39
const std::vector< uint32_t > & itemsAfterVeto() const
Definition Lvl1Result.h:57
const std::vector< uint32_t > & itemsAfterPrescale() const
Definition Lvl1Result.h:56
const std::vector< uint32_t > & itemsBeforePrescale() const
Definition Lvl1Result.h:55
list of all HLT chains in a trigger menu
The TrigDecision is an object which merges trigger informations from various levels.
const HLT::HLTResult & getEFResult() const
const HLT::HLTResult & getL2Result() const
This class contains trigger related information.
Definition TriggerInfo.h:77
const std::vector< number_type > & level1TriggerInfo() const
get level1 trigger info
TrigDecisionCnvTool(const std::string &type, const std::string &name, const IInterface *parent)
Regular AlgTool constructor.
ServiceHandle< TrigConf::IHLTConfigSvc > m_trigconf
Connection to the HLT configuration.
virtual StatusCode initialize() override
Function initialising the tool.
static StatusCode setBit(std::vector< uint32_t > &bitset, uint32_t chainId, bool value=true)
Function setting the status of one bit in a bitset.
virtual StatusCode convert(const TrigDec::TrigDecision *aod, xAOD::TrigDecision *xaod, const TriggerInfo *level1TriggerInfo) const final
Function filling an xAOD::TrigDecision object with information.
PublicToolHandle< Trig::TrigDecisionTool > m_tdt
Connection to the TrigDecisionTool.
void setLVL2Resurrected(const std::vector< uint32_t > &value)
Set the LVL2 resurrected bits.
void setTBP(const std::vector< uint32_t > &value)
Set the Trigger Before Prescale bits.
const std::vector< uint32_t > & tav() const
Get the Trigger After Veto bits.
void setEFPassedPhysics(const std::vector< uint32_t > &value)
Set the EF physics decision bits.
void setEFTruncated(bool value)
Set whether the EF result is truncated.
void setEFPrescaled(const std::vector< uint32_t > &value)
Set the EF prescaled bits.
void setLVL2Prescaled(const std::vector< uint32_t > &value)
Set the LVL2 prescaled bits.
void setEFPassedThrough(const std::vector< uint32_t > &value)
Set the EF pass-through bits.
void setEFResurrected(const std::vector< uint32_t > &value)
Set the EF resurrected bits.
const std::vector< uint32_t > & tap() const
Get the Trigger After Prescale bits.
void setLVL2PassedPhysics(const std::vector< uint32_t > &value)
Set the LVL2 physics decision bits.
void setLVL2PassedRaw(const std::vector< uint32_t > &value)
Set the LVL2 passed-raw bits.
char bgCode() const
Get the bunch group code of the current event.
void setEFPassedRaw(const std::vector< uint32_t > &value)
Set the EF passed-raw bits.
const std::vector< uint32_t > & tbp() const
Get the Trigger Before Prescale bits.
void setSMK(uint32_t value)
Set the Super Master Key describing this object.
void setLVL2PassedThrough(const std::vector< uint32_t > &value)
Set the LVL2 pass-through bits.
void setTAP(const std::vector< uint32_t > &value)
Set the Trigger After Prescale bits.
void setEFErrorBits(uint32_t value)
Set a summary of all errors that happened during the EF execution.
void setTAV(const std::vector< uint32_t > &value)
Set the Trigger After Veto bits.
void setLVL2Truncated(bool value)
Set whether the LVL2 result is truncated.
void setLVL2ErrorBits(uint32_t value)
Set a summary of all errors that happened during the LVL2 execution.
void setBGCode(char value)
Set the bunch group code of the current event.
@ NoRegex
Do not use regular expressions.
static const unsigned int EF_passedRaw
static const unsigned int EF_prescaled
static const unsigned int L2_passThrough
static const unsigned int EF_resurrected
static const unsigned int enforceLogicalFlow
static const unsigned int L2_passedRaw
static const unsigned int L2_resurrected
static const unsigned int L2_prescaled
static const unsigned int Physics
static const unsigned int EF_passThrough
static const unsigned int requireDecision
static const uint32_t BITSET_SIZE
Size of the bitset vectors.
static const uint32_t MAXIMUM_CHAIN_ID
The range in which we copy the trigger decision for the chains.
TrigDecision_v1 TrigDecision
Define the latest version of the trigger decision class.