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 //
20 
21 // system include files
22 #include <algorithm>
23 #include <string>
24 #include <vector>
25 #include "boost/bind.hpp"
26 #include "boost/shared_ptr.hpp"
27 
28 // user include files
31 
32 namespace edm {
33  class Event;
34  class EventSetup;
35 }
36 
37 // forward declarations
38 namespace simproducer {
40  public:
41  ProductInfoBase(const std::string& iInstanceName):
42  m_instanceName(iInstanceName) {}
43 
44  virtual ~ProductInfoBase() {}
45 
46  const std::string& instanceName() const {
47  return m_instanceName; }
48 
49  virtual void registerProduct(edm::ProducerBase*) const = 0;
50  private:
52  };
53 
54  template<class T>
55  class ProductInfo : public ProductInfoBase {
56  public:
57  ProductInfo(const std::string& iInstanceName) :
58  ProductInfoBase(iInstanceName) {}
59 
60  void registerProduct(edm::ProducerBase* iProd) const {
61  (*iProd). template produces<T>(this->instanceName());
62  }
63  };
64 }
65 
66 class SimProducer : public SimWatcher
67 {
68 
69  public:
71  //virtual ~SimProducer();
72 
73  // ---------- const member functions ---------------------
74 
75  // ---------- static member functions --------------------
76 
77  // ---------- member functions ---------------------------
78  virtual void produce(edm::Event&, const edm::EventSetup&) = 0;
79 
81  std::for_each(m_info.begin(), m_info.end(),
82  boost::bind(&simproducer::ProductInfoBase::registerProduct,_1, &iProd));
83  }
84  protected:
85  template<class T>
86  void produces() {
87  produces<T>("");
88  }
89 
90  template<class T>
91  void produces(const std::string& instanceName) {
92  m_info.push_back(
93  boost::shared_ptr<simproducer::ProductInfo<T> >(new simproducer::ProductInfo<T>(instanceName) ));
94  }
95 
96  private:
97  SimProducer(const SimProducer&); // stop default
98 
99  const SimProducer& operator=(const SimProducer&); // stop default
100 
101  // ---------- member data --------------------------------
102  std::vector<boost::shared_ptr< simproducer::ProductInfoBase> > m_info;
103 };
104 
105 
106 #endif
void produces(const std::string &instanceName)
Definition: SimProducer.h:91
void registerProducts(edm::ProducerBase &iProd)
Definition: SimProducer.h:80
const std::string & instanceName() const
Definition: SimProducer.h:46
void registerProduct(edm::ProducerBase *iProd) const
Definition: SimProducer.h:60
std::vector< boost::shared_ptr< simproducer::ProductInfoBase > > m_info
Definition: SimProducer.h:102
virtual void registerProduct(edm::ProducerBase *) const =0
void produces()
Definition: SimProducer.h:86
ProductInfoBase(const std::string &iInstanceName)
Definition: SimProducer.h:41
ProductInfo(const std::string &iInstanceName)
Definition: SimProducer.h:57