Line | Branch | Exec | Source |
---|---|---|---|
1 | #include "Algorithm.h" | ||
2 | |||
3 | namespace iguana { | ||
4 | |||
5 | 12 | void Algorithm::Start() | |
6 | { | ||
7 |
1/2✓ Branch 0 (2→3) taken 12 times.
✗ Branch 1 (2→5) not taken.
|
12 | m_rows_only = true; |
8 | hipo::banklist no_banks = {}; | ||
9 |
1/2✓ Branch 0 (2→3) taken 12 times.
✗ Branch 1 (2→5) not taken.
|
12 | Start(no_banks); |
10 | 12 | } | |
11 | |||
12 | /////////////////////////////////////////////////////////////////////////////// | ||
13 | |||
14 | template <typename OPTION_TYPE> | ||
15 | 84 | OPTION_TYPE Algorithm::GetOptionScalar(std::string const& key, YAMLReader::node_path_t node_path) const | |
16 | { | ||
17 | 84 | CompleteOptionNodePath(key, node_path); | |
18 | 84 | auto opt = GetCachedOption<OPTION_TYPE>(key); | |
19 |
2/2✓ Branch 0 (4→5) taken 82 times.
✓ Branch 1 (4→13) taken 2 times.
|
84 | if(!opt.has_value()) { |
20 |
3/4✓ Branch 0 (5→6) taken 81 times.
✓ Branch 1 (5→36) taken 1 times.
✓ Branch 2 (6→7) taken 46 times.
✗ Branch 3 (6→30) not taken.
|
128 | opt = m_yaml_config->GetScalar<OPTION_TYPE>(node_path); |
21 | } | ||
22 |
2/2✓ Branch 0 (13→14) taken 2 times.
✓ Branch 1 (13→21) taken 81 times.
|
83 | if(!opt.has_value()) { |
23 |
1/2✓ Branch 0 (16→17) taken 2 times.
✗ Branch 1 (16→32) not taken.
|
2 | m_log->Error("Failed to `GetOptionScalar` for key {:?}", key); |
24 |
1/2✓ Branch 0 (19→20) taken 2 times.
✗ Branch 1 (19→34) not taken.
|
2 | throw std::runtime_error("config file parsing issue"); |
25 | } | ||
26 |
2/6✓ Branch 0 (21→22) taken 81 times.
✗ Branch 1 (21→36) not taken.
✓ Branch 2 (22→23) taken 48 times.
✗ Branch 3 (22→24) not taken.
✗ Branch 4 (36→37) not taken.
✗ Branch 5 (36→39) not taken.
|
81 | PrintOptionValue(key, opt.value()); |
27 | 81 | return opt.value(); | |
28 | } | ||
29 | template int Algorithm::GetOptionScalar(std::string const& key, YAMLReader::node_path_t node_path) const; | ||
30 | template double Algorithm::GetOptionScalar(std::string const& key, YAMLReader::node_path_t node_path) const; | ||
31 | template std::string Algorithm::GetOptionScalar(std::string const& key, YAMLReader::node_path_t node_path) const; | ||
32 | |||
33 | /////////////////////////////////////////////////////////////////////////////// | ||
34 | |||
35 | template <typename OPTION_TYPE> | ||
36 | 41 | std::vector<OPTION_TYPE> Algorithm::GetOptionVector(std::string const& key, YAMLReader::node_path_t node_path) const | |
37 | { | ||
38 | 41 | CompleteOptionNodePath(key, node_path); | |
39 | 41 | auto opt = GetCachedOption<std::vector<OPTION_TYPE>>(key); | |
40 |
2/2✓ Branch 0 (4→5) taken 31 times.
✓ Branch 1 (4→13) taken 10 times.
|
41 | if(!opt.has_value()) { |
41 |
2/4✓ Branch 0 (5→6) taken 31 times.
✗ Branch 1 (5→35) not taken.
✓ Branch 2 (6→7) taken 31 times.
✗ Branch 3 (6→29) not taken.
|
62 | opt = m_yaml_config->GetVector<OPTION_TYPE>(node_path); |
42 | } | ||
43 |
2/2✓ Branch 0 (13→14) taken 4 times.
✓ Branch 1 (13→21) taken 37 times.
|
41 | if(!opt.has_value()) { |
44 |
1/2✓ Branch 0 (16→17) taken 4 times.
✗ Branch 1 (16→31) not taken.
|
4 | m_log->Error("Failed to `GetOptionVector` for key {:?}", key); |
45 |
1/2✓ Branch 0 (19→20) taken 4 times.
✗ Branch 1 (19→33) not taken.
|
4 | throw std::runtime_error("config file parsing issue"); |
46 | } | ||
47 |
2/6✓ Branch 0 (21→22) taken 37 times.
✗ Branch 1 (21→35) not taken.
✓ Branch 2 (22→23) taken 37 times.
✗ Branch 3 (22→24) not taken.
✗ Branch 4 (35→36) not taken.
✗ Branch 5 (35→38) not taken.
|
41 | PrintOptionValue(key, opt.value()); |
48 |
1/2✓ Branch 0 (23→25) taken 37 times.
✗ Branch 1 (23→35) not taken.
|
74 | return opt.value(); |
49 | } | ||
50 | template std::vector<int> Algorithm::GetOptionVector(std::string const& key, YAMLReader::node_path_t node_path) const; | ||
51 | template std::vector<double> Algorithm::GetOptionVector(std::string const& key, YAMLReader::node_path_t node_path) const; | ||
52 | template std::vector<std::string> Algorithm::GetOptionVector(std::string const& key, YAMLReader::node_path_t node_path) const; | ||
53 | |||
54 | /////////////////////////////////////////////////////////////////////////////// | ||
55 | |||
56 | template <typename OPTION_TYPE> | ||
57 | 17 | std::set<OPTION_TYPE> Algorithm::GetOptionSet(std::string const& key, YAMLReader::node_path_t node_path) const | |
58 | { | ||
59 |
3/4✓ Branch 0 (3→4) taken 15 times.
✓ Branch 1 (3→8) taken 2 times.
✓ Branch 2 (5→6) taken 15 times.
✗ Branch 3 (5→10) not taken.
|
17 | auto val_vec = GetOptionVector<OPTION_TYPE>(key, node_path); |
60 | std::set<OPTION_TYPE> val_set; | ||
61 | std::copy(val_vec.begin(), val_vec.end(), std::inserter(val_set, val_set.end())); | ||
62 | 15 | return val_set; | |
63 | 1 | } | |
64 | template std::set<int> Algorithm::GetOptionSet(std::string const& key, YAMLReader::node_path_t node_path) const; | ||
65 | template std::set<double> Algorithm::GetOptionSet(std::string const& key, YAMLReader::node_path_t node_path) const; | ||
66 | template std::set<std::string> Algorithm::GetOptionSet(std::string const& key, YAMLReader::node_path_t node_path) const; | ||
67 | |||
68 | /////////////////////////////////////////////////////////////////////////////// | ||
69 | |||
70 | 100 | void Algorithm::SetName(std::string_view name) | |
71 | { | ||
72 | 100 | Object::SetName(name); | |
73 |
1/2✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→8) taken 100 times.
|
100 | if(m_yaml_config) |
74 | ✗ | m_yaml_config->SetName("config|" + m_name); | |
75 | 100 | } | |
76 | |||
77 | /////////////////////////////////////////////////////////////////////////////// | ||
78 | |||
79 | 42 | std::unique_ptr<YAMLReader> const& Algorithm::GetConfig() const | |
80 | { | ||
81 | 42 | return m_yaml_config; | |
82 | } | ||
83 | |||
84 | /////////////////////////////////////////////////////////////////////////////// | ||
85 | |||
86 | ✗ | void Algorithm::SetConfig(std::unique_ptr<YAMLReader>&& yaml_config) | |
87 | { | ||
88 | m_yaml_config = std::move(yaml_config); | ||
89 | ✗ | } | |
90 | |||
91 | /////////////////////////////////////////////////////////////////////////////// | ||
92 | |||
93 | 6 | void Algorithm::SetConfigFile(std::string const& name) | |
94 | { | ||
95 |
2/4✓ Branch 0 (3→4) taken 6 times.
✗ Branch 1 (3→12) not taken.
✓ Branch 2 (4→5) taken 6 times.
✗ Branch 3 (4→10) not taken.
|
12 | o_user_config_file = SetOption("config_file", name); |
96 | 6 | } | |
97 | |||
98 | /////////////////////////////////////////////////////////////////////////////// | ||
99 | |||
100 | 6 | void Algorithm::SetConfigDirectory(std::string const& name) | |
101 | { | ||
102 |
2/4✓ Branch 0 (3→4) taken 6 times.
✗ Branch 1 (3→12) not taken.
✓ Branch 2 (4→5) taken 6 times.
✗ Branch 3 (4→10) not taken.
|
12 | o_user_config_dir = SetOption("config_dir", name); |
103 | 6 | } | |
104 | |||
105 | /////////////////////////////////////////////////////////////////////////////// | ||
106 | |||
107 |
1/2✓ Branch 0 (2→3) taken 41 times.
✗ Branch 1 (2→32) not taken.
|
41 | void Algorithm::ParseYAMLConfig() |
108 | { | ||
109 | |||
110 | // start YAMLReader instance, if not yet started | ||
111 |
1/2✓ Branch 0 (2→3) taken 41 times.
✗ Branch 1 (2→32) not taken.
|
41 | if(!m_yaml_config) { |
112 | // set config files and directories specified by `::SetConfigFile`, `::SetConfigDirectory`, etc. | ||
113 |
2/4✓ Branch 0 (4→5) taken 41 times.
✗ Branch 1 (4→62) not taken.
✓ Branch 2 (5→6) taken 41 times.
✗ Branch 3 (5→58) not taken.
|
41 | o_user_config_file = GetCachedOption<std::string>("config_file").value_or(""); |
114 |
2/4✓ Branch 0 (13→14) taken 41 times.
✗ Branch 1 (13→68) not taken.
✓ Branch 2 (14→15) taken 41 times.
✗ Branch 3 (14→64) not taken.
|
82 | o_user_config_dir = GetCachedOption<std::string>("config_dir").value_or(""); |
115 | 41 | m_log->Debug("Instantiating `YAMLReader`"); | |
116 |
1/2✓ Branch 0 (23→24) taken 41 times.
✗ Branch 1 (23→70) not taken.
|
82 | m_yaml_config = std::make_unique<YAMLReader>("config|" + m_name); |
117 | 41 | m_yaml_config->SetLogLevel(m_log->GetLevel()); // synchronize log levels | |
118 | 41 | m_yaml_config->AddDirectory(o_user_config_dir); | |
119 | 41 | m_yaml_config->AddFile(m_default_config_file); | |
120 | 41 | m_yaml_config->AddFile(o_user_config_file); | |
121 | } | ||
122 | else | ||
123 | ✗ | m_log->Debug("`YAMLReader` already instantiated for this algorithm; using that"); | |
124 | |||
125 | // parse the files | ||
126 | 41 | m_yaml_config->LoadFiles(); | |
127 | |||
128 | // if "log" was not set by `SetOption` (i.e., not in `m_option_cache`) | ||
129 | // - NB: not using `GetCachedOption<T>` here, since `T` can be a few different types for key=='log' | ||
130 |
2/2✓ Branch 0 (38→39) taken 24 times.
✓ Branch 1 (38→57) taken 17 times.
|
82 | if(m_option_cache.find("log") == m_option_cache.end()) { |
131 | // check if 'log' is set in the YAML node for this algorithm | ||
132 |
6/10✓ Branch 0 (41→42) taken 24 times.
✗ Branch 1 (41→74) not taken.
✓ Branch 2 (42→43) taken 24 times.
✗ Branch 3 (42→72) not taken.
✓ Branch 4 (45→46) taken 48 times.
✓ Branch 5 (45→48) taken 24 times.
✓ Branch 6 (48→49) taken 3 times.
✓ Branch 7 (48→53) taken 21 times.
✗ Branch 8 (75→76) not taken.
✗ Branch 9 (75→78) not taken.
|
72 | auto log_level_from_yaml = m_yaml_config->GetScalar<std::string>({m_class_name, "log"}); |
133 |
2/2✓ Branch 0 (48→49) taken 3 times.
✓ Branch 1 (48→53) taken 21 times.
|
24 | if(log_level_from_yaml) { |
134 |
1/2✓ Branch 0 (49→50) taken 3 times.
✗ Branch 1 (49→84) not taken.
|
3 | m_log->SetLevel(log_level_from_yaml.value()); |
135 |
2/4✓ Branch 0 (50→51) taken 3 times.
✗ Branch 1 (50→52) not taken.
✓ Branch 2 (51→53) taken 3 times.
✗ Branch 3 (51→84) not taken.
|
3 | m_yaml_config->SetLogLevel(log_level_from_yaml.value()); |
136 | } | ||
137 | } | ||
138 |
0/2✗ Branch 0 (80→81) not taken.
✗ Branch 1 (80→83) not taken.
|
41 | } |
139 | |||
140 | /////////////////////////////////////////////////////////////////////////////// | ||
141 | |||
142 | 134 | hipo::banklist::size_type Algorithm::GetBankIndex(hipo::banklist& banks, std::string const& bank_name) const | |
143 | { | ||
144 |
2/2✓ Branch 0 (2→3) taken 114 times.
✓ Branch 1 (2→9) taken 20 times.
|
134 | if(m_rows_only) |
145 | return 0; | ||
146 | try { | ||
147 |
1/2✓ Branch 0 (3→4) taken 114 times.
✗ Branch 1 (3→12) not taken.
|
114 | auto idx = hipo::getBanklistIndex(banks, bank_name); |
148 |
1/2✓ Branch 0 (6→7) taken 114 times.
✗ Branch 1 (6→10) not taken.
|
114 | m_log->Debug("cached index of bank '{}' is {}", bank_name, idx); |
149 | 114 | return idx; | |
150 | ✗ | } catch(std::runtime_error const& ex) { | |
151 | ✗ | m_log->Error("required input bank '{}' not found; cannot `Start` algorithm '{}'", bank_name, m_class_name); | |
152 | ✗ | auto creators = AlgorithmFactory::QueryNewBank(bank_name); | |
153 | ✗ | if(creators) | |
154 | ✗ | m_log->Error(" -> this bank is created by algorithm(s) [{}]; please `Start` ONE of them BEFORE this algorithm", fmt::join(creators.value(), ", ")); | |
155 | ✗ | throw std::runtime_error("cannot cache bank index"); | |
156 | ✗ | } | |
157 | } | ||
158 | |||
159 | /////////////////////////////////////////////////////////////////////////////// | ||
160 | |||
161 | 23 | void Algorithm::PrintOptionValue(std::string const& key, int const& val, Logger::Level const level, std::string_view prefix) const | |
162 | { | ||
163 |
1/2✓ Branch 0 (3→4) taken 23 times.
✗ Branch 1 (3→6) not taken.
|
23 | m_log->Print(level, "{}: {:>20} = {} [int]", prefix, key, val); |
164 | 23 | } | |
165 | |||
166 | 10 | void Algorithm::PrintOptionValue(std::string const& key, double const& val, Logger::Level const level, std::string_view prefix) const | |
167 | { | ||
168 |
1/2✓ Branch 0 (3→4) taken 10 times.
✗ Branch 1 (3→6) not taken.
|
10 | m_log->Print(level, "{}: {:>20} = {} [double]", prefix, key, val); |
169 | 10 | } | |
170 | |||
171 | 48 | void Algorithm::PrintOptionValue(std::string const& key, std::string const& val, Logger::Level const level, std::string_view prefix) const | |
172 | { | ||
173 |
1/2✓ Branch 0 (5→6) taken 48 times.
✗ Branch 1 (5→9) not taken.
|
48 | m_log->Print(level, "{}: {:>20} = {:?} [string]", prefix, key, val); |
174 | 48 | } | |
175 | |||
176 |
1/2✓ Branch 0 (2→3) taken 16 times.
✗ Branch 1 (2→9) not taken.
|
16 | void Algorithm::PrintOptionValue(std::string const& key, std::vector<int> const& val, Logger::Level const level, std::string_view prefix) const |
177 | { | ||
178 |
1/2✓ Branch 0 (4→5) taken 16 times.
✗ Branch 1 (4→7) not taken.
|
16 | m_log->Print(level, "{}: {:>20} = ({}) [std::vector<int>]", prefix, key, fmt::join(val, ", ")); |
179 | 16 | } | |
180 | |||
181 |
1/2✓ Branch 0 (2→3) taken 16 times.
✗ Branch 1 (2→9) not taken.
|
16 | void Algorithm::PrintOptionValue(std::string const& key, std::vector<double> const& val, Logger::Level const level, std::string_view prefix) const |
182 | { | ||
183 |
1/2✓ Branch 0 (4→5) taken 16 times.
✗ Branch 1 (4→7) not taken.
|
16 | m_log->Print(level, "{}: {:>20} = ({}) [std::vector<double>]", prefix, key, fmt::join(val, ", ")); |
184 | 16 | } | |
185 | |||
186 | 5 | void Algorithm::PrintOptionValue(std::string const& key, std::vector<std::string> const& val, Logger::Level const level, std::string_view prefix) const | |
187 | { | ||
188 | std::vector<std::string> val_quoted; | ||
189 |
2/2✓ Branch 0 (7→3) taken 12 times.
✓ Branch 1 (7→8) taken 5 times.
|
17 | for(auto const& s : val) |
190 |
1/2✓ Branch 0 (4→5) taken 12 times.
✗ Branch 1 (4→14) not taken.
|
24 | val_quoted.push_back(fmt::format("{:?}", s)); |
191 |
1/2✓ Branch 0 (10→11) taken 5 times.
✗ Branch 1 (10→16) not taken.
|
5 | m_log->Print(level, "{}: {:>20} = ({}) [std::vector<string>]", prefix, key, fmt::join(val_quoted, ", ")); |
192 | 5 | } | |
193 | |||
194 | /////////////////////////////////////////////////////////////////////////////// | ||
195 | |||
196 | 105900 | hipo::bank& Algorithm::GetBank(hipo::banklist& banks, hipo::banklist::size_type const idx, std::string const& expected_bank_name) const | |
197 | { | ||
198 |
1/2✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→5) taken 105900 times.
|
105900 | if(m_rows_only) { |
199 | ✗ | m_log->Error("algorithm is in 'rows only' mode; cannot call `Run` since banks are not cached; use action function(s) instead"); | |
200 | } | ||
201 | else { | ||
202 | try { | ||
203 |
1/2✓ Branch 0 (5→6) taken 105900 times.
✗ Branch 1 (5→30) not taken.
|
105900 | auto& result = banks.at(idx); |
204 |
4/6✓ Branch 0 (6→7) taken 92600 times.
✓ Branch 1 (6→13) taken 13300 times.
✗ Branch 2 (9→10) not taken.
✓ Branch 3 (9→11) taken 92600 times.
✗ Branch 4 (13→14) not taken.
✓ Branch 5 (13→22) taken 105900 times.
|
291100 | if(!expected_bank_name.empty() && result.getSchema().getName() != expected_bank_name) |
205 | ✗ | m_log->Error("expected input bank '{}' at index={}; got bank named '{}'", expected_bank_name, idx, result.getSchema().getName()); | |
206 | else | ||
207 | 105900 | return result; | |
208 | } | ||
209 | ✗ | catch(std::out_of_range const& o) { | |
210 | ✗ | m_log->Error("required input bank '{}' not found; cannot `Run` algorithm '{}'", expected_bank_name, m_class_name); | |
211 | ✗ | auto creators = AlgorithmFactory::QueryNewBank(expected_bank_name); | |
212 | ✗ | if(creators) | |
213 | ✗ | m_log->Error(" -> this bank is created by algorithm(s) [{}]; please `Run` ONE of them BEFORE this algorithm", fmt::join(creators.value(), ", ")); | |
214 | ✗ | } | |
215 | } | ||
216 | ✗ | throw std::runtime_error("GetBank failed"); | |
217 | } | ||
218 | |||
219 | /////////////////////////////////////////////////////////////////////////////// | ||
220 | |||
221 | 19 | hipo::schema Algorithm::CreateBank( | |
222 | hipo::banklist& banks, | ||
223 | hipo::banklist::size_type& bank_idx, | ||
224 | std::string const& bank_name) const noexcept(false) | ||
225 | { | ||
226 | // loop over bank definitions | ||
227 | // NOTE: `BANK_DEFS` is generated at build-time using `src/iguana/bankdefs/iguana.json` | ||
228 |
1/2✓ Branch 0 (38→3) taken 45 times.
✗ Branch 1 (38→39) not taken.
|
45 | for(auto const& bank_def : BANK_DEFS) { |
229 |
2/2✓ Branch 0 (3→4) taken 19 times.
✓ Branch 1 (3→37) taken 26 times.
|
45 | if(bank_def.name == bank_name) { |
230 | // make sure the new bank is in REGISTER_IGUANA_ALGORITHM | ||
231 |
1/2✗ Branch 0 (8→9) not taken.
✓ Branch 1 (8→18) taken 19 times.
|
38 | if(!AlgorithmFactory::QueryNewBank(bank_name)) { |
232 | ✗ | m_log->Error("{:?} creates bank {:?}, which is not registered; new banks must be included in `REGISTER_IGUANA_ALGORITHM` arguments", m_class_name, bank_name); | |
233 | ✗ | throw std::runtime_error("CreateBank failed"); | |
234 | } | ||
235 | // create the schema format string | ||
236 | std::vector<std::string> schema_def; | ||
237 |
2/2✓ Branch 0 (26→19) taken 162 times.
✓ Branch 1 (26→27) taken 19 times.
|
181 | for(auto const& entry : bank_def.entries) |
238 |
1/2✓ Branch 0 (19→20) taken 162 times.
✗ Branch 1 (19→60) not taken.
|
324 | schema_def.push_back(entry.name + "/" + entry.type); |
239 | 19 | auto format_string = fmt::format("{}", fmt::join(schema_def, ",")); | |
240 | // create the new bank schema | ||
241 |
1/2✓ Branch 0 (28→29) taken 19 times.
✗ Branch 1 (28→58) not taken.
|
19 | hipo::schema bank_schema(bank_name.c_str(), bank_def.group, bank_def.item); |
242 |
1/2✓ Branch 0 (29→30) taken 19 times.
✗ Branch 1 (29→56) not taken.
|
19 | bank_schema.parse(format_string); |
243 | // create the new bank | ||
244 |
1/2✓ Branch 0 (30→31) taken 19 times.
✗ Branch 1 (30→56) not taken.
|
38 | banks.push_back({bank_schema}); |
245 |
1/2✓ Branch 0 (33→34) taken 19 times.
✗ Branch 1 (33→56) not taken.
|
19 | bank_idx = GetBankIndex(banks, bank_name); |
246 | 19 | return bank_schema; | |
247 | 19 | } | |
248 | } | ||
249 | ✗ | throw std::runtime_error(fmt::format("bank {:?} not found in 'BankDefs.h'; is this bank defined in src/iguana/bankdefs/iguana.json ?", bank_name)); | |
250 | } | ||
251 | |||
252 | /////////////////////////////////////////////////////////////////////////////// | ||
253 | |||
254 | ✗ | void Algorithm::ShowBanks(hipo::banklist& banks, std::string_view message, Logger::Level const level) const | |
255 | { | ||
256 | ✗ | if(m_log->GetLevel() <= level) { | |
257 | ✗ | if(!message.empty()) | |
258 | ✗ | m_log->Print(level, message); | |
259 | ✗ | for(auto& bank : banks) | |
260 | ✗ | bank.show(); | |
261 | } | ||
262 | ✗ | } | |
263 | |||
264 | /////////////////////////////////////////////////////////////////////////////// | ||
265 | |||
266 | 58968 | void Algorithm::ShowBank(hipo::bank& bank, std::string_view message, Logger::Level const level) const | |
267 | { | ||
268 |
1/2✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→7) taken 58968 times.
|
58968 | if(m_log->GetLevel() <= level) { |
269 | ✗ | if(!message.empty()) | |
270 | ✗ | m_log->Print(level, message); | |
271 | ✗ | bank.show(); | |
272 | } | ||
273 | 58968 | } | |
274 | |||
275 | /////////////////////////////////////////////////////////////////////////////// | ||
276 | |||
277 | template <typename OPTION_TYPE> | ||
278 | 207 | std::optional<OPTION_TYPE> Algorithm::GetCachedOption(std::string const& key) const | |
279 | { | ||
280 |
1/2✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 207 times.
|
207 | if(key == "") |
281 | ✗ | return {}; | |
282 |
2/2✓ Branch 0 (5→6) taken 24 times.
✓ Branch 1 (5→10) taken 183 times.
|
207 | if(auto it{m_option_cache.find(key)}; it != m_option_cache.end()) { |
283 | try { // get the expected type | ||
284 | ✗ | return std::get<OPTION_TYPE>(it->second); | |
285 | } | ||
286 | ✗ | catch(std::bad_variant_access const& ex) { | |
287 | ✗ | auto printer = [&key, this](auto const& v) { | |
288 | ✗ | m_log->Error("wrong type used in SetOption call for option {:?}; using its default value instead", key); | |
289 | ✗ | PrintOptionValue(key, v, Logger::Level::error, " USER"); | |
290 | ✗ | if(m_log->GetLevel() > Logger::Level::debug) | |
291 | ✗ | m_log->Error("to see the actual option values used (and their types), set the log level to 'debug' or lower"); | |
292 | }; | ||
293 | ✗ | std::visit(printer, it->second); | |
294 | } | ||
295 | } | ||
296 | 36 | return {}; | |
297 | } | ||
298 | template std::optional<int> Algorithm::GetCachedOption(std::string const& key) const; | ||
299 | template std::optional<double> Algorithm::GetCachedOption(std::string const& key) const; | ||
300 | template std::optional<std::string> Algorithm::GetCachedOption(std::string const& key) const; | ||
301 | template std::optional<std::vector<int>> Algorithm::GetCachedOption(std::string const& key) const; | ||
302 | template std::optional<std::vector<double>> Algorithm::GetCachedOption(std::string const& key) const; | ||
303 | template std::optional<std::vector<std::string>> Algorithm::GetCachedOption(std::string const& key) const; | ||
304 | |||
305 | /////////////////////////////////////////////////////////////////////////////// | ||
306 | |||
307 |
2/2✓ Branch 0 (2→3) taken 56 times.
✓ Branch 1 (2→7) taken 69 times.
|
125 | void Algorithm::CompleteOptionNodePath(std::string const& key, YAMLReader::node_path_t& node_path) const |
308 | { | ||
309 |
2/2✓ Branch 0 (2→3) taken 56 times.
✓ Branch 1 (2→7) taken 69 times.
|
125 | if(node_path.empty()) |
310 | 56 | node_path.push_front(key); | |
311 | 125 | node_path.push_front(m_class_name); | |
312 | 125 | } | |
313 | } | ||
314 |