diff --git a/fairmq/Plugin.h b/fairmq/Plugin.h index bf3b9e0f..5524f081 100644 --- a/fairmq/Plugin.h +++ b/fairmq/Plugin.h @@ -84,6 +84,7 @@ class Plugin // device config API // see for docs + auto PropertyExists(const std::string& key) -> int { return fPluginServices->PropertyExists(key); } template auto SetProperty(const std::string& key, T val) -> void { fPluginServices->SetProperty(key, val); } template diff --git a/fairmq/PluginServices.h b/fairmq/PluginServices.h index 11450955..342452c0 100644 --- a/fairmq/PluginServices.h +++ b/fairmq/PluginServices.h @@ -165,6 +165,9 @@ class PluginServices auto UnsubscribeFromDeviceStateChange(const std::string& subscriber) -> void { fDevice->UnsubscribeFromStateChange(subscriber); } // Config API + struct PropertyNotFoundError : std::runtime_error { using std::runtime_error::runtime_error; }; + + auto PropertyExists(const std::string& key) const -> bool { return fConfig->Count(key) > 0; } /// @brief Set config property /// @param key @@ -195,14 +198,24 @@ class PluginServices /// TODO Currently, if a non-existing key is requested and a default constructed object is returned. /// This behaviour will be changed in the future to throw an exception in that case to provide a proper sentinel. template - auto GetProperty(const std::string& key) const -> T { return fConfig->GetValue(key); } + auto GetProperty(const std::string& key) const -> T { + if (PropertyExists(key)) { + return fConfig->GetValue(key); + } + throw PropertyNotFoundError(fair::mq::tools::ToString("Config has no key: ", key)); + } /// @brief Read config property as string /// @param key /// @return config property value converted to string /// /// If a type is not supported, the user can provide support by overloading the ostream operator for this type - auto GetPropertyAsString(const std::string& key) const -> std::string { return fConfig->GetStringValue(key); } + auto GetPropertyAsString(const std::string& key) const -> std::string { + if (PropertyExists(key)) { + return fConfig->GetStringValue(key); + } + throw PropertyNotFoundError(fair::mq::tools::ToString("Config has no key: ", key)); + } auto GetChannelInfo() const -> std::unordered_map { return fConfig->GetChannelInfo(); } diff --git a/fairmq/options/FairProgOptions.h b/fairmq/options/FairProgOptions.h index aacd8ad7..62b5b842 100644 --- a/fairmq/options/FairProgOptions.h +++ b/fairmq/options/FairProgOptions.h @@ -17,6 +17,7 @@ #include "FairMQLogger.h" #include "FairProgOptionsHelper.h" +#include #include #include @@ -26,6 +27,7 @@ #include #include #include +#include namespace po = boost::program_options; namespace fs = boost::filesystem; @@ -61,21 +63,14 @@ class FairProgOptions std::unique_lock lock(fConfigMutex); T val = T(); - try + + if (fVarMap.count(key)) { - if (fVarMap.count(key)) - { - val = fVarMap[key].as(); - } - else - { - LOG(error) << "Config has no key: " << key; - } + val = fVarMap[key].as(); } - catch (std::exception& e) + else { - LOG(error) << "Exception thrown for the key '" << key << "'"; - LOG(error) << e.what(); + LOG(warn) << "Config has no key: " << key << ". Returning default constructed object."; } return val; diff --git a/fairmq/plugins/DDS/DDS.cxx b/fairmq/plugins/DDS/DDS.cxx index 50532e83..1f6e84ce 100644 --- a/fairmq/plugins/DDS/DDS.cxx +++ b/fairmq/plugins/DDS/DDS.cxx @@ -182,8 +182,14 @@ auto DDS::FillChannelContainers() -> void } // save properties that will have multiple values arriving (with only some of them to be used) - vector iValues = GetProperty>("dds-i"); - vector inValues = GetProperty>("dds-i-n"); + vector iValues; + if (PropertyExists("dds-i")) { + iValues = GetProperty>("dds-i"); + } + vector inValues; + if (PropertyExists("dds-i-n")) { + inValues = GetProperty>("dds-i-n"); + } for (const auto& vi : iValues) { size_t pos = vi.find(":"); diff --git a/fairmq/shmem/FairMQSocketSHM.cxx b/fairmq/shmem/FairMQSocketSHM.cxx index c4f0d2e3..0bfe7cb9 100644 --- a/fairmq/shmem/FairMQSocketSHM.cxx +++ b/fairmq/shmem/FairMQSocketSHM.cxx @@ -292,6 +292,8 @@ int64_t FairMQSocketSHM::Send(vector& msgVec, const int flags) return nbytes; } } + + return -1; } @@ -365,6 +367,8 @@ int64_t FairMQSocketSHM::Receive(vector& msgVec, const int fla return nbytes; } } + + return -1; } void FairMQSocketSHM::Close()