12#include <nlohmann/json.hpp>
13#include <nlohmann/json_fwd.hpp>
45 std::vector<std::string>
data;
53 std::string
data =
"output.root";
54 std::string
par =
"output.par.root";
59 std::unique_ptr<FairRun>
run,
60 std::reference_wrapper<Options> option);
69 template <
typename CLIAPP,
typename OptionType>
72 template <
typename OptionType>
75 template <
typename OptionType>
86 option_.get().input.par_2 = inputpar_filename;
90 option_.get().output.par = outputpar_filename;
95 std::copy(input_filename.begin(), input_filename.end(), std::back_inserter(
option_.get().input.data));
99 std::copy(input_filename.begin(), input_filename.end(), std::back_inserter(
option_.get().input.tree_data));
108 template <
typename OptionType>
128 void init()
override;
153 const std::vector<std::string>& filenames_or_options);
156 template <
typename OptionType>
159 using json = nlohmann::ordered_json;
160 auto json_obj =
json{ options };
161 if (json_obj.is_array())
163 fmt::print(
"{}\n", json_obj.front().dump(4));
167 fmt::print(
"{}\n", json_obj.dump(4));
171 template <
typename OptionType>
174 using json = nlohmann::ordered_json;
175 auto file = std::ofstream{ filename, std::ios::trunc };
176 auto json_obj =
json{ options };
177 if (json_obj.is_array())
179 file << json_obj.front().dump(4);
183 file << json_obj.dump(4);
185 fmt::println(
"Configuration of {} is saved into the file {:?}",
app_name_, filename);
188 template <
typename OptionType>
192 auto json_obj = [&options]()
194 auto json_obj_tmp = nlohmann::ordered_json{ options };
195 return json_obj_tmp.is_array() ? json_obj_tmp.front() : json_obj_tmp;
198 json_obj.get_to(options);
CLIAbstract()=default
Default constructor.
bool has_print_default_options_
void post_parse() override
Action done after the option parsing.
static void patch_files_or_strings(nlohmann::ordered_json &json_obj, const std::vector< std::string > &filenames_or_options)
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_
CLIApplication(const CLIApplication &)=delete
virtual void post_init(FairRun *run)
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)
void set_second_inputpar_filename(std::string_view inputpar_filename)
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)
void set_inputpar_filename(std::string_view inputpar_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
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
nlohmann::ordered_json json
std::string verbose_level
struct R3B::Neuland::CLIApplication::Options::Input input
struct R3B::Neuland::CLIApplication::Options::Output output