CMS 3D CMS Logo

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:
35  MonElemManagerBase()= default;
36  virtual ~MonElemManagerBase()= default;
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  ~MonElemManagerHist() override;
57 
58  MonitorElement* monElem(){return monElem_;}
59  const MonitorElement* monElem()const{return monElem_;}
60 
61  void fill(const T& obj,float weight) override =0;
62 
63 
64  };
65 
67  monElem_(nullptr)
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):
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:
100  varType (T::*varFunc)()const):
101  MonElemManagerHist<T>(iBooker, name,title,nrBins,xMin,xMax),
102  varFunc_(varFunc){}
103  ~MonElemManager() override;
104 
105 
106  void fill(const T& obj,float weight) override;
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  = default;
118 
119 
120  //fills a 2D monitor element with member functions of T returning varType1 and varType2
121  template<class T,typename varTypeX,typename varTypeY=varTypeX> class MonElemManager2D : public MonElemManagerHist<T> {
122  private:
123 
124  varTypeX (T::*varFuncX_)()const;
125  varTypeY (T::*varFuncY_)()const;
126 
127  //disabling copying and assignment as I havnt figured out how I want them to work yet
128  private:
130  MonElemManager2D& operator=(const MonElemManager2D& rhs){return *this;}
131 
132  public:
133  MonElemManager2D(DQMStore::IBooker &iBooker, std::string name,std::string title,int nrBinsX,double xMin,double xMax,int nrBinsY,double yMin,double yMax,
134  varTypeX (T::*varFuncX)()const,varTypeY (T::*varFuncY)()const):
135  MonElemManagerHist<T>(iBooker, name,title,nrBinsX,xMin,xMax,nrBinsY,yMin,yMax),
136  varFuncX_(varFuncX),varFuncY_(varFuncY){}
137  ~MonElemManager2D() override;
138 
139 
140  void fill(const T& obj,float weight) override;
141 
142 
143  };
144 
145  template<class T,typename varTypeX,typename varTypeY> void MonElemManager2D<T,varTypeX,varTypeY>::fill(const T& obj,float weight)
146  {
147  MonElemManagerHist<T>::monElem()->Fill((obj.*varFuncX_)(),(obj.*varFuncY_)(),weight);
148  }
149 
150  template<class T,typename varTypeX,typename varTypeY> MonElemManager2D<T,varTypeX,varTypeY>::~MonElemManager2D()
151  = default;
152 }
153 
154 
155 #endif
MonElemManager2D(const MonElemManager2D &rhs)
~MonElemManager() override
~MonElemManager2D() override
void fill(const T &obj, float weight) override
Definition: weight.py:1
#define nullptr
virtual ~MonElemManagerBase()=default
MonElemManager(const MonElemManager &rhs)
MonElemManagerHist(const MonElemManagerHist &rhs)
void Fill(long long x)
MonElemManagerHist & operator=(const MonElemManagerHist &rhs)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
virtual void fill(const T &obj, float weight)=0
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
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
void fill(const T &obj, float weight) override
void fill(const T &obj, float weight) override=0
long double T
MonElemManager(DQMStore::IBooker &iBooker, std::string name, std::string title, int nrBins, double xMin, double xMax, varType(T::*varFunc)() const)