CMS 3D CMS Logo

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.1 2005/11/29 18:40:25 chrjones 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          using namespace simproducer;
00087          m_info.push_back( 
00088             boost::shared_ptr<ProductInfo<T> >(new ProductInfo<T>(instanceName) ));
00089       }
00090 
00091    private:
00092       SimProducer(const SimProducer&); // stop default
00093 
00094       const SimProducer& operator=(const SimProducer&); // stop default
00095 
00096       // ---------- member data --------------------------------
00097       std::vector<boost::shared_ptr< simproducer::ProductInfoBase> > m_info;
00098 };
00099 
00100 
00101 #endif

Generated on Tue Jun 9 17:47:10 2009 for CMSSW by  doxygen 1.5.4