16 using InputType =
const StructData*;
17 using OutputType = int;
18 using CoroType = asio::experimental::coro<OutputType(std::optional<InputType>)>;
19 using InputFuture = boost::shared_future<std::optional<InputType>>;
20 using OutputFuture = boost::unique_future<std::optional<OutputType>>;
21 static constexpr auto IsStructType =
true;
23 explicit RootFile(asio::thread_pool& thread_pool,
auto&&... args)
24 : root_file{ std::forward<decltype(args)>(args)... }
26 spdlog::debug(
"Root file {:?} has been opened.", root_file.GetName());
27 tree.SetDirectory(&root_file);
28 tree.Branch(
"srs_frame_data", &output_buffer_);
29 coro_ = generate_coro(thread_pool.get_executor());
30 common::coro_sync_start(coro_, std::optional<InputType>{}, asio::use_awaitable);
39 spdlog::error(
"Root file {:?} is not closed successfully. Data might not be written completely.",
44 auto write(
auto pre_future) -> OutputFuture {
return common::create_coro_future(coro_, pre_future); }
45 [[nodiscard]]
static auto get_convert_mode() -> process::DataConvertOptions
47 return process::DataConvertOptions::structure;
51 bool is_closed_ =
false;
54 TTree tree{
"srs_data_tree",
"Data structures from SRS system" };
55 StructData output_buffer_;
58 auto generate_coro(asio::any_io_executor ) -> CoroType
60 InputType data_struct{};
65 if (data_struct !=
nullptr)
67 output_buffer_ = *data_struct;
71 auto data_temp =
co_yield res;
72 if (data_temp.has_value())
74 data_struct = data_temp.value();
79 spdlog::info(
"ROOT file {} is closed successfully", root_file.GetName());
87 RootFile(
const RootFile&) =
delete;
88 RootFile(RootFile&&) =
delete;
89 RootFile& operator=(
const RootFile&) =
delete;
90 RootFile& operator=(RootFile&&) =
delete;