rivet is hosted by Hepforge, IPPP Durham
RivetYODA.cc
Go to the documentation of this file.
00001 #include "Rivet/Config/RivetCommon.hh"
00002 #include "Rivet/Tools/RivetYODA.hh"
00003 #include "Rivet/Tools/RivetPaths.hh"
00004 #include "YODA/ReaderYODA.h"
00005 #include "YODA/ReaderAIDA.h"
00006 #include "boost/algorithm/string/split.hpp"
00007 
00008 using namespace std;
00009 
00010 namespace Rivet {
00011 
00012 
00013   string getDatafilePath(const string& papername) {
00014     /// Try to find YODA otherwise fall back to try AIDA
00015     const string path1 = findAnalysisRefFile(papername + ".yoda");
00016     if (!path1.empty()) return path1;
00017     const string path2 = findAnalysisRefFile(papername + ".aida");
00018     if (!path2.empty()) return path2;
00019     throw Rivet::Error("Couldn't find ref data file '" + papername + ".yoda/aida" +
00020                        " in $RIVET_REF_PATH, '" + getRivetDataPath() + "', or '.'");
00021   }
00022 
00023 
00024   map<string, AnalysisObjectPtr> getRefData(const string& papername) {
00025     const string datafile = getDatafilePath(papername);
00026 
00027     // Make an appropriate data file reader and read the data objects
00028     YODA::Reader& reader = (datafile.find(".yoda") != string::npos) ?   \
00029       YODA::ReaderYODA::create() : YODA::ReaderAIDA::create();
00030     vector<YODA::AnalysisObject *> aovec;
00031     reader.read(datafile, aovec);
00032 
00033     // Return value, to be populated
00034     map<string, AnalysisObjectPtr> rtn;
00035     foreach ( YODA::AnalysisObject* ao, aovec ) {
00036       // Scatter2DPtr refdata( dynamic_cast<Scatter2D*>(ao) );
00037       AnalysisObjectPtr refdata(ao);
00038       if (!refdata) continue;
00039       string plotpath = refdata->path();
00040 
00041       // Split path at "/" and only return the last field, i.e. the histogram ID
00042       vector<string> pathvec;
00043       split( pathvec, plotpath, is_any_of("/"), token_compress_on );
00044       plotpath = pathvec.back();
00045 
00046       rtn[plotpath] = refdata;
00047     }
00048     return rtn;
00049   }
00050 
00051 
00052 }