diff --git a/neuland/application/R3BNeulandAnalysisApp.h b/neuland/application/R3BNeulandAnalysisApp.h index fbc586de7..83734f4f6 100644 --- a/neuland/application/R3BNeulandAnalysisApp.h +++ b/neuland/application/R3BNeulandAnalysisApp.h @@ -112,7 +112,7 @@ namespace R3B::Neuland void print_json_options() override; void dump_json_options(const std::string& filename) override; void setup_application_options(CLI::App& program_options) override; - void ParseApplicationOption(const std::string& filename) override + void ParseApplicationOption(const std::vector& filename) override { ParseApplicationOptionImp(filename, options_); } diff --git a/neuland/application/R3BNeulandApp.cxx b/neuland/application/R3BNeulandApp.cxx index 6a873144b..823db98fa 100644 --- a/neuland/application/R3BNeulandApp.cxx +++ b/neuland/application/R3BNeulandApp.cxx @@ -1,5 +1,5 @@ -#include "R3BFileSource2.h" #include "R3BNeulandApp.h" +#include "R3BFileSource2.h" #include #include #include @@ -96,7 +96,7 @@ namespace R3B::Neuland dump_json_filename_ = filename; }; - auto use_config_callback = [this](const std::string& filename) + auto use_config_callback = [this](const std::vector& filename) { if (not is_already_parsed_) { @@ -107,10 +107,10 @@ namespace R3B::Neuland auto& options = option_.get(); program_options - .add_option_function("-c, --config-file", use_config_callback, "Set the json config file") + .add_option_function>( + "-c, --config-file", use_config_callback, "Set the json config file") ->default_val(fmt::format("{}_{}", app_name_, DEFAULT_JSON_FILENAME)) ->run_callback_for_default() - ->expected(0, 1) ->trigger_on_parse(); program_options.add_flag("--print-config", has_print_default_options_, "Print default option value"); program_options @@ -150,7 +150,6 @@ namespace R3B::Neuland void Application::add_inout_files() { const auto& option = option_.get(); - // output files: const auto output_name = option.enable_mpi ? fmt::format("{}.{}", option.output.data, rank_num_) : option.output.data; if (not option_.get().output.data.empty()) @@ -164,6 +163,7 @@ namespace R3B::Neuland if (option_.get().run_id >= 0) { file_source->SetInitRunID(option_.get().run_id); + run_->SetRunId(option_.get().run_id); R3BLOG(info, fmt::format("Filesource2: Set to run id {}", option_.get().run_id)); } add_input_filename(file_source.get()); @@ -191,8 +191,11 @@ namespace R3B::Neuland if (not option_.get().output.par.empty()) { + const auto& option = option_.get(); + const auto output_name = + option.enable_mpi ? fmt::format("{}.{}", option.output.par, rank_num_) : option.output.par; auto fileio = std::make_unique(true); - fileio->open(option_.get().output.par.c_str(), "RECREATE"); + fileio->open(output_name.c_str(), "RECREATE"); auto* rtdb = run_->GetRuntimeDb(); rtdb->setOutput(fileio.release()); } diff --git a/neuland/application/R3BNeulandApp.h b/neuland/application/R3BNeulandApp.h index 57be72206..a3448ac41 100644 --- a/neuland/application/R3BNeulandApp.h +++ b/neuland/application/R3BNeulandApp.h @@ -108,7 +108,7 @@ namespace R3B::Neuland protected: template - void ParseApplicationOptionImp(const std::string& filename, OptionType& option); + void ParseApplicationOptionImp(const std::vector& filename, OptionType& option); private: bool is_failed_ = false; @@ -127,7 +127,7 @@ namespace R3B::Neuland // private virtual methods: virtual void pre_init(FairRun* run) = 0; - virtual void ParseApplicationOption(const std::string& filename) = 0; + virtual void ParseApplicationOption(const std::vector& filename) = 0; virtual void post_init(FairRun* run) {} void add_input_filename(R3BFileSource2* filesource); virtual void print_json_options() {} @@ -175,11 +175,17 @@ namespace R3B::Neuland } template - void Application::ParseApplicationOptionImp(const std::string& filename, OptionType& option) + void Application::ParseApplicationOptionImp(const std::vector& filenames, OptionType& option) { - auto file = std::ifstream{ filename }; - auto json_obj = nlohmann::json{}; - file >> json_obj; + auto json_obj = nlohmann::ordered_json{ option }; + for (const auto& filename : filenames) + { + auto json_file_obj = nlohmann::ordered_json{}; + auto file = std::ifstream{ filename }; + file >> json_file_obj; + R3BLOG(info, fmt::format("Reading the configuration from the json file {:?}", filename)); + json_obj.merge_patch(json_file_obj); + } json_obj.get_to(option); } } // namespace R3B::Neuland diff --git a/neuland/application/R3BNeulandSimApp.h b/neuland/application/R3BNeulandSimApp.h index 2c7ad4f1d..d89569f1f 100644 --- a/neuland/application/R3BNeulandSimApp.h +++ b/neuland/application/R3BNeulandSimApp.h @@ -68,7 +68,7 @@ namespace R3B::Neuland void print_json_options() override; void dump_json_options(const std::string& filename) override; void run_action(FairRun* run, int num_of_events) override; - void ParseApplicationOption(const std::string& filename) override + void ParseApplicationOption(const std::vector& filename) override { ParseApplicationOptionImp(filename, options_); } diff --git a/neuland/executables/neuland_cli.cxx b/neuland/executables/neuland_cli.cxx index 46b15a8c8..b86503435 100644 --- a/neuland/executables/neuland_cli.cxx +++ b/neuland/executables/neuland_cli.cxx @@ -60,6 +60,8 @@ auto main(int argc, char** argv) -> int return EXIT_SUCCESS; } + app->set_rank_num(num_rank); + app->set_num_of_procs(num_proc); app->init(); app->run(); }