CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQMOffline/Trigger/interface/EgHLTMonElemManager.h

Go to the documentation of this file.
00001 #ifndef DQMOFFLINE_TRIGGER_EGHLTMONELEMMANAGER
00002 #define DQMOFFLINE_TRIGGER_EGHLTMONELEMMANAGER
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 namespace egHLT {
00032   template<class T> class MonElemManagerBase {
00033     
00034   public:
00035     MonElemManagerBase(){}
00036     virtual ~MonElemManagerBase(){}
00037     
00038     virtual void fill(const T& obj,float weight)=0;
00039     
00040   };
00041 
00042   //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
00043   template<class T> class MonElemManagerHist : public MonElemManagerBase<T> {
00044     
00045   private:
00046     MonitorElement *monElem_; //we own this (or do we, currently I have decided we dont) FIXME
00047     
00048     //disabling copying and assignment as I havnt figured out how I want them to work yet
00049     //incidently we cant copy a MonitorElement anyway at the moment (and we prob dont want to)
00050   private:
00051     MonElemManagerHist(const MonElemManagerHist& rhs){}
00052     MonElemManagerHist& operator=(const MonElemManagerHist& rhs){return *this;}
00053   public:
00054     MonElemManagerHist(std::string name,std::string title,int nrBins,double xMin,double xMax);
00055     MonElemManagerHist(std::string name,std::string title,int nrBinsX,double xMin,double xMax,int nrBinsY,double yMin,double yMax);
00056     virtual ~MonElemManagerHist();
00057     
00058     MonitorElement* monElem(){return monElem_;}
00059     const MonitorElement* monElem()const{return monElem_;}
00060     
00061     virtual void fill(const T& obj,float weight)=0;
00062     
00063     
00064   };
00065   
00066   template <class T> MonElemManagerHist<T>::MonElemManagerHist(std::string name,std::string title,int nrBins,double xMin,double xMax):
00067     monElem_(NULL)
00068   {
00069     DQMStore* dbe = edm::Service<DQMStore>().operator->();
00070     monElem_ =dbe->book1D(name,title,nrBins,xMin,xMax);
00071   }
00072   
00073   template <class T> MonElemManagerHist<T>::MonElemManagerHist(std::string name,std::string title,
00074                                                                int nrBinsX,double xMin,double xMax,
00075                                                                int nrBinsY,double yMin,double yMax):
00076     monElem_(NULL)
00077   {
00078     DQMStore* dbe = edm::Service<DQMStore>().operator->();
00079     monElem_ =dbe->book2D(name,title,nrBinsX,xMin,xMax,nrBinsY,yMin,yMax);
00080   }
00081   
00082   
00083   template <class T> MonElemManagerHist<T>::~MonElemManagerHist()
00084   {
00085     // delete monElem_;
00086   }
00087   
00088   //fills the MonitorElement with a member function of class T returning type varType
00089   template<class T,typename varType> class MonElemManager : public MonElemManagerHist<T> {
00090   private:
00091     
00092     varType (T::*varFunc_)()const;
00093     
00094     
00095     //disabling copying and assignment as I havnt figured out how I want them to work yet
00096   private:
00097   MonElemManager(const MonElemManager& rhs){}
00098     MonElemManager& operator=(const MonElemManager& rhs){return *this;}
00099     
00100   public:
00101     MonElemManager(std::string name,std::string title,int nrBins,double xMin,double xMax,
00102                    varType (T::*varFunc)()const):
00103       MonElemManagerHist<T>(name,title,nrBins,xMin,xMax),
00104       varFunc_(varFunc){}
00105     ~MonElemManager();
00106     
00107     
00108     void fill(const T& obj,float weight);
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 
00161 #endif