test
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(DQMStore::IBooker &iBooker, std::string name,std::string title,int nrBins,double xMin,double xMax);
55  MonElemManagerHist(DQMStore::IBooker &iBooker, 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(DQMStore::IBooker &iBooker, std::string name,std::string title,int nrBins,double xMin,double xMax):
67  monElem_(NULL)
68  {
69  monElem_ = iBooker.book1D(name,title,nrBins,xMin,xMax);
70  }
71 
73  int nrBinsX,double xMin,double xMax,
74  int nrBinsY,double yMin,double yMax):
75  monElem_(NULL)
76  {
77  monElem_ = iBooker.book2D(name,title,nrBinsX,xMin,xMax,nrBinsY,yMin,yMax);
78  }
79 
80 
82  {
83  // delete monElem_;
84  }
85 
86  //fills the MonitorElement with a member function of class T returning type varType
87  template<class T,typename varType> class MonElemManager : public MonElemManagerHist<T> {
88  private:
89 
90  varType (T::*varFunc_)()const;
91 
92 
93  //disabling copying and assignment as I havnt figured out how I want them to work yet
94  private:
96  MonElemManager& operator=(const MonElemManager& rhs){return *this;}
97 
98  public:
99  MonElemManager(DQMStore::IBooker &iBooker, std::string name,std::string title,int nrBins,double xMin,double xMax,
100  varType (T::*varFunc)()const):
101  MonElemManagerHist<T>(iBooker, name,title,nrBins,xMin,xMax),
102  varFunc_(varFunc){}
103  ~MonElemManager();
104 
105 
106  void fill(const T& obj,float weight);
107 
108  };
109 
110 
111  template<class T,typename varType> void MonElemManager<T,varType>::fill(const T& obj,float weight)
112  {
113  MonElemManagerHist<T>::monElem()->Fill((obj.*varFunc_)(),weight);
114  }
115 
116  template<class T,typename varType> MonElemManager<T,varType>::~MonElemManager()
117  {
118 
119  }
120 
121 
122  //fills a 2D monitor element with member functions of T returning varType1 and varType2
123  template<class T,typename varTypeX,typename varTypeY=varTypeX> class MonElemManager2D : public MonElemManagerHist<T> {
124  private:
125 
126  varTypeX (T::*varFuncX_)()const;
127  varTypeY (T::*varFuncY_)()const;
128 
129  //disabling copying and assignment as I havnt figured out how I want them to work yet
130  private:
132  MonElemManager2D& operator=(const MonElemManager2D& rhs){return *this;}
133 
134  public:
135  MonElemManager2D(DQMStore::IBooker &iBooker, std::string name,std::string title,int nrBinsX,double xMin,double xMax,int nrBinsY,double yMin,double yMax,
136  varTypeX (T::*varFuncX)()const,varTypeY (T::*varFuncY)()const):
137  MonElemManagerHist<T>(iBooker, name,title,nrBinsX,xMin,xMax,nrBinsY,yMin,yMax),
138  varFuncX_(varFuncX),varFuncY_(varFuncY){}
140 
141 
142  void fill(const T& obj,float weight);
143 
144 
145  };
146 
147  template<class T,typename varTypeX,typename varTypeY> void MonElemManager2D<T,varTypeX,varTypeY>::fill(const T& obj,float weight)
148  {
149  MonElemManagerHist<T>::monElem()->Fill((obj.*varFuncX_)(),(obj.*varFuncY_)(),weight);
150  }
151 
152  template<class T,typename varTypeX,typename varTypeY> MonElemManager2D<T,varTypeX,varTypeY>::~MonElemManager2D()
153  {
154 
155  }
156 }
157 
158 
159 #endif
void fill(const T &obj, float weight)
MonElemManager2D(const MonElemManager2D &rhs)
varTypeX(T::* varFuncX_)() 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
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
virtual void fill(const T &obj, float weight)=0
void fill(const T &obj, float weight)
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
MonElemManager & operator=(const MonElemManager &rhs)
MonElemManager2D & operator=(const MonElemManager2D &rhs)
MonElemManager2D(DQMStore::IBooker &iBooker, 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)
const MonitorElement * monElem() const
virtual void fill(const T &obj, float weight)=0
int weight
Definition: histoStyle.py:50
varTypeY(T::* varFuncY_)() const
long double T
MonElemManager(DQMStore::IBooker &iBooker, std::string name, std::string title, int nrBins, double xMin, double xMax, varType(T::*varFunc)() const)