6#include <FairRtdbRun.h>
10#include <fairlogger/Logger.h>
23 auto get_cycle_number(TFile* root_file, TObject* obj) ->
int
25 if (
auto* key = root_file->GetKey(obj->GetName()); key !=
nullptr)
27 return key->GetCycle();
30 "Failed to get the key with the name {:?} after it's written to the file {:?}",
32 root_file->GetName());
42 auto par_det_io = std::make_unique<DetParRootFileIo>(
this);
43 setDetParIo(par_det_io.release());
48 if (root_file ==
nullptr)
52 if (not root_file->IsOpen())
54 throw R3B::logic_error(fmt::format(
"Cannot open the root file {:?}", root_file->GetName()));
58 auto option = std::string_view{ root_file->GetOption() };
59 if (option !=
"read" and option !=
"READ")
61 LOGP(warn,
"Input parameter file {:?} should have read only permision", root_file->GetName());
66 if (not root_file->IsWritable())
68 throw R3B::logic_error(fmt::format(
"Cannot write the root file {:?}", root_file->GetName()));
76 open(std::make_unique<TFile>(file_name.data(), file_option.data()));
77 LOGP(debug,
"Open root file {:?}", file_name);
82 for (
const auto& file_name : filenames)
84 open(file_name, file_option);
107 auto ret_val = root_file->WriteObject(par, par->GetName());
112 "Failed to write the parameter {:?} to the file {:?} with the return value: {}",
114 root_file->GetName(),
118 return get_cycle_number(root_file, par);
123 auto old_log = gErrorIgnoreLevel;
124 gErrorIgnoreLevel = 1001;
125 const auto* par_name = par->GetName();
130 auto* par_run = root_file->GetKey(
run_name_.data());
131 if (par_run ==
nullptr)
137 auto ret_val = root_file->ReadTObject(par, par_name);
143 LOGP(info,
"Read parameter {:?} in the file {:?}", par_name, root_file->GetName());
144 gErrorIgnoreLevel = old_log;
147 gErrorIgnoreLevel = old_log;
167 LOGP(error,
"Input parameter IO has no files to read!");
171 LOGP(error,
"Output parameter IO has no file to write!");
180 LOGP(warn,
"Output parameter IO has more than one files (choosing the first)!");
183 LOGP(warn,
"\t{}", root_file->GetName());
194 LOGP(debug,
"closing the par IO file {}", root_file->GetName());
auto check() -> bool override
~ParRootFileIo() override
bool read_parameter(FairParSet *par)
Read a parameter from the input root file.
std::vector< std::unique_ptr< TFile > > root_files_
void open(std::string_view file_name, std::string_view file_option)
auto read_parameter_from_run(FairParSet *par, bool is_ignored) -> bool
void readVersions(FairRtdbRun *current_par_run) override
int write_parameter(FairParSet *par)
Write the parameter to the output root file.
ParRootFileIo(bool is_input)