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
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:91
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:76
SimWatcher.h
Event
simproducer::ProductInfoBase::ProductInfoBase
ProductInfoBase(const std::string &iInstanceName)
Definition: SimProducer.h:41
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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:33
edm::EventSetup
Definition: EventSetup.h:57
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:86
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:101
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