RivetPaths.cc
Go to the documentation of this file.
00001 #include "Rivet/Rivet.hh" 00002 #include "Rivet/Tools/RivetPaths.hh" 00003 #include "Rivet/Tools/RivetBoost.hh" 00004 #include "Rivet/Tools/Utils.hh" 00005 #include "binreloc.h" 00006 00007 namespace Rivet { 00008 00009 00010 inline string _findFile(const string& filename, const vector<string>& paths) { 00011 foreach (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 char* env = 0; 00057 env = getenv("RIVET_ANALYSIS_PATH"); 00058 if (env) { 00059 // Use the Rivet analysis path variable if set... 00060 dirs += pathsplit(env); 00061 } 00062 // ... otherwise fall back to the Rivet library install path 00063 dirs += getLibPath(); 00064 return dirs; 00065 } 00066 00067 string findAnalysisLibFile(const string& filename) { 00068 return _findFile(filename, getAnalysisLibPaths()); 00069 } 00070 00071 00072 vector<string> getAnalysisRefPaths() { 00073 vector<string> dirs; 00074 char* env = 0; 00075 env = getenv("RIVET_REF_PATH"); 00076 if (env) { 00077 // Use the Rivet analysis path variable if set... 00078 dirs += pathsplit(env); 00079 } 00080 // Then fall back to the Rivet data install path... 00081 dirs += getRivetDataPath(); 00082 // ... and also add any analysis plugin search dirs for convenience 00083 dirs += getAnalysisLibPaths(); 00084 return dirs; 00085 } 00086 00087 string findAnalysisRefFile(const string& filename, 00088 const vector<string>& pathprepend, const vector<string>& pathappend) { 00089 const vector<string> paths = pathprepend + getAnalysisRefPaths() + pathappend; 00090 return _findFile(filename, paths); 00091 } 00092 00093 00094 vector<string> getAnalysisInfoPaths() { 00095 vector<string> dirs; 00096 char* env = 0; 00097 env = getenv("RIVET_INFO_PATH"); 00098 if (env) { 00099 // Use the Rivet analysis path variable if set... 00100 dirs += pathsplit(env); 00101 } 00102 // Then fall back to the Rivet data install path... 00103 dirs += getRivetDataPath(); 00104 // ... and also add any analysis plugin search dirs for convenience 00105 dirs += getAnalysisLibPaths(); 00106 return dirs; 00107 } 00108 00109 string findAnalysisInfoFile(const string& filename, 00110 const vector<string>& pathprepend, const vector<string>& pathappend) { 00111 const vector<string> paths = pathprepend + getAnalysisInfoPaths() + pathappend; 00112 return _findFile(filename, paths); 00113 } 00114 00115 00116 vector<string> getAnalysisPlotPaths() { 00117 vector<string> dirs; 00118 char* env = 0; 00119 env = getenv("RIVET_PLOT_PATH"); 00120 if (env) { 00121 // Use the Rivet analysis path variable if set... 00122 dirs += pathsplit(env); 00123 } 00124 // Then fall back to the Rivet data install path... 00125 dirs += getRivetDataPath(); 00126 // ... and also add any analysis plugin search dirs for convenience 00127 dirs += getAnalysisLibPaths(); 00128 return dirs; 00129 } 00130 00131 string findAnalysisPlotFile(const string& filename, 00132 const vector<string>& pathprepend, const vector<string>& pathappend) { 00133 const vector<string> paths = pathprepend + getAnalysisPlotPaths() + pathappend; 00134 return _findFile(filename, paths); 00135 } 00136 00137 00138 } Generated on Fri Oct 25 2013 12:41:47 for The Rivet MC analysis system by ![]() |