diff --git a/src/config.cc b/src/config.cc index 629c144df889d10f7e3b711d66df94163f1ae83e..04e4ebda4768679b98afdbe0b278a3dc4ac2429d 100644 --- a/src/config.cc +++ b/src/config.cc @@ -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; } } diff --git a/src/config.h b/src/config.h index 96ac8aa21d8c4b6071d312d0a5fec7b537d1527e..5146db0f4bb841ab70ef1b1caeeefd6b7490ee93 100644 --- a/src/config.h +++ b/src/config.h @@ -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); } } }