CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EgHLTMonElemManager.h
Go to the documentation of this file.
1 #ifndef DQMOFFLINE_TRIGGER_EGHLTMONELEMMANAGER
2 #define DQMOFFLINE_TRIGGER_EGHLTMONELEMMANAGER
3 
4 
5 //class: MonElemManager, short for MonitorElementManager (note not MonEleManager as Ele might be confused for electron
6 //
7 //author: Sam Harper (June 2008)
8 //
9 //WARNING: interface is NOT final, please dont use this class for now without clearing it with me
10 // as I will change it and possibly break all your code
11 //
12 //aim: to make MonitorElement objects "fire and forget"
13 // specifically it allows to you just add the MonitorElement to a vector containing all
14 // your monitor elements to be filled at a certain location so it will be automatically filled
15 // at that location and read out
16 // it does this by allowing you to specify the function pointer to the member variable you wish to fill at
17 // at the time of declaration
18 //
19 //implimentation: currently experimental and limited to 1D histograms but will expand later
20 // each object, Photon, GsfElectron, is a seperate (templated) class which means
21 // that seperate vectors of MonElemManagers are needed for each type
22 // however each type has a base class which the various types (int,float,double)
23 // of variable inherit from so dont need seperate vectors
24 
25 
28 
30 
31 namespace egHLT {
32  template<class T> class MonElemManagerBase {
33 
34  public:
36  virtual ~MonElemManagerBase(){}
37 
38  virtual void fill(const T& obj,float weight)=0;
39 
40  };
41 
42  //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
43  template<class T> class MonElemManagerHist : public MonElemManagerBase<T> {
44 
45  private:
46  MonitorElement *monElem_; //we own this (or do we, currently I have decided we dont) FIXME
47 
48  //disabling copying and assignment as I havnt figured out how I want them to work yet
49  //incidently we cant copy a MonitorElement anyway at the moment (and we prob dont want to)
50  private:
52  MonElemManagerHist& operator=(const MonElemManagerHist& rhs){return *this;}
53  public:
54  MonElemManagerHist(std::string name,std::string title,int nrBins,double xMin,double xMax);
55  MonElemManagerHist(std::string name,std::string title,int nrBinsX,double xMin,double xMax,int nrBinsY,double yMin,double yMax);
56  virtual ~MonElemManagerHist();
57 
59  const MonitorElement* monElem()const{return monElem_;}
60 
61  virtual void fill(const T& obj,float weight)=0;
62 
63 
64  };
65 
66  template <class T> MonElemManagerHist<T>::MonElemManagerHist(std::string name,std::string title,int nrBins,double xMin,double xMax):
67  monElem_(NULL)
68  {
70  monElem_ =dbe->book1D(name,title,nrBins,xMin,xMax);
71  }
72 
74  int nrBinsX,double xMin,double xMax,
75  int nrBinsY,double yMin,double yMax):
76  monElem_(NULL)
77  {
79  monElem_ =dbe->book2D(name,title,nrBinsX,xMin,xMax,nrBinsY,yMin,yMax);
80  }
81 
82 
84  {
85  // delete monElem_;
86  }
87 
88  //fills the MonitorElement with a member function of class T returning type varType
89  template<class T,typename varType> class MonElemManager : public MonElemManagerHist<T> {
90  private:
91 
92  varType (T::*varFunc_)()const;
93 
94 
95  //disabling copying and assignment as I havnt figured out how I want them to work yet
96  private:
98  MonElemManager& operator=(const MonElemManager& rhs){return *this;}
99 
100  public:
101  MonElemManager(std::string name,std::string title,int nrBins,double xMin,double xMax,
102  varType (T::*varFunc)()const):
103  MonElemManagerHist<T>(name,title,nrBins,xMin,xMax),
104  varFunc_(varFunc){}
105  ~MonElemManager();
106 
107 
108  void fill(const T& obj,float weight);
109 
110  };
111 
112 
113  template<class T,typename varType> void MonElemManager<T,varType>::fill(const T& obj,float weight)
114  {
115  MonElemManagerHist<T>::monElem()->Fill((obj.*varFunc_)(),weight);
116  }
117 
118  template<class T,typename varType> MonElemManager<T,varType>::~MonElemManager()
119  {
120 
121  }
122 
123 
124  //fills a 2D monitor element with member functions of T returning varType1 and varType2
125  template<class T,typename varTypeX,typename varTypeY=varTypeX> class MonElemManager2D : public MonElemManagerHist<T> {
126  private:
127 
128  varTypeX (T::*varFuncX_)()const;
129  varTypeY (T::*varFuncY_)()const;
130 
131  //disabling copying and assignment as I havnt figured out how I want them to work yet
132  private:
134  MonElemManager2D& operator=(const MonElemManager2D& rhs){return *this;}
135 
136  public:
137  MonElemManager2D(std::string name,std::string title,int nrBinsX,double xMin,double xMax,int nrBinsY,double yMin,double yMax,
138  varTypeX (T::*varFuncX)()const,varTypeY (T::*varFuncY)()const):
139  MonElemManagerHist<T>(name,title,nrBinsX,xMin,xMax,nrBinsY,yMin,yMax),
140  varFuncX_(varFuncX),varFuncY_(varFuncY){}
142 
143 
144  void fill(const T& obj,float weight);
145 
146 
147  };
148 
149  template<class T,typename varTypeX,typename varTypeY> void MonElemManager2D<T,varTypeX,varTypeY>::fill(const T& obj,float weight)
150  {
151  MonElemManagerHist<T>::monElem()->Fill((obj.*varFuncX_)(),(obj.*varFuncY_)(),weight);
152  }
153 
154  template<class T,typename varTypeX,typename varTypeY> MonElemManager2D<T,varTypeX,varTypeY>::~MonElemManager2D()
155  {
156 
157  }
158 }
159 
160 
161 #endif
void fill(const T &obj, float weight)
MonElemManager2D(const MonElemManager2D &rhs)
varTypeX(T::* varFuncX_)() const
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:954
MonElemManager(std::string name, std::string title, int nrBins, double xMin, double xMax, varType(T::*varFunc)() const)
#define NULL
Definition: scimark2.h:8
MonElemManager(const MonElemManager &rhs)
MonElemManagerHist(const MonElemManagerHist &rhs)
void Fill(long long x)
MonElemManagerHist & operator=(const MonElemManagerHist &rhs)
varType(T::* varFunc_)() const
virtual void fill(const T &obj, float weight)=0
MonElemManager2D(std::string name, std::string title, int nrBinsX, double xMin, double xMax, int nrBinsY, double yMin, double yMax, varTypeX(T::*varFuncX)() const, varTypeY(T::*varFuncY)() const)
void fill(const T &obj, float weight)
MonElemManager & operator=(const MonElemManager &rhs)
MonElemManager2D & operator=(const MonElemManager2D &rhs)
const MonitorElement * monElem() const
virtual void fill(const T &obj, float weight)=0
int weight
Definition: histoStyle.py:50
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1082
varTypeY(T::* varFuncY_)() const
long double T