1#include "DataWriter.hpp"
10#include <asio/ip/udp.hpp>
11#include <asio/thread_pool.hpp>
12#include <magic_enum/magic_enum.hpp>
17#include <spdlog/spdlog.h>
20#include <system_error>
32 auto convert_str_to_endpoint(asio::thread_pool& thread_pool, std::string_view ip_port)
33 -> std::optional<asio::ip::udp::endpoint>
35 const auto question_pos = ip_port.find(
'?');
36 const auto colon_pos = ip_port.find(
':');
37 if (colon_pos == std::string::npos)
39 spdlog::critical(
"Ill format socket string {:?}. Please set it as \"ip:port\"", ip_port);
42 auto ip_string = ip_port.substr(0, colon_pos);
44 (question_pos == std::string::npos) ? ip_port.substr(colon_pos + 1) : ip_port.substr(question_pos + 1);
46 auto err_code = std::error_code{};
47 auto resolver = asio::ip::udp::resolver{ thread_pool };
48 auto iter = resolver.resolve(std::string{ ip_string }, std::string{ port_str }, err_code).begin();
51 spdlog::critical(
"Cannot query the ip address {:?} with port {:?}. Error code: {}",
60 auto check_root_dependency() ->
bool
65 spdlog::error(
"Cannot output to a root file. Please make sure the program is "
66 "built with the ROOT library.");
82 auto is_required =
false;
84 { is_required |= convert_option_has_dependency(dependee, writer.get_required_conversion()); });
90 constexpr auto conversions = magic_enum::enum_values<process::DataConvertOptions>();
92 std::views::transform(conversions,
93 [
this](
const auto conversion) -> std::pair<process::DataConvertOptions, bool>
95 std::ranges::to<std::map<process::DataConvertOptions, bool>>();
96 if (not std::ranges::contains(convert_map | std::views::values,
true))
114 .try_emplace(filename,
115 std::make_unique<BinaryFile>(filename, prev_conversion,
workflow_handler_->get_n_lines()))
122 auto endpoint = convert_str_to_endpoint(app.get_io_context(), filename);
123 if (endpoint.has_value())
126 .try_emplace(filename,
127 std::make_unique<UDP>(app.get_io_context(),
128 std::move(endpoint.value()),
143 std::make_unique<RootFile>(filename.c_str(), prev_conversion,
workflow_handler_->get_n_lines()))
153 .try_emplace(filename, std::make_unique<Json>(filename, prev_conversion,
workflow_handler_->get_n_lines()))
159 for (
const auto& filename : filenames)
161 if (filename.empty())
172 spdlog::error(
"Extension of the filename {:?} cannot be recognized!", filename);
182 if (not check_root_dependency())
195 spdlog::info(
"Add the output source {:?}", filename);
199 spdlog::error(
"The filename {:?} has been already added!", filename);
auto add_root_file(const std::string &filename, process::DataConvertOptions prev_conversion) -> bool
void enable_frame_count_checker()
std::map< std::string, std::unique_ptr< BinaryFile > > binary_files_
std::unique_ptr< FrameCountChecker > frame_count_checker_
std::map< std::string, std::unique_ptr< Json > > json_files_
void set_output_filenames(const std::vector< std::string > &filenames)
auto add_binary_file(const std::string &filename, process::DataConvertOptions prev_conversion) -> bool
auto is_convert_required(process::DataConvertOptions dependee) const -> bool
Manager(workflow::AnalysisHandle *processor)
std::map< std::string, std::unique_ptr< UDP > > udp_files_
auto add_json_file(const std::string &filename, process::DataConvertOptions prev_conversion) -> bool
workflow::AnalysisHandle * workflow_handler_
void do_for_each_sink(SinkVisitor auto visitor)
auto add_udp_file(const std::string &filename, process::DataConvertOptions prev_conversion) -> bool
auto generate_conversion_req_map() const -> std::map< process::DataConvertOptions, bool >
auto get_filetype_from_filename(std::string_view filename) -> std::tuple< DataWriterOption, process::DataConvertOptions >