25 auto check_compact_max_size(
const T& value,
size_t length) -> std::expected<void, std::string_view>
27 if (value >= 1ULL << length)
29 return std::unexpected(
"Serialization: exceeding size limit!");
35 -> std::expected<void, std::string_view>
37 auto is_correct_sizes =
42 return check_compact_max_size(
43 marker_data.srs_timestamp,
46 if (!is_correct_sizes)
48 return std::unexpected(is_correct_sizes.error());
50#pragma GCC diagnostic push
51#pragma GCC diagnostic ignored "-Wconversion"
53 std::bitset<common::SRS_TIMESTAMP_HIGH_BIT_LENGTH + common::SRS_TIMESTAMP_LOW_BIT_LENGTH>(
54 marker_data.srs_timestamp);
57 marker_data_compact.timestamp_low_bits =
58 static_cast<decltype(marker_data_compact.timestamp_low_bits)
>(timestamp_low_bits.to_ulong());
59 marker_data_compact.timestamp_high_bits =
60 static_cast<decltype(marker_data_compact.timestamp_high_bits)
>(timestamp_high_bits.to_ullong());
61 marker_data_compact.flag =
static_cast<decltype(marker_data_compact.flag)
>(0);
62 marker_data_compact.vmm_id =
static_cast<decltype(marker_data_compact.vmm_id)
>(marker_data.vmm_id);
64#pragma GCC diagnostic pop
68 -> std::expected<void, std::string_view>
70 auto is_correct_sizes =
76 if (!is_correct_sizes)
78 return std::unexpected(is_correct_sizes.error());
80#pragma GCC diagnostic push
81#pragma GCC diagnostic ignored "-Wconversion"
82 hit_data_compact.vmm_id =
static_cast<decltype(hit_data_compact.vmm_id)
>(hit_data.vmm_id);
83 hit_data_compact.flag =
static_cast<decltype(hit_data_compact.flag)
>(1);
84 hit_data_compact.adc =
static_cast<decltype(hit_data_compact.adc)
>(hit_data.adc);
85 hit_data_compact.bc_id =
static_cast<decltype(hit_data_compact.bc_id)
>(hit_data.bc_id);
87 hit_data_compact.channel_num =
static_cast<decltype(hit_data_compact.channel_num)
>(hit_data.channel_num);
88 hit_data_compact.is_over_threshold =
89 static_cast<decltype(hit_data_compact.is_over_threshold)
>(hit_data.is_over_threshold);
90 hit_data_compact.offset =
static_cast<decltype(hit_data_compact.offset)
>(hit_data.offset);
91 hit_data_compact.tdc =
static_cast<decltype(hit_data_compact.tdc)
>(hit_data.tdc);
92#pragma GCC diagnostic pop
99 auto compact_to_vector(
const T& compact_data, std::vector<char>& output) ->
void
101 auto compact_bitset =
103 output.resize(
sizeof(std::uint64_t));
104 auto write_to_output = zpp::bits::out{ output, zpp::bits::endian::network{}, zpp::bits::no_size{} };
105 write_to_output(compact_bitset).or_throw();
106 output.erase(output.begin(), output.begin() + 2);
107 std::ranges::reverse(output);
120 [[maybe_unused]] std::vector<char>& output,
121 std::vector<char>& compact_data_buffer)
122 -> std::expected<std::size_t, std::string_view>
124 compact_data_buffer.resize(0, 0);
125 auto serialize_to = zpp::bits::out{ output, zpp::bits::endian::network{}, zpp::bits::no_size{} };
126 serialize_to(input->header).or_throw();
127 for (
auto hit : input->hit_data)
129 std::ranges::fill(compact_data_buffer, 0);
131 if (
auto res = hit_to_compact(hit, hit_compact); !res)
133 return std::unexpected(res.error());
135 compact_to_vector(hit_compact, compact_data_buffer);
138 for (
auto marker : input->marker_data)
140 std::ranges::fill(compact_data_buffer, 0);
142 if (
auto res = marker_to_compact(marker, marker_compact); !res)
144 return std::unexpected(res.error());
146 compact_to_vector(marker_compact, compact_data_buffer);
147 serialize_to(compact_data_buffer).or_throw();
149 return input->marker_data.size() + input->hit_data.size();
ConverterTask(std::string_view name, DataConvertOptions prev_convert, std::size_t n_lines=1)
std::vector< std::vector< char > > output_data_
auto convert(const StructData *input, std::vector< char > &output, std::vector< char > &compact_data_buffer) -> std::expected< std::size_t, std::string_view >
StructSerializer(size_t n_lines=1)
std::vector< std::vector< char > > compact_data_buffer_
constexpr auto binary_to_gray(T bin_val)
constexpr auto get_high_bits(const std::bitset< total_size > &bits) -> std::bitset< high_size >
constexpr auto SRS_TIMESTAMP_LOW_BIT_LENGTH
constexpr auto get_low_bits(const std::bitset< total_size > &bits) -> std::bitset< low_size >
constexpr auto BYTE_BIT_LENGTH
constexpr auto SRS_TIMESTAMP_HIGH_BIT_LENGTH
constexpr auto OFFSET_BIT_LENGTH
constexpr auto ADC_BIT_LENGTH
constexpr auto BC_ID_BIT_LENGTH
constexpr auto VMM_ID_BIT_LENGTH
constexpr auto CHANNEL_NUM_BIT_LENGTH