46 template<
typename T,
typename U>
54 }
catch (
const std::exception&
e) {
67 inline std::string
to_str(
const std::vector<T>&
vec) {
69 for (
size_t i = 0;
i <
vec.size(); ++
i) {
71 if (
i <
vec.size()-1)
rtn +=
", ";
85 inline std::string
join(
const std::vector<std::string>&
svec,
const std::string&
sep) {
87 for (
size_t i = 0;
i <
svec.size(); ++
i) {
95 inline std::vector<std::string>
split(
const std::string&
s,
const std::string&
sep) {
111 return s.find(
sub) != string::npos;
116 return s.find(
sub) == 0;
121 return s.find(
sub) ==
s.length()-
sub.length();
126 return std::count(
s.begin(),
s.end(),
c);
130 inline std::string
trim(
const std::string&
s) {
167 inline std::string
operator / (
const std::string&
a,
const std::string&
b) {
169 const string anorm = (
a.find(
"/") != std::string::npos) ?
a.substr(0,
a.find_last_not_of(
"/")+1) :
a;
170 const string bnorm = (
b.find(
"/") != std::string::npos) ?
b.substr(
b.find_first_not_of(
"/")) :
b;
177 return p.substr(
p.rfind(
"/")+1);
183 return p.substr(0,
p.rfind(
"/"));
189 return f.substr(0,
f.rfind(
"."));
195 return f.substr(
f.rfind(
".")+1);
207 template <
typename N>
211 template <
typename N>
238 template <
typename T>
250 template <
typename K,
typename T>
double chisquared_quantile(double p, double ndf)
Quantiles of the chi-squared probability distribution function.
bool has_key(const std::map< K, T > &container, const K &key)
Does the map<K,T> container have a key K key?
Definition Utils.h:251
int in_open_range(double x, double low, double high)
Check if a number is in a range (open-open)
Definition Utils.h:221
std::string to_str_zeropad(int val, size_t nchars=4)
Format an integer val as a zero-padded string of length nchars.
Definition Utils.h:78
bool path_exists(const std::string &p, int mode=0)
Check if a path p (either file or dir) exists.
bool contains(const std::string &s, const std::string &sub)
Does a string s contain the sub substring?
Definition Utils.h:110
int in_closed_range(double x, double low, double high)
Check if a number is in a range (closed-closed)
Definition Utils.h:218
std::string to_str(const T &val)
Make a string representation of val.
Definition Utils.h:61
size_t countchar(const std::string &s, const char c)
How many times does a string s contain the character c?
Definition Utils.h:125
std::string operator/(const std::string &a, const std::string &b)
Operator for joining strings a and b with filesystem separators.
Definition Utils.h:167
double norm_quantile(double p)
Quantiles of the standard normal probability distribution function.
bool startswith(const std::string &s, const std::string &sub)
Does a string s start with the sub substring?
Definition Utils.h:115
int sgn(N val)
Get the sign of a number.
Definition Utils.h:212
std::string basename(const std::string &p)
Get the basename (i.e. terminal file name) from a path p.
Definition Utils.h:175
N sqr(const N &x)
Convenience function for squaring (of any type)
Definition Utils.h:208
std::string dirname(const std::string &p)
Get the dirname (i.e. path to the penultimate directory) from a path p.
Definition Utils.h:181
T lexical_cast(const U &in)
Convert between types via stringstream.
Definition Utils.h:47
std::string file_stem(const std::string &f)
Get the stem (i.e. part without a file extension) from a filename f.
Definition Utils.h:187
std::string to_upper(const std::string &s)
Convert a string to upper-case (not in-place)
Definition Utils.h:145
bool file_exists(const std::string &p, int mode=0)
Check if a file p exists.
int in_range(double x, double low, double high)
Check if a number is in a range (closed-open)
Definition Utils.h:215
bool dir_exists(const std::string &p, int mode=0)
Check if a dir p exists.
std::string to_lower(const std::string &s)
Convert a string to lower-case (not in-place)
Definition Utils.h:138
bool endswith(const std::string &s, const std::string &sub)
Does a string s end with the sub substring?
Definition Utils.h:120
std::string join(const std::vector< std::string > &svec, const std::string &sep)
Concatenate strings with separator strings between each element.
Definition Utils.h:85
bad_lexical_cast(const std::string &what)
Constructor.
Definition Utils.h:42
std::string trim(const std::string &s)
Strip leading and trailing spaces (not in-place)
Definition Utils.h:130
std::vector< std::string > split(const std::string &s, const std::string &sep)
Split a string by a given separator.
Definition Utils.h:95
std::string file_extn(const std::string &f)
Get the file extension from a filename f.
Definition Utils.h:193
Namespace for all LHAPDF functions and classes.
Definition AlphaS.h:14
When lexical_cast goes bad.
Definition Utils.h:40