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::ProducesCollector) 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::ProducesCollector producesCollector) const override {
59  producesCollector.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 
76  void registerProducts(edm::ProducesCollector producesCollector) {
77  std::for_each(m_info.begin(),
78  m_info.end(),
79  [&producesCollector](std::shared_ptr<simproducer::ProductInfoBase> const &ptr) mutable {
80  ptr->registerProduct(producesCollector);
81  });
82  }
83 
84 protected:
85  template <class T>
86  void produces() {
87  produces<T>("");
88  }
89 
90  template <class T>
92  m_info.push_back(std::make_shared<simproducer::ProductInfo<T>>(instanceName));
93  }
94 
95 private:
96  SimProducer(const SimProducer &) = delete; // stop default
97 
98  const SimProducer &operator=(const SimProducer &) = delete; // stop default
99 
100  // ---------- member data --------------------------------
101  std::vector<std::shared_ptr<simproducer::ProductInfoBase>> m_info;
102 };
103 
104 #endif
void produces(const std::string &instanceName)
Definition: SimProducer.h:91
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
const std::string & instanceName() const
Definition: SimProducer.h:45
void registerProducts(edm::ProducesCollector producesCollector)
Definition: SimProducer.h:76
void produces()
Definition: SimProducer.h:86
HLT enums.
ProductInfoBase(const std::string &iInstanceName)
Definition: SimProducer.h:41
long double T
ProductInfo(const std::string &iInstanceName)
Definition: SimProducer.h:56
void registerProduct(edm::ProducesCollector producesCollector) const override
Definition: SimProducer.h:58
std::vector< std::shared_ptr< simproducer::ProductInfoBase > > m_info
Definition: SimProducer.h:101