24 constexpr
static auto START_DATA = std::size_t{2 * 32};
25 auto readPointer = std::size_t{START_DATA};
26 int version = parse_version_workaround(readPointer);
27 decode_header(readPointer,
version);
28 decode_data(readPointer);
29 decode_trailer(readPointer);
53 m_head_fragID, m_head_sectID, m_head_EC, m_head_flags, m_head_BCID, m_head_orbit, m_head_spare, m_L1ID));
61 m_l1a_wdw_matching_engines_usage =
96 if (anchor == anchor_value)
105 static constexpr
auto PADDING_BITS_END = std::size_t{16};
107 while (readPointer < endOfData) {
110 if (readPointer + SIZE_DATA_HEADER > endOfData) {
111 throw std::length_error(
112 Muon::nsw::format(
"Read pointer ({}) would excede memory dedicated to data chunks ({}) while parsing the header (size: {})",
113 readPointer, endOfData, SIZE_DATA_HEADER));
115 const auto header_data = decode_data_header(readPointer);
117 if (header_data.total_expected_size > m_wordCountFlx - ceil(readPointer / WORD_SIZE) + 1) {
118 throw std::length_error(
Muon::nsw::format(
"STG TP stream size {} larger than expected packet size {}",
119 header_data.total_expected_size,
120 m_wordCountFlx - ceil(readPointer / WORD_SIZE) + 1));
122 if (header_data.nwords * header_data.data_size + readPointer > endOfData) {
123 throw std::length_error(
Muon::nsw::format(
"Requested to decode {} bits but only {} bits are remaining",
124 header_data.nwords * header_data.data_size, endOfData - readPointer));
127 m_stream_data.push_back(decode_data_payload(readPointer, header_data));
133 std::size_t& readPointer) {
141 const auto corrected_current_stream_head_nbits = correct_size_for_padding(current_stream_head_nbits);
143 m_stream_head_nbits.push_back(corrected_current_stream_head_nbits);
144 m_stream_head_nwords.push_back(current_stream_head_nwords);
145 m_stream_head_fifo_size.push_back(current_stream_head_fifo_size);
146 m_stream_head_streamID.push_back(current_stream_head_streamID);
148 const auto data_size =
static_cast<std::size_t
>(std::ceil(corrected_current_stream_head_nbits / WORD_SIZE_DOUBLE));
149 const auto total_expected_size = data_size * current_stream_head_nwords;
151 ERS_DEBUG(2,
Muon::nsw::format(
"stream_head_nbits: {}", corrected_current_stream_head_nbits));
152 ERS_DEBUG(2,
Muon::nsw::format(
"stream_head_nwords: {}", current_stream_head_nwords));
153 ERS_DEBUG(2,
Muon::nsw::format(
"stream_head_fifo_size: {}", current_stream_head_fifo_size));
154 ERS_DEBUG(2,
Muon::nsw::format(
"stream_head_streamID: {}", current_stream_head_streamID));
155 ERS_DEBUG(2,
Muon::nsw::format(
"total_expected_size: {}", data_size * current_stream_head_nwords));
156 ERS_DEBUG(2,
Muon::nsw::format(
"m_wordCountFlx: {}, ceil(readPointer/{}): {}", m_wordCountFlx, WORD_SIZE_DOUBLE,
157 ceil(readPointer / WORD_SIZE_DOUBLE)));
159 return {corrected_current_stream_head_nbits, current_stream_head_nwords, current_stream_head_fifo_size,
160 current_stream_head_streamID, total_expected_size, data_size};
165 std::vector<std::vector<std::uint32_t>> current_stream_data{};
167 for (std::size_t
i = 0;
i <
header.nwords; ++
i) {
168 std::vector<std::uint32_t>
data{};
169 for (std::size_t j = 0; j <
header.data_size; ++j) {
170 data.push_back(
decode(readPointer, WORD_SIZE));
172 current_stream_data.push_back(
data);
174 return current_stream_data;
183 return Muon::nsw::decode_and_advance<std::uint64_t, std::uint32_t>(
m_data, readPointer,
size);
187 auto counterChunk = std::size_t{0};
188 for (
const auto& dataChunk : m_stream_data) {
189 for (
const auto& dataWord : dataChunk) {
190 const auto expectedSize =
191 static_cast<std::size_t
>(std::ceil(m_stream_head_nbits.at(counterChunk) / WORD_SIZE_DOUBLE));
192 if (
std::size(dataWord) != expectedSize) {
193 throw std::length_error(
Muon::nsw::format(
"Stream data size {} does not match expected number of messages {}",
196 switch (m_stream_head_streamID.at(counterChunk)) {
198 m_pad_packets.emplace_back(dataWord);
201 m_segment_packets.emplace_back(dataWord);
204 throw std::runtime_error(
Muon::nsw::format(
"Invalid stream type {}", m_stream_head_streamID.at(counterChunk)));
212 static constexpr
auto PADDING = 16;
213 if (initial % PADDING) {
214 return ((initial + PADDING - 1) / PADDING) * PADDING;