[Rivet-svn] r2831 - in trunk: . bin doc include/Rivet/Tools src/Core src/Tools

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Tue Dec 7 17:45:19 GMT 2010


Author: buckley
Date: Tue Dec  7 17:45:19 2010
New Revision: 2831

Log:
Path lookup improvements, including programmatic setting and appending to analysis library search paths, and by default also looking in the plugin search paths for analysis .info and .aida files.

Modified:
   trunk/ChangeLog
   trunk/bin/rivet
   trunk/doc/rivet-manual.tex
   trunk/include/Rivet/Tools/RivetPaths.hh
   trunk/include/Rivet/Tools/Utils.hh
   trunk/src/Core/AnalysisInfo.cc
   trunk/src/Tools/RivetAIDA.cc
   trunk/src/Tools/RivetPaths.cc

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Tue Dec  7 17:08:47 2010	(r2830)
+++ trunk/ChangeLog	Tue Dec  7 17:45:19 2010	(r2831)
@@ -1,3 +1,20 @@
+2010-12-07  Andy Buckley  <andy at insectnation.org>
+
+	* Update the documentation to explain this latest bump to path
+	lookup behaviours.
+
+	* Various improvements to existing path lookups. In particular,
+	the analysis lib path locations are added to the info and ref
+	paths to avoid having to set three variables when you have all
+	three file types in the same personal plugin directory.
+
+	* Adding setAnalysisLibPaths and addAnalysisLibPath
+	functions. rivet --analysis-path{,-append} now use these and work
+	correctly. Hurrah!
+
+	* Add --show-analyses as an alias for --show-analysis, following a
+	comment at the ATLAS tutorial.
+
 2010-12-07  Hendrik Hoeth <hendrik.hoeth at cern.ch>
 
 	* Change LegendXPos behaviour in make-plots. Now the top left

Modified: trunk/bin/rivet
==============================================================================
--- trunk/bin/rivet	Tue Dec  7 17:08:47 2010	(r2830)
+++ trunk/bin/rivet	Tue Dec  7 17:45:19 2010	(r2831)
@@ -207,18 +207,10 @@
 
 ## Override/modify analysis search path
 if opts.ANALYSIS_PATH:
-    os.environ["RIVET_ANALYSIS_PATH"] = opts.ANALYSIS_PATH
-    os.environ["RIVET_REF_PATH"] = opts.ANALYSIS_PATH
+    rivet.setAnalysisLibPaths(opts.ANALYSIS_PATH.split(":"))
 if opts.ANALYSIS_PATH_APPEND:
-    for var in ["RIVET_ANALYSIS_PATH", "RIVET_REF_PATH"]:
-        anapath = os.environ.get(var, "")
-        if anapath:
-            anapath += ":"
-        anapath += opts.ANALYSIS_PATH_APPEND
-        os.environ[var] = anapath
-# logging.debug("RIVET_ANALYSIS_PATH = " + os.environ.get("RIVET_ANALYSIS_PATH", ""))
-# logging.debug("RIVET_REF_PATH = " + os.environ.get("RIVET_REF_PATH", ""))
-# logging.debug("RIVET_INFO_PATH = " + os.environ.get("RIVET_INFO_PATH", ""))
+    for ap in opts.ANALYSIS_PATH_APPEND.split(":"):
+        rivet.addAnalysisLibPath(ap)
 
 
 ## List of analyses

Modified: trunk/doc/rivet-manual.tex
==============================================================================
--- trunk/doc/rivet-manual.tex	Tue Dec  7 17:08:47 2010	(r2830)
+++ trunk/doc/rivet-manual.tex	Tue Dec  7 17:45:19 2010	(r2831)
@@ -1125,7 +1125,10 @@
 You may also wish or need to use the \var{RIVET_REF_PATH} and
 \var{RIVET_INFO_PATH} variables, which respectively provide similar search paths
 for analysis reference data and analysis metadata (e.g. author, date, run
-conditions, experiment, etc.) files.
+conditions, experiment, etc.) files. To make life easier for typical users who
+have written a few plugins of their own, the analysis plugin library lookup
+paths are searched for the reference data and analysis info files -- but again
+only if the corresponding variables are \emph{not} set.
 
 To get started writing your analysis and understand
 the plugin system better, you should check out the documentation in the wiki on

Modified: trunk/include/Rivet/Tools/RivetPaths.hh
==============================================================================
--- trunk/include/Rivet/Tools/RivetPaths.hh	Tue Dec  7 17:08:47 2010	(r2830)
+++ trunk/include/Rivet/Tools/RivetPaths.hh	Tue Dec  7 17:45:19 2010	(r2831)
@@ -18,6 +18,12 @@
   /// Get Rivet analysis plugin library search paths
   const std::vector<std::string> getAnalysisLibPaths();
 
+  /// Set the Rivet analysis plugin library search paths
+  void setAnalysisLibPaths(const std::vector<std::string>& paths);
+
+  /// Set the Rivet analysis plugin library search paths
+  void addAnalysisLibPath(const std::string& extrapath);
+
   /// Get Rivet analysis reference data search paths
   const std::vector<std::string> getAnalysisRefPaths();
 

Modified: trunk/include/Rivet/Tools/Utils.hh
==============================================================================
--- trunk/include/Rivet/Tools/Utils.hh	Tue Dec  7 17:08:47 2010	(r2830)
+++ trunk/include/Rivet/Tools/Utils.hh	Tue Dec  7 17:45:19 2010	(r2831)
@@ -2,7 +2,6 @@
 #ifndef RIVET_Utils_HH
 #define RIVET_Utils_HH
 
-// #include <Rivet/Rivet.hh>
 #include <Rivet/Math/Math.hh>
 #include <cctype>
 #include <algorithm>
@@ -51,29 +50,49 @@
   }
 
 
+  /// Check whether a string @a end is found at the end of @a s
   inline bool endsWith(const string& s, const string& end) {
     if (s.length() < end.length()) return false;
     return s.substr(s.length() - end.length()) == end;
   }
 
-  /// Split a string with single-character delimiters, ignoring zero-length
-  /// substrings. Designed for getting elements of filesystem paths, naturally.
-  inline vector<string> split(string path, const string delim = ":") {
+
+  /// @brief Split a path string with colon delimiters.
+  /// Ignores zero-length substrings. Designed for getting elements of filesystem paths, naturally.
+  inline vector<string> pathsplit(const string& path) {
+    const string delim = ":";
     vector<string> dirs;
-    if (delim.length() != 1) {
-      throw Error("Rivet::split(string): delimiter must be a single character.");
-    }
+    string tmppath = path;
     while (true) {
-      const size_t delim_pos = path.find(delim);
+      const size_t delim_pos = tmppath.find(delim);
       if (delim_pos == string::npos) break;
-      const string dir = path.substr(0, delim_pos);
+      const string dir = tmppath.substr(0, delim_pos);
       if (dir.length()) dirs.push_back(dir); // Don't insert "empties"
-      path.replace(0, delim_pos+1, "");
+      tmppath.replace(0, delim_pos+1, "");
     }
-    if (path.length()) dirs.push_back(path); // Don't forget the trailing component!
+    if (tmppath.length()) dirs.push_back(tmppath); // Don't forget the trailing component!
     return dirs;
   }
 
+  /// @deprecated Use @c pathsplit instead.
+  inline vector<string> split(const string& path, const string& UNUSED(delim) = ":") {
+    return pathsplit(path);
+  }
+
+  /// @brief Join several filesystem paths together with a delimiter character.
+  /// Note that this does NOT join path elements together with a platform-portable
+  /// directory delimiter, cf. the Python @c{os.path.join}!
+  inline string pathjoin(const vector<string>& paths) {
+    const string delim = ":";
+    string rtn;
+    for (vector<string>::const_iterator is = paths.begin(); is != paths.end(); ++is) {
+      if (rtn.size() > 0) rtn += delim;
+      rtn += *is;
+    }
+    return rtn;
+  }
+
+
   /// Get library install path
   const string getLibPath();
 

Modified: trunk/src/Core/AnalysisInfo.cc
==============================================================================
--- trunk/src/Core/AnalysisInfo.cc	Tue Dec  7 17:08:47 2010	(r2830)
+++ trunk/src/Core/AnalysisInfo.cc	Tue Dec  7 17:45:19 2010	(r2831)
@@ -26,7 +26,7 @@
     char* env = 0;
     // First try to use the Rivet data path variable
     env = getenv("RIVET_INFO_PATH");
-    if (env) dirs += split(env);
+    if (env) dirs += pathsplit(env);
     // Then try to use the Rivet data install path
     dirs += getRivetDataPath();
     // And the current dir

Modified: trunk/src/Tools/RivetAIDA.cc
==============================================================================
--- trunk/src/Tools/RivetAIDA.cc	Tue Dec  7 17:08:47 2010	(r2830)
+++ trunk/src/Tools/RivetAIDA.cc	Tue Dec  7 17:45:19 2010	(r2831)
@@ -22,13 +22,7 @@
 
 
   const string getDatafilePath(string papername) {
-    char* env = getenv("RIVET_REF_PATH");
-    vector<string> searchpaths;
-    if (env) {
-      searchpaths = split(env);
-    }
-    searchpaths.push_back(getRivetDataPath());
-    searchpaths.push_back(".");
+    const vector<string> searchpaths = getAnalysisRefPaths();
     foreach (const string& dir, searchpaths) {
       std::ifstream in;
       const string file = dir + "/" + papername + ".aida";

Modified: trunk/src/Tools/RivetPaths.cc
==============================================================================
--- trunk/src/Tools/RivetPaths.cc	Tue Dec  7 17:08:47 2010	(r2830)
+++ trunk/src/Tools/RivetPaths.cc	Tue Dec  7 17:45:19 2010	(r2831)
@@ -36,7 +36,7 @@
     env = getenv("RIVET_ANALYSIS_PATH");
     if (env) {
       // Use the Rivet analysis path variable if set...
-      dirs += split(env);
+      dirs += pathsplit(env);
     } else {
       // ... otherwise fall back to the Rivet library install path
       dirs += getLibPath();
@@ -45,16 +45,31 @@
   }
 
 
+  void setAnalysisLibPaths(const vector<string>& paths) {
+    const string pathstr = pathjoin(paths);
+    setenv("RIVET_ANALYSIS_PATH", pathstr.c_str(), 1);
+  }
+
+
+  void addAnalysisLibPath(const string& extrapath) {
+    vector<string> paths = getAnalysisLibPaths();
+    paths.push_back(extrapath);
+    setAnalysisLibPaths(paths);
+  }
+
+
   const vector<string> getAnalysisRefPaths() {
     vector<string> dirs;
     char* env = 0;
     env = getenv("RIVET_REF_PATH");
     if (env) {
       // Use the Rivet analysis path variable if set...
-      dirs += split(env);
+      dirs += pathsplit(env);
     } else {
       // ... otherwise fall back to the Rivet data install path
       dirs += getRivetDataPath();
+      // ... and also add any analysis plugin search dirs for convenience
+      dirs += getAnalysisLibPaths();
     }
     return dirs;
   }
@@ -66,10 +81,12 @@
     env = getenv("RIVET_INFO_PATH");
     if (env) {
       // Use the Rivet analysis path variable if set...
-      dirs += split(env);
+      dirs += pathsplit(env);
     } else {
       // ... otherwise fall back to the Rivet data install path
       dirs += getRivetDataPath();
+      // ... and also add any analysis plugin search dirs for convenience
+      dirs += getAnalysisLibPaths();
     }
     return dirs;
   }


More information about the Rivet-svn mailing list