Skip to content
Snippets Groups Projects
Commit 79c1c4ad authored by Giovanna Lazzari Miotto's avatar Giovanna Lazzari Miotto :mushroom:
Browse files

doc: config: Improve comments, logging, exceptions

parent 43f71a5d
No related branches found
No related tags found
1 merge request!86refactor: config: Overhaul `Config` interface
......@@ -21,12 +21,14 @@ uint32_t ConfigMap::Get<uint32_t>(const std::string &k) {
ValueType value = at(k);
try {
return value.asUInt();
} catch (std::exception &e) {
LOG(DEBUG) << "Value '" << value.asString() << "' not natively convertible to uint32";
} catch (std::exception &e1) {
const auto str_val = value.asString();
LOG(DEBUG) << "Key: " << k << "| Value '" << str_val << "' | Exception: " << e1.what();
LOG(DEBUG) << "Recovering by converting to uint32_t";
try {
return static_cast<uint32_t>(std::stoul(value.asString()));
} catch (std::exception &e) {
LOG(ERROR) << "Configuration error with key: '" << k << "'";
return static_cast<uint32_t>(std::stoul(str_val));
} catch (std::exception &e2) {
LOG(ERROR) << "Conversion of '" << str_val << "' failed with exception: " << e2.what();
throw;
}
}
......@@ -37,12 +39,14 @@ uint64_t ConfigMap::Get<uint64_t>(const std::string &k) {
ValueType value = at(k);
try {
return value.asUInt64();
} catch (std::exception &e) {
LOG(DEBUG) << "Value '" << value.asString() << "' not natively convertible to uint64";
} catch (std::exception &e1) {
const auto str_val = value.asString();
LOG(DEBUG) << "Key: " << k << "| Value '" << str_val << "' | Exception: " << e1.what();
LOG(DEBUG) << "Recovering by converting to uint64_t";
try {
return static_cast<uint64_t>(std::stoul(value.asString()));
} catch (std::exception &e) {
LOG(ERROR) << "Configuration error with key: '" << k << "'";
return static_cast<uint64_t>(std::stoul(str_val));
} catch (std::exception &e2) {
LOG(ERROR) << "Conversion of '" << str_val << "' failed with exception: " << e2.what();
throw;
}
}
......@@ -53,12 +57,14 @@ int ConfigMap::Get<int>(const std::string &k) {
ValueType value = at(k);
try {
return value.asInt();
} catch (std::exception &e) {
LOG(DEBUG) << "Value '" << value.asString() << "' not natively convertible to integer";
} catch (std::exception &e1) {
const auto str_val = value.asString();
LOG(DEBUG) << "Key: " << k << "| Value '" << str_val << "' | Exception: " << e1.what();
LOG(DEBUG) << "Recovering by converting to int";
try {
return std::stoi(value.asString());
} catch (std::exception &e) {
LOG(ERROR) << "Configuration error with key: '" << k << "'";
return static_cast<int>(std::stoul(str_val));
} catch (std::exception &e2) {
LOG(ERROR) << "Conversion of '" << str_val << "' failed with exception: " << e2.what();
throw;
}
}
......
......@@ -146,22 +146,24 @@ class Config {
}
inline uint32_t GetSourceID(ProcessorType processor) const {
// Source ID is only used to fill the output CMSSW FRD event header, which is currently
// supported for the GMT and Calo processors.
switch (processor) {
case ProcessorType::GMT:
return 1;
case ProcessorType::CALO:
return 2;
default:
if (support_cmssw_headers_) {
LOG(ERROR)
<< "PROCESSOR_TYPE INCOMPATIBLE WITH CMSSW HEADER OUTPUT OPTION, PLEASE DISABLE "
"CMSSW HEADERS OR CHANGE PROCESSOR_TYPE, EXITING";
throw std::invalid_argument(
"ERROR: PROCESSOR_TYPE INCOMPATIBLE WITH CMSSW HEADER OUTPUT OPTION, PLEASE DISABLE "
"CMSSW HEADERS OR CHANGE PROCESSOR_TYPE");
} else {
LOG(WARNING) << "Undefined source ID has been requested: returning 0.";
if (!support_cmssw_headers_) {
LOG(WARNING)
<< "Specified `processor_type` has no pre-defined source ID. Using `source_id`=0.";
return 0;
} else {
const char msg_incompatible[] =
"Specified `processor_type` incompatible with CMSSW header-enabled outputs. Disable "
"`cmsswHeaders` or change `processor_type` to one of {GMT, CALO}.";
LOG(ERROR) << msg_incompatible;
throw std::invalid_argument(msg_incompatible);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment