CMS 3D CMS Logo

PluginUsingProducer.cc
Go to the documentation of this file.
1 
14 
15 #include <vector>
16 
17 namespace edm {
18  class EventSetup;
19 }
20 
21 namespace edmtest {
22  struct IntMakerBase {
23  virtual ~IntMakerBase() = default;
24  virtual int value() const = 0;
25  };
26 
28 } // namespace edmtest
30 
31 namespace edmtest {
32 
33  struct OneMaker : public IntMakerBase {
34  explicit OneMaker(edm::ParameterSet const&) {}
35  int value() const final { return 1; };
36 
38  };
39 
40  struct ValueMaker : public IntMakerBase {
41  explicit ValueMaker(edm::ParameterSet const& iPSet) : value_{iPSet.getParameter<int>("value")} {}
42  int value() const final { return value_; };
43 
44  static void fillPSetDescription(edm::ParameterSetDescription& iDesc) { iDesc.add<int>("value", 5); }
45 
46  int value_;
47  };
48 
50  public:
51  explicit PluginUsingProducer(edm::ParameterSet const&);
52 
53  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
54 
57  pluginDesc.addNode(edm::PluginDescription<IntFactory>("type", "edmtestValueMaker", true));
58 
60  top.add<edm::ParameterSetDescription>("plugin", pluginDesc);
61 
62  iConf.addWithDefaultLabel(top);
63  }
64 
65  private:
66  std::unique_ptr<IntMakerBase> maker_;
68  };
69 
70  PluginUsingProducer::PluginUsingProducer(edm::ParameterSet const& pset) : putToken_{produces<int>()} {
71  auto pluginPSet = pset.getParameter<edm::ParameterSet>("plugin");
72  maker_ = std::unique_ptr<IntMakerBase>{
73  IntFactory::get()->create(pluginPSet.getParameter<std::string>("type"), pluginPSet)};
74  }
75 
77  event.emplace(putToken_, maker_->value());
78  }
79 } // namespace edmtest
82 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
#define EDM_REGISTER_VALIDATED_PLUGINFACTORY(_factory_, _category_)
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
int value() const final
virtual int value() const =0
#define DEFINE_EDM_VALIDATED_PLUGIN(factory, type, name)
PluginUsingProducer(edm::ParameterSet const &)
static void fillDescriptions(edm::ConfigurationDescriptions &iConf)
OneMaker(edm::ParameterSet const &)
static void fillPSetDescription(edm::ParameterSetDescription &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::unique_ptr< IntMakerBase > maker_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
ValueMaker(edm::ParameterSet const &iPSet)
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
HLT enums.
edm::EDPutTokenT< int > putToken_
int value() const final
#define get
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
Definition: event.py:1
virtual ~IntMakerBase()=default