SRS-control 0.1.4
Loading...
Searching...
No Matches
RootFileWriter.hpp
Go to the documentation of this file.
1#pragma once
2
3#ifdef HAS_ROOT
9#include <TFile.h>
10#include <TSystem.h>
11#include <TTree.h>
12#include <cassert>
13#include <cstddef>
14#include <memory>
15#include <spdlog/spdlog.h>
16#include <string>
17#include <vector>
18
19namespace srs::writer
20{
21 class RootFile : public process::WriterTask<DataWriterOption::root, const StructData*, std::size_t>
22 {
23 public:
24 static constexpr auto IsStructType = true;
25
26 RootFile(const std::string& filename, process::DataConvertOptions convert_mode, std::size_t n_lines);
27
28 auto run(const OutputTo<InputType> auto& prev_data_converter, std::size_t line_number) -> RunResult
29 {
30 assert(line_number < get_n_lines());
31 const auto* input_data = prev_data_converter(line_number);
32 assert(input_data != nullptr);
33 data_struct_buffers_[line_number] = *input_data;
34 output_data_[line_number] = static_cast<std::size_t>(trees_[line_number]->Fill());
35 return output_data_[line_number];
36 }
37
38 ~RootFile();
39 RootFile(const RootFile&) = delete;
40 RootFile(RootFile&&) = delete;
41 RootFile& operator=(const RootFile&) = delete;
42 RootFile& operator=(RootFile&&) = delete;
43
44 private:
45 std::string base_filename_;
46 std::vector<std::unique_ptr<TFile>> root_files_;
47 std::vector<TTree*> trees_;
48 std::vector<StructData> data_struct_buffers_;
49 std::vector<OutputType> output_data_;
50 };
51
52} // namespace srs::writer
53
54#endif