File indexing completed on 2024-04-06 12:09:49
0001 #ifndef DQMOFFLINE_TRIGGER_EGHLTMONELEMMANAGER
0002 #define DQMOFFLINE_TRIGGER_EGHLTMONELEMMANAGER
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include "DQMServices/Core/interface/DQMStore.h"
0025
0026 #include "FWCore/ServiceRegistry/interface/Service.h"
0027
0028 namespace egHLT {
0029 using dqm::legacy::DQMStore;
0030 using dqm::legacy::MonitorElement;
0031
0032 template <class T>
0033 class MonElemManagerBase {
0034 public:
0035 MonElemManagerBase() = default;
0036 virtual ~MonElemManagerBase() = default;
0037
0038 virtual void fill(const T& obj, float weight) = 0;
0039 };
0040
0041
0042 template <class T>
0043 class MonElemManagerHist : public MonElemManagerBase<T> {
0044 private:
0045 MonitorElement* monElem_;
0046
0047
0048
0049 private:
0050 MonElemManagerHist(const MonElemManagerHist& rhs) {}
0051 MonElemManagerHist& operator=(const MonElemManagerHist& rhs) { return *this; }
0052
0053 public:
0054 MonElemManagerHist(
0055 DQMStore::IBooker& iBooker, std::string name, std::string title, int nrBins, double xMin, double xMax);
0056 MonElemManagerHist(DQMStore::IBooker& iBooker,
0057 std::string name,
0058 std::string title,
0059 int nrBinsX,
0060 double xMin,
0061 double xMax,
0062 int nrBinsY,
0063 double yMin,
0064 double yMax);
0065 ~MonElemManagerHist() override;
0066
0067 MonitorElement* monElem() { return monElem_; }
0068 const MonitorElement* monElem() const { return monElem_; }
0069
0070 void fill(const T& obj, float weight) override = 0;
0071 };
0072
0073 template <class T>
0074 MonElemManagerHist<T>::MonElemManagerHist(
0075 DQMStore::IBooker& iBooker, std::string name, std::string title, int nrBins, double xMin, double xMax)
0076 : monElem_(nullptr) {
0077 monElem_ = iBooker.book1D(name, title, nrBins, xMin, xMax);
0078 }
0079
0080 template <class T>
0081 MonElemManagerHist<T>::MonElemManagerHist(DQMStore::IBooker& iBooker,
0082 std::string name,
0083 std::string title,
0084 int nrBinsX,
0085 double xMin,
0086 double xMax,
0087 int nrBinsY,
0088 double yMin,
0089 double yMax)
0090 : monElem_(nullptr) {
0091 monElem_ = iBooker.book2D(name, title, nrBinsX, xMin, xMax, nrBinsY, yMin, yMax);
0092 }
0093
0094 template <class T>
0095 MonElemManagerHist<T>::~MonElemManagerHist() {
0096
0097 }
0098
0099
0100 template <class T, typename varType>
0101 class MonElemManager : public MonElemManagerHist<T> {
0102 private:
0103 varType (T::*varFunc_)() const;
0104
0105
0106 private:
0107 MonElemManager(const MonElemManager& rhs) {}
0108 MonElemManager& operator=(const MonElemManager& rhs) { return *this; }
0109
0110 public:
0111 MonElemManager(DQMStore::IBooker& iBooker,
0112 std::string name,
0113 std::string title,
0114 int nrBins,
0115 double xMin,
0116 double xMax,
0117 varType (T::*varFunc)() const)
0118 : MonElemManagerHist<T>(iBooker, name, title, nrBins, xMin, xMax), varFunc_(varFunc) {}
0119 ~MonElemManager() override;
0120
0121 void fill(const T& obj, float weight) override;
0122 };
0123
0124 template <class T, typename varType>
0125 void MonElemManager<T, varType>::fill(const T& obj, float weight) {
0126 MonElemManagerHist<T>::monElem()->Fill((obj.*varFunc_)(), weight);
0127 }
0128
0129 template <class T, typename varType>
0130 MonElemManager<T, varType>::~MonElemManager() = default;
0131
0132
0133 template <class T, typename varTypeX, typename varTypeY = varTypeX>
0134 class MonElemManager2D : public MonElemManagerHist<T> {
0135 private:
0136 varTypeX (T::*varFuncX_)() const;
0137 varTypeY (T::*varFuncY_)() const;
0138
0139
0140 private:
0141 MonElemManager2D(const MonElemManager2D& rhs) {}
0142 MonElemManager2D& operator=(const MonElemManager2D& rhs) { return *this; }
0143
0144 public:
0145 MonElemManager2D(DQMStore::IBooker& iBooker,
0146 std::string name,
0147 std::string title,
0148 int nrBinsX,
0149 double xMin,
0150 double xMax,
0151 int nrBinsY,
0152 double yMin,
0153 double yMax,
0154 varTypeX (T::*varFuncX)() const,
0155 varTypeY (T::*varFuncY)() const)
0156 : MonElemManagerHist<T>(iBooker, name, title, nrBinsX, xMin, xMax, nrBinsY, yMin, yMax),
0157 varFuncX_(varFuncX),
0158 varFuncY_(varFuncY) {}
0159 ~MonElemManager2D() override;
0160
0161 void fill(const T& obj, float weight) override;
0162 };
0163
0164 template <class T, typename varTypeX, typename varTypeY>
0165 void MonElemManager2D<T, varTypeX, varTypeY>::fill(const T& obj, float weight) {
0166 MonElemManagerHist<T>::monElem()->Fill((obj.*varFuncX_)(), (obj.*varFuncY_)(), weight);
0167 }
0168
0169 template <class T, typename varTypeX, typename varTypeY>
0170 MonElemManager2D<T, varTypeX, varTypeY>::~MonElemManager2D() = default;
0171 }
0172
0173 #endif