9#include <glaze/core/opts.hpp>
10#include <glaze/core/write.hpp>
13#include <spdlog/spdlog.h>
35 for (
const auto& hit : hits)
37 hit_data.at(
"is_over_threshold").push_back(
static_cast<uint16_t
>(hit.is_over_threshold));
38 hit_data.at(
"channel_num").push_back(hit.channel_num);
39 hit_data.at(
"tdc").push_back(hit.tdc);
40 hit_data.at(
"offset").push_back(hit.offset);
41 hit_data.at(
"vmm_id").push_back(hit.vmm_id);
42 hit_data.at(
"adc").push_back(hit.adc);
43 hit_data.at(
"bc_id").push_back(hit.bc_id);
55 for (
const auto& marker : markers)
58 marker_data.at(
"srs_timestamp").push_back(marker.srs_timestamp);
63 :
WriterTask{
"JSONWriter", convert_mode, n_lines }
73 for (
auto idx : std::views::iota(0,
static_cast<int>(n_lines)))
76 file_streams_.emplace_back(full_filename, std::ios::out | std::ios::trunc);
81 if (not file_stream.is_open())
83 spdlog::critical(
"JsonWriter: cannot open the file with filename {:?}", filename);
84 throw std::runtime_error(
"Error occurred with JsonWriter");
91 for (
auto [idx, file_stream] : std::views::zip(std::views::iota(0),
file_streams_))
95 spdlog::debug(
"JSON file {} with index {} is closed successfully",
filename_, idx);
97 spdlog::info(
"Writer: JSON file writer with the base name {:?} is closed successfully.",
filename_);
112 auto error_code = glz::write<glz::opts{ .prettify =
true, .new_lines_in_arrays =
false }>(
116 spdlog::critical(
"JsonWriter: cannot interpret data struct to json. Error: {}",
117 error_code.custom_error_message);
118 throw std::runtime_error(
"Error occurred with JsonWriter");
WriterTask(std::string_view name, DataConvertOptions prev_convert, std::size_t n_lines=1)
std::vector< Bool > is_first_item_
std::vector< std::string > string_buffers_
Json(const std::string &filename, process::DataConvertOptions convert_mode, std::size_t n_lines=1)
std::vector< CompactExportData > data_buffers_
std::vector< std::fstream > file_streams_
void write_json(const StructData &data_struct, std::size_t line_num)
std::vector< OutputType > output_data_
constexpr auto insert_index_to_filename(std::string_view native_name, int idx) -> std::string
ReceiveDataHeader header
Header data.
std::vector< MarkerData > marker_data
Marker data.
std::vector< HitData > hit_data
Hit data.
void fill_hit_data(const std::vector< HitData > &hits)
std ::map< std::string, std::vector< uint64_t > > marker_data
std ::map< std::string, std::vector< uint16_t > > hit_data
void fill_marker_data(const std::vector< MarkerData > &markers)
void set_value(const StructData &data_struct)