Skip to content

Commit a1e0cbb

Browse files
committed
ConfigurableParam::updateFromFile may skip already touched params
1 parent 8496bac commit a1e0cbb

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

Common/Utils/include/CommonUtils/ConfigurableParam.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class ConfigurableParam
242242
// provide a path to a configuration file with ConfigurableParam key/values
243243
// If nonempty comma-separated paramsList is provided, only those params will
244244
// be updated, absence of data for any of requested params will lead to fatal
245-
static void updateFromFile(std::string const&, std::string const& paramsList = "");
245+
static void updateFromFile(std::string const&, std::string const& paramsList = "", bool unchangedOnly = false);
246246

247247
protected:
248248
// constructor is doing nothing else but

Common/Utils/src/ConfigurableParam.cxx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,9 @@ void ConfigurableParam::printAllRegisteredParamNames()
395395
// It can be in JSON or INI format.
396396
// If nonempty comma-separated paramsList is provided, only those params will
397397
// be updated, absence of data for any of requested params will lead to fatal
398-
void ConfigurableParam::updateFromFile(std::string const& configFile, std::string const& paramsList)
398+
// If unchangedOnly is true, then only those parameters whose provenance is kCODE will be updated
399+
// (to allow prefernce of run-time settings)
400+
void ConfigurableParam::updateFromFile(std::string const& configFile, std::string const& paramsList, bool unchangedOnly)
399401
{
400402
if (!sIsFullyInitialized) {
401403
initialize();
@@ -413,7 +415,9 @@ void ConfigurableParam::updateFromFile(std::string const& configFile, std::strin
413415
auto request = splitString(paramsList, ',', true);
414416
std::unordered_map<std::string, int> requestMap;
415417
for (const auto& par : request) {
416-
requestMap[par] = 0;
418+
if (!par.empty()) {
419+
requestMap[par] = 0;
420+
}
417421
}
418422

419423
try {
@@ -430,8 +434,10 @@ void ConfigurableParam::updateFromFile(std::string const& configFile, std::strin
430434
auto name = subKey.first;
431435
auto value = subKey.second.get_value<std::string>();
432436
std::string key = mainKey + "." + name;
433-
std::pair<std::string, std::string> pair = std::make_pair(key, trimSpace(value));
434-
keyValPairs.push_back(pair);
437+
if (!unchangedOnly || getProvenance(key) == kCODE) {
438+
std::pair<std::string, std::string> pair = std::make_pair(key, trimSpace(value));
439+
keyValPairs.push_back(pair);
440+
}
435441
}
436442
}
437443
} catch (std::exception const& error) {

0 commit comments

Comments
 (0)