46 MACH3LOG_ERROR(
"Where config.yaml is a valid config file, compatible with the Manager class (Manager/Manager.cpp/h)");
55 if ((argc == 4 && arg2 ==
"--override") ||
56 (argc == 3 && arg2.size() >= 5 && arg2.compare(arg2.size() - 5, 5,
".yaml") == 0)) {
57 std::string overrideFile;
59 if (arg2 ==
"--override") {
60 overrideFile = argv[3];
64 MACH3LOG_INFO(
"Merging configuration files: base config '{}', override config '{}'. "
65 "Options in '{}' will take precedence over '{}'.",
66 argv[1], overrideFile, overrideFile, argv[1]);
73 YAML::Node merged =
MergeNodes(config1, config2);
74 auto FitManager = std::make_unique<Manager>(merged);
80 auto FitManager = std::make_unique<Manager>(argv[1]);
83 auto SanityOverwrite = [](
const std::string& Name) {
84 if (Name.find(
"Systematics") != std::string::npos ||
85 Name.find(
"Samples") != std::string::npos)
87 MACH3LOG_CRITICAL(
"You are overwriting settings ({}) that are highly likely intended to be committed.", Name);
89 MACH3LOG_CRITICAL(
"If you're sure you want to do this, e.g. for testing or step size tuning, you can remove the throw that lives here:");
94 for (
int i = 2; i < argc; ++i)
96 const std::string arg = argv[i];
97 const size_t colonCount = std::count(arg.begin(), arg.end(),
':');
100 if (colonCount == 1) {
101 const size_t firstColon = arg.find(
':');
102 const std::string section = arg.substr(0, firstColon);
103 const std::string value = arg.substr(firstColon + 1);
105 MACH3LOG_INFO(
"Overriding setting: Section={}, Value={}", section, value);
106 SanityOverwrite(section);
107 FitManager->OverrideSettings(section, value);
108 }
else if (colonCount == 2) {
109 const size_t firstColon = arg.find(
':');
110 const size_t secondColon = arg.find(
':', firstColon + 1);
112 const std::string section = arg.substr(0, firstColon);
113 const std::string key = arg.substr(firstColon + 1, secondColon - firstColon - 1);
114 const std::string value = arg.substr(secondColon + 1);
116 MACH3LOG_INFO(
"Overriding setting: Section={}, Key={}, Value={}", section, key, value);
117 SanityOverwrite(section);
118 SanityOverwrite(key);
119 FitManager->OverrideSettings(section, key, value);
120 }
else if (colonCount == 3) {
121 const size_t firstColon = arg.find(
':');
122 const size_t secondColon = arg.find(
':', firstColon + 1);
123 const size_t thridColon = arg.find(
':', secondColon + 1);
125 const std::string section = arg.substr(0, firstColon);
126 const std::string key = arg.substr(firstColon + 1, secondColon - firstColon - 1);
127 const std::string key2 = arg.substr(secondColon + 1, thridColon - secondColon - 1);
128 const std::string value = arg.substr(thridColon + 1);
130 MACH3LOG_INFO(
"Overriding setting: Section={}, Key={}, Key={}, Value={}", section, key, key2, value);
131 SanityOverwrite(section);
132 SanityOverwrite(key);
133 SanityOverwrite(key2);
134 FitManager->OverrideSettings(section, key, key2, value);
135 }
else if (colonCount == 4) {
136 const size_t firstColon = arg.find(
':');
137 const size_t secondColon = arg.find(
':', firstColon + 1);
138 const size_t thirdColon = arg.find(
':', secondColon + 1);
139 const size_t fourthColon = arg.find(
':', thirdColon + 1);
141 const std::string section = arg.substr(0, firstColon);
142 const std::string key = arg.substr(firstColon + 1, secondColon - firstColon - 1);
143 const std::string key2 = arg.substr(secondColon + 1, thirdColon - secondColon - 1);
144 const std::string key3 = arg.substr(thirdColon + 1, fourthColon - thirdColon - 1);
145 const std::string value = arg.substr(fourthColon + 1);
148 "Overriding setting: Section={}, Key={}, Key={}, Key={}, Value={}",
149 section, key, key2, key3, value);
151 SanityOverwrite(section);
152 SanityOverwrite(key);
153 SanityOverwrite(key2);
154 SanityOverwrite(key3);
156 FitManager->OverrideSettings(section, key, key2, key3, value);
159 MACH3LOG_ERROR(
"Expected format:Section:Key:Key:Value, Section:Key:Value or Section:Value");
#define MACH3LOG_CRITICAL
YAML::Node MergeNodes(const YAML::Node &a, const YAML::Node &b)
KS: Recursively merges two YAML nodes.
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Custom exception class used throughout MaCh3.