CMS 3D CMS Logo

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