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