15 #ifndef FAIRPROGOPTIONS_H 16 #define FAIRPROGOPTIONS_H 18 #include "FairMQLogger.h" 19 #include "FairProgOptionsHelper.h" 20 #include <fairmq/Tools.h> 22 #include <boost/program_options.hpp> 23 #include <boost/filesystem.hpp> 33 namespace fs = boost::filesystem;
41 auto GetPropertyKeys()
const -> std::vector<std::string>
43 std::lock_guard<std::mutex> lock{fConfigMutex};
45 std::vector<std::string> result;
47 for (
const auto& it : fVarMap)
49 result.push_back(it.first.c_str());
57 po::options_description& GetCmdLineOptions();
61 T GetValue(
const std::string& key)
const 63 std::unique_lock<std::mutex> lock(fConfigMutex);
67 if (fVarMap.count(key))
69 val = fVarMap[key].as<T>();
73 LOG(warn) <<
"Config has no key: " << key <<
". Returning default constructed object.";
80 std::string GetStringValue(
const std::string& key)
82 std::unique_lock<std::mutex> lock(fConfigMutex);
87 if (fVarMap.count(key))
92 catch (std::exception& e)
94 LOG(error) <<
"Exception thrown for the key '" << key <<
"'";
95 LOG(error) << e.what();
101 int Count(
const std::string& key)
const 103 std::unique_lock<std::mutex> lock(fConfigMutex);
105 return fVarMap.count(key);
110 T ConvertTo(
const std::string& strValue)
112 if (std::is_arithmetic<T>::value)
114 std::istringstream iss(strValue);
121 LOG(error) <<
"the provided string " << strValue <<
" cannot be converted in the requested type. The target types must be arithmetic types";
125 const po::variables_map& GetVarMap()
const {
return fVarMap; }
127 int ParseCmdLine(
const int argc,
char const*
const* argv,
bool allowUnregistered =
false);
128 void ParseDefaults();
130 virtual int ParseAll(
const int argc,
char const*
const* argv,
bool allowUnregistered =
false) = 0;
132 virtual int PrintOptions();
133 virtual int PrintOptionsRaw();
137 po::variables_map fVarMap;
140 po::options_description fGeneralOptions;
141 po::options_description fAllOptions;
143 mutable std::mutex fConfigMutex;
145 virtual int ImmediateOptions() = 0;
149 void UpdateVarMap(
const std::string& key,
const T& val)
151 Replace(fVarMap, key, val);
155 void Replace(std::map<std::string, po::variable_value>& vm,
const std::string& key,
const T& val)
157 vm[key].value() = boost::any(val);
163 static void Max(
int& val,
const int& comp)
Definition: FairProgOptionsHelper.h:32
Definition: FairProgOptions.h:35
int AddToCmdLineOptions(const po::options_description optDesc, bool visible=true)
Add option descriptions.
Definition: FairProgOptions.cxx:47
Definition: FairProgOptionsHelper.h:137