24 auto check_compact_max_size(
const T& value,
size_t length) -> std::expected<void, std::string_view>
26 if (value >= 1ULL << length)
28 return std::unexpected(
"Serialization: exceeding size limit!");
34 -> std::expected<void, std::string_view>
36 auto is_correct_sizes =
41 return check_compact_max_size(
42 marker_data.srs_timestamp,
45 if (!is_correct_sizes)
47 return std::unexpected(is_correct_sizes.error());
50 std::bitset<common::SRS_TIMESTAMP_HIGH_BIT_LENGTH + common::SRS_TIMESTAMP_LOW_BIT_LENGTH>(
51 marker_data.srs_timestamp);
54 marker_data_compact.timestamp_low_bits =
55 static_cast<decltype(marker_data_compact.timestamp_low_bits)
>(timestamp_low_bits.to_ulong());
56 marker_data_compact.timestamp_high_bits =
57 static_cast<decltype(marker_data_compact.timestamp_high_bits)
>(timestamp_high_bits.to_ullong());
58 marker_data_compact.flag =
static_cast<decltype(marker_data_compact.flag)
>(0);
59 marker_data_compact.vmm_id =
static_cast<decltype(marker_data_compact.vmm_id)
>(marker_data.vmm_id);
64 -> std::expected<void, std::string_view>
66 auto is_correct_sizes =
72 if (!is_correct_sizes)
74 return std::unexpected(is_correct_sizes.error());
76 hit_data_compact.vmm_id =
static_cast<decltype(hit_data_compact.vmm_id)
>(hit_data.vmm_id);
77 hit_data_compact.flag =
static_cast<decltype(hit_data_compact.flag)
>(1);
78 hit_data_compact.adc =
static_cast<decltype(hit_data_compact.adc)
>(hit_data.adc);
79 hit_data_compact.bc_id =
static_cast<decltype(hit_data_compact.bc_id)
>(hit_data.bc_id);
81 hit_data_compact.channel_num =
static_cast<decltype(hit_data_compact.channel_num)
>(hit_data.channel_num);
82 hit_data_compact.is_over_threshold =
83 static_cast<decltype(hit_data_compact.is_over_threshold)
>(hit_data.is_over_threshold);
84 hit_data_compact.offset =
static_cast<decltype(hit_data_compact.offset)
>(hit_data.offset);
85 hit_data_compact.tdc =
static_cast<decltype(hit_data_compact.tdc)
>(hit_data.tdc);
92 auto compact_to_vector(
const T& compact_data, std::vector<char>& output) ->
void
96 output.resize(
sizeof(std::uint64_t));
97 auto write_to_output = zpp::bits::out{ output, zpp::bits::endian::network{}, zpp::bits::no_size{} };
98 write_to_output(compact_bitset).or_throw();
99 output.erase(output.begin(), output.begin() + 2);
100 std::ranges::reverse(output);
113 [[maybe_unused]] std::vector<char>& output,
114 std::vector<char>& compact_data_buffer)
115 -> std::expected<std::size_t, std::string_view>
117 compact_data_buffer.resize(0, 0);
118 auto serialize_to = zpp::bits::out{ output, zpp::bits::endian::network{}, zpp::bits::no_size{} };
119 serialize_to(input->header).or_throw();
120 for (
auto hit : input->hit_data)
122 std::ranges::fill(compact_data_buffer, 0);
124 if (
auto res = hit_to_compact(hit, hit_compact); !res)
126 return std::unexpected(res.error());
128 compact_to_vector(hit_compact, compact_data_buffer);
131 for (
auto marker : input->marker_data)
133 std::ranges::fill(compact_data_buffer, 0);
135 if (
auto res = marker_to_compact(marker, marker_compact); !res)
137 return std::unexpected(res.error());
139 compact_to_vector(marker_compact, compact_data_buffer);
140 serialize_to(compact_data_buffer).or_throw();
142 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_low_bits(const std::bitset< total_size > &bits) -> std::bitset< low_size >
constexpr auto SRS_TIMESTAMP_LOW_BIT_LENGTH
constexpr auto BYTE_BIT_LENGTH
constexpr auto SRS_TIMESTAMP_HIGH_BIT_LENGTH
constexpr auto get_high_bits(const std::bitset< total_size > &bits) -> std::bitset< high_size >
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