rivet is hosted by Hepforge, IPPP Durham
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/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 unless the path ends in ::
00063     if (!env || strlen(env) < 2 || string(env).substr(strlen(env)-2) != "::") {
00064       dirs += getLibPath();
00065     }
00066     return dirs;
00067   }
00068 
00069   string findAnalysisLibFile(const string& filename) {
00070     return _findFile(filename, getAnalysisLibPaths());
00071   }
00072 
00073 
00074   vector<string> getAnalysisRefPaths() {
00075     vector<string> dirs;
00076     char* env = 0;
00077     env = getenv("RIVET_REF_PATH");
00078     if (env) {
00079       // Use the Rivet analysis path variable if set...
00080       dirs += pathsplit(env);
00081     }
00082     // ... then, unless the path ends in :: ...
00083     if (!env || strlen(env) < 2 || string(env).substr(strlen(env)-2) != "::") {
00084       // ... fall back to the Rivet data install path...
00085       dirs += getRivetDataPath();
00086       // ... and also add any analysis plugin search dirs for convenience
00087       dirs += getAnalysisLibPaths();
00088     }
00089     return dirs;
00090   }
00091 
00092   string findAnalysisRefFile(const string& filename,
00093                              const vector<string>& pathprepend, const vector<string>& pathappend) {
00094     const vector<string> paths = pathprepend + getAnalysisRefPaths() + pathappend;
00095     return _findFile(filename, paths);
00096   }
00097 
00098 
00099   vector<string> getAnalysisInfoPaths() {
00100     vector<string> dirs;
00101     char* env = 0;
00102     env = getenv("RIVET_INFO_PATH");
00103     if (env) {
00104       // Use the Rivet analysis path variable if set...
00105       dirs += pathsplit(env);
00106     }
00107     // ... then, unless the path ends in :: ...
00108     if (!env || strlen(env) < 2 || string(env).substr(strlen(env)-2) != "::") {
00109       // ... fall back to the Rivet data install path...
00110       dirs += getRivetDataPath();
00111       // ... and also add any analysis plugin search dirs for convenience
00112       dirs += getAnalysisLibPaths();
00113     }
00114     return dirs;
00115   }
00116 
00117   string findAnalysisInfoFile(const string& filename,
00118                               const vector<string>& pathprepend, const vector<string>& pathappend) {
00119     const vector<string> paths = pathprepend + getAnalysisInfoPaths() + pathappend;
00120     return _findFile(filename, paths);
00121   }
00122 
00123 
00124   vector<string> getAnalysisPlotPaths() {
00125     vector<string> dirs;
00126     char* env = 0;
00127     env = getenv("RIVET_PLOT_PATH");
00128     if (env) {
00129       // Use the Rivet analysis path variable if set...
00130       dirs += pathsplit(env);
00131     }
00132     // ... then, unless the path ends in :: ...
00133     if (!env || strlen(env) < 2 || string(env).substr(strlen(env)-2) != "::") {
00134       // ... fall back to the Rivet data install path...
00135       dirs += getRivetDataPath();
00136       // ... and also add any analysis plugin search dirs for convenience
00137       dirs += getAnalysisLibPaths();
00138     }
00139     return dirs;
00140   }
00141 
00142   string findAnalysisPlotFile(const string& filename,
00143                               const vector<string>& pathprepend, const vector<string>& pathappend) {
00144     const vector<string> paths = pathprepend + getAnalysisPlotPaths() + pathappend;
00145     return _findFile(filename, paths);
00146   }
00147 
00148 
00149 }