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 
68  virtual void produce(edm::Event &, const edm::EventSetup &) = 0;
69 
70  void registerProducts(edm::ProducesCollector producesCollector) {
71  std::for_each(m_info.begin(),
72  m_info.end(),
73  [&producesCollector](std::shared_ptr<simproducer::ProductInfoBase> const &ptr) mutable {
74  ptr->registerProduct(producesCollector);
75  });
76  }
77 
78  SimProducer(const SimProducer &) = delete;
79  const SimProducer &operator=(const SimProducer &) = delete;
80 
81 protected:
82  template <class T>
83  void produces() {
84  produces<T>("");
85  }
86 
87  template <class T>
89  m_info.push_back(std::make_shared<simproducer::ProductInfo<T>>(instanceName));
90  }
91 
92 private:
93  std::vector<std::shared_ptr<simproducer::ProductInfoBase>> m_info;
94 };
95 
96 #endif
void produces(const std::string &instanceName)
Definition: SimProducer.h:88
const std::string & instanceName() const
Definition: SimProducer.h:45
void registerProduct(edm::ProducesCollector producesCollector) const override
Definition: SimProducer.h:58
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
virtual void registerProduct(edm::ProducesCollector) const =0
void registerProducts(edm::ProducesCollector producesCollector)
Definition: SimProducer.h:70
const SimProducer & operator=(const SimProducer &)=delete
virtual void produce(edm::Event &, const edm::EventSetup &)=0
void produces()
Definition: SimProducer.h:83
HLT enums.
ProductInfoBase(const std::string &iInstanceName)
Definition: SimProducer.h:41
long double T
ProductInfo(const std::string &iInstanceName)
Definition: SimProducer.h:56
std::vector< std::shared_ptr< simproducer::ProductInfoBase > > m_info
Definition: SimProducer.h:93