Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:09:49

0001 #ifndef DQMOFFLINE_TRIGGER_EGHLTMONELEMMANAGER
0002 #define DQMOFFLINE_TRIGGER_EGHLTMONELEMMANAGER
0003 
0004 //class: MonElemManager, short for MonitorElementManager (note not MonEleManager as Ele might be confused for electron
0005 //
0006 //author: Sam Harper (June 2008)
0007 //
0008 //WARNING: interface is NOT final, please dont use this class for now without clearing it with me
0009 //         as I will change it and possibly break all your code
0010 //
0011 //aim: to make MonitorElement objects "fire and forget"
0012 //     specifically it allows to you just add the MonitorElement to a vector containing all
0013 //     your monitor elements to be filled at a certain location so it will be automatically filled
0014 //     at that location and read out
0015 //     it does this by allowing you to specify the function pointer to the member variable you wish to fill at
0016 //     at the time of declaration
0017 //
0018 //implimentation: currently experimental and limited to 1D histograms but will expand later
0019 //                each object, Photon, GsfElectron, is a seperate (templated) class which means
0020 //                that seperate vectors of MonElemManagers are needed for each type
0021 //                however each type has a base class which the various types (int,float,double)
0022 //                of variable inherit from so dont need seperate vectors
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   //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
0042   template <class T>
0043   class MonElemManagerHist : public MonElemManagerBase<T> {
0044   private:
0045     MonitorElement* monElem_;  //we own this (or do we, currently I have decided we dont) FIXME
0046 
0047     //disabling copying and assignment as I havnt figured out how I want them to work yet
0048     //incidently we cant copy a MonitorElement anyway at the moment (and we prob dont want to)
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     // delete monElem_;
0097   }
0098 
0099   //fills the MonitorElement with a member function of class T returning type varType
0100   template <class T, typename varType>
0101   class MonElemManager : public MonElemManagerHist<T> {
0102   private:
0103     varType (T::*varFunc_)() const;
0104 
0105     //disabling copying and assignment as I havnt figured out how I want them to work yet
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   //fills a 2D monitor element with member functions of T returning varType1 and varType2
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     //disabling copying and assignment as I havnt figured out how I want them to work yet
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 }  // namespace egHLT
0172 
0173 #endif