ATLAS Offline Software
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 
18 namespace 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 
83  }
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
xAOD::TrigDecision_v1::setSMK
void setSMK(uint32_t value)
Set the Super Master Key describing this object.
xAOD::TrigDecision_v1::setLVL2ErrorBits
void setLVL2ErrorBits(uint32_t value)
Set a summary of all errors that happened during the LVL2 execution.
GroupProperties.h
HLTChainList.h
xAOD::TrigDecision_v1::setEFPassedPhysics
void setEFPassedPhysics(const std::vector< uint32_t > &value)
Set the EF physics decision bits.
TrigConf::L2
@ L2
Definition: HLTLevel.h:12
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
xAOD::TrigDecision_v1::setLVL2PassedRaw
void setLVL2PassedRaw(const std::vector< uint32_t > &value)
Set the LVL2 passed-raw bits.
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
LVL1CTP::Lvl1Result::isConfigured
bool isConfigured() const
is LVL1 configured ?
Definition: Lvl1Result.h:39
xAOD::TrigDecision_v1::setEFTruncated
void setEFTruncated(bool value)
Set whether the EF result is truncated.
TrigDec::TrigDecision::masterKey
uint32_t masterKey() const
Definition: Trigger/TrigEvent/TrigDecisionEvent/TrigDecisionEvent/TrigDecision.h:85
xAOD::TrigDecision_v1::tav
const std::vector< uint32_t > & tav() const
Get the Trigger After Veto bits.
xAODMaker::TrigDecisionCnvTool::initialize
virtual StatusCode initialize() override
Function initialising the tool.
Definition: TrigDecisionCnvTool.cxx:86
athena.value
value
Definition: athena.py:124
ChainGroup.h
xAODMaker
Definition: StoreGateSvc.h:72
TrigDec::TrigDecision
The TrigDecision is an object which merges trigger informations from various levels.
Definition: Trigger/TrigEvent/TrigDecisionEvent/TrigDecisionEvent/TrigDecision.h:61
xAOD::tap
setBGCode tap
Definition: TrigDecision_v1.cxx:43
xAOD::TrigDecision_v1::setLVL2PassedThrough
void setLVL2PassedThrough(const std::vector< uint32_t > &value)
Set the LVL2 pass-through bits.
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
LVL1CTP::Lvl1Result::itemsBeforePrescale
const std::vector< uint32_t > & itemsBeforePrescale() const
Definition: Lvl1Result.h:55
LVL1CTP::Lvl1Result::itemsAfterVeto
const std::vector< uint32_t > & itemsAfterVeto() const
Definition: Lvl1Result.h:57
TriggerInfo::level1TriggerInfo
const std::vector< number_type > & level1TriggerInfo() const
get level1 trigger info
Definition: TriggerInfo.cxx:143
xAOD::TrigDecision_v1::setEFPassedThrough
void setEFPassedThrough(const std::vector< uint32_t > &value)
Set the EF pass-through bits.
TrigDec::TrigDecision::BGCode
char BGCode() const
Definition: Trigger/TrigEvent/TrigDecisionEvent/TrigDecisionEvent/TrigDecision.h:86
TrigConf::HLTChainList
list of all HLT chains in a trigger menu
Definition: HLTChainList.h:56
TrigDecision.h
xAOD::TrigDecision_v1::setTAP
void setTAP(const std::vector< uint32_t > &value)
Set the Trigger After Prescale bits.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
HLT::HLTResult::isHLTResultTruncated
bool isHLTResultTruncated() const
is serialized HLTResult truncated
Definition: HLTResult.h:248
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::TrigDecision_v1::setTBP
void setTBP(const std::vector< uint32_t > &value)
Set the Trigger Before Prescale bits.
test_pyathena.parent
parent
Definition: test_pyathena.py:15
TrigDefs::Group::NoRegex
@ NoRegex
Do not use regular expressions.
HLT::HLTResult::error_bits
virtual uint32_t error_bits() const
bit flags to explain problems during processing
Definition: HLTResult.cxx:106
TrigDec::TrigDecision::getL1Result
const LVL1CTP::Lvl1Result & getL1Result() const
Definition: Trigger/TrigEvent/TrigDecisionEvent/TrigDecisionEvent/TrigDecision.h:88
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
xAOD::TrigDecision_v1::setTAV
void setTAV(const std::vector< uint32_t > &value)
Set the Trigger After Veto bits.
xAOD::TrigDecision_v1::setLVL2Resurrected
void setLVL2Resurrected(const std::vector< uint32_t > &value)
Set the LVL2 resurrected bits.
xAOD::TrigDecision_v1::setEFErrorBits
void setEFErrorBits(uint32_t value)
Set a summary of all errors that happened during the EF execution.
xAODMaker::TrigDecisionCnvTool::m_trigconf
ServiceHandle< TrigConf::IHLTConfigSvc > m_trigconf
Connection to the HLT configuration.
Definition: TrigDecisionCnvTool.h:62
xAODMaker::TrigDecisionCnvTool::TrigDecisionCnvTool
TrigDecisionCnvTool(const std::string &type, const std::string &name, const IInterface *parent)
Regular AlgTool constructor.
Definition: TrigDecisionCnvTool.cxx:72
xAODMaker::TrigDecisionCnvTool::convert
virtual StatusCode convert(const TrigDec::TrigDecision *aod, xAOD::TrigDecision *xaod, const TriggerInfo *level1TriggerInfo) const final
Function filling an xAOD::TrigDecision object with information.
Definition: TrigDecisionCnvTool.cxx:108
Trig::ChainGroup
Definition: ChainGroup.h:51
TrigDecisionCnvTool.h
TriggerInfo
This class contains trigger related information.
Definition: TriggerInfo.h:77
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TrigDec::TrigDecision::getEFResult
const HLT::HLTResult & getEFResult() const
Definition: TrigDecision.cxx:118
xAOD::TrigDecision_v1::tap
const std::vector< uint32_t > & tap() const
Get the Trigger After Prescale bits.
xAOD::TrigDecision_v1::setEFPrescaled
void setEFPrescaled(const std::vector< uint32_t > &value)
Set the EF prescaled bits.
xAOD::TrigDecision_v1::bgCode
char bgCode() const
Get the bunch group code of the current event.
python.copyTCTOutput.chains
chains
Definition: copyTCTOutput.py:81
xAODMaker::TrigDecisionCnvTool::~TrigDecisionCnvTool
virtual ~TrigDecisionCnvTool()
Definition: TrigDecisionCnvTool.cxx:82
CaloLCW_tf.group
group
Definition: CaloLCW_tf.py:28
TrigDefs
Definition: TrigEvent/TrigDecisionInterface/TrigDecisionInterface/Conditions.h:19
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::TrigDecision_v1::setEFPassedRaw
void setEFPassedRaw(const std::vector< uint32_t > &value)
Set the EF passed-raw bits.
xAODMaker::TrigDecisionCnvTool::m_tdt
PublicToolHandle< Trig::TrigDecisionTool > m_tdt
Connection to the TrigDecisionTool.
Definition: TrigDecisionCnvTool.h:59
xAOD::TrigDecision_v1::setLVL2PassedPhysics
void setLVL2PassedPhysics(const std::vector< uint32_t > &value)
Set the LVL2 physics decision bits.
xAOD::TrigDecision_v1::setLVL2Prescaled
void setLVL2Prescaled(const std::vector< uint32_t > &value)
Set the LVL2 prescaled bits.
xAOD::TrigDecision_v1::tbp
const std::vector< uint32_t > & tbp() const
Get the Trigger Before Prescale bits.
xAOD::TrigDecision_v1::setBGCode
void setBGCode(char value)
Set the bunch group code of the current event.
xAOD::TrigDecision_v1::setEFResurrected
void setEFResurrected(const std::vector< uint32_t > &value)
Set the EF resurrected bits.
AthAlgTool
Definition: AthAlgTool.h:26
TrigDec::TrigDecision::getL2Result
const HLT::HLTResult & getL2Result() const
Definition: TrigDecision.cxx:107
xAOD::TrigDecision_v1::setLVL2Truncated
void setLVL2Truncated(bool value)
Set whether the LVL2 result is truncated.
xAOD::TrigDecision_v1
Interface to the raw trigger decision information of the event.
Definition: TrigDecision_v1.h:44
xAODMaker::TrigDecisionCnvTool::setBit
static StatusCode setBit(std::vector< uint32_t > &bitset, uint32_t chainId, bool value=true)
Function setting the status of one bit in a bitset.
Definition: TrigDecisionCnvTool.cxx:248
LVL1CTP::Lvl1Result::itemsAfterPrescale
const std::vector< uint32_t > & itemsAfterPrescale() const
Definition: Lvl1Result.h:56