CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/SimG4Core/Watcher/interface/SimProducer.h

Go to the documentation of this file.
00001 #ifndef Watcher_SimProducer_h
00002 #define Watcher_SimProducer_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Watcher
00006 // Class  :     SimProducer
00007 // 
00016 //
00017 // Original Author:  Chris D. Jones
00018 //         Created:  Mon Nov 28 16:02:21 EST 2005
00019 // $Id: SimProducer.h,v 1.2 2010/03/26 22:55:39 sunanda Exp $
00020 //
00021 
00022 // system include files
00023 #include <string>
00024 #include <vector>
00025 #include "boost/shared_ptr.hpp"
00026 
00027 // user include files
00028 #include "SimG4Core/Watcher/interface/SimWatcher.h"
00029 #include "FWCore/Framework/interface/EDProducer.h"
00030 
00031 // forward declarations
00032 namespace simproducer {
00033    class ProductInfoBase {
00034       public:
00035          ProductInfoBase(const std::string& iInstanceName):
00036             m_instanceName(iInstanceName) {}
00037 
00038          virtual ~ProductInfoBase() {}
00039 
00040          const std::string& instanceName() const {
00041             return m_instanceName; }
00042 
00043          virtual void registerProduct(edm::EDProducer*) const = 0;
00044       private:
00045          std::string m_instanceName;
00046    };
00047 
00048    template<class T>
00049    class ProductInfo : public ProductInfoBase {
00050       public:
00051          ProductInfo(const std::string& iInstanceName) :
00052             ProductInfoBase(iInstanceName) {}
00053 
00054          void registerProduct(edm::EDProducer* iProd) const {
00055             (*iProd). template produces<T>(this->instanceName());
00056          }
00057    };
00058 }
00059 
00060 class SimProducer : public SimWatcher
00061 {
00062 
00063    public:
00064       SimProducer() {}
00065       //virtual ~SimProducer();
00066 
00067       // ---------- const member functions ---------------------
00068 
00069       // ---------- static member functions --------------------
00070 
00071       // ---------- member functions ---------------------------
00072       virtual void produce(edm::Event&, const edm::EventSetup&) = 0;
00073       
00074       void registerProducts(edm::EDProducer& iProd) {
00075          std::for_each(m_info.begin(), m_info.end(),
00076                        boost::bind(&simproducer::ProductInfoBase::registerProduct,_1, &iProd));
00077       }
00078    protected:
00079       template<class T>
00080       void produces() {
00081          produces<T>("");
00082       }
00083 
00084       template<class T>
00085       void produces(const std::string& instanceName) {
00086          m_info.push_back( 
00087                           boost::shared_ptr<simproducer::ProductInfo<T> >(new simproducer::ProductInfo<T>(instanceName) ));
00088       }
00089 
00090    private:
00091       SimProducer(const SimProducer&); // stop default
00092 
00093       const SimProducer& operator=(const SimProducer&); // stop default
00094 
00095       // ---------- member data --------------------------------
00096       std::vector<boost::shared_ptr< simproducer::ProductInfoBase> > m_info;
00097 };
00098 
00099 
00100 #endif