00001
00002 #ifndef RIVET_Utils_HH
00003 #define RIVET_Utils_HH
00004
00005 #include <Rivet/Rivet.hh>
00006 #include <Rivet/Math/Math.hh>
00007 #include <cctype>
00008 #include <algorithm>
00009 #include <cerrno>
00010
00011
00012 namespace Rivet {
00013
00014
00015 inline int nocase_cmp(const string& s1, const string& s2) {
00016 string::const_iterator it1 = s1.begin();
00017 string::const_iterator it2 = s2.begin();
00018 while ( (it1 != s1.end()) && (it2 != s2.end()) ) {
00019 if(::toupper(*it1) != ::toupper(*it2)) {
00020
00021 return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1;
00022 }
00023
00024 ++it1;
00025 ++it2;
00026 }
00027 size_t size1 = s1.size(), size2 = s2.size();
00028
00029 if (size1 == size2) return 0;
00030 return (size1 < size2) ? -1 : 1;
00031 }
00032
00033
00034 inline string toLower(const string& s) {
00035 string out = s;
00036 transform(out.begin(), out.end(), out.begin(), (int(*)(int)) tolower);
00037 return out;
00038 }
00039
00040
00041 inline string toUpper(const string& s) {
00042 string out = s;
00043 std::transform(out.begin(), out.end(), out.begin(), (int(*)(int)) toupper);
00044 return out;
00045 }
00046
00047
00048 inline bool startsWith(const string& s, const string& start) {
00049 if (s.length() < start.length()) return false;
00050 return s.substr(0, start.length()) == start;
00051 }
00052
00053
00054 inline bool endsWith(const string& s, const string& end) {
00055 if (s.length() < end.length()) return false;
00056 return s.substr(s.length() - end.length()) == end;
00057 }
00058
00059
00060
00061 inline vector<string> split(string path, const string delim = ":") {
00062 vector<string> dirs;
00063 if (delim.length() != 1) {
00064 throw Error("Rivet::split(string): delimiter must be a single character.");
00065 }
00066 while (true) {
00067 const size_t delim_pos = path.find(delim);
00068 if (delim_pos == string::npos) break;
00069 const string dir = path.substr(0, delim_pos);
00070 if (dir.length()) dirs.push_back(dir);
00071 path.replace(0, delim_pos+1, "");
00072 }
00073 if (path.length()) dirs.push_back(path);
00074 return dirs;
00075 }
00076
00077
00078 const string getLibPath();
00079
00080
00081 const string getDataPath();
00082
00083
00084 const string getRivetDataPath();
00085
00086
00087 const string getRivetgunDataPath();
00088
00089
00090
00091 double get2dClosestApproach(const HepMC::GenParticle& track, const Vector3& vtx3pos);
00092
00093
00094 double get3dClosestApproach(const HepMC::GenParticle& track, const Vector3& vtx3pos);
00095
00096
00097 double get2dDecayLength(const Vector3& vtx1, const Vector3& vtx2, const FourMomentum& jetaxis);
00098
00099
00100 double get3dDecayLength(const Vector3& vtx1, const Vector3& vtx2, const FourMomentum& jetaxis);
00101
00102 }
00103 #endif
00104
00105
00106 #ifndef CEDARSTD
00107 #define CEDARSTD
00108 namespace std {
00109
00110 template <typename T>
00111 inline void operator+=(set<T>& s1, const set<T>& s2) {
00112 for (typename set<T>::const_iterator s = s2.begin(); s != s2.end(); ++s) {
00113 s1.insert(*s);
00114 }
00115 }
00116
00117 template <typename T>
00118 inline void operator+=(vector<T>& s1, const vector<T>& s2) {
00119 for (typename vector<T>::const_iterator s = s2.begin(); s != s2.end(); ++s) {
00120 s1.push_back(*s);
00121 }
00122 }
00123
00124 template <typename T>
00125 inline string join(const vector<T>& v, const string& sep = " ") {
00126 stringstream out;
00127 for (size_t i = 0; i < v.size(); ++i) {
00128 if (i != 0) out << sep;
00129 out << v[i];
00130 }
00131 return out.str();
00132 }
00133
00134 }
00135 #endif