9#include <fairlogger/Logger.h>
12#include <fmt/format.h>
15#include <glaze/core/context.hpp>
16#include <glaze/core/opts.hpp>
17#include <glaze/core/ostream_buffer.hpp>
18#include <glaze/core/reflect.hpp>
19#include <glaze/json/write.hpp>
66 std::vector<std::string>
data;
68 std::vector<std::string>
par;
73 std::string
data =
"output.root";
74 std::string
par =
"output.par.root";
80 std::unique_ptr<FairRun>
run,
81 std::reference_wrapper<Options> option);
90 template <
typename CLIAPP,
typename OptionType>
93 template <
typename OptionType>
96 template <
typename OptionType>
106 option_.get().input.par.emplace_back(inputpar_filename);
110 option_.get().output.par = outputpar_filename;
115 std::ranges::copy(input_filename, std::back_inserter(
option_.get().input.data));
119 std::ranges::copy(input_filename, std::back_inserter(
option_.get().input.tree_data));
128 template <
typename OptionType>
148 void init()
override;
184 template <
typename OptionType>
187 fmt::println(
"{}", glz::write<glz::opts{ .prettify =
true }>(options).value_or(
"error occurred"));
190 template <
typename OptionType>
194 auto file = std::ofstream{ filename, std::ios::trunc };
195 auto buffer = glz::basic_ostream_buffer<std::ofstream>{
file };
196 auto error = glz::write<glz::opts{ .prettify =
true }>(options, buffer);
200 fmt::println(
"Error occurred:{}", glz::format_error(error));
204 fmt::println(
"Configuration of {} is saved into the file {:?}",
app_name_, filename);
208 template <
typename OptionType>
212 auto buffer = std::string{};
214 for (
const auto& filename_or_option : filenames_or_options)
217 auto error_code = glz::error_ctx{};
222 buffer = filename_or_option;
223 LOGP(info,
"Reading the configuration from the native JSON string {:?}.", buffer);
224 error_code = glz::read_json(options, buffer);
230 LOGP(info,
"Reading the configuration from the string {:?}.", buffer);
231 error_code = glz::read_json(options, buffer);
236 LOGP(info,
"Reading the configuration from the JSON file {:?}.", filename_or_option);
237 error_code = glz::read_file_json(options, filename_or_option, buffer);
241 throw R3B::logic_error(fmt::format(
"Cannot parse the string {:?}", filename_or_option));
245 throw R3B::logic_error(fmt::format(
"Failed to parse to the JSON object from {:?}:\n{}",
247 glz::format_error(error_code, buffer)));
CLIAbstract()=default
Default constructor.
bool has_print_default_options_
void post_parse() override
Action done after the option parsing.
auto operator=(const CLIApplication &) -> CLIApplication &=delete
void set_rank_num(int val) override
void set_input_filename(const std::vector< std::string > &input_filename)
virtual void setup_application_options(CLI::App &program_options)
std::vector< std::pair< std::string, bool > > input_files_
static auto check_json_input_type(std::string_view input) -> JSONConfigInputType
CLIApplication(const CLIApplication &)=delete
virtual void post_init(FairRun *run)
static void transform_to_json_string(std::string_view input, std::string &buffer)
void dump_options() override
void set_outputpar_filename(std::string_view outputpar_filename)
void set_log_level(std::string_view log_level)
auto operator=(CLIApplication &&) -> CLIApplication &=delete
void run() override
Run the CLI program.
void extract_input_files()
std::reference_wrapper< Options > option_
std::string dump_json_filename_
void ParseApplicationOptionImp(const std::vector< std::string > &filename, OptionType &options)
void add_input_filename(R3BFileSource2 *filesource)
CLIApplication(std::string_view name, std::unique_ptr< FairRun > run, std::reference_wrapper< Options > option)
auto has_dump() const -> bool override
Check whether the options should be dump to a JSON file.
void set_event_num(int val)
auto has_print_default_options() const -> bool override
Check the flag whether the default options should be printed in JSON strings.
~CLIApplication() override
void set_run_id(int run_id)
void set_output_filename(std::string_view output_filename)
void dump_json_options(const OptionType &options, const std::string &filename)
virtual void ParseApplicationOption(const std::vector< std::string > &filename_or_option)=0
void setup_options(CLI::App &program_options) override
Setup the CLI options given to the program.
virtual void pre_init(FairRun *run)=0
void add_inputpar_filename(std::string_view inputpar_filename)
virtual void run_action(FairRun *run, int num_of_events)
CLIApplication(CLIApplication &&)=delete
void init() override
Initialization of a CLI program.
static void setup_logger()
auto get_run() -> FairRun *
void set_num_of_procs(int val) override
std::unique_ptr< FairRun > run_
virtual void print_json_options()
void setup_common_options(CLIAPP &program_options, OptionType &options)
void print_options() override
virtual void dump_json_options(const std::string &filename)
void set_tree_input_filename(const std::vector< std::string > &input_filename)
Simulation of NeuLAND Bar/Paddle.
constexpr auto DEFAULT_EVENT_NUM
const auto DEFAULT_JSON_FILENAME
constexpr auto DEFAULT_RUN_ID
std::string verbose_level
struct R3B::Neuland::CLIApplication::Options::Input input
struct R3B::Neuland::CLIApplication::Options::Output output