26#include <boost/dynamic_bitset.hpp>
38 bool resultObjectIsUsed =
true;
40 ATH_MSG_INFO(
"TrigDecisionMakerMT is setting up to run after the Trigger in a job with POOL output. "
41 "The TriggerBitsMakerTool will be used directly to create the xAOD::TrigDecision.");
43 resultObjectIsUsed =
false;
45 ATH_MSG_INFO(
"TrigDecisionMakerMT is setting up to read the trigger bits from trigger bytestream. "
46 "The HLTResultMT object will be used as the source of the trigger bits.");
63 return StatusCode::SUCCESS;
70 ATH_MSG_DEBUG (
"=============================================");
75 ATH_MSG_DEBUG (
"=============================================");
77 return StatusCode::SUCCESS;
88 std::unique_ptr<xAOD::TrigDecision> trigDec = std::make_unique<xAOD::TrigDecision>();
89 std::unique_ptr<xAOD::TrigDecisionAuxInfo> trigDecAux = std::make_unique<xAOD::TrigDecisionAuxInfo>();
90 trigDec->setStore(trigDecAux.get());
94 trigDec->setSMK(hltMenu->smk());
111 boost::dynamic_bitset<uint32_t> passRawBitset, prescaledBitset;
115 ATH_MSG_DEBUG (
"MC Mode: Creating bits with TriggerBitsMakerTool");
124 passRawBitset = hltResult->getHltPassRawBits();
125 prescaledBitset = hltResult->getHltPrescaledBits();
128 const std::vector<HLT::OnlineErrorCode> errorCodes = hltResult->getErrorCodes();
129 bool truncated =
false;
131 for (
size_t i = 0; i < errorCodes.size(); ++i) {
134 code =
static_cast<uint32_t
>(errorCodes.at(0));
146 std::set<uint16_t> allModuleIds;
147 for (
const auto& itr : hltResult->getSerialisedData()) allModuleIds.insert(itr.first);
149 for (uint16_t moduleId : allModuleIds) {
150 const std::vector<uint32_t>& status = hltResult->getRobStatus(moduleId);
151 if (status.size() > 1) {
155 if (moduleId==0)
break;
159 trigDec->setEFErrorBits(code);
160 trigDec->setEFTruncated(truncated);
163 ATH_MSG_DEBUG (
"Number of HLT chains passed raw: " << passRawBitset.count());
164 ATH_MSG_DEBUG (
"Number of HLT chains prescaled out: " << prescaledBitset.count());
166 if (passRawBitset.any()) {
170 std::vector<uint32_t> passRaw, prescaled;
172 passRaw.resize(passRawBitset.num_blocks());
173 prescaled.resize(prescaledBitset.num_blocks());
175 boost::to_block_range(passRawBitset, passRaw.begin());
176 boost::to_block_range(prescaledBitset, prescaled.begin());
181 static const std::set<unsigned> buggyPrescaleBitRuns = {429603, 429606, 429612, 429658, 429697, 429716};
182 const bool isBuggyPrescaleBitsRun = (std::find(buggyPrescaleBitRuns.begin(), buggyPrescaleBitRuns.end(), context.eventID().run_number()) != buggyPrescaleBitRuns.end());
183 if (isBuggyPrescaleBitsRun) {
184 ATH_MSG_DEBUG(
"T0 Trigger fix for 429603-429716 is deleting incorrect isPrescaled trigger bits decoded from the bytestream.");
185 for (
size_t i = 0; i < prescaled.size(); ++i) {
190 if (passRaw.size() != prescaled.size()) {
191 ATH_MSG_ERROR(
"Trigger bitsets are not all the same size! passRaw:"
192 << passRaw.size() <<
" prescaled:" << prescaled.size() );
193 return StatusCode::FAILURE;
198 trigDec->setEFPassedRaw(passRaw);
199 trigDec->setEFPassedPhysics(passRaw);
200 trigDec->setEFPrescaled(prescaled);
211 trigDec->setBGCode(
static_cast<char>(l1bgs->
bgPattern(eventInfo->
bcid())) );
219 <<
"'; BCID '" << eventInfo->
bcid()
220 <<
"'; BG Code '" <<
static_cast<int>(trigDec->bgCode()) <<
"'" ) ;
222 ATH_MSG_DEBUG (
"Decision object dump: " << *(trigDec.get()));
224 ATH_CHECK( trigDecWriteHandle.record( std::move( trigDec ), std::move( trigDecAux ) ) );
227 return StatusCode::SUCCESS;
240 auto lvl1Result = std::make_unique<LVL1CTP::Lvl1Result>(
true);
243 const std::vector<uint32_t> ctpTBPWords = ctpResult->getTBPWords();
244 for (
unsigned int iWord=0; iWord < ctpTBPWords.size(); ++iWord) {
245 lvl1Result->itemsBeforePrescale().push_back(ctpTBPWords[iWord]);
246 ATH_MSG_DEBUG(
"TBP word #" << iWord <<
" is 0x" << std::hex << std::setw( 8 ) << std::setfill(
'0' ) << ctpTBPWords[iWord] << std::dec);
250 const std::vector<uint32_t> ctpTAPWords = ctpResult->getTAPWords();
251 for (
unsigned int iWord=0; iWord < ctpTAPWords.size(); ++iWord) {
252 lvl1Result->itemsAfterPrescale().push_back(ctpTAPWords[iWord]);
253 ATH_MSG_DEBUG(
"TAP word #" << iWord <<
" is 0x" << std::hex << std::setw( 8 ) << std::setfill(
'0' ) << ctpTAPWords[iWord] << std::dec);
257 const std::vector<uint32_t> ctpTAVWords = ctpResult->getTAVWords();
258 for (
unsigned int iWord = 0; iWord < ctpTAVWords.size(); ++iWord) {
259 lvl1Result->itemsAfterVeto().push_back(ctpTAVWords[iWord]);
260 ATH_MSG_DEBUG(
"TAV word #" << iWord <<
" is 0x" << std::hex << std::setw( 8 ) << std::setfill(
'0' ) << ctpTAVWords[iWord] << std::dec);
264 if (lvl1Result->itemsBeforePrescale().size() < 8) lvl1Result->itemsBeforePrescale().resize(8, 0);
265 if (lvl1Result->itemsAfterPrescale().size() < 8) lvl1Result->itemsAfterPrescale().resize(8, 0);
266 if (lvl1Result->itemsAfterVeto().size() < 8) lvl1Result->itemsAfterVeto().resize(8, 0);
269 if (result ==
nullptr) {
270 ATH_MSG_ERROR (
"Could not construct L1 result from xAOD::CTPResult");
271 return StatusCode::FAILURE;
275 ATH_MSG_DEBUG (
"Built LVL1CTP::Lvl1Result from valid xAOD::CTPResult.");
282 std::vector< std::unique_ptr<LVL1CTP::Lvl1Item> > itemConfig =
m_lvl1Tool->makeLvl1ItemConfig(context);
284 if (roIBResult->cTPResult().isComplete()) {
285 m_lvl1Tool->createL1Items(itemConfig, *roIBResult, &result);
286 ATH_MSG_DEBUG (
"Built LVL1CTP::Lvl1Result from valid ROIB::CTPResult.");
289 if (result ==
nullptr) {
290 ATH_MSG_ERROR (
"Could not construct L1 result from roIBResult");
291 return StatusCode::FAILURE;
296 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
An algorithm that can be simultaneously executed in multiple threads.
const std::vector< uint32_t > & itemsAfterVeto() const
bool isAccepted() const
final LVL1 decision && isConfigured
const std::vector< uint32_t > & itemsAfterPrescale() const
const std::vector< uint32_t > & itemsBeforePrescale() const
virtual bool isValid() override final
Can the handle be successfully dereferenced?
bgPattern_t bgPattern(size_t bcid) const
Return word with bit-pattern of fired bunchgroups for given bcid.
Gaudi::Property< bool > m_useEDMxAOD
SG::ReadHandleKey< HLT::HLTResultMT > m_hltResultKeyIn
virtual StatusCode finalize() override
std Gaudi finalize method -> print out statistics
ToolHandle< HLT::ILvl1ResultAccessTool > m_lvl1Tool
tool to ease the access to the L1 results (RoIs, items, etc)
Gaudi::Property< bool > m_doL1
SG::ReadHandleKey< xAOD::CTPResult > m_CTPResultKeyIn
virtual StatusCode execute(const EventContext &context) const override
Re-entrant execute to create the xAOD::TrigDecision.
SG::WriteHandleKey< LVL1CTP::Lvl1Result > m_l1ResultKeyOut
SG::ReadCondHandleKey< TrigConf::L1BunchGroupSet > m_bgKey
StatusCode getL1Result(const LVL1CTP::Lvl1Result *&result, const EventContext &context) const
retrieve LVL1 result (called in execute)
std::atomic< uint32_t > m_nEvents
std::atomic< uint32_t > m_hltPassed
Gaudi::Property< bool > m_doHLT
std::atomic< uint32_t > m_l1Passed
virtual StatusCode initialize() override
std Gaudi initialize method -> read-in trigger configuration
SG::ReadHandleKey< ROIB::RoIBResult > m_ROIBResultKeyIn
SG::ReadHandleKey< xAOD::EventInfo > m_EventInfoKeyIn
TrigDecisionMakerMT(const std::string &name, ISvcLocator *pSvcLocator)
std Gaudi Algorithm constructor
SG::ReadHandleKey< TrigConf::HLTMenu > m_HLTMenuKey
SG::WriteHandleKey< xAOD::TrigDecision > m_trigDecisionKeyOut
~TrigDecisionMakerMT()
std deconstructor
ToolHandle< ITriggerBitsMakerTool > m_bitsMakerTool
uint32_t bcid() const
The bunch crossing ID of the event.
uint32_t runNumber() const
The current event's run number.
uint64_t eventNumber() const
The current event's event number.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
EventInfo_v1 EventInfo
Definition of the latest event info version.