10 #include "LHAPDF/Utils.h"
11 #include "LHAPDF/Paths.h"
12 #include "LHAPDF/Exceptions.h"
40 Info(
const std::string& path) {
57 void load(
const std::string& filepath);
89 virtual bool has_key(
const std::string& key)
const {
97 throw MetadataError(
"Metadata for key: " + key +
" not found.");
108 virtual const std::string&
get_entry(
const std::string& key)
const {
114 virtual const std::string&
get_entry(
const std::string& key,
const std::string& fallback)
const {
127 template <
typename T>
130 return lexical_cast<T>(s);
135 template <
typename T>
138 return get_entry_as<T>(key);
146 template <
typename T>
169 bool rtn = lexical_cast<bool>(s);
172 if (s ==
"true" || s ==
"on" || s ==
"yes")
return true;
173 if (s ==
"false" || s ==
"off" || s ==
"no")
return false;
175 throw MetadataError(
"'" + s +
"' is not a valid string for conversion to bool type");
180 static const string delim =
",";
186 const vector<string> strs = get_entry_as< vector<string> >(key);
188 rtn.reserve(strs.size());
190 for (
size_t i = 0; i < strs.size(); ++i) rtn.push_back( lexical_cast<int>(strs[i]) );
191 assert(rtn.size() == strs.size());
197 const vector<string> strs = get_entry_as< vector<string> >(key);
199 rtn.reserve(strs.size());
201 for (
size_t i = 0; i < strs.size(); ++i) rtn.push_back( lexical_cast<double>(strs[i]) );
202 assert(rtn.size() == strs.size());
Info(const std::string &path)
Constructor.
Definition: Info.h:40
virtual bool has_key(const std::string &key) const
Definition: Info.h:89
std::map< std::string, std::string > _metadict
The string -> string native metadata storage container.
Definition: Info.h:157
const std::string & get_entry_local(const std::string &key) const
Retrieve a metadata string by key name, as defined on this specific object.
Definition: Info.h:95
std::string to_str(const T &val)
Make a string representation of val.
Definition: Utils.h:60
void load(const std::string &filepath)
Metadata base class for PDFs, PDF sets, or global configuration.
Definition: Info.h:30
void set_entry(const std::string &key, const T &val)
Set a keyed value entry.
Definition: Info.h:147
T get_entry_as(const std::string &key) const
Definition: Info.h:128
std::vector< std::string > split(const std::string &s, const std::string &sep)
Split a string by a given separator.
Definition: Utils.h:94
virtual ~Info()
Virtual destructor to allow inheritance.
Definition: Info.h:45
virtual const std::string & get_entry(const std::string &key, const std::string &fallback) const
Retrieve a metadata string by key name, with a default fallback.
Definition: Info.h:114
bool has_key_local(const std::string &key) const
Is a value defined for the given key on this specific object?
Definition: Info.h:77
Info()
Default constructor.
Definition: Info.h:37
virtual const std::string & get_entry(const std::string &key) const
Definition: Info.h:108
Namespace for all LHAPDF functions and classes.
Definition: AlphaS.h:14
T get_entry_as(const std::string &key, const T &fallback) const
Retrieve a metadata entry by key name, with an inline type cast and default fallback.
Definition: Info.h:136