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

except: Handle parsing errors

parent 4be5a1f8
No related branches found
No related tags found
1 merge request!86refactor: config: Overhaul `Config` interface
...@@ -17,17 +17,50 @@ bool ends_with(const std::string &str, const std::string &suffix) { ...@@ -17,17 +17,50 @@ bool ends_with(const std::string &str, const std::string &suffix) {
template <> template <>
uint32_t ConfigMap::Get<uint32_t>(const std::string &k) { uint32_t ConfigMap::Get<uint32_t>(const std::string &k) {
return get(k).asUInt(); ValueType value = get(k);
try {
return value.asUInt();
} catch (std::exception &e) {
LOG(DEBUG) << "Value '" << value.asString() << "' not natively convertible to uint32";
try {
return static_cast<uint32_t>(std::stoul(value.asString()));
} catch (std::exception &e) {
LOG(ERROR) << "Configuration error with key: '" << k << "'";
throw;
}
}
} }
template <> template <>
uint64_t ConfigMap::Get<uint64_t>(const std::string &k) { uint64_t ConfigMap::Get<uint64_t>(const std::string &k) {
return get(k).asUInt64(); ValueType value = get(k);
try {
return value.asUInt64();
} catch (std::exception &e) {
LOG(DEBUG) << "Value '" << value.asString() << "' not natively convertible to uint64";
try {
return static_cast<uint64_t>(std::stoul(value.asString()));
} catch (std::exception &e) {
LOG(ERROR) << "Configuration error with key: '" << k << "'";
throw;
}
}
} }
template <> template <>
int ConfigMap::Get<int>(const std::string &k) { int ConfigMap::Get<int>(const std::string &k) {
return get(k).asInt(); ValueType value = get(k);
try {
return value.asInt();
} catch (std::exception &e) {
LOG(DEBUG) << "Value '" << value.asString() << "' not natively convertible to integer";
try {
return std::stoi(value.asString());
} catch (std::exception &e) {
LOG(ERROR) << "Configuration error with key: '" << k << "'";
throw;
}
}
} }
template <> template <>
...@@ -128,8 +161,8 @@ Config::Config(const std::string &filename) { ...@@ -128,8 +161,8 @@ Config::Config(const std::string &filename) {
dma_device_ = dict_.at("dma_dev"); dma_device_ = dict_.at("dma_dev");
attempt_tcp_reconnect_ = dict_.Get<bool>("dev_TCPAutoReconnectOnFailure"); attempt_tcp_reconnect_ = dict_.Get<bool>("dev_TCPAutoReconnectOnFailure");
source_id_ = dict_.Get<uint32_t>("sourceID"); // source_id_ = dict_.Get<uint32_t>("sourceID");
port_ = dict_.Get<uint32_t>("port"), port_ = dict_.Get<int>("port"),
num_threads_ = dict_.Get<uint32_t>("threads"); num_threads_ = dict_.Get<uint32_t>("threads");
max_file_size_ = dict_.Get<uint64_t>("max_file_size"); max_file_size_ = dict_.Get<uint64_t>("max_file_size");
...@@ -147,7 +180,7 @@ Config::Config(const std::string &filename) { ...@@ -147,7 +180,7 @@ Config::Config(const std::string &filename) {
num_orbits_per_file_ = dict_.Get<uint64_t>("nOrbitsPerFile"); num_orbits_per_file_ = dict_.Get<uint64_t>("nOrbitsPerFile");
force_write_out_ = dict_.Get<bool>("output_force_write"); force_write_out_ = dict_.Get<bool>("output_force_write");
processor_type_ = ToProcessorType(dict_.Get("processorType")); processor_type_ = ToProcessorType(dict_.Get("processor_type"));
enable_processing_ = dict_.Get<bool>("enable_stream_processor"); enable_processing_ = dict_.Get<bool>("enable_stream_processor");
apply_zero_suppression_ = dict_.Get<bool>("doZS"); apply_zero_suppression_ = dict_.Get<bool>("doZS");
} }
......
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