File indexing completed on 2024-04-06 12:12:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021 #include <optional>
0022
0023
0024 #include "FWCore/Framework/interface/ModuleFactory.h"
0025 #include "FWCore/Framework/interface/ESProducer.h"
0026 #include "FWCore/Framework/interface/ESHandle.h"
0027 #include "FWCore/Framework/interface/TriggerNamesService.h"
0028
0029 #include "WhatsIt.h"
0030 #include "Doodad.h"
0031 #include "GadgetRcd.h"
0032
0033 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0034 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0035 #include "FWCore/Utilities/interface/EDMException.h"
0036 #include "FWCore/Utilities/interface/ESGetToken.h"
0037
0038 #include "FWCore/ServiceRegistry/interface/Service.h"
0039
0040
0041
0042
0043 namespace edmtest {
0044
0045 class WhatsItESProducer : public edm::ESProducer {
0046 public:
0047 WhatsItESProducer(edm::ParameterSet const& pset);
0048 ~WhatsItESProducer() override;
0049
0050 typedef std::unique_ptr<WhatsIt> ReturnType;
0051 typedef std::unique_ptr<const WhatsIt> ReturnTypeA;
0052 typedef std::shared_ptr<WhatsIt> ReturnTypeB;
0053 typedef std::shared_ptr<const WhatsIt> ReturnTypeC;
0054 typedef std::optional<WhatsIt> ReturnTypeD;
0055
0056 ReturnType produce(const GadgetRcd&);
0057 ReturnTypeA produceA(const GadgetRcd&);
0058 ReturnTypeB produceB(const GadgetRcd&);
0059 ReturnTypeC produceC(const GadgetRcd&);
0060 ReturnTypeD produceD(const GadgetRcd&);
0061
0062 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0063
0064 private:
0065
0066 edm::ESGetToken<edmtest::Doodad, GadgetRcd> token_;
0067 edm::ESGetToken<edmtest::Doodad, GadgetRcd> tokenA_;
0068 edm::ESGetToken<edmtest::Doodad, GadgetRcd> tokenB_;
0069 edm::ESGetToken<edmtest::Doodad, GadgetRcd> tokenC_;
0070 edm::ESGetToken<edmtest::Doodad, GadgetRcd> tokenD_;
0071 };
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084 WhatsItESProducer::WhatsItESProducer(edm::ParameterSet const& pset) {
0085 if (pset.getUntrackedParameter<bool>("test", true)) {
0086 throw edm::Exception(edm::errors::Configuration, "Something is wrong with ESProducer validation\n")
0087 << "Or the test configuration parameter was set true (it should never be true unless you want this "
0088 "exception)\n";
0089 }
0090
0091
0092
0093 auto collector = setWhatProduced(this);
0094 auto collectorA = setWhatProduced(this, &WhatsItESProducer::produceA, edm::es::Label("A"));
0095 auto collectorB = setWhatProduced(this, &WhatsItESProducer::produceB, edm::es::Label("B"));
0096 auto collectorC = setWhatProduced(this, &WhatsItESProducer::produceC, edm::es::Label("C"));
0097 auto collectorD = setWhatProduced(this, &WhatsItESProducer::produceD, edm::es::Label("D"));
0098
0099
0100 auto const data_label = pset.exists("doodadLabel") ? pset.getParameter<std::string>("doodadLabel") : std::string{};
0101 token_ = collector.consumes<edmtest::Doodad>(edm::ESInputTag{"", data_label});
0102 tokenA_ = collectorA.consumes<edmtest::Doodad>(edm::ESInputTag{"", data_label});
0103 tokenB_ = collectorB.consumes<edmtest::Doodad>(edm::ESInputTag{"", data_label});
0104 tokenC_ = collectorC.consumes<edmtest::Doodad>(edm::ESInputTag{"", data_label});
0105 tokenD_ = collectorD.consumes<edmtest::Doodad>(edm::ESInputTag{"", data_label});
0106 }
0107
0108 WhatsItESProducer::~WhatsItESProducer() {
0109
0110
0111 }
0112
0113
0114
0115
0116
0117
0118 WhatsItESProducer::ReturnType WhatsItESProducer::produce(const GadgetRcd& iRecord) {
0119
0120 edm::Service<edm::service::TriggerNamesService> tns;
0121 tns->getProcessName();
0122
0123 edm::ESHandle<Doodad> doodad = iRecord.getHandle(token_);
0124 auto pWhatsIt = std::make_unique<WhatsIt>();
0125 pWhatsIt->a = doodad->a;
0126 return pWhatsIt;
0127 }
0128
0129 WhatsItESProducer::ReturnTypeA WhatsItESProducer::produceA(const GadgetRcd& iRecord) {
0130 edm::ESHandle<Doodad> doodad = iRecord.getHandle(tokenA_);
0131 auto pWhatsIt = std::make_unique<WhatsIt>();
0132 pWhatsIt->a = doodad->a;
0133 return pWhatsIt;
0134 }
0135
0136 WhatsItESProducer::ReturnTypeB WhatsItESProducer::produceB(const GadgetRcd& iRecord) {
0137 edm::ESHandle<Doodad> doodad = iRecord.getHandle(tokenB_);
0138 auto pWhatsIt = std::make_shared<WhatsIt>();
0139 pWhatsIt->a = doodad->a;
0140 return pWhatsIt;
0141 }
0142
0143 WhatsItESProducer::ReturnTypeC WhatsItESProducer::produceC(const GadgetRcd& iRecord) {
0144 edm::ESHandle<Doodad> doodad = iRecord.getHandle(tokenC_);
0145 auto pWhatsIt = std::make_shared<WhatsIt>();
0146 pWhatsIt->a = doodad->a;
0147 return pWhatsIt;
0148 }
0149
0150 WhatsItESProducer::ReturnTypeD WhatsItESProducer::produceD(const GadgetRcd& iRecord) {
0151 edm::ESHandle<Doodad> doodad = iRecord.getHandle(tokenD_);
0152 auto pWhatsIt = std::make_optional<WhatsIt>();
0153 pWhatsIt->a = doodad->a;
0154 return pWhatsIt;
0155 }
0156
0157 void WhatsItESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0158 edm::ParameterSetDescription desc;
0159 desc.addOptional<std::string>("doodadLabel");
0160 desc.addUntracked<bool>("test", false)
0161 ->setComment("This parameter exists only to test the parameter set validation for ESSources");
0162 descriptions.add("WhatsItESProducer", desc);
0163 }
0164 }
0165 using namespace edmtest;
0166
0167 DEFINE_FWK_EVENTSETUP_MODULE(WhatsItESProducer);