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 /// Singleton instance 00036 /// @todo Threading? 00037 static HistoHandler* _instance; 00038 00039 /// Private destructor means no inheritance from this class. 00040 ~HistoHandler(); 00041 00042 /// The assignment operator is hidden. 00043 HistoHandler& operator=(const HistoHandler&); 00044 00045 /// The copy constructor is hidden. 00046 HistoHandler(const HistoHandler&); 00047 00048 public: 00049 /// Singleton creation function 00050 static HistoHandler* create(); 00051 00052 00053 //////////////////////////////////////////////////////// 00054 00055 00056 public: 00057 /// @name Histo registration. */ 00058 //@{ 00059 /// Copy an analysis object into a central collection and return the copy. 00060 const AnalysisObject* registerAnalysisObject(const Analysis& parent, 00061 const AnalysisObject& histo, 00062 const string& name); 00063 00064 00065 /// @name Histo retrieval. */ 00066 //@{ 00067 00068 /// Retrieve a named histo for the given Analysis parent (const version). 00069 const AnalysisObject* getAnalysisObject(const Analysis& parent, 00070 const string& name) const { 00071 return _getAnalysisObject(parent, name); 00072 } 00073 00074 00075 /// Retrieve a named histo for the given Analysis parent (non-const version). 00076 AnalysisObject* getAnalysisObject(const Analysis& parent, 00077 const string& name) { 00078 return _getAnalysisObject(parent, name); 00079 } 00080 00081 //@} 00082 00083 00084 /// Histo clearing method: deletes all known histos and empties the 00085 /// reference collections. 00086 void clear(); 00087 00088 00089 private: 00090 00091 AnalysisObject* _getAnalysisObject(const Analysis& parent, 00092 const string& name) const; 00093 00094 /// Get a logger. 00095 Log& getLog() const; 00096 00097 00098 private: 00099 00100 /// Typedef for histo pointer, to allow conversion to a smart pointer in this context. 00101 typedef const AnalysisObject* HistoHandle; 00102 00103 /// Typedef for a vector of histo pointers. 00104 typedef vector<HistoHandle> HistoHandles; 00105 00106 /// @brief Typedef for the structure used to contain named histos for a 00107 /// particular containing Analysis. 00108 typedef map<const string, HistoHandle> NamedHistos; 00109 00110 /// Structure used to map a containing Analysis to its set of histos. 00111 typedef map<const Analysis*, NamedHistos> NamedHistosMap; 00112 00113 /// Core data member, associating a given Analysis to its histos. 00114 NamedHistosMap _namedhistos; 00115 }; 00116 00117 00118 } 00119 00120 #endif