HistoHandler.cc
Go to the documentation of this file.
00001 // -*- C++ -*- 00002 #include "Rivet/Rivet.hh" 00003 #include "Rivet/Tools/Logging.hh" 00004 #include "Rivet/HistoHandler.hh" 00005 #include "Rivet/Analysis.hh" 00006 #include <algorithm> 00007 00008 namespace Rivet { 00009 00010 00011 // Get a logger. 00012 Log& HistoHandler::getLog() const { 00013 return Log::getLog("Rivet.HistoHandler"); 00014 } 00015 00016 00017 void HistoHandler::clear() { 00018 _namedhistos.clear(); 00019 } 00020 00021 00022 // Delete contained pointers. 00023 HistoHandler::~HistoHandler() { 00024 clear(); 00025 } 00026 00027 00028 const AnalysisObject* HistoHandler::registerAnalysisObject(const Analysis& parent, 00029 const AnalysisObject& ao, 00030 const string& name) { 00031 getLog() << Log::TRACE << "Trying to register" 00032 << " analysis object " << &ao 00033 << " for parent " << &parent << "(" << parent.name() << ")" 00034 << " with name '" << name << "'" << endl; 00035 00036 // If this name is already registered for this analysis, throw a complaint 00037 NamedHistosMap::const_iterator nhs = _namedhistos.find(&parent); 00038 if (nhs != _namedhistos.end()) { 00039 NamedHistos::const_iterator nh = nhs->second.find(name); 00040 if (nh != nhs->second.end()) { 00041 stringstream ss; 00042 ss << "Histogram \"" << name 00043 << "\" already exists for parent analysis " << &parent; 00044 throw Error(ss.str()); 00045 } 00046 } 00047 00048 _namedhistos[&parent][name] = &ao; 00049 //return *(_namedhistos[&parent][name]); 00050 return const_cast<AnalysisObject*>(_namedhistos[&parent][name]); 00051 } 00052 00053 00054 00055 AnalysisObject* HistoHandler::_getAnalysisObject(const Analysis& parent, 00056 const string& name) const { 00057 getLog() << Log::TRACE << "Searching for child histo '" 00058 << name << "' of " << &parent << endl; 00059 00060 NamedHistosMap::const_iterator nhs = _namedhistos.find(&parent); 00061 if (nhs == _namedhistos.end()) { 00062 stringstream ss; 00063 ss << "Couldn't find any histograms for parent analysis " << &parent; 00064 throw Error(ss.str()); 00065 } 00066 00067 NamedHistos::const_iterator nh = nhs->second.find(name); 00068 if (nh == nhs->second.end()) { 00069 stringstream ss; 00070 ss << "Couldn't find histogram \"" << name 00071 << "\" for parent analysis " << &parent; 00072 throw Error(ss.str()); 00073 } 00074 00075 //return *(nh->second); 00076 AnalysisObject* rtn = const_cast<AnalysisObject*>(nh->second); 00077 return rtn; 00078 } 00079 00080 00081 } Generated on Fri Dec 21 2012 15:03:40 for The Rivet MC analysis system by ![]() |