5#include "Rivet/Tools/RivetSTL.hh"
6#include "Rivet/Tools/TypeTraits.hh"
7#include "Rivet/Tools/PrettyPrint.hh"
8#include "Rivet/Tools/Exceptions.hh"
26#if __GNUC__ && __cplusplus && RIVET_NO_DEPRECATION_WARNINGS == 0
27 #define DEPRECATED(x) __attribute__((deprecated(x)))
38 static constexpr double DBL_NAN = std::numeric_limits<double>::quiet_NaN();
47 inline T&
maybe(
const T& x, std::function<
bool(
const T&)> fn,
const T& fallback) {
48 return fn(x) ? x : fallback;
56 struct bad_lexical_cast :
public std::runtime_error {
57 bad_lexical_cast(
const std::string& what) : std::runtime_error(what) {}
61 template<
typename T,
typename U>
69 }
catch (
const std::exception& e) {
83 inline string&
ireplace_first(
string& str,
const string& patt,
const string& repl) {
84 if (!
contains(str, patt))
return str;
85 str.replace(str.find(patt), patt.size(), repl);
97 inline string toStr(T&& x) {
return to_str(std::forward<T>(x)); }
101 inline string replace_first(
string str,
const string& patt,
const string& repl) {
110 inline string&
ireplace_all(
string& str,
const string& patt,
const string& repl) {
111 if (!
contains(str, patt))
return str;
113 string::size_type it = str.find(patt);
114 if (it == string::npos)
break;
115 str.replace(it, patt.size(), repl);
125 inline string replace_all(
string str,
const string& patt,
const string& repl) {
134 while ( (it1 != s1.end()) && (it2 != s2.end()) ) {
135 if(::toupper(*it1) != ::toupper(*it2)) {
137 return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1;
143 size_t size1 = s1.size(), size2 = s2.size();
145 if (size1 == size2)
return 0;
146 return (size1 < size2) ? -1 : 1;
159 std::transform(out.begin(), out.end(), out.begin(), (
int(*)(
int)) std::tolower);
167 std::transform(out.begin(), out.end(), out.begin(), (
int(*)(
int)) std::toupper);
173 inline bool startsWith(
const string& s,
const string& start) {
174 if (s.length() < start.length())
return false;
175 return s.substr(0, start.length()) == start;
180 inline bool endsWith(
const string& s,
const string& end) {
181 if (s.length() < end.length())
return false;
182 return s.substr(s.length() - end.length()) == end;
187 inline string strcat() {
return ""; }
189 template<
typename T,
typename... Ts>
190 inline string strcat(T value, Ts... fargs) {
192 const string strnext = strcat(fargs...);
193 return strnext.empty() ? strthis : strthis + strnext;
198 template <
typename T>
199 inline string join(
const vector<T>& v,
const string& sep=
" ") {
201 for (
size_t i = 0; i < v.size(); ++i) {
202 if (i != 0) rtn += sep;
210 inline string join(
const vector<string>& v,
const string& sep) {
212 for (
size_t i = 0; i < v.size(); ++i) {
213 if (i != 0) rtn += sep;
220 template <
typename T>
221 inline string join(
const set<T>& s,
const string& sep=
" ") {
223 for (
const T& x : s) {
224 if (rtn.size() > 0) rtn += sep;
232 inline string join(
const set<string>& s,
const string& sep) {
234 for (
const string & x : s) {
235 if (rtn.size() > 0) rtn += sep;
242 inline vector<string>
split(
const string& s,
const string& sep) {
246 const size_t delim_pos = tmp.find(sep);
247 if (delim_pos == string::npos)
break;
248 const string dir = tmp.substr(0, delim_pos);
249 if (dir.length()) dirs.push_back(dir);
250 tmp.replace(0, delim_pos+1,
"");
252 if (tmp.length()) dirs.push_back(tmp);
257 inline string lpad(
const string& s,
size_t width,
const string& padchar=
" ") {
258 if (s.size() >= width)
return s;
259 return string(width - s.size(), padchar[0]) + s;
263 inline string rpad(
const string& s,
size_t width,
const string& padchar=
" ") {
264 if (s.size() >= width)
return s;
265 return s + string(width - s.size(), padchar[0]);
279 return split(path,
":");
286 inline string pathjoin(
const vector<string>& paths) {
287 return join(paths,
":");
291 inline string operator / (
const string& a,
const string& b) {
293 const string anorm = (a.find(
"/") != string::npos) ? a.substr(0, a.find_last_not_of(
"/")+1) : a;
294 const string bnorm = (b.find(
"/") != string::npos) ? b.substr(b.find_first_not_of(
"/")) : b;
295 return anorm +
"/" + bnorm;
301 return p.substr(
p.rfind(
"/")+1);
307 return p.substr(0,
p.rfind(
"/"));
313 return f.substr(0, f.rfind(
"."));
319 return f.substr(f.rfind(
".")+1);
330 template <
typename CONTAINER,
331 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
332 inline unsigned int count(
const CONTAINER& c) {
334 unsigned int rtn = 0;
335 for (
const auto& x : c)
if (
bool(x)) rtn += 1;
346 template <
typename CONTAINER,
typename FN,
348 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
349 inline unsigned int count(
const CONTAINER& c,
const FN& f) {
350 return std::count_if(std::begin(c), std::end(c), f);
356 template <
typename CONTAINER,
357 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
358 inline bool any(
const CONTAINER& c) {
360 for (
const auto& x : c)
if (
bool(x))
return true;
371 template <
typename CONTAINER,
typename FN,
373 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
374 inline bool any(
const CONTAINER& c,
const FN& f) {
375 return std::any_of(std::begin(c), std::end(c), f);
381 template <
typename CONTAINER,
382 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
383 inline bool all(
const CONTAINER& c) {
385 for (
const auto& x : c)
if (!
bool(x))
return false;
396 template <
typename CONTAINER,
typename FN,
398 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
399 inline bool all(
const CONTAINER& c,
const FN& f) {
400 return std::all_of(std::begin(c), std::end(c), f);
405 template <
typename CONTAINER,
406 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
407 inline bool none(
const CONTAINER& c) {
409 for (
const auto& x : c)
if (
bool(x))
return false;
420 template <
typename CONTAINER,
typename FN,
422 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
423 inline bool none(
const CONTAINER& c,
const FN& f) {
424 return std::none_of(std::begin(c), std::end(c), f);
438 template <
typename CONTAINER1,
typename CONTAINER2,
439 typename FN =
typename std::decay_t<CONTAINER2>::value_type(
440 const typename std::decay_t<CONTAINER1>::value_type::ParticleBase&),
441 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER1>> &&
442 is_citerable_v<std::decay_t<CONTAINER2>> >>
443 inline const CONTAINER2& transform(
const CONTAINER1& in, CONTAINER2& out, FN&& f) {
444 out.clear(); out.resize(in.size());
445 std::transform(in.begin(), in.end(), out.begin(), std::forward<FN>(f));
452 template <
typename CONTAINER1,
typename RTN,
453 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER1>> >>
454 inline std::vector<RTN> transform(
const CONTAINER1& in,
455 const std::function<RTN(
typename CONTAINER1::value_type::ParticleBase)>& f) {
456 std::vector<RTN> out;
457 transform(in, out, f);
469 template <
typename CONTAINER1,
typename T,
typename FN,
470 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER1>> >>
471 inline T
accumulate(
const CONTAINER1& in,
const T& init,
const FN& f) {
472 const T rtn = std::accumulate(in.begin(), in.end(), init, f);
480 template <
typename CONTAINER,
481 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
482 inline typename CONTAINER::value_type
sum(
const CONTAINER& c) {
483 typename CONTAINER::value_type rtn;
484 for (
const auto& x : c) rtn += x;
491 template <
typename CONTAINER,
typename T,
492 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
493 inline T
sum(
const CONTAINER& c,
const T& start) {
495 for (
const auto& x : c) rtn += x;
500 template <
typename CONTAINER,
typename T,
501 typename FN = T(
const typename std::decay_t<CONTAINER>::value_type::ParticleBase&),
502 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
503 inline T
sum(
const CONTAINER& c, FN&& fn,
const T& start=T()) {
504 auto f = std::function(std::forward<FN>(fn));
506 for (
const auto& x : c) rtn += fn(x);
514 template <
typename CONTAINER,
typename T,
515 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
516 inline T&
isum(
const CONTAINER& c, T& out) {
517 for (
const auto& x : c) out += x;
524 template <
typename CONTAINER,
typename FN,
typename T,
526 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
527 inline T&
isum(
const CONTAINER& c,
const FN& f, T& out) {
528 for (
const auto& x : c) out += f(x);
537 template <
typename CONTAINER,
typename FN,
538 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
539 inline CONTAINER&
idiscard(CONTAINER& c,
const FN& f) {
540 const auto newend = std::remove_if(std::begin(c), std::end(c), f);
541 c.erase(newend, c.end());
546 template <
typename CONTAINER,
547 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
548 inline CONTAINER&
idiscard(CONTAINER& c,
const typename CONTAINER::value_type& y) {
549 return idiscard(c, [&](
typename CONTAINER::value_type& x){
return x == y; });
553 template <
typename CONTAINER,
554 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
556 return idiscard(c, [&](
typename CONTAINER::value_type& x){
return contains(ys, x); });
563 template <
typename CONTAINER,
typename FN,
564 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
565 inline CONTAINER
discard(
const CONTAINER& c,
const FN& f) {
571 template <
typename CONTAINER,
572 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
573 inline CONTAINER
discard(
const CONTAINER& c,
const typename CONTAINER::value_type& y) {
574 return discard(c, [&](
typename CONTAINER::value_type& x){
return x == y; });
578 template <
typename CONTAINER,
579 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
581 return discard(c, [&](
typename CONTAINER::value_type& x){
return contains(ys, x); });
590 template <
typename CONTAINER,
typename FN,
592 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
593 inline CONTAINER&
discard(
const CONTAINER& c,
const FN& f, CONTAINER& out) {
599 template <
typename CONTAINER,
600 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
601 inline CONTAINER&
discard(
const CONTAINER& c,
const typename CONTAINER::value_type& y, CONTAINER& out) {
602 return discard(c, [&](
typename CONTAINER::value_type& x){
return x == y; }, out);
606 template <
typename CONTAINER,
607 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
608 inline CONTAINER&
discard_if_any(
const CONTAINER& c,
const CONTAINER& ys, CONTAINER& out) {
609 return discard(c, [&](
typename CONTAINER::value_type& x){
return contains(ys, x); }, out);
617 template <
typename CONTAINER,
typename FN,
618 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
619 inline CONTAINER&
iselect(CONTAINER& c,
const FN& f) {
620 auto invf = [&](
const typename CONTAINER::value_type& x){
return !f(x); };
627 template <
typename CONTAINER,
628 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
630 return iselect(c, [&](
typename CONTAINER::value_type& x){
return contains(ys, x); });
637 template <
typename CONTAINER,
typename FN,
638 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
639 inline CONTAINER
select(
const CONTAINER& c,
const FN& f) {
647 template <
typename CONTAINER,
648 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
650 return select(c, [&](
typename CONTAINER::value_type& x){
return contains(ys, x); });
659 template <
typename CONTAINER,
typename FN,
660 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
661 inline CONTAINER&
select(
const CONTAINER& c,
const FN& f, CONTAINER& out) {
669 template <
typename CONTAINER,
670 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
671 inline CONTAINER&
select_if_any(
const CONTAINER& c,
const CONTAINER& ys, CONTAINER& out) {
672 return select(c, [&](
typename CONTAINER::value_type& x){
return contains(ys, x); }, out);
681 template <
typename CONTAINER,
682 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
683 inline CONTAINER
slice(
const CONTAINER& c,
int i,
int j) {
685 const size_t off1 = (i >= 0) ? i : c.size() + i;
686 const size_t off2 = (j >= 0) ? j : c.size() + j;
687 if (off1 > c.size() || off2 > c.size())
throw RangeError(
"Attempting to slice beyond requested offsets");
688 if (off2 < off1)
throw RangeError(
"Requested offsets in invalid order");
689 rtn.resize(off2 - off1);
690 std::copy(c.begin()+off1, c.begin()+off2, rtn.begin());
697 template <
typename CONTAINER,
698 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
699 inline CONTAINER
slice(
const CONTAINER& c,
int i) {
700 return slice(c, i, c.size());
706 template <
typename CONTAINER,
707 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
708 inline CONTAINER
head(
const CONTAINER& c,
int n) {
710 if (n < 0) n = std::max(0, (
int)c.size()+n);
711 n = std::min(n, (
int)c.size());
712 return slice(c, 0, n);
718 template <
typename CONTAINER,
719 typename = std::enable_if_t< is_citerable_v<std::decay_t<CONTAINER>> >>
720 inline CONTAINER
tail(
const CONTAINER& c,
int n) {
722 if (n < 0) n = std::max(0, (
int)c.size()+n);
723 n = std::min(n, (
int)c.size());
724 return slice(c, c.size()-n);
732 inline double min(
const vector<double>& in,
double errval=
DBL_NAN) {
733 const auto e = std::min_element(in.begin(), in.end());
734 return e != in.end() ? *e : errval;
738 inline double max(
const vector<double>& in,
double errval=
DBL_NAN) {
739 const auto e = std::max_element(in.begin(), in.end());
740 return e != in.end() ? *e : errval;
744 inline pair<double,double>
minmax(
const vector<double>& in,
double errval=
DBL_NAN) {
745 const auto e = std::minmax_element(in.begin(), in.end());
746 const double rtnmin = e.first != in.end() ? *e.first : errval;
747 const double rtnmax = e.second != in.end() ? *e.first : errval;
748 return std::make_pair(rtnmin, rtnmax);
753 inline int min(
const vector<int>& in,
int errval=-1) {
754 const auto e = std::min_element(in.begin(), in.end());
755 return e != in.end() ? *e : errval;
759 inline int max(
const vector<int>& in,
int errval=-1) {
760 const auto e = std::max_element(in.begin(), in.end());
761 return e != in.end() ? *e : errval;
765 inline pair<int,int>
minmax(
const vector<int>& in,
int errval=-1) {
766 const auto e = std::minmax_element(in.begin(), in.end());
767 const double rtnmin = e.first != in.end() ? *e.first : errval;
768 const double rtnmax = e.second != in.end() ? *e.first : errval;
769 return std::make_pair(rtnmin, rtnmax);
783 template <
typename CONTAINER,
784 typename FN = double(
const typename std::decay_t<CONTAINER>::value_type::ParticleBase&),
785 typename = isCIterable<CONTAINER>>
787 double target,
double minval=-DBL_MAX,
double maxval=DBL_MAX) {
788 auto f = std::function(std::forward<FN>(fn));
791 for (
size_t i = 0; i < c.size(); ++i) {
792 const double val = f(c[i]);
793 if (isnan(val))
continue;
794 if (val < minval || val > maxval)
continue;
795 if (isnan(best) || fabs(val-target) < fabs(best-target)) {
811 template <
typename CONTAINER1,
typename CONTAINER2,
812 typename FN = double(
const typename std::decay_t<CONTAINER1>::value_type::ParticleBase&,
813 const typename std::decay_t<CONTAINER2>::value_type::ParticleBase&),
814 typename = isCIterable<CONTAINER1, CONTAINER2>>
816 double target,
double minval=-DBL_MAX,
double maxval=DBL_MAX) {
817 auto f = std::function(std::forward<FN>(fn));
818 pair<int,int> ijbest{-1,-1};
820 for (
size_t i = 0; i < c1.size(); ++i) {
821 for (
size_t j = 0; j < c2.size(); ++j) {
822 const double val = f(c1[i], c2[j]);
823 if (isnan(val))
continue;
824 if (val < minval || val > maxval)
continue;
825 if (isnan(best) || fabs(val-target) < fabs(best-target)) {
842 template <
typename CONTAINER,
typename T,
843 typename FN = double(
const typename std::decay_t<CONTAINER>::value_type::ParticleBase&,
const std::decay_t<T>&),
844 typename = isCIterable<CONTAINER>>
846 double target,
double minval=-DBL_MAX,
double maxval=DBL_MAX) {
847 pair<int,int> ijbest =
closestMatchIndices(c, vector<T>{x}, std::forward<FN>(fn), target, minval, maxval);
859 template <
typename CONTAINER,
typename T,
typename FN,
typename = isCIterable<CONTAINER>>
861 double target,
double minval=-DBL_MAX,
double maxval=DBL_MAX) {
873 template <
typename T>
875 char* env = getenv(name.c_str());
885 vector<T>
slice(
const vector<T>& v,
int startidx,
int endidx) {
887 if (startidx < 0 || endidx <= startidx || endidx >= v.size())
888 throw RangeError(
"Requested start or end indices incompatible with given vector");
890 auto start = v.begin() + startidx;
891 auto end = v.begin() + endidx;
893 vector<T> output(endidx - startidx);
895 copy(start, end, output.begin());
int closestMatchIndex(const CONTAINER &c, FN &&fn, double target, double minval=-DBL_MAX, double maxval=DBL_MAX)
Return the index from a vector which best matches fn(c[i]) to the target value.
Definition Utils.hh:786
pair< int, int > closestMatchIndices(const CONTAINER1 &c1, const CONTAINER2 &c2, FN &&fn, double target, double minval=-DBL_MAX, double maxval=DBL_MAX)
Return the indices from two vectors which best match fn(c1[i], c2[j]) to the target value.
Definition Utils.hh:815
CONTAINER head(const CONTAINER &c, int n)
Head slice of the n first container elements.
Definition Utils.hh:708
bool any(const CONTAINER &c)
Return true if x is true for any x in container c, otherwise false.
Definition Utils.hh:358
CONTAINER discard_if_any(const CONTAINER &c, const CONTAINER &ys)
Version with several element-equality comparisons in place of a function.
Definition Utils.hh:580
CONTAINER slice(const CONTAINER &c, int i, int j)
Slice of the container elements cf. Python's [i:j] syntax.
Definition Utils.hh:683
T accumulate(const CONTAINER1 &in, const T &init, const FN &f)
A single-container-arg version of std::accumulate, aka reduce.
Definition Utils.hh:471
CONTAINER & idiscard_if_any(CONTAINER &c, const CONTAINER &ys)
Version with several element-equality comparisons in place of a function.
Definition Utils.hh:555
pair< double, double > minmax(const vector< double > &in, double errval=DBL_NAN)
Find the minimum and maximum values in the vector.
Definition Utils.hh:744
bool none(const CONTAINER &c)
Return true if x is false for all x in container c, otherwise false.
Definition Utils.hh:407
CONTAINER tail(const CONTAINER &c, int n)
Tail slice of the n last container elements.
Definition Utils.hh:720
bool all(const CONTAINER &c)
Return true if x is true for all x in container c, otherwise false.
Definition Utils.hh:383
unsigned int count(const CONTAINER &c)
Return number of true elements in the container c .
Definition Utils.hh:332
T & isum(const CONTAINER &c, T &out)
Definition Utils.hh:516
CONTAINER & iselect_if_any(CONTAINER &c, const CONTAINER &ys)
Version with several element-equality comparisons in place of a function.
Definition Utils.hh:629
CONTAINER select_if_any(const CONTAINER &c, const CONTAINER &ys)
Version with several element-equality comparisons in place of a function.
Definition Utils.hh:649
Jets & idiscard(Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that fails the supplied Cut.
Jets select(const Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that passes the supplied Cut.
Definition JetUtils.hh:157
Jets & iselect(Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that passes the supplied Cut.
Jets discard(const Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that fails the supplied Cut.
Definition JetUtils.hh:176
double p(const ParticleBase &p)
Unbound function access to p.
Definition ParticleBaseUtils.hh:653
string dirname(const string &p)
Get the dirname (i.e. path to the penultimate directory) from a path p.
Definition Utils.hh:305
string file_extn(const string &f)
Get the file extension from a filename f.
Definition Utils.hh:317
string pathjoin(const vector< string > &paths)
Join several filesystem paths together with the standard ':' delimiter.
Definition Utils.hh:286
vector< string > pathsplit(const string &path)
Split a path string with colon delimiters.
Definition Utils.hh:278
string basename(const string &p)
Get the basename (i.e. terminal file name) from a path p.
Definition Utils.hh:299
string file_stem(const string &f)
Get the stem (i.e. part without a file extension) from a filename f.
Definition Utils.hh:311
bool endsWith(const string &s, const string &end)
Check whether a string end is found at the end of s.
Definition Utils.hh:180
bool nocase_equals(const string &s1, const string &s2)
Case-insensitive string equality function.
Definition Utils.hh:151
string toStr(T &&x)
Perfect-forwarding alias for to_str() with a more Rivet-user-facing name.
Definition Utils.hh:97
bool startsWith(const string &s, const string &start)
Check whether a string start is found at the start of s.
Definition Utils.hh:173
string & ireplace_all(string &str, const string &patt, const string &repl)
Replace all instances of patt with repl in-place.
Definition Utils.hh:110
string toUpper(const string &s)
Convert a string to upper-case.
Definition Utils.hh:165
string rpad(const string &s, size_t width, const string &padchar=" ")
Right-pad the given string s to width width.
Definition Utils.hh:263
string to_str(const T &x)
Convert any object to a string.
Definition Utils.hh:78
string lpad(const string &s, size_t width, const string &padchar=" ")
Left-pad the given string s to width width.
Definition Utils.hh:257
string toLower(const string &s)
Convert a string to lower-case.
Definition Utils.hh:157
string replace_all(string str, const string &patt, const string &repl)
Replace all instances of patt with repl.
Definition Utils.hh:125
T lexical_cast(const U &in)
Convert between any types via stringstream.
Definition Utils.hh:62
vector< string > split(const string &s, const string &sep)
Split a string on a specified separator string.
Definition Utils.hh:242
string join(const vector< T > &v, const string &sep=" ")
Make a string containing the string representations of each item in v, separated by sep.
Definition Utils.hh:199
string & ireplace_first(string &str, const string &patt, const string &repl)
Replace the first instance of patt with repl in-place.
Definition Utils.hh:83
string replace_first(string str, const string &patt, const string &repl)
Replace the first instance of patt with repl.
Definition Utils.hh:101
int nocase_cmp(const string &s1, const string &s2)
Case-insensitive string comparison function.
Definition Utils.hh:131
T getEnvParam(const std::string name, const T &fallback)
Get a parameter from a named environment variable, with automatic type conversion.
Definition Utils.hh:874
Definition MC_CENT_PPB_Projections.hh:10
std::enable_if_t< std::is_arithmetic_v< N1 > &&std::is_arithmetic_v< N2 >, signed_if_mixed_t< N1, N2 > > max(N1 a, N2 b)
Get the maximum of two numbers.
Definition MathUtils.hh:115
T sum(const DressedLeptons &c, FN &&fn, const T &start=T())
Generic sum function, adding fn(x) for all x in container c, starting with start.
Definition DressedLepton.hh:60
static constexpr double DBL_NAN
Convenient const for getting the double NaN value.
Definition Utils.hh:38
std::enable_if_t< std::is_arithmetic_v< N1 > &&std::is_arithmetic_v< N2 >, signed_if_mixed_t< N1, N2 > > min(N1 a, N2 b)
Get the minimum of two numbers.
Definition MathUtils.hh:104
bool contains(const std::string &s, const std::string &sub)
Does s contain sub as a substring?
Definition RivetSTL.hh:201
T & maybe(const T &x, std::function< bool(const T &)> fn, const T &fallback)
Wrapper for avoiding repetition/recalculation when computing and maybe using a value.
Definition Utils.hh:47
std::string toString(const AnalysisInfo &ai)
String representation.
Error for e.g. use of invalid bin ranges.
Definition Exceptions.hh:22
Exception class for throwing from lexical_cast when a parse goes wrong.
Definition Utils.hh:56