CMS 3D CMS Logo

MonElemManager.h

Go to the documentation of this file.
00001 #ifndef DQMOFFLINE_TRIGGER_MONELEMMANAGER
00002 #define DQMOFFLINE_TRIGGER_MONELEMMANAGER
00003 
00004 
00005 //class: MonElemManager, short for MonitorElementManager (note not MonEleManager as Ele might be confused for electron
00006 //
00007 //author: Sam Harper (June 2008)
00008 //
00009 //WARNING: interface is NOT final, please dont use this class for now without clearing it with me
00010 //         as I will change it and possibly break all your code
00011 //
00012 //aim: to make MonitorElement objects "fire and forget"
00013 //     specifically it allows to you just add the MonitorElement to a vector containing all
00014 //     your monitor elements to be filled at a certain location so it will be automatically filled
00015 //     at that location and read out
00016 //     it does this by allowing you to specify the function pointer to the member variable you wish to fill at
00017 //     at the time of declaration
00018 //
00019 //implimentation: currently experimental and limited to 1D histograms but will expand later
00020 //                each object, Photon, GsfElectron, is a seperate (templated) class which means
00021 //                that seperate vectors of MonElemManagers are needed for each type
00022 //                however each type has a base class which the various types (int,float,double) 
00023 //                of variable inherit from so dont need seperate vectors
00024 
00025 
00026 #include "DQMServices/Core/interface/DQMStore.h"
00027 #include "DQMServices/Core/interface/MonitorElement.h"
00028 
00029 #include "FWCore/ServiceRegistry/interface/Service.h"
00030 
00031 template<class T> class MonElemManagerBase {
00032   
00033 public:
00034   MonElemManagerBase(){}
00035   virtual ~MonElemManagerBase(){}
00036   
00037   virtual void fill(const T& obj,float weight)=0;
00038 
00039 };
00040 
00041 //this was the orginal base class but then I made a change where I wanted multiple MonElems wraped into a single Manager (ie endcap barrel) so a new base class was designed with interface only
00042 template<class T> class MonElemManagerHist : public MonElemManagerBase<T> {
00043 
00044  private:
00045   MonitorElement *monElem_; //we own this (or do we, currently I have decided we dont) FIXME
00046 
00047  //disabling copying and assignment as I havnt figured out how I want them to work yet
00048  //incidently we cant copy a MonitorElement anyway at the moment (and we prob dont want to)
00049  private:
00050   MonElemManagerHist(const MonElemManagerHist& rhs){}
00051   MonElemManagerHist& operator=(const MonElemManagerHist& rhs){return *this;}
00052  public:
00053   MonElemManagerHist(std::string name,std::string title,int nrBins,double xMin,double xMax);
00054   MonElemManagerHist(std::string name,std::string title,int nrBinsX,double xMin,double xMax,int nrBinsY,double yMin,double yMax);
00055   virtual ~MonElemManagerHist();
00056 
00057   MonitorElement* monElem(){return monElem_;}
00058   const MonitorElement* monElem()const{return monElem_;}
00059   
00060   virtual void fill(const T& obj,float weight)=0;
00061 
00062 
00063 };
00064 
00065 template <class T> MonElemManagerHist<T>::MonElemManagerHist(std::string name,std::string title,int nrBins,double xMin,double xMax):
00066   monElem_(NULL)
00067 {
00068   DQMStore* dbe = edm::Service<DQMStore>().operator->();
00069   monElem_ =dbe->book1D(name,title,nrBins,xMin,xMax);
00070 }
00071   
00072 template <class T> MonElemManagerHist<T>::MonElemManagerHist(std::string name,std::string title,
00073                                                              int nrBinsX,double xMin,double xMax,
00074                                                              int nrBinsY,double yMin,double yMax):
00075   monElem_(NULL)
00076 {
00077   DQMStore* dbe = edm::Service<DQMStore>().operator->();
00078   monElem_ =dbe->book2D(name,title,nrBinsX,xMin,xMax,nrBinsY,yMin,yMax);
00079 }
00080 
00081  
00082 template <class T> MonElemManagerHist<T>::~MonElemManagerHist()
00083 {
00084   // delete monElem_;
00085 }
00086 
00087 //fills the MonitorElement with a member function of class T returning type varType
00088 template<class T,typename varType> class MonElemManager : public MonElemManagerHist<T> {
00089  private:
00090 
00091   varType (T::*varFunc_)()const;
00092 
00093 
00094   //disabling copying and assignment as I havnt figured out how I want them to work yet
00095  private:
00096   MonElemManager(const MonElemManager& rhs){}
00097   MonElemManager& operator=(const MonElemManager& rhs){return *this;}
00098   
00099  public:
00100   MonElemManager(std::string name,std::string title,int nrBins,double xMin,double xMax,
00101                  varType (T::*varFunc)()const):
00102     MonElemManagerHist<T>(name,title,nrBins,xMin,xMax),
00103     varFunc_(varFunc){}
00104   ~MonElemManager();
00105 
00106 
00107   void fill(const T& obj,float weight);
00108 
00109 
00110 };
00111 
00112 
00113 template<class T,typename varType> void MonElemManager<T,varType>::fill(const T& obj,float weight)
00114 {
00115   MonElemManagerHist<T>::monElem()->Fill((obj.*varFunc_)(),weight);
00116 }
00117 
00118 template<class T,typename varType> MonElemManager<T,varType>::~MonElemManager()
00119 {
00120  
00121 }
00122 
00123 
00124 //fills a 2D monitor element with member functions of T returning varType1 and varType2 
00125 template<class T,typename varTypeX,typename varTypeY=varTypeX> class MonElemManager2D : public MonElemManagerHist<T> {
00126  private:
00127 
00128  varTypeX (T::*varFuncX_)()const;
00129  varTypeY (T::*varFuncY_)()const;
00130 
00131   //disabling copying and assignment as I havnt figured out how I want them to work yet
00132  private:
00133  MonElemManager2D(const MonElemManager2D& rhs){}
00134  MonElemManager2D& operator=(const MonElemManager2D& rhs){return *this;}
00135  
00136  public:
00137  MonElemManager2D(std::string name,std::string title,int nrBinsX,double xMin,double xMax,int nrBinsY,double yMin,double yMax,
00138                   varTypeX (T::*varFuncX)()const,varTypeY (T::*varFuncY)()const):
00139                   MonElemManagerHist<T>(name,title,nrBinsX,xMin,xMax,nrBinsY,yMin,yMax),
00140                   varFuncX_(varFuncX),varFuncY_(varFuncY){}
00141  ~MonElemManager2D();
00142 
00143 
00144  void fill(const T& obj,float weight);
00145 
00146 
00147 };
00148 
00149 template<class T,typename varTypeX,typename varTypeY> void MonElemManager2D<T,varTypeX,varTypeY>::fill(const T& obj,float weight)
00150 {
00151   MonElemManagerHist<T>::monElem()->Fill((obj.*varFuncX_)(),(obj.*varFuncY_)(),weight);
00152 }
00153 
00154 template<class T,typename varTypeX,typename varTypeY> MonElemManager2D<T,varTypeX,varTypeY>::~MonElemManager2D()
00155 {
00156  
00157 }
00158 
00159 
00160 #endif

Generated on Tue Jun 9 17:34:09 2009 for CMSSW by  doxygen 1.5.4