CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/DQM/EcalCommon/interface/DQWorker.h

Go to the documentation of this file.
00001 #ifndef DQWorker_H
00002 #define DQWorker_H
00003 
00004 #include <string>
00005 #include <vector>
00006 #include <map>
00007 
00008 #include "DQM/EcalCommon/interface/MESet.h"
00009 
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 
00012 namespace edm{
00013   class Run;
00014   class LuminosityBlock;
00015   class Event;
00016   class EventSetup;
00017 }
00018 class DQMStore;
00019 
00020 namespace ecaldqm{
00021 
00022   class DQWorker {
00023   public :
00024     DQWorker(const edm::ParameterSet&, const edm::ParameterSet&, std::string const&);
00025     virtual ~DQWorker();
00026 
00027     virtual void beginRun(const edm::Run &, const edm::EventSetup &){};
00028     virtual void endRun(const edm::Run &, const edm::EventSetup &){};
00029 
00030     virtual void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &){};
00031     virtual void endLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &){};
00032 
00033     virtual void bookMEs();
00034 
00035     virtual void reset();
00036     virtual std::string const& getName() { return name_; }
00037     virtual bool isInitialized() { return initialized_; }
00038     virtual void setInitialized(bool _init) { initialized_ = _init; }
00039     virtual void setVerbosity(int _verbosity) { verbosity_ = _verbosity; }
00040 
00041     const std::vector<MESet*>& getMEs() { return MEs_; }
00042 
00043     enum MESets {
00044       nMESets
00045     };
00046 
00047     static std::map<std::string, std::vector<MEData> > meData;
00048     // needs to be declared in each derived class
00049     static void setMEData(std::vector<MEData>&);
00050 
00051   protected :
00052     void meSet_(unsigned, edm::ParameterSet const&);
00053     MESet* createMESet_(std::string const&, MEData const&, bool _readOnly = false) const;
00054 
00055     std::string name_;
00056     std::vector<MESet*> MEs_; // [nMESets]
00057     bool initialized_;
00058 
00059     int verbosity_;
00060   };
00061 
00062 
00063 
00064   typedef DQWorker* (*WorkerFactory)(const edm::ParameterSet&, const edm::ParameterSet&);
00065 
00066   // template of WorkerFactory instance
00067   template<class W>
00068     DQWorker* 
00069     workerFactory(const edm::ParameterSet& _params, const edm::ParameterSet& _paths)
00070     {
00071       W* worker(new W(_params, _paths));
00072       return worker;
00073     }
00074 
00075   // to be instantiated after the implementation of each worker module
00076   class SetWorker {
00077   public:
00078     template <class W> SetWorker(const std::string& _name, W*){
00079       workerFactories_[_name] = workerFactory<W>;
00080 
00081       std::vector<MEData>& data(DQWorker::meData[_name]);
00082       data.clear();
00083       data.resize(W::nMESets);
00084       W::setMEData(data);
00085     }
00086     static WorkerFactory findFactory(const std::string&);
00087   private:
00088     static std::map<std::string, WorkerFactory> workerFactories_;
00089   };
00090 
00091 }
00092 
00093 #define DEFINE_ECALDQM_WORKER(TYPE) \
00094   TYPE *p##TYPE(0); SetWorker TYPE##Instance(#TYPE, p##TYPE)
00095 
00096 #endif