CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SimProducer.h
Go to the documentation of this file.
1 #ifndef Watcher_SimProducer_h
2 #define Watcher_SimProducer_h
3 // -*- C++ -*-
4 //
5 // Package: Watcher
6 // Class : SimProducer
7 //
16 //
17 // Original Author: Chris D. Jones
18 // Created: Mon Nov 28 16:02:21 EST 2005
19 // $Id: SimProducer.h,v 1.2 2010/03/26 22:55:39 sunanda Exp $
20 //
21 
22 // system include files
23 #include <string>
24 #include <vector>
25 #include "boost/shared_ptr.hpp"
26 
27 // user include files
30 
31 // forward declarations
32 namespace simproducer {
34  public:
35  ProductInfoBase(const std::string& iInstanceName):
36  m_instanceName(iInstanceName) {}
37 
38  virtual ~ProductInfoBase() {}
39 
40  const std::string& instanceName() const {
41  return m_instanceName; }
42 
43  virtual void registerProduct(edm::EDProducer*) const = 0;
44  private:
46  };
47 
48  template<class T>
49  class ProductInfo : public ProductInfoBase {
50  public:
51  ProductInfo(const std::string& iInstanceName) :
52  ProductInfoBase(iInstanceName) {}
53 
54  void registerProduct(edm::EDProducer* iProd) const {
55  (*iProd). template produces<T>(this->instanceName());
56  }
57  };
58 }
59 
60 class SimProducer : public SimWatcher
61 {
62 
63  public:
65  //virtual ~SimProducer();
66 
67  // ---------- const member functions ---------------------
68 
69  // ---------- static member functions --------------------
70 
71  // ---------- member functions ---------------------------
72  virtual void produce(edm::Event&, const edm::EventSetup&) = 0;
73 
75  std::for_each(m_info.begin(), m_info.end(),
76  boost::bind(&simproducer::ProductInfoBase::registerProduct,_1, &iProd));
77  }
78  protected:
79  template<class T>
80  void produces() {
81  produces<T>("");
82  }
83 
84  template<class T>
85  void produces(const std::string& instanceName) {
86  m_info.push_back(
87  boost::shared_ptr<simproducer::ProductInfo<T> >(new simproducer::ProductInfo<T>(instanceName) ));
88  }
89 
90  private:
91  SimProducer(const SimProducer&); // stop default
92 
93  const SimProducer& operator=(const SimProducer&); // stop default
94 
95  // ---------- member data --------------------------------
96  std::vector<boost::shared_ptr< simproducer::ProductInfoBase> > m_info;
97 };
98 
99 
100 #endif
void produces(const std::string &instanceName)
Definition: SimProducer.h:85
const std::string & instanceName() const
Definition: SimProducer.h:40
void registerProduct(edm::EDProducer *iProd) const
Definition: SimProducer.h:54
std::vector< boost::shared_ptr< simproducer::ProductInfoBase > > m_info
Definition: SimProducer.h:96
virtual void registerProduct(edm::EDProducer *) const =0
void produces()
Definition: SimProducer.h:80
void registerProducts(edm::EDProducer &iProd)
Definition: SimProducer.h:74
ProductInfoBase(const std::string &iInstanceName)
Definition: SimProducer.h:35
ProductInfo(const std::string &iInstanceName)
Definition: SimProducer.h:51