rivet is hosted by Hepforge, IPPP Durham
RivetPaths.cc
Go to the documentation of this file.
00001 #include "Rivet/Rivet.hh"
00002 #include "Rivet/Tools/RivetPaths.hh"
00003 #include "Rivet/Tools/Utils.hh"
00004 #include "Rivet/RivetBoost.hh"
00005 #include "binreloc.h"
00006 //#include <sys/stat.h>
00007 
00008 namespace Rivet {
00009 
00010 
00011   inline string _findFile(const string& filename, const vector<string>& paths) {
00012     //struct stat stFileInfo;
00013     foreach (const string& dir, paths) {
00014       const string path = dir + "/" + filename;
00015       //if (stat(path.c_str(), &stFileInfo) == 0) {
00016       if (access(path.c_str(), R_OK) == 0) {
00017         return path;
00018       }
00019     }
00020     return "";
00021   }
00022 
00023 
00024   string getLibPath() {
00025     BrInitError error;
00026     br_init_lib(&error);
00027     char* temp = br_find_lib_dir(DEFAULTLIBDIR);
00028     const string libdir(temp);
00029     free (temp);
00030     return libdir;
00031   }
00032 
00033   string getDataPath() {
00034     BrInitError error;
00035     br_init_lib(&error);
00036     char* temp = br_find_data_dir(DEFAULTDATADIR);
00037     const string sharedir(temp);
00038     free (temp);
00039     return sharedir;
00040   }
00041 
00042   string getRivetDataPath() {
00043     return getDataPath() + "/Rivet";
00044   }
00045 
00046 
00047 
00048   void setAnalysisLibPaths(const vector<string>& paths) {
00049     const string pathstr = pathjoin(paths);
00050     setenv("RIVET_ANALYSIS_PATH", pathstr.c_str(), 1);
00051   }
00052 
00053   void addAnalysisLibPath(const string& extrapath) {
00054     vector<string> paths = getAnalysisLibPaths();
00055     paths.push_back(extrapath);
00056     setAnalysisLibPaths(paths);
00057   }
00058 
00059   vector<string> getAnalysisLibPaths() {
00060     vector<string> dirs;
00061     char* env = 0;
00062     env = getenv("RIVET_ANALYSIS_PATH");
00063     if (env) {
00064       // Use the Rivet analysis path variable if set...
00065       dirs += pathsplit(env);
00066     }
00067     // ... otherwise fall back to the Rivet library install path
00068     dirs += getLibPath();
00069     return dirs;
00070   }
00071 
00072   string findAnalysisLibFile(const string& filename) {
00073     return _findFile(filename, getAnalysisLibPaths());
00074   }
00075 
00076 
00077   vector<string> getAnalysisRefPaths() {
00078     vector<string> dirs;
00079     char* env = 0;
00080     env = getenv("RIVET_REF_PATH");
00081     if (env) {
00082       // Use the Rivet analysis path variable if set...
00083       dirs += pathsplit(env);
00084     }
00085     // Then fall back to the Rivet data install path...
00086     dirs += getRivetDataPath();
00087     // ... and also add any analysis plugin search dirs for convenience
00088     dirs += getAnalysisLibPaths();
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 fall back to the Rivet data install path...
00108     dirs += getRivetDataPath();
00109     // ... and also add any analysis plugin search dirs for convenience
00110     dirs += getAnalysisLibPaths();
00111     return dirs;
00112   }
00113 
00114   string findAnalysisInfoFile(const string& filename,
00115                               const vector<string>& pathprepend, const vector<string>& pathappend) {
00116     const vector<string> paths = pathprepend + getAnalysisInfoPaths() + pathappend;
00117     return _findFile(filename, paths);
00118   }
00119 
00120 
00121   vector<string> getAnalysisPlotPaths() {
00122     vector<string> dirs;
00123     char* env = 0;
00124     env = getenv("RIVET_PLOT_PATH");
00125     if (env) {
00126       // Use the Rivet analysis path variable if set...
00127       dirs += pathsplit(env);
00128     }
00129     // Then fall back to the Rivet data install path...
00130     dirs += getRivetDataPath();
00131     // ... and also add any analysis plugin search dirs for convenience
00132     dirs += getAnalysisLibPaths();
00133     return dirs;
00134   }
00135 
00136   string findAnalysisPlotFile(const string& filename,
00137                               const vector<string>& pathprepend, const vector<string>& pathappend) {
00138     const vector<string> paths = pathprepend + getAnalysisPlotPaths() + pathappend;
00139     return _findFile(filename, paths);
00140   }
00141 
00142 
00143 }