00001 // -*- C++ -*- 00002 #ifndef RIVET_HistoHandler_HH 00003 #define RIVET_HistoHandler_HH 00004 00005 #include "Rivet/Rivet.hh" 00006 #include "Rivet/Tools/Logging.fhh" 00007 #include "Rivet/Analysis.fhh" 00008 00009 namespace Rivet { 00010 00011 /// Forward declaration of Histo base class. 00012 class AnalysisObject; 00013 00014 00015 /// @brief The projection handler is a central repository for histograms (and 00016 /// other analysis stats objects) to be used in a Rivet analysis run. This 00017 /// eliminates the need for analysis classes to contain large numbers of 00018 /// histogram pointer members, and allows histograms to be accessed via more 00019 /// user-friendly names than C++ variable names allow. 00020 /// 00021 /// The core of the HistoHandler design is that it is a singleton class, 00022 /// essentially a wrapper around a map of @c AnalysisObject*, indexed by a 00023 /// hash of the registering object and its local name for the registered 00024 /// projection. 00025 /// 00026 class HistoHandler { 00027 private: 00028 00029 /// @name Construction. */ 00030 //@{ 00031 /// The standard constructor. 00032 HistoHandler() { } 00033 //@} 00034 00035 /// Private destructor means no inheritance from this class. 00036 ~HistoHandler(); 00037 00038 /// The assignment operator is hidden. 00039 HistoHandler& operator=(const HistoHandler&); 00040 00041 /// The copy constructor is hidden. 00042 HistoHandler(const HistoHandler&); 00043 00044 00045 public: 00046 00047 /// Singleton getter function 00048 static HistoHandler& getInstance() { 00049 static HistoHandler _instance; 00050 return _instance; 00051 } 00052 00053 00054 //////////////////////////////////////////////////////// 00055 00056 00057 public: 00058 /// @name Histo registration. */ 00059 //@{ 00060 /// Copy an analysis object into a central collection and return the copy. 00061 const AnalysisObject* registerAnalysisObject(const Analysis& parent, 00062 const AnalysisObject& histo, 00063 const string& name); 00064 00065 00066 /// @name Histo retrieval. */ 00067 //@{ 00068 00069 /// Retrieve a named histo for the given Analysis parent (const version). 00070 const AnalysisObject* getAnalysisObject(const Analysis& parent, 00071 const string& name) const { 00072 return _getAnalysisObject(parent, name); 00073 } 00074 00075 00076 /// Retrieve a named histo for the given Analysis parent (non-const version). 00077 AnalysisObject* getAnalysisObject(const Analysis& parent, 00078 const string& name) { 00079 return _getAnalysisObject(parent, name); 00080 } 00081 00082 //@} 00083 00084 00085 /// Histo clearing method: deletes all known histos and empties the 00086 /// reference collections. 00087 void clear(); 00088 00089 00090 private: 00091 00092 AnalysisObject* _getAnalysisObject(const Analysis& parent, 00093 const string& name) const; 00094 00095 /// Get a logger. 00096 Log& getLog() const; 00097 00098 00099 private: 00100 00101 /// Typedef for histo pointer, to allow conversion to a smart pointer in this context. 00102 typedef const AnalysisObject* HistoHandle; 00103 00104 /// Typedef for a vector of histo pointers. 00105 typedef vector<HistoHandle> HistoHandles; 00106 00107 /// @brief Typedef for the structure used to contain named histos for a 00108 /// particular containing Analysis. 00109 typedef map<const string, HistoHandle> NamedHistos; 00110 00111 /// Structure used to map a containing Analysis to its set of histos. 00112 typedef map<const Analysis*, NamedHistos> NamedHistosMap; 00113 00114 /// Core data member, associating a given Analysis to its histos. 00115 NamedHistosMap _namedhistos; 00116 }; 00117 00118 00119 } 00120 00121 #endif