Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DQMOFFLINE_TRIGGER_EGHLTMONELEMCONTAINER
0002 #define DQMOFFLINE_TRIGGER_EGHLTMONELEMCONTAINER
0003 
0004 //class: MonElemContainer, short for Monitor Element Container
0005 
0006 //author: Sam Harper (Aug 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 improve the fire and forget nature of MonElemManger
0012 //      holds a collection on monitor elements for which there is a global cut
0013 //      for example: they all have to pass a paricular trigger
0014 
0015 //implimentation: a cut to pass and then a list of monitor elements to fill
0016 //                two seperate vectors of MonitorElements and MonElemsWithCuts
0017 
0018 #include "DQMOffline/Trigger/interface/EgHLTMonElemManager.h"
0019 #include "DQMOffline/Trigger/interface/EgHLTMonElemWithCut.h"
0020 #include "DQMOffline/Trigger/interface/EgHLTDQMCut.h"
0021 #include "DQMOffline/Trigger/interface/EgHLTOffEvt.h"
0022 
0023 #include <string>
0024 #include <utility>
0025 #include <vector>
0026 namespace egHLT {
0027   template <class T>
0028   class MonElemContainer : public MonElemWithCutBase<T> {
0029   private:
0030     std::string baseName_;
0031     std::string baseTitle_;
0032 
0033     //so I want the ability to have both normal monitor elements and monitor elements with indivdual cuts
0034     //so untill the two classes are merged, I just have two vectors
0035     std::vector<MonElemWithCutBase<T>*> cutMonElems_;  //we own these
0036     std::vector<MonElemManagerBase<T>*> monElems_;     //we own these
0037     EgHLTDQMCut<T>* cut_;                              //we also own this
0038 
0039   private:
0040     MonElemContainer(const MonElemContainer& rhs) {}
0041     MonElemContainer& operator=(const MonElemContainer& rhs) { return *this; }
0042 
0043   public:
0044     MonElemContainer(std::string baseName = "", std::string baseTitle = "", EgHLTDQMCut<T>* cut = nullptr)
0045         : baseName_(std::move(baseName)), baseTitle_(std::move(baseTitle)), cut_(cut) {}
0046 
0047     ~MonElemContainer() override;
0048 
0049     //yes this is little more than a struct with some unnecessary function wrapers
0050     std::vector<MonElemWithCutBase<T>*>& cutMonElems() { return cutMonElems_; }
0051     const std::vector<MonElemWithCutBase<T>*>& cutMonElems() const { return cutMonElems_; }
0052     std::vector<MonElemManagerBase<T>*>& monElems() { return monElems_; }
0053     const std::vector<MonElemManagerBase<T>*>& monElems() const { return monElems_; }
0054 
0055     const std::string& name() const { return baseName_; }
0056     const std::string& title() const { return baseTitle_; }
0057 
0058     void fill(const T& obj, const OffEvt& evt, float weight) override;
0059   };
0060 
0061   template <class T>
0062   MonElemContainer<T>::~MonElemContainer() {
0063     for (size_t i = 0; i < monElems_.size(); i++)
0064       delete monElems_[i];
0065     for (size_t i = 0; i < cutMonElems_.size(); i++)
0066       delete cutMonElems_[i];
0067     if (cut_ != nullptr)
0068       delete cut_;
0069   }
0070 
0071   template <class T>
0072   void MonElemContainer<T>::fill(const T& obj, const OffEvt& evt, float weight) {
0073     if (cut_ == nullptr || cut_->pass(obj, evt)) {
0074       for (size_t i = 0; i < monElems_.size(); i++)
0075         monElems_[i]->fill(obj, weight);
0076       for (size_t i = 0; i < cutMonElems_.size(); i++)
0077         cutMonElems_[i]->fill(obj, evt, weight);
0078     }
0079   }
0080 }  // namespace egHLT
0081 #endif