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
SimProducer::SimProducer
SimProducer()
Definition: SimProducer.h:66
edm
HLT enums.
Definition: AlignableModifier.h:19
simproducer::ProductInfo::registerProduct
void registerProduct(edm::ProducesCollector producesCollector) const override
Definition: SimProducer.h:58
simproducer
Definition: SimProducer.h:38
SimProducer::produces
void produces(const std::string &instanceName)
Definition: SimProducer.h:88
simproducer::ProductInfoBase::~ProductInfoBase
virtual ~ProductInfoBase()
Definition: SimProducer.h:43
simproducer::ProductInfo::ProductInfo
ProductInfo(const std::string &iInstanceName)
Definition: SimProducer.h:56
ProducesCollector.h
SimProducer::registerProducts
void registerProducts(edm::ProducesCollector producesCollector)
Definition: SimProducer.h:70
SimWatcher.h
Event
simproducer::ProductInfoBase::ProductInfoBase
ProductInfoBase(const std::string &iInstanceName)
Definition: SimProducer.h:41
SimProducer::produce
virtual void produce(edm::Event &, const edm::EventSetup &)=0
SimProducer
Definition: SimProducer.h:64
edm::ProducesCollector::produces
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
Definition: ProducesCollector.h:52
SimWatcher
Definition: SimWatcher.h:27
edm::EventSetup
Definition: EventSetup.h:58
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
simproducer::ProductInfoBase
Definition: SimProducer.h:39
simproducer::ProductInfo
Definition: SimProducer.h:54
edm::ProducesCollector
Definition: ProducesCollector.h:43
SimProducer::operator=
const SimProducer & operator=(const SimProducer &)=delete
T
long double T
Definition: Basic3DVectorLD.h:48
SimProducer::produces
void produces()
Definition: SimProducer.h:83
EventSetup
edm::Event
Definition: Event.h:73
simproducer::ProductInfoBase::instanceName
const std::string & instanceName() const
Definition: SimProducer.h:45
SimProducer::m_info
std::vector< std::shared_ptr< simproducer::ProductInfoBase > > m_info
Definition: SimProducer.h:93
simproducer::ProductInfoBase::m_instanceName
std::string m_instanceName
Definition: SimProducer.h:50
MuonErrorMatrixAdjuster_cfi.instanceName
instanceName
Definition: MuonErrorMatrixAdjuster_cfi.py:16
simproducer::ProductInfoBase::registerProduct
virtual void registerProduct(edm::ProducesCollector) const =0