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