File indexing completed on 2024-04-06 12:12:34
0001
0002
0003
0004
0005 #include "FWCore/Framework/interface/global/EDProducer.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0011 #include "FWCore/ParameterSet/interface/PluginDescription.h"
0012 #include "FWCore/ParameterSet/interface/ValidatedPluginMacros.h"
0013 #include "FWCore/ParameterSet/interface/ValidatedPluginFactoryMacros.h"
0014
0015 #include <vector>
0016
0017 namespace edm {
0018 class EventSetup;
0019 }
0020
0021 namespace edmtest {
0022 struct IntMakerBase {
0023 virtual ~IntMakerBase() = default;
0024 virtual int value() const = 0;
0025 };
0026
0027 using IntFactory = edmplugin::PluginFactory<IntMakerBase*(edm::ParameterSet const&)>;
0028 }
0029 EDM_REGISTER_VALIDATED_PLUGINFACTORY(edmtest::IntFactory, "edmtestIntFactory");
0030
0031 namespace edmtest {
0032
0033 struct OneMaker : public IntMakerBase {
0034 explicit OneMaker(edm::ParameterSet const&) {}
0035 int value() const final { return 1; };
0036
0037 static void fillPSetDescription(edm::ParameterSetDescription&) {}
0038 };
0039
0040 struct ValueMaker : public IntMakerBase {
0041 explicit ValueMaker(edm::ParameterSet const& iPSet) : value_{iPSet.getParameter<int>("value")} {}
0042 int value() const final { return value_; };
0043
0044 static void fillPSetDescription(edm::ParameterSetDescription& iDesc) { iDesc.add<int>("value", 5); }
0045
0046 int value_;
0047 };
0048
0049 class PluginUsingProducer : public edm::global::EDProducer<> {
0050 public:
0051 explicit PluginUsingProducer(edm::ParameterSet const&);
0052
0053 void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
0054
0055 static void fillDescriptions(edm::ConfigurationDescriptions& iConf) {
0056 edm::ParameterSetDescription pluginDesc;
0057 pluginDesc.addNode(edm::PluginDescription<IntFactory>("type", "edmtestValueMaker", true));
0058
0059 edm::ParameterSetDescription top;
0060 top.add<edm::ParameterSetDescription>("plugin", pluginDesc);
0061
0062 iConf.addWithDefaultLabel(top);
0063 }
0064
0065 private:
0066 std::unique_ptr<IntMakerBase> maker_;
0067 edm::EDPutTokenT<int> putToken_;
0068 };
0069
0070 PluginUsingProducer::PluginUsingProducer(edm::ParameterSet const& pset) : putToken_{produces<int>()} {
0071 auto pluginPSet = pset.getParameter<edm::ParameterSet>("plugin");
0072 maker_ = std::unique_ptr<IntMakerBase>{
0073 IntFactory::get()->create(pluginPSet.getParameter<std::string>("type"), pluginPSet)};
0074 }
0075
0076 void PluginUsingProducer::produce(edm::StreamID, edm::Event& event, edm::EventSetup const&) const {
0077 event.emplace(putToken_, maker_->value());
0078 }
0079 }
0080 using edmtest::PluginUsingProducer;
0081 DEFINE_FWK_MODULE(PluginUsingProducer);
0082
0083 DEFINE_EDM_VALIDATED_PLUGIN(edmtest::IntFactory, edmtest::OneMaker, "edmtestOneMaker");
0084 DEFINE_EDM_VALIDATED_PLUGIN(edmtest::IntFactory, edmtest::ValueMaker, "edmtestValueMaker");