ATLAS Offline Software
TriggerBitsMakerTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
7 #include "GaudiKernel/IAlgExecStateSvc.h"
8 
9 #include <algorithm>
10 
11 TriggerBitsMakerTool::TriggerBitsMakerTool(const std::string& type, const std::string& name, const IInterface* parent) :
12  base_class(type, name, parent){}
13 
15 
16  ATH_CHECK( m_finalChainDecisions.initialize() );
18 
19  return StatusCode::SUCCESS;
20 }
21 
24  ATH_CHECK( hltMenuHandle.isValid() );
25  ATH_MSG_INFO("Configuring from " << m_HLTMenuKey << " with " << hltMenuHandle->size() << " chains");
26 
27  m_mapping.clear();
28  m_largestBit = 0;
29  for (const TrigConf::Chain& ch : *hltMenuHandle) {
30  ATH_MSG_DEBUG( "Chain " << ch.name() << " will flip " << ch.counter() << " bit" );
31  ATH_CHECK(preInsertCheck(ch.name(), ch.counter()));
32  ATH_CHECK(hashConsistencyCheck(ch.name(), ch.namehash()));
33  m_mapping[ HLT::Identifier( ch.name() ).numeric() ] = ch.counter();
34  m_largestBit = std::max(m_largestBit, ch.counter());
35  }
36 
37  // This block allows extra mappings to be supplied by python, e.g. for testing purposes
38  for (const auto& chainAndBit: m_extraChainToBit ) {
39  struct { std::string chain; uint32_t bit; } conf { chainAndBit.first, chainAndBit.second };
40  ATH_MSG_DEBUG( "Extra Chain " << conf.chain << " will flip " << conf.bit << " bit" );
41  ATH_CHECK(preInsertCheck(conf.chain, conf.bit));
42  m_mapping[ HLT::Identifier( conf.chain ).numeric() ] = conf.bit;
44  }
45 
46  return StatusCode::SUCCESS;
47 }
48 
49 
50 StatusCode TriggerBitsMakerTool::hashConsistencyCheck(const std::string& chain, const size_t hash) const {
51  if (HLT::Identifier( chain ).numeric() != hash) {
52  ATH_MSG_ERROR("Inconsistent hashes found for chain:" << chain << ", from Python:" << hash
53  << ", from C++:" << HLT::Identifier( chain ).numeric());
54  return StatusCode::FAILURE;
55  }
56  return StatusCode::SUCCESS;
57 }
58 
59 StatusCode TriggerBitsMakerTool::preInsertCheck(const std::string& chain, const uint32_t bit) const {
60  const auto checkIt = std::find_if(
61  m_mapping.begin(), m_mapping.end(),
62  [&](const std::pair<TrigCompositeUtils::DecisionID, uint32_t>& m) { return m.second == bit; }
63  );
64  if (checkIt != m_mapping.end()) {
65  ATH_MSG_ERROR( "Multiple chains " << HLT::Identifier(checkIt->first)
66  << " and " << chain << " are both configured with ChainCounter:" << bit);
67  return StatusCode::FAILURE;
68  }
69  if (chain.empty()) {
70  ATH_MSG_ERROR( "Trying to register an empty string as a Chain." );
71  return StatusCode::FAILURE;
72  }
73  return StatusCode::SUCCESS;
74 }
75 
76 StatusCode TriggerBitsMakerTool::getBits(boost::dynamic_bitset<uint32_t>& passRaw,
77  boost::dynamic_bitset<uint32_t>& prescaled,
78  const EventContext& ctx) const
79 {
80  using namespace TrigCompositeUtils;
81 
82  passRaw.clear();
83  prescaled.clear();
84 
85  auto chainsHandle = SG::makeHandle(m_finalChainDecisions, ctx);
86  if (!chainsHandle.isValid()) {
87  SmartIF<IAlgExecStateSvc> aess = svcLoc()->service<IAlgExecStateSvc>("AlgExecStateSvc", false);
88  if (aess.isValid() && aess->eventStatus(ctx) != EventStatus::Success) {
89  ATH_MSG_WARNING("Failed event, " << m_finalChainDecisions.key() << " is unavailable. Skipping trigger bits making.");
90  return StatusCode::SUCCESS;
91  }
92  ATH_MSG_ERROR("Unable to read in the " << m_finalChainDecisions.key() << " from the DecisionSummaryMakerAlg");
93  return StatusCode::FAILURE;
94  }
95 
96  passRaw.resize(m_largestBit + 1);
97  prescaled.resize(m_largestBit + 1);
98 
99  const Decision* HLTPassRaw = nullptr;
100  const Decision* HLTPrescaled = nullptr;
101 
102  DecisionIDContainer passRawIDs;
103  DecisionIDContainer prescaledIDs;
104 
105  // Read the sets of chain IDs
106  for (const Decision* decisionObject : *chainsHandle) {
107  // Collect all decisions (IDs of passed/prescaled chains) from named decisionObjects
108  if (decisionObject->name() == TrigCompositeUtils::summaryPassNodeName()) {
109  HLTPassRaw = decisionObject;
110  } else if (decisionObject->name() == TrigCompositeUtils::summaryPrescaledNodeName()) {
111  HLTPrescaled = decisionObject;
112  }
113  if (HLTPassRaw != nullptr && HLTPrescaled != nullptr) {
114  break;
115  }
116  }
117 
118  ATH_CHECK(HLTPassRaw != nullptr);
119  ATH_CHECK(HLTPrescaled != nullptr);
120 
121  decisionIDs(HLTPassRaw, passRawIDs);
122  decisionIDs(HLTPrescaled, prescaledIDs);
123 
124  for ( DecisionID chain: passRawIDs ) {
125  ATH_CHECK(setBit(chain, passRaw));
126  }
127 
128  for ( DecisionID chain: prescaledIDs ) {
129  ATH_CHECK(setBit(chain, prescaled));
130  }
131 
132  return StatusCode::SUCCESS;
133 
134 }
135 
136 StatusCode TriggerBitsMakerTool::fill( HLT::HLTResultMT& resultToFill, const EventContext& ctx ) const {
137 
138  {
139  boost::dynamic_bitset<uint32_t> passRaw;
140  boost::dynamic_bitset<uint32_t> prescaled;
141 
142  ATH_CHECK(getBits(passRaw, prescaled, ctx));
143  resultToFill.setHltBits(passRaw, prescaled);
144  }
145 
146  if ( msgLvl( MSG::DEBUG ) ) {
147  const boost::dynamic_bitset<uint32_t>& passRawBits = resultToFill.getHltPassRawBits();
148  std::vector<uint32_t> bitsTemp(passRawBits.num_blocks());
149  boost::to_block_range(passRawBits, bitsTemp.begin());
150  ATH_MSG_VERBOSE("HLT result now has " << bitsTemp.size() << " words with HLT pass raw bits:");
151  for (const auto& w : bitsTemp) ATH_MSG_VERBOSE("0x" << MSG::hex << w << MSG::dec);
152  //
153  const boost::dynamic_bitset<uint32_t>& prescaleBits = resultToFill.getHltPrescaledBits();
154  boost::to_block_range(prescaleBits, bitsTemp.begin());
155  ATH_MSG_VERBOSE("HLT result now has " << bitsTemp.size() << " words with HLT prescale bits:");
156  for (const auto& w : bitsTemp) ATH_MSG_VERBOSE("0x" << MSG::hex << w << MSG::dec);
157  //
158  const std::vector<uint32_t>& words = resultToFill.getHltBitsAsWords();
159  ATH_MSG_DEBUG("HLT result now has " << words.size() << " words with the final trigger bits:");
160  for (const uint32_t w : words) ATH_MSG_DEBUG("0x" << MSG::hex << w << MSG::dec);
161  }
162 
163  return StatusCode::SUCCESS;
164 
165 }
166 
168  boost::dynamic_bitset<uint32_t>& resultToFill) const
169 {
170  // Ignore per-leg IDs, only use chain-IDs
172  return StatusCode::SUCCESS;
173  }
174 
175  auto mappingIter = m_mapping.find( chain );
176  // each chain has to have the counter
177  if( mappingIter == m_mapping.end() ) {
178  ATH_MSG_ERROR("Each chain has to have the bit/counter associated whereas the " << HLT::Identifier( chain ) << " does not" );
179  return StatusCode::FAILURE;
180  }
181  const int chainBitPosition = mappingIter->second;
182  ATH_MSG_DEBUG("Setting bit " << chainBitPosition << " corresponding to chain "<< HLT::Identifier(chain));
183  if (resultToFill.test(chainBitPosition)) {
184  ATH_MSG_WARNING(HLT::Identifier(chain) << " is setting its trigger bit " << chainBitPosition << " more than once");
185  }
186  resultToFill.set(chainBitPosition);
187  return StatusCode::SUCCESS;
188 }
TrigCompositeUtils::summaryPrescaledNodeName
const std::string & summaryPrescaledNodeName()
Definition: TrigCompositeUtilsRoot.cxx:924
HLT::HLTResultMT::setHltBits
void setHltBits(const boost::dynamic_bitset< uint32_t > &passRawBitset, const boost::dynamic_bitset< uint32_t > &prescaledBitset)
Replace both HLT pass raw and prescaled bits with the given bitsets.
Definition: HLTResultMT.cxx:125
TriggerBitsMakerTool::preInsertCheck
StatusCode preInsertCheck(const std::string &chain, const uint32_t bit) const
Check that no existing key maps to a given value and that the string is not empty.
Definition: TriggerBitsMakerTool.cxx:59
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
TrigCompositeUtils::DecisionID
unsigned int DecisionID
Definition: TrigComposite_v1.h:27
TriggerBitsMakerTool::m_extraChainToBit
Gaudi::Property< std::map< std::string, uint32_t > > m_extraChainToBit
Definition: TriggerBitsMakerTool.h:54
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
HLT::Identifier::numeric
TrigCompositeUtils::DecisionID numeric() const
numeric ID
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:47
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TriggerBitsMakerTool::m_finalChainDecisions
SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > m_finalChainDecisions
Definition: TriggerBitsMakerTool.h:49
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
TriggerBitsMakerTool::m_HLTMenuKey
SG::ReadHandleKey< TrigConf::HLTMenu > m_HLTMenuKey
Definition: TriggerBitsMakerTool.h:52
TriggerBitsMakerTool::setBit
StatusCode setBit(const TrigCompositeUtils::DecisionID chain, boost::dynamic_bitset< uint32_t > &resultToFill) const
Set to 1 the bit correspinding to 'chain' in 'resultToFill'.
Definition: TriggerBitsMakerTool.cxx:167
HLT::HLTResultMT
A container class for data required to build online output from HLT.
Definition: HLTResultMT.h:38
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TriggerBitsMakerTool::hashConsistencyCheck
StatusCode hashConsistencyCheck(const std::string &chain, const size_t hash) const
Check that a chain's hash in the menu JSON (via python) agrees with the C++ implementation.
Definition: TriggerBitsMakerTool.cxx:50
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
python.ConfigurableDb.conf
def conf
Definition: ConfigurableDb.py:282
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HLTUtils.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TriggerBitsMakerTool::start
virtual StatusCode start() override
Definition: TriggerBitsMakerTool.cxx:22
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TriggerBitsMakerTool.h
TriggerBitsMakerTool::TriggerBitsMakerTool
TriggerBitsMakerTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TriggerBitsMakerTool.cxx:11
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
HLT::Identifier
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:20
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TriggerBitsMakerTool::getBits
virtual StatusCode getBits(boost::dynamic_bitset< uint32_t > &passRaw, boost::dynamic_bitset< uint32_t > &prescaled, const EventContext &ctx) const override
Definition: TriggerBitsMakerTool.cxx:76
TrigConf::HLTMenu::size
std::size_t size() const
Accessor to the number of HLT chains.
Definition: HLTMenu.cxx:35
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TrigCompositeUtils::summaryPassNodeName
const std::string & summaryPassNodeName()
Definition: TrigCompositeUtilsRoot.cxx:916
TriggerBitsMakerTool::m_mapping
ChainToBitMap m_mapping
Mapping of each chain's hash ID to its chain counter.
Definition: TriggerBitsMakerTool.h:58
TriggerBitsMakerTool::fill
virtual StatusCode fill(HLT::HLTResultMT &resultToFill, const EventContext &ctx) const override
Definition: TriggerBitsMakerTool.cxx:136
TrigCompositeUtils::isLegId
bool isLegId(const HLT::Identifier &legIdentifier)
Recognise whether the chain ID is a leg ID.
Definition: TrigCompositeUtilsRoot.cxx:204
TrigCompositeUtils::DecisionIDContainer
std::set< DecisionID > DecisionIDContainer
Definition: TrigComposite_v1.h:28
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
HLTIdentifier.h
TrigCompositeUtils::decisionIDs
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
Definition: TrigCompositeUtilsRoot.cxx:67
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
HLT::HLTResultMT::getHltPrescaledBits
const boost::dynamic_bitset< uint32_t > & getHltPrescaledBits() const
Const-getter for HLT prescaled bits.
Definition: HLTResultMT.cxx:95
HLT::HLTResultMT::getHltBitsAsWords
const std::vector< uint32_t > & getHltBitsAsWords() const
Const-getter for HLT bits as uint32_t array. Ordering: PassRaw, Prescaled.
Definition: HLTResultMT.cxx:100
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
TrigConf::Chain
HLT chain configuration.
Definition: TrigConfData/TrigConfData/HLTChain.h:18
checkFileSG.words
words
Definition: checkFileSG.py:76
TriggerBitsMakerTool::m_largestBit
uint32_t m_largestBit
Largest chain counter hence largest bit needed to be stored in result bitmap.
Definition: TriggerBitsMakerTool.h:60
TriggerBitsMakerTool::initialize
virtual StatusCode initialize() override
Definition: TriggerBitsMakerTool.cxx:14
HLT::HLTResultMT::getHltPassRawBits
const boost::dynamic_bitset< uint32_t > & getHltPassRawBits() const
Const-getter for HLT pass raw bits.
Definition: HLTResultMT.cxx:90