RivetPaths.cc
Go to the documentation of this file.
00001 #include "Rivet/Config/RivetCommon.hh" 00002 #include "Rivet/Tools/RivetPaths.hh" 00003 #include "Rivet/Tools/Utils.hh" 00004 #include "binreloc.h" 00005 #include <cstring> 00006 00007 namespace Rivet { 00008 00009 00010 inline string _findFile(const string& filename, const vector<string>& paths) { 00011 for (const string& dir : paths) { 00012 const string path = dir + "/" + filename; 00013 if (fileexists(path)) return path; 00014 } 00015 return ""; 00016 } 00017 00018 00019 string getLibPath() { 00020 BrInitError error; 00021 br_init_lib(&error); 00022 char* temp = br_find_lib_dir(DEFAULTLIBDIR); 00023 const string libdir(temp); 00024 free (temp); 00025 return libdir; 00026 } 00027 00028 string getDataPath() { 00029 BrInitError error; 00030 br_init_lib(&error); 00031 char* temp = br_find_data_dir(DEFAULTDATADIR); 00032 const string sharedir(temp); 00033 free (temp); 00034 return sharedir; 00035 } 00036 00037 string getRivetDataPath() { 00038 return getDataPath() + "/Rivet"; 00039 } 00040 00041 00042 00043 void setAnalysisLibPaths(const vector<string>& paths) { 00044 const string pathstr = pathjoin(paths); 00045 setenv("RIVET_ANALYSIS_PATH", pathstr.c_str(), 1); 00046 } 00047 00048 void addAnalysisLibPath(const string& extrapath) { 00049 vector<string> paths = getAnalysisLibPaths(); 00050 paths.push_back(extrapath); 00051 setAnalysisLibPaths(paths); 00052 } 00053 00054 vector<string> getAnalysisLibPaths() { 00055 vector<string> dirs; 00056 // Use the Rivet analysis path variable if set... 00057 const char* env = getenv("RIVET_ANALYSIS_PATH"); 00058 if (env) dirs += pathsplit(env); 00059 // ... otherwise fall back to the Rivet library install path unless the path ends in :: 00060 if (!env || strlen(env) < 2 || string(env).substr(strlen(env)-2) != "::") 00061 dirs += getLibPath(); 00062 return dirs; 00063 } 00064 00065 string findAnalysisLibFile(const string& filename) { 00066 return _findFile(filename, getAnalysisLibPaths()); 00067 } 00068 00069 00070 00071 void setAnalysisDataPaths(const vector<string>& paths) { 00072 const string pathstr = pathjoin(paths); 00073 setenv("RIVET_DATA_PATH", pathstr.c_str(), 1); 00074 } 00075 00076 void addAnalysisDataPath(const string& extrapath) { 00077 vector<string> paths = getAnalysisDataPaths(); 00078 paths.push_back(extrapath); 00079 setAnalysisDataPaths(paths); 00080 } 00081 00082 vector<string> getAnalysisDataPaths() { 00083 vector<string> dirs; 00084 // Use the Rivet data path variable if set... 00085 const char* env = getenv("RIVET_DATA_PATH"); 00086 if (env) dirs += pathsplit(env); 00087 // ... then, unless the path ends in :: ... 00088 if (!env || strlen(env) < 2 || string(env).substr(strlen(env)-2) != "::") { 00089 // ... fall back to the Rivet data install path... 00090 dirs += getRivetDataPath(); 00091 // ... and also add any analysis plugin search dirs for convenience 00092 dirs += getAnalysisLibPaths(); 00093 } 00094 return dirs; 00095 } 00096 00097 string findAnalysisDataFile(const string& filename, 00098 const vector<string>& pathprepend, const vector<string>& pathappend) { 00099 const vector<string> paths = pathprepend + getAnalysisDataPaths() + pathappend; 00100 return _findFile(filename, paths); 00101 } 00102 00103 00104 vector<string> getAnalysisRefPaths() { 00105 vector<string> dirs; 00106 // Use the Rivet ref path variable if set... 00107 const char* env = getenv("RIVET_REF_PATH"); 00108 if (env) dirs += pathsplit(env); 00109 // ... and append the universal Rivet data paths, unless the env path ends in :: 00110 if (!env || strlen(env) < 2 || string(env).substr(strlen(env)-2) != "::") 00111 dirs += getAnalysisDataPaths(); 00112 return dirs; 00113 } 00114 00115 string findAnalysisRefFile(const string& filename, 00116 const vector<string>& pathprepend, const vector<string>& pathappend) { 00117 const vector<string> paths = pathprepend + getAnalysisRefPaths() + pathappend; 00118 return _findFile(filename, paths); 00119 } 00120 00121 00122 vector<string> getAnalysisInfoPaths() { 00123 vector<string> dirs; 00124 // Use the Rivet info path variable if set... 00125 const char* env = getenv("RIVET_INFO_PATH"); 00126 if (env) dirs += pathsplit(env); 00127 // ... and append the universal Rivet data paths, unless the env path ends in :: 00128 if (!env || strlen(env) < 2 || string(env).substr(strlen(env)-2) != "::") 00129 dirs += getAnalysisDataPaths(); 00130 return dirs; 00131 } 00132 00133 string findAnalysisInfoFile(const string& filename, 00134 const vector<string>& pathprepend, const vector<string>& pathappend) { 00135 const vector<string> paths = pathprepend + getAnalysisInfoPaths() + pathappend; 00136 return _findFile(filename, paths); 00137 } 00138 00139 00140 vector<string> getAnalysisPlotPaths() { 00141 vector<string> dirs; 00142 // Use the Rivet plot path variable if set... 00143 const char* env = getenv("RIVET_PLOT_PATH"); 00144 if (env) dirs += pathsplit(env); 00145 // ... and append the universal Rivet data paths, unless the env path ends in :: 00146 if (!env || strlen(env) < 2 || string(env).substr(strlen(env)-2) != "::") 00147 dirs += getAnalysisDataPaths(); 00148 return dirs; 00149 } 00150 00151 string findAnalysisPlotFile(const string& filename, 00152 const vector<string>& pathprepend, const vector<string>& pathappend) { 00153 const vector<string> paths = pathprepend + getAnalysisPlotPaths() + pathappend; 00154 return _findFile(filename, paths); 00155 } 00156 00157 00158 } Generated on Tue Dec 13 2016 16:32:40 for The Rivet MC analysis system by ![]() |