|
[Rivet-svn] r1808 - trunk/srcblackhole at projects.hepforge.org blackhole at projects.hepforge.orgWed Sep 2 14:29:08 BST 2009
Author: buckley Date: Wed Sep 2 14:29:07 2009 New Revision: 1808 Log: Improvements to analysis loader path search, and adding use of RIVET_DATA_PATH variable for finding .info files Modified: trunk/src/Analysis.cc trunk/src/AnalysisInfo.cc trunk/src/AnalysisLoader.cc Modified: trunk/src/Analysis.cc ============================================================================== --- trunk/src/Analysis.cc Wed Sep 2 12:07:46 2009 (r1807) +++ trunk/src/Analysis.cc Wed Sep 2 14:29:07 2009 (r1808) @@ -17,6 +17,7 @@ _analysishandler(0), _madeHistoDir(false) { + _defaultname = name; _info.reset( AnalysisInfo::make(name) ); setBeams(ANY, ANY); } @@ -85,7 +86,7 @@ std::string Analysis::name() const { if (_info && !_info->name().empty()) return _info->name(); - return ""; + return _defaultname; } std::string Analysis::spiresId() const { Modified: trunk/src/AnalysisInfo.cc ============================================================================== --- trunk/src/AnalysisInfo.cc Wed Sep 2 12:07:46 2009 (r1807) +++ trunk/src/AnalysisInfo.cc Wed Sep 2 14:29:07 2009 (r1808) @@ -19,14 +19,37 @@ /// Static factory method - AnalysisInfo* AnalysisInfo::make(const std::string& name) { - // Search metadata path and read first matching file - string datapath = getRivetDataPath() + "/" + name + ".info"; - Log::getLog("Rivet.Analysis") - << Log::DEBUG << "Reading analysis data from " << datapath << endl; - if (access(datapath.c_str(), R_OK) != 0) return 0; + AnalysisInfo* AnalysisInfo::make(const std::string& ananame) { + // Build the list of directories to search + vector<string> dirs; + char* env = 0; + // First try to use the Rivet data path variable + env = getenv("RIVET_DATA_PATH"); + if (env) dirs += split(env); + // Then try to use the Rivet data install path + dirs += getRivetDataPath(); + // And the current dir + dirs += "."; + + bool found = false; + string datapath = ""; + foreach (const string& d, dirs) { + if (d.empty()) continue; + /// @todo Use system-independent separator (e.g. Boost.File) + datapath = d + "/" + ananame + ".info"; + Log::getLog("Rivet.AnalysisInfo") + << Log::TRACE << "Looking for analysis data file '" << datapath << "'" << endl; + if (access(datapath.c_str(), R_OK) == 0) { + found = true; + break; + } + } + /// If no ana data file found, return null pointer + if (!found) return 0; // Read data from YAML document + Log::getLog("Rivet.AnalysisInfo") + << Log::DEBUG << "Reading analysis data from " << datapath << endl; std::ifstream io(datapath.c_str()); YAML::Parser parser(io); YAML::Node doc; @@ -34,7 +57,7 @@ parser.GetNextDocument(doc); //cout << doc << endl; } catch (const YAML::ParserException& ex) { - Log::getLog("Rivet.Analysis") + Log::getLog("Rivet.AnalysisInfo") << Log::ERROR << "Parse error when reading analysis data from " << datapath << endl; return 0; @@ -44,8 +67,11 @@ for (YAML::Iterator it = doc.begin(); it != doc.end(); ++it) { string key; it.first() >> key; - Log::getLog("Rivet.Analysis") - << Log::TRACE << key << ": " << it.second() << endl; + stringstream sec; + sec << it.second(); + const string secstr = sec.str().substr(0, sec.str().length()-1); + Log::getLog("Rivet.AnalysisInfo") + << Log::TRACE << key << ": " << secstr << endl; try { if (key == "Name") { it.second() >> ai->_name; Modified: trunk/src/AnalysisLoader.cc ============================================================================== --- trunk/src/AnalysisLoader.cc Wed Sep 2 12:07:46 2009 (r1807) +++ trunk/src/AnalysisLoader.cc Wed Sep 2 14:29:07 2009 (r1808) @@ -66,11 +66,11 @@ // Build the list of directories to search vector<string> dirs; char* env = 0; - // Always (try to) use the Rivet library install path - dirs += getLibPath(); - // Then use the Rivet analysis path variable + // First use the Rivet analysis path variable env = getenv("RIVET_ANALYSIS_PATH"); if (env) dirs += split(env); + // Then the Rivet library install path + dirs += getLibPath(); // And then the user's (non-system) library path env = getenv("LD_LIBRARY_PATH"); if (env) dirs += split(env); @@ -81,6 +81,7 @@ // Find plugin module library files vector<string> pluginfiles; foreach (const string& d, dirs) { + if (d.empty()) continue; oslink::directory dir(d); while (dir) { string filename = dir.next();
More information about the Rivet-svn mailing list |