Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:38

0001 // -*- C++ -*-
0002 //
0003 // Package:    WhatsItESProducer
0004 // Class:      WhatsItESProducer
0005 //
0006 /**\class WhatsItESProducer WhatsItESProducer.h test/WhatsItESProducer/interface/WhatsItESProducer.h
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Chris Jones
0015 //         Created:  Fri Jun 24 14:33:04 EDT 2005
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <optional>
0022 
0023 // user include files
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 // class decleration
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     // ----------member data ---------------------------
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   // constants, enums and typedefs
0075   //
0076 
0077   //
0078   // static data member definitions
0079   //
0080 
0081   //
0082   // constructors and destructor
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     //the following line is needed to tell the framework what
0092     // data is being produced
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     //now do what ever other initialization is needed
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     // do anything here that needs to be done at desctruction time
0110     // (e.g. close files, deallocate resources etc.)
0111   }
0112 
0113   //
0114   // member functions
0115   //
0116 
0117   // ------------ method called to produce the data  ------------
0118   WhatsItESProducer::ReturnType WhatsItESProducer::produce(const GadgetRcd& iRecord) {
0119     //This tests that the Service system is accessible from a ESProducer
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 }  // namespace edmtest
0165 using namespace edmtest;
0166 //define this as a plug-in
0167 DEFINE_FWK_EVENTSETUP_MODULE(WhatsItESProducer);