21 constexpr static auto START_DATA = std::size_t{2 * 32};
22 auto readPointer = std::size_t{START_DATA};
108 if (anchor == anchor_value)
118 auto PADDING_BITS_END = std::size_t{16};
123 while (readPointer < endOfData) {
126 if (readPointer + SIZE_DATA_HEADER > endOfData) {
127 throw std::length_error(
128 Muon::nsw::format(
"Read pointer ({}) would excede memory dedicated to data chunks ({}) while parsing the header (size: {})",
129 readPointer, endOfData, SIZE_DATA_HEADER));
133 throw std::length_error(
Muon::nsw::format(
"STG TP stream size {} larger than expected packet size {}",
134 header_data.total_expected_size,
137 if (header_data.nwords * header_data.data_size + readPointer > endOfData) {
138 throw std::length_error(
Muon::nsw::format(
"Requested to decode {} bits but only {} bits are remaining",
139 header_data.nwords * header_data.data_size, endOfData - readPointer));
151 auto PADDING_BITS_END = std::size_t{16};
154 while (readPointer < endOfData) {
157 if (readPointer + SIZE_DATA_HEADER > endOfData) {
158 throw std::length_error(
159 Muon::nsw::format(
"Read pointer ({}) would excede memory dedicated to data chunks ({}) while parsing the header (size: {})",
160 readPointer, endOfData, SIZE_DATA_HEADER));
165 throw std::length_error(
Muon::nsw::format(
"STG TP stream size {} larger than expected packet size {}",
166 header_data.total_expected_size,
169 if (header_data.nwords * header_data.data_size + readPointer > endOfData) {
170 throw std::length_error(
Muon::nsw::format(
"Requested to decode {} bits but only {} bits are remaining",
171 header_data.nwords * header_data.data_size, endOfData - readPointer));
180 std::size_t& readPointer,
int version) {
184 throw std::invalid_argument(
"decode_data_header_v3 version should be exactly 3");
188 auto PADDING_BITS_END = std::size_t{16};
195 size_t current_stream_head_nbits = 0;
196 size_t current_stream_head_nwords = 0;
198 switch (current_stream_head_streamID)
213 if (current_stream_head_nbits == 0 )
215 throw std::runtime_error(
"Corrupted message - sTGC stream has an unrecognized stream header");
218 if (readPointer + total_expected_size > endOfData)
220 throw std::runtime_error(
"Corrupted message - sTGC expected size goes beyond the end of data");
223 current_stream_head_nwords = (
stream_head_nwords == 0) ? 0 : total_expected_size / current_stream_head_nbits;
224 size_t data_size = std::ceil(total_expected_size / felix_word_size);
236 ERS_DEBUG(2,
Muon::nsw::format(
"stream_head_nbits: {}", current_stream_head_nbits));
237 ERS_DEBUG(2,
Muon::nsw::format(
"stream_head_nwords: {}", current_stream_head_nwords));
238 ERS_DEBUG(2,
Muon::nsw::format(
"stream_head_fifo_size: {}", current_stream_head_fifo_size));
239 ERS_DEBUG(2,
Muon::nsw::format(
"stream_head_streamID: {}", current_stream_head_streamID));
242 ceil(readPointer / felix_word_size)));
245 return {current_stream_head_nbits, current_stream_head_nwords, current_stream_head_fifo_size,
246 current_stream_head_streamID, total_expected_size, data_size};
250 std::size_t& readPointer,
int version) {
269 const auto data_size =
static_cast<std::size_t
>(std::ceil(corrected_current_stream_head_nbits / word_size));
270 const auto total_expected_size = data_size * current_stream_head_nwords;
272 ERS_DEBUG(2,
Muon::nsw::format(
"stream_head_nbits: {}", corrected_current_stream_head_nbits));
273 ERS_DEBUG(2,
Muon::nsw::format(
"stream_head_nwords: {}", current_stream_head_nwords));
274 ERS_DEBUG(2,
Muon::nsw::format(
"stream_head_fifo_size: {}", current_stream_head_fifo_size));
275 ERS_DEBUG(2,
Muon::nsw::format(
"stream_head_streamID: {}", current_stream_head_streamID));
276 ERS_DEBUG(2,
Muon::nsw::format(
"total_expected_size: {}", data_size * current_stream_head_nwords));
278 ceil(readPointer / word_size)));
280 return {corrected_current_stream_head_nbits, current_stream_head_nwords, current_stream_head_fifo_size,
281 current_stream_head_streamID, total_expected_size, data_size};
286 std::vector<std::vector<std::uint32_t>> current_stream_data{};
289 throw std::invalid_argument(
"decode_data_header_v3 version should be at least 3");
293 size_t felix_n_words = (
header.nwords == 0 ) ? 0 : std::ceil(
header.data_size /
header.nwords);
294 for (std::size_t i = 0; i <
header.nwords; ++i) {
295 std::vector<std::uint32_t>
data{};
296 for (std::size_t j = 0; j < felix_n_words; ++j) {
297 data.push_back(
decode(readPointer, word_size));
299 current_stream_data.push_back(std::move(
data));
301 return current_stream_data;
305 std::vector<std::vector<std::uint32_t>> current_stream_data{};
310 for (std::size_t i = 0; i <
header.nwords; ++i) {
311 std::vector<std::uint32_t>
data{};
312 for (std::size_t j = 0; j <
header.data_size; ++j) {
313 data.push_back(
decode(readPointer, word_size));
315 current_stream_data.push_back(std::move(
data));
317 return current_stream_data;
333 auto counterChunk = std::size_t{0};
335 for (
const auto& dataWord : dataChunk) {
336 const auto expectedSize =
338 if (std::size(dataWord) != expectedSize) {
339 throw std::length_error(
Muon::nsw::format(
"Stream data size {} does not match expected number of messages {}",
340 std::size(dataWord), expectedSize));
370 auto counterChunk = std::size_t{0};
372 for (
const auto& dataWord : dataChunk) {
373 const auto expectedSize =
375 if (std::size(dataWord) != expectedSize) {
376 throw std::length_error(
Muon::nsw::format(
"Stream data size {} does not match expected number of messages {}",
377 std::size(dataWord), expectedSize));
398 static constexpr auto PADDING = 16;
399 if (initial % PADDING) {
400 return ((initial + PADDING - 1) / PADDING) * PADDING;
char data[hepevt_bytes_allocation_ATLAS]
NSWTriggerElink(const uint32_t *bs, uint32_t remaining)
unsigned int m_wordCountFlx
std::uint32_t m_head_BCID
void decode_data(std::size_t &readPointer, int version)
Decode the pad and segment data.
std::vector< STGTPMMPacket > m_mm_packets
std::vector< std::uint32_t > m_stream_head_streamID
std::vector< STGTPSegmentPacket > m_segment_packets
const std::vector< std::uint32_t > & stream_head_nwords() const
std::vector< std::vector< std::vector< std::uint32_t > > > m_stream_data
std::uint32_t m_l1a_open_BCID_offset
std::uint32_t m_l1a_local_req_BCID
static constexpr auto WORD_SIZE_DOUBLE
std::vector< STGTPStripPacket > m_strip_packets
std::vector< std::uint32_t > m_stream_head_fifo_size
std::uint32_t m_l1a_padding
std::uint32_t m_head_flags
std::uint32_t m_l1a_close_BCID
DataHeader decode_data_header_v3(std::size_t &readPointer, int version)
std::uint32_t m_head_orbit
std::uint32_t m_l1a_close_BCID_offset
std::vector< std::vector< std::uint32_t > > decode_data_payload(std::size_t &readPointer, const DataHeader &header, int version) const
Decode the payload of each data segment.
NSWTriggerSTGL1AElink(const std::uint32_t *bs, std::uint32_t remaining)
std::uint32_t m_trailer_CRC
void decode_data_v3(std::size_t &readPointer, int version)
void decode_header(std::size_t &readPointer, int &version)
Decode the header.
std::uint32_t m_l1a_link_const
std::uint32_t m_l1a_timeout
std::uint32_t m_l1a_open_BCID
std::uint32_t m_l1a_req_BCID
std::vector< std::vector< std::uint32_t > > decode_data_payload_v3(std::size_t &readPointer, const DataHeader &header, int version) const
void analyze_data(int version)
Analyze data chunks and create decoded objects.
static std::uint64_t correct_size_for_padding(std::uint64_t initial)
std::uint32_t m_l1a_req_BCID_offset
static constexpr auto WORD_SIZE
void analyze_data_v3(int version)
int parse_version_workaround(std::size_t &readPointer)
parse version workaround
std::uint32_t m_l1a_engine_snapshot
DataHeader decode_data_header(std::size_t &readPointer, int version)
Decode the header of each data segment.
std::uint32_t m_l1a_timeout_config
std::uint32_t m_l1a_versionID
std::uint32_t m_head_sectID
std::uint32_t m_l1a_local_rel_BCID
void decode_trailer(std::size_t &readPointer)
Decode the trailer.
const std::vector< std::uint32_t > & stream_head_nbits() const
std::uint32_t m_head_spare
std::uint32_t m_l1a_wdw_matching_engines_usage
std::span< const std::uint32_t > m_data
std::vector< STGTPPadPacket > m_pad_packets
std::vector< std::uint32_t > m_stream_head_nbits
std::uint32_t m_head_fragID
std::uint32_t m_l1a_busy_thr
std::uint64_t decode(std::size_t &readPointer, std::size_t size) const
Decode a value.
std::vector< std::uint32_t > m_stream_head_nwords
constexpr uint32_t version1_anchor_value
constexpr int size_head_spare
constexpr int size_l1a_open_BCID_offset
constexpr int size_stream_head_fifo_size
constexpr int size_l1a_open_BCID
constexpr int size_head_flags
constexpr int size_l1a_req_BCID
constexpr int size_l1a_padding
constexpr int size_stream_head_streamID
constexpr int size_l1a_timeout
constexpr int size_head_fragID
constexpr int size_l1a_link_const
constexpr int size_l1a_local_req_BCID
constexpr int size_head_EC
constexpr int size_l1a_close_BCID_offset
constexpr int size_trailer_CRC
constexpr int size_l1a_local_rel_BCID
constexpr int size_head_orbit
constexpr int size_l1a_timeout_config
constexpr int size_l1a_engine_snapshot
constexpr int size_l1a_req_BCID_offset
constexpr int size_head_BCID
constexpr int size_l1a_close_BCID
constexpr int size_l1a_versionID
constexpr int size_l1a_wdw_matching_engines_usage
constexpr int size_stream_head_nwords
constexpr int size_stream_head_nbits
constexpr int size_head_sectID
constexpr int size_l1a_busy_thr
constexpr int loc_version1_anchor
constexpr int mm_stream_header
constexpr std::size_t size_v3
constexpr std::size_t pad_stream_header
constexpr std::size_t size_v3
constexpr std::size_t size_v3
constexpr int merge_stream_header
constexpr int strip_stream_header
std::string format(const std::string &str, const T &arg)
constexpr Target decode_at_loc(const std::span< const Source > words, std::size_t &start, const int offset, const std::size_t size)
Decode bits from data of words at read pointer + offset and NOT advance the read pointer.
constexpr Target decode_and_advance(const std::span< const Source > words, std::size_t &start, const std::size_t size)
Decode bits from data of words and advance the read pointer.