|
[Rivet-svn] r4181 - in trunk: include/Rivet include/Rivet/Tools src/Core src/Toolsblackhole at projects.hepforge.org blackhole at projects.hepforge.orgTue Mar 5 10:23:44 GMT 2013
Author: buckley Date: Tue Mar 5 10:23:44 2013 New Revision: 4181 Log: Making the findDatafile() function primarily find YODA data files, then fall back to AIDA. The ref data loader will use the appropriate YODA format reader. Modified: trunk/include/Rivet/RivetYODA.hh trunk/include/Rivet/Tools/RivetPaths.hh trunk/src/Core/Analysis.cc trunk/src/Tools/RivetPaths.cc trunk/src/Tools/RivetYODA.cc Modified: trunk/include/Rivet/RivetYODA.hh ============================================================================== --- trunk/include/Rivet/RivetYODA.hh Mon Mar 4 12:24:54 2013 (r4180) +++ trunk/include/Rivet/RivetYODA.hh Tue Mar 5 10:23:44 2013 (r4181) @@ -15,13 +15,10 @@ #include "YODA/Profile1D.h" #include "YODA/Scatter2D.h" #include "YODA/Point2D.h" -#include "YODA/ReaderAIDA.h" namespace Rivet { using YODA::WriterYODA; - using YODA::ReaderAIDA; - typedef YODA::Histo1D Histo1D; typedef YODA::Profile1D Profile1D; typedef YODA::Scatter2D Scatter2D; Modified: trunk/include/Rivet/Tools/RivetPaths.hh ============================================================================== --- trunk/include/Rivet/Tools/RivetPaths.hh Mon Mar 4 12:24:54 2013 (r4180) +++ trunk/include/Rivet/Tools/RivetPaths.hh Tue Mar 5 10:23:44 2013 (r4181) @@ -5,6 +5,12 @@ namespace Rivet { + /// Convenience function for determining if a filesystem path exists + inline bool fileexists(const string& path) { + return (access(path.c_str(), R_OK) == 0); + } + + /// @name Installation directory paths //@{ Modified: trunk/src/Core/Analysis.cc ============================================================================== --- trunk/src/Core/Analysis.cc Mon Mar 4 12:24:54 2013 (r4180) +++ trunk/src/Core/Analysis.cc Tue Mar 5 10:23:44 2013 (r4181) @@ -7,6 +7,8 @@ #include "Rivet/Tools/Logging.hh" namespace Rivet { + + Analysis::Analysis(const string& name) : _crossSection(-1.0), _gotCrossSection(false), @@ -35,15 +37,18 @@ const string Analysis::histoDir() const { - /// @todo This doesn't change: calc and cache at first use! - string path = "/" + name(); - if (handler().runName().length() > 0) { - path = "/" + handler().runName() + path; - } - while (find_first(path, "//")) { - replace_all(path, "//", "/"); + // Caching... + static string _histoDir; + if (_histoDir.empty()) { + _histoDir = "/" + name(); + if (handler().runName().length() > 0) { + _histoDir = "/" + handler().runName() + _histoDir; + } + while (find_first(_histoDir, "//")) { + replace_all(_histoDir, "//", "/"); + } } - return path; + return _histoDir; } Modified: trunk/src/Tools/RivetPaths.cc ============================================================================== --- trunk/src/Tools/RivetPaths.cc Mon Mar 4 12:24:54 2013 (r4180) +++ trunk/src/Tools/RivetPaths.cc Tue Mar 5 10:23:44 2013 (r4181) @@ -3,19 +3,14 @@ #include "Rivet/Tools/Utils.hh" #include "Rivet/RivetBoost.hh" #include "binreloc.h" -//#include <sys/stat.h> namespace Rivet { inline string _findFile(const string& filename, const vector<string>& paths) { - //struct stat stFileInfo; foreach (const string& dir, paths) { const string path = dir + "/" + filename; - //if (stat(path.c_str(), &stFileInfo) == 0) { - if (access(path.c_str(), R_OK) == 0) { - return path; - } + if (fileexists(path)) return path; } return ""; } Modified: trunk/src/Tools/RivetYODA.cc ============================================================================== --- trunk/src/Tools/RivetYODA.cc Mon Mar 4 12:24:54 2013 (r4180) +++ trunk/src/Tools/RivetYODA.cc Tue Mar 5 10:23:44 2013 (r4181) @@ -1,6 +1,8 @@ #include "Rivet/RivetYODA.hh" #include "Rivet/Rivet.hh" #include "Rivet/Tools/RivetPaths.hh" +#include "YODA/ReaderYODA.h" +#include "YODA/ReaderAIDA.h" #include "boost/algorithm/string/split.hpp" using namespace std; @@ -9,25 +11,29 @@ string getDatafilePath(const string& papername) { - const string path = findAnalysisRefFile(papername + ".aida"); - if (!path.empty()) return path; - throw Rivet::Error("Couldn't find ref data file '" + papername + ".aida" + - " in $RIVET_REF_PATH, " + getRivetDataPath() + ", or ."); - return ""; + /// Try to find YODA otherwise fall back to try AIDA + const string path1 = findAnalysisRefFile(papername + ".yoda"); + if (!path1.empty()) return path1; + const string path2 = findAnalysisRefFile(papername + ".aida"); + if (!path2.empty()) return path2; + throw Rivet::Error("Couldn't find ref data file '" + papername + ".yoda/aida" + + " in $RIVET_REF_PATH, '" + getRivetDataPath() + "', or '.'"); + //return ""; } RefDataMap getRefData(const string& papername) { - // Get filename - const string xmlfile = getDatafilePath(papername); + const string datafile = getDatafilePath(papername); - YODA::Reader & reader = ReaderAIDA::create(); + // Make an appropriate data file reader and read the data objects + YODA::Reader& reader = (datafile.find(".yoda") != string::npos) ? \ + YODA::ReaderYODA::create() : YODA::ReaderAIDA::create(); vector<YODA::AnalysisObject *> aovec; - reader.read(xmlfile, aovec); + reader.read(datafile, aovec); // Return value, to be populated RefDataMap rtn; - foreach ( YODA::AnalysisObject * ao, aovec ) { + foreach ( YODA::AnalysisObject* ao, aovec ) { Scatter2DPtr refdata( dynamic_cast<Scatter2D *>(ao) ); if (!refdata) continue; string plotpath = refdata->path();
More information about the Rivet-svn mailing list |