Skip to content

Commit

Permalink
allow to override setting in manager
Browse files Browse the repository at this point in the history
  • Loading branch information
KSkwarczynski committed Oct 8, 2024
1 parent fdbc0a9 commit 5929cdb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
5 changes: 2 additions & 3 deletions manager/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ manager::~manager() {
// *************************

if(!Modes) delete Modes;

}

// *************************
Expand Down Expand Up @@ -101,8 +100,8 @@ void manager::SaveSettings(TFile* const OutputFile) {
// *************************
void manager::Print() {
// *************************

MACH3LOG_INFO("---------------------------------");
std::cout << config << "\n";
MaCh3Utils::PrintConfig(config);
MACH3LOG_INFO("---------------------------------");
}

37 changes: 37 additions & 0 deletions manager/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,43 @@ class manager {
MaCh3Modes* GetMaCh3Modes() const { return Modes; }
/// @brief Get class name
inline std::string GetName()const {return "Manager";};

/// @brief Overrides the configuration settings based on provided arguments.
///
/// This function allows you to set configuration options for the manager.
/// It accepts either two or three string arguments:
/// - For two arguments, the first argument is a key, and the second is the value.
/// - For three arguments, the first two arguments are keys, and the third is the value.
///
/// @param args The arguments to override the configuration.
/// - When two arguments are provided, they represent the key and value, respectively.
/// - When three arguments are provided, they represent two keys and a value.
///
/// @note Example usage:
/// @code
/// FitManager->OverrideConfig("General", "OutputFile", "Wooimbouttamakeanameformyselfere.root");
/// @endcode
template <typename... Args>
void OverrideConfig(Args... args) {
static_assert(sizeof...(args) == 2 || sizeof...(args) == 3,
"OverrideConfig accepts either 2 or 3 arguments.");

auto args_tuple = std::make_tuple(args...); // Create a tuple from the parameter pack

if constexpr (sizeof...(args) == 2) {
std::string blarb1 = std::get<0>(args_tuple); // First argument
std::string result = std::get<1>(args_tuple); // Second argument

config[blarb1] = result;
}
else if constexpr (sizeof...(args) == 3) {
std::string blarb1 = std::get<0>(args_tuple); // First argument
std::string blarb2 = std::get<1>(args_tuple); // Second argument
std::string result = std::get<2>(args_tuple); // Third argument

config[blarb1][blarb2] = result;
}
}
private:
/// The YAML node containing the configuration data.
YAML::Node config;
Expand Down

0 comments on commit 5929cdb

Please sign in to comment.