ATLAS Offline Software
Loading...
Searching...
No Matches
HLTResultMT.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include <algorithm>
8#include <utility>
9#include <string_view>
10
11// Local constants
12namespace {
21 constexpr HLT::HLTResultMT::RODMinorVersion s_currentHltRodMinorVersion{1,2};
22
24 constexpr std::string_view s_contextName{"HLT::HLTResultMT"};
25}
26
27// =============================================================================
28// Standard constructor
29// =============================================================================
30HLT::HLTResultMT::HLTResultMT(std::vector<eformat::helper::StreamTag> streamTags,
31 boost::dynamic_bitset<uint32_t> hltPassRawBits,
32 boost::dynamic_bitset<uint32_t> hltPrescaledBits,
33 std::unordered_map<uint16_t, std::vector<uint32_t> > data)
34: m_streamTags(std::move(streamTags)),
35 m_hltPassRawBits(std::move(hltPassRawBits)),
36 m_hltPrescaledBits(std::move(hltPrescaledBits)),
37 m_data(std::move(data)),
38 m_version(s_currentHltRodMinorVersion) {}
39
40// =============================================================================
41// Getter/setter methods for stream tags
42// =============================================================================
43const std::vector<eformat::helper::StreamTag>& HLT::HLTResultMT::getStreamTags() const {
44 return m_streamTags;
45}
46
47// -----------------------------------------------------------------------------
48std::vector<eformat::helper::StreamTag>& HLT::HLTResultMT::getStreamTagsNonConst() {
49 return m_streamTags;
50}
51
52// -----------------------------------------------------------------------------
53StatusCode HLT::HLTResultMT::setStreamTags(const std::vector<eformat::helper::StreamTag>& streamTags) {
54 m_streamTags.clear();
55 for (const auto& st : streamTags) {
57 }
58 return StatusCode::SUCCESS;
59}
60
61// -----------------------------------------------------------------------------
62StatusCode HLT::HLTResultMT::addStreamTag(const eformat::helper::StreamTag& streamTag) {
63 // Check if a stream tag with the same type and name is already in the result
64 auto compareTypeName = [&streamTag](const eformat::helper::StreamTag& existingStreamTag) {
65 return streamTag.type == existingStreamTag.type && streamTag.name == existingStreamTag.name;
66 };
67 auto p = std::find_if(m_streamTags.begin(), m_streamTags.end(), compareTypeName);
68
69 // In case of duplicate, merge ROBs and SubDets, otherwise just append the tag to the result
70 if (p != m_streamTags.end()) {
71 if (streamTag.obeys_lumiblock != p->obeys_lumiblock) {
72 ATH_REPORT_ERROR_WITH_CONTEXT(StatusCode::FAILURE, s_contextName.data())
73 << "Stream tags have equal type and name (" << streamTag.type << "/" << streamTag.name
74 << "), but inconsistent obeys_lumiblock flag";
75 return StatusCode::FAILURE;
76 }
77 p->robs.insert(streamTag.robs.begin(), streamTag.robs.end());
78 p->dets.insert(streamTag.dets.begin(), streamTag.dets.end());
79 }
80 else {
81 m_streamTags.push_back(streamTag);
82 }
83
84 return StatusCode::SUCCESS;
85}
86
87// =============================================================================
88// Getter/setter methods for trigger bits
89// =============================================================================
90const boost::dynamic_bitset<uint32_t>& HLT::HLTResultMT::getHltPassRawBits() const {
91 return m_hltPassRawBits;
92}
93
94// -----------------------------------------------------------------------------
95const boost::dynamic_bitset<uint32_t>& HLT::HLTResultMT::getHltPrescaledBits() const {
96 return m_hltPrescaledBits;
97}
98
99// -----------------------------------------------------------------------------
100const std::vector<uint32_t>& HLT::HLTResultMT::getHltBitsAsWords() const {
101 if (m_hltPassRawBits.num_blocks() != m_hltPrescaledBits.num_blocks()) {
102 throw std::runtime_error("Must have the same number of bits in m_hltPassRawBits and m_hltPrescaledBits");
103 }
104 if (m_hltBitWords.size() != m_hltPassRawBits.num_blocks() + m_hltPrescaledBits.num_blocks()) {
105 throw std::runtime_error("m_hltBitWords size differs from the sum of m_hltPassRawBits and m_hltPrescaledBits");
106 }
107 return m_hltBitWords;
108}
109
110// -----------------------------------------------------------------------------
111void HLT::HLTResultMT::setHltPassRawBits(const boost::dynamic_bitset<uint32_t>& bitset) {
112 // copy assignment
113 m_hltPassRawBits = bitset;
115}
116
117// -----------------------------------------------------------------------------
118void HLT::HLTResultMT::setHltPrescaledBits(const boost::dynamic_bitset<uint32_t>& bitset) {
119 // copy assignment
120 m_hltPrescaledBits = bitset;
122}
123
124// -----------------------------------------------------------------------------
125void HLT::HLTResultMT::setHltBits(const boost::dynamic_bitset<uint32_t>& passRawBitset,
126 const boost::dynamic_bitset<uint32_t>& prescaledBitset) {
127 if (passRawBitset.num_blocks() != prescaledBitset.num_blocks()) {
128 throw std::runtime_error("Must have the same number of bits in passRawBitset and prescaledBitset");
129 }
130 // copy assignments
131 m_hltPassRawBits = passRawBitset;
132 m_hltPrescaledBits = prescaledBitset;
134}
135
136// -----------------------------------------------------------------------------
138 m_hltBitWords.clear();
139 m_hltBitWords.resize(m_hltPassRawBits.num_blocks() + m_hltPrescaledBits.num_blocks(), 0);
140 boost::to_block_range(m_hltPassRawBits, m_hltBitWords.begin());
141 boost::to_block_range(m_hltPrescaledBits, m_hltBitWords.begin() + m_hltPassRawBits.num_blocks());
142}
143
144// =============================================================================
145// Getter/setter methods for serialised data
146// =============================================================================
147const std::unordered_map<uint16_t, std::vector<uint32_t> >& HLT::HLTResultMT::getSerialisedData() const {
148 return m_data;
149}
150
151// -----------------------------------------------------------------------------
152StatusCode HLT::HLTResultMT::getSerialisedData(const uint16_t moduleId, const std::vector<uint32_t>*& data) const {
153 data = nullptr;
154 const auto it = m_data.find(moduleId);
155 if (it==m_data.cend()) {
156 REPORT_MESSAGE_WITH_CONTEXT(MSG::DEBUG, s_contextName.data())
157 << "No data available in the stored map for the requested moduleId=" << moduleId;
158 return StatusCode::FAILURE;
159 }
160 else {
161 data = &(it->second);
162 }
163 return StatusCode::SUCCESS;
164}
165
166// -----------------------------------------------------------------------------
167void HLT::HLTResultMT::setSerialisedData(std::unordered_map<uint16_t, std::vector<uint32_t> > data) {
168 // WARNING, copying data which may be large - recommend calling this with std::move if appropriate
169 m_data = std::move(data);
170}
171
172// -----------------------------------------------------------------------------
173void HLT::HLTResultMT::addSerialisedData(const uint16_t moduleId, const std::vector<uint32_t>& data) {
174 std::vector<uint32_t>& v = m_data[moduleId]; // creates new empty vector if the key doesn't exist
175 // WARNING, copying data which may be large
176 v.insert(v.end(),data.begin(),data.end());
177}
178
179// -----------------------------------------------------------------------------
180StatusCode HLT::HLTResultMT::addSerialisedDataWithCheck(const uint16_t moduleId, std::vector<uint32_t> data) {
181 if (m_data.find(moduleId)!=m_data.cend()) {
182 ATH_REPORT_ERROR_WITH_CONTEXT(StatusCode::FAILURE, s_contextName.data())
183 << "Trying to add data for a module which already exists in the stored map, moduleId=" << moduleId;
184 return StatusCode::FAILURE;
185 }
186 else {
187 // moving data
188 m_data[moduleId] = std::move(data);
189 }
190 return StatusCode::SUCCESS;
191}
192
193// =============================================================================
194// Getter/setter methods for status words
195// =============================================================================
196const std::vector<uint32_t>& HLT::HLTResultMT::getStatus() const {
197 return m_status;
198}
199
200// -----------------------------------------------------------------------------
201const std::vector<HLT::OnlineErrorCode> HLT::HLTResultMT::getErrorCodes() const {
202 std::vector<HLT::OnlineErrorCode> errorCodes;
203 if (m_status.size()<2)
204 return errorCodes;
205 for (auto it=m_status.cbegin()+1; it!=m_status.cend(); ++it) {
206 errorCodes.push_back(static_cast<HLT::OnlineErrorCode>(*it));
207 }
208 return errorCodes;
209}
210
211// -----------------------------------------------------------------------------
212void HLT::HLTResultMT::setStatus(std::vector<uint32_t> status) {
213 // move assignment
214 m_status = std::move(status);
215}
216
217// -----------------------------------------------------------------------------
219 const eformat::helper::Status& firstStatusWord) {
220 if (m_status.empty()) m_status.push_back(firstStatusWord.code());
221 else m_status[0] |= firstStatusWord.code();
222 m_status.push_back(static_cast<uint32_t>(errorCode));
223}
224
225// -----------------------------------------------------------------------------
226const std::vector<uint32_t>& HLT::HLTResultMT::getRobStatus(uint16_t moduleId) const {
227 const auto it = m_robStatus.find(moduleId);
228 if (it==m_robStatus.end()) {
229 static const std::vector<uint32_t> empty;
230 return empty;
231 }
232 else return it->second;
233}
234
235
236// =============================================================================
237// Getter/setter methods for HLT ROD minor version
238// =============================================================================
242
243// -----------------------------------------------------------------------------
245 m_version = version;
246}
247
248// =============================================================================
249// Getter/setter methods for truncation information
250// =============================================================================
251const std::set<uint16_t>& HLT::HLTResultMT::getTruncatedModuleIds() const {
253}
254
255// -----------------------------------------------------------------------------
256void HLT::HLTResultMT::addTruncatedModuleId(const uint16_t moduleId, bool severeTruncation) {
257 // decide if event should go to the debug stream
259
260 auto [itr, inserted] = m_truncatedModuleIds.insert(moduleId);
261 // Also update ROB status words
262 if (inserted) {
263 // Note that the per-ROB status requires the specific status bits to be zero
264 // if a problem is detected by the HLT framework. This is different from the
265 // event status where we set PSC_PROBLEM.
266 // See eformat v5.0.2, section 5.8.2 (https://cds.cern.ch/record/683741)
267 eformat::helper::Status firstStatusWord(eformat::GenericStatus::DATA_CORRUPTION);
268 m_robStatus[moduleId] = {firstStatusWord.code(),
269 static_cast<uint32_t>(HLT::OnlineErrorCode::RESULT_TRUNCATION)};
270 }
271}
272
273// =============================================================================
274std::ostream& operator<<(std::ostream& str, const HLT::HLTResultMT& hltResult) {
275 auto printWord = [&str](const uint32_t word, const size_t width=8){
276 str << "0x" << std::hex << std::setw(width) << std::setfill('0') << word << " " << std::dec;
277 };
278 str << "Printing HLTResultMT:" << std::endl;
279
280 // Status
281 str << "--> Status words = ";
282 for (const uint32_t word : hltResult.getStatus()) {
283 printWord(word);
284 }
285 str << std::endl;
286
287 // Stream tags
288 str << "--> Stream tags = ";
289 bool first = true;
290 for (const eformat::helper::StreamTag& st : hltResult.getStreamTags()) {
291 if (first) first=false;
292 else str << " ";
293 str << "{" << st.name << ", " << st.type << ", obeysLB=" << st.obeys_lumiblock << ", robs=[";
294 for (const auto& robid : st.robs) printWord(robid);
295 str << "], dets = [";
296 for (const auto& detid : st.dets) printWord(detid,2);
297 str << "]}" << std::endl;
298 }
299 if (hltResult.getStreamTags().empty()) str << std::endl;
300
301 // HLT bits
302 std::vector<uint32_t> hltPassRawBitWords;
303 std::vector<uint32_t> hltPrescaledBitWords;
304 hltPassRawBitWords.resize(hltResult.getHltPassRawBits().num_blocks());
305 hltPrescaledBitWords.resize(hltResult.getHltPrescaledBits().num_blocks());
306 boost::to_block_range(hltResult.getHltPassRawBits(),hltPassRawBitWords.begin());
307 boost::to_block_range(hltResult.getHltPrescaledBits(),hltPrescaledBitWords.begin());
308 str << "--> HLT bits = ";
309 for (const uint32_t word : hltPassRawBitWords) {
310 printWord(word);
311 }
312 for (const uint32_t word : hltPrescaledBitWords) {
313 printWord(word);
314 }
315 str << std::endl;
316
317 // Payload size
318 str << "--> Payload size = ";
319 first = true;
320 for (const auto& p : hltResult.getSerialisedData()) {
321 if (first) first=false;
322 else str << " ";
323 str << "{module " << p.first << ": " << p.second.size() << " words}" << std::endl;
324 }
325
326 // Truncation information
327 if (!hltResult.getTruncatedModuleIds().empty()) {
328 str << "--> Truncated results = ";
329 first = true;
330 for (const uint16_t moduleId : hltResult.getTruncatedModuleIds()) {
331 if (first) first=false;
332 else str << ", ";
333 str << moduleId;
334 }
335 str << std::endl;
336 }
337
338 return str;
339}
#define ATH_REPORT_ERROR_WITH_CONTEXT
Report an error, with an explicitly specified context name.
#define ATH_CHECK
Evaluate an expression and check for errors.
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
const double width
static const Attributes_t empty
A container class for data required to build online output from HLT.
Definition HLTResultMT.h:38
std::set< uint16_t > m_truncatedModuleIds
List of module IDs with truncation.
std::vector< uint32_t > m_hltBitWords
Vector storing m_hltBits converted to 4-byte words.
StatusCode addSerialisedDataWithCheck(const uint16_t moduleId, std::vector< uint32_t > data)
Add serialised data for a given moduleId.
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.
const std::vector< uint32_t > & getHltBitsAsWords() const
Const-getter for HLT bits as uint32_t array. Ordering: PassRaw, Prescaled.
RODMinorVersion getVersion() const
ROD minor version getter.
const std::set< uint16_t > & getTruncatedModuleIds() const
Getter for the truncation information.
void updateHltBitWords()
Update m_hltBitWords with the contents of m_hltPassRawBits and m_hltPrescaledBits.
const boost::dynamic_bitset< uint32_t > & getHltPassRawBits() const
Const-getter for HLT pass raw bits.
void addErrorCode(const HLT::OnlineErrorCode &errorCode, const eformat::helper::Status &firstStatusWord={ eformat::GenericStatus::DATA_CORRUPTION, eformat::FullEventStatus::PSC_PROBLEM })
Append an error code.
void addTruncatedModuleId(const uint16_t moduleId, bool severeTruncation=true)
Add module ID to the list of truncated results.
boost::dynamic_bitset< uint32_t > m_hltPassRawBits
HLT bits (flagging which chains passed)
const std::vector< eformat::helper::StreamTag > & getStreamTags() const
Const-getter for stream tags.
bool m_severeTruncation
Should the event be sent to the debug stream due to severe truncation?
boost::dynamic_bitset< uint32_t > m_hltPrescaledBits
void addSerialisedData(const uint16_t moduleId, const std::vector< uint32_t > &data)
Append serialised data (copy of input) for a given moduleId, doesn't remove existing data.
bool severeTruncation() const
Truncation in at least one collection that is not allowed to be truncated.
std::pair< uint8_t, uint8_t > RODMinorVersion
Type to store decoded ROD minor version (16-bit version split into two 8-bit numbers)
Definition HLTResultMT.h:50
std::unordered_map< uint16_t, std::vector< uint32_t > > m_data
Serialised result (ROBFragment payload) for each moduleId (0 for full result, >0 for data scouting)
const std::unordered_map< uint16_t, std::vector< uint32_t > > & getSerialisedData() const
Serialised data getter.
const boost::dynamic_bitset< uint32_t > & getHltPrescaledBits() const
Const-getter for HLT prescaled bits.
const std::vector< uint32_t > & getStatus() const
Full event status reference getter (1 bit-mask status word + error code words)
StatusCode setStreamTags(const std::vector< eformat::helper::StreamTag > &streamTags)
Replace the stored list of stream tags with the given one.
const std::vector< uint32_t > & getRobStatus(uint16_t moduleId) const
Status words for ROB with given moduleId.
void setVersion(RODMinorVersion version)
ROD minor version setter.
void setHltPrescaledBits(const boost::dynamic_bitset< uint32_t > &bitset)
Replace HLT prescaled bits with the given bitset.
void setHltPassRawBits(const boost::dynamic_bitset< uint32_t > &bitset)
Replace HLT pass raw bits with the given bitset.
std::unordered_map< uint16_t, std::vector< uint32_t > > m_robStatus
ROBFragment status words for each moduleId.
std::vector< eformat::helper::StreamTag > & getStreamTagsNonConst()
Non-const-getter for stream tags needed by the result maker to remove disabled ROBs/SubDets.
StatusCode addStreamTag(const eformat::helper::StreamTag &streamTag)
Append one stream tag to the stored list.
HLTResultMT(std::vector< eformat::helper::StreamTag > streamTags={}, boost::dynamic_bitset< uint32_t > hltPassRawBits=boost::dynamic_bitset< uint32_t >(), boost::dynamic_bitset< uint32_t > hltPrescaledBits=boost::dynamic_bitset< uint32_t >(), std::unordered_map< uint16_t, std::vector< uint32_t > > data={})
Standard constructor.
const std::vector< HLT::OnlineErrorCode > getErrorCodes() const
Error codes getter (by value) - strips off the first bit-mask status word.
std::vector< eformat::helper::StreamTag > m_streamTags
Stream tags of the event.
std::vector< uint32_t > m_status
FullEvent status words (first word is eformat::helper::Status, next words are optional error codes)
void setSerialisedData(std::unordered_map< uint16_t, std::vector< uint32_t > > data)
Replaces serialised data with a copy of the given data.
void setStatus(std::vector< uint32_t > status)
Replace the full status words with the given data.
RODMinorVersion m_version
Stores the ROD minor version of the HLT ROBFragments.
MsgStream & operator<<(MsgStream &m, const Navigation &nav)
STL namespace.