CMS 3D CMS Logo

WhatsItESProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: WhatsItESProducer
4 // Class: WhatsItESProducer
5 //
13 //
14 // Original Author: Chris Jones
15 // Created: Fri Jun 24 14:33:04 EDT 2005
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <optional>
22 
23 // user include files
28 
29 #include "WhatsIt.h"
30 #include "Doodad.h"
31 #include "GadgetRcd.h"
32 
37 
39 
40 //
41 // class decleration
42 //
43 namespace edmtest {
44 
46  public:
48  ~WhatsItESProducer() override;
49 
50  typedef std::unique_ptr<WhatsIt> ReturnType;
51  typedef std::unique_ptr<const WhatsIt> ReturnTypeA;
52  typedef std::shared_ptr<WhatsIt> ReturnTypeB;
53  typedef std::shared_ptr<const WhatsIt> ReturnTypeC;
54  typedef std::optional<WhatsIt> ReturnTypeD;
55 
61 
62  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
63 
64  private:
65  // ----------member data ---------------------------
71  };
72 
73  //
74  // constants, enums and typedefs
75  //
76 
77  //
78  // static data member definitions
79  //
80 
81  //
82  // constructors and destructor
83  //
85  if (pset.getUntrackedParameter<bool>("test", true)) {
86  throw edm::Exception(edm::errors::Configuration, "Something is wrong with ESProducer validation\n")
87  << "Or the test configuration parameter was set true (it should never be true unless you want this "
88  "exception)\n";
89  }
90 
91  //the following line is needed to tell the framework what
92  // data is being produced
93  auto collector = setWhatProduced(this);
94  auto collectorA = setWhatProduced(this, &WhatsItESProducer::produceA, edm::es::Label("A"));
95  auto collectorB = setWhatProduced(this, &WhatsItESProducer::produceB, edm::es::Label("B"));
96  auto collectorC = setWhatProduced(this, &WhatsItESProducer::produceC, edm::es::Label("C"));
97  auto collectorD = setWhatProduced(this, &WhatsItESProducer::produceD, edm::es::Label("D"));
98 
99  //now do what ever other initialization is needed
100  auto const data_label = pset.exists("doodadLabel") ? pset.getParameter<std::string>("doodadLabel") : std::string{};
101  token_ = collector.consumes<edmtest::Doodad>(edm::ESInputTag{"", data_label});
102  tokenA_ = collectorA.consumes<edmtest::Doodad>(edm::ESInputTag{"", data_label});
103  tokenB_ = collectorB.consumes<edmtest::Doodad>(edm::ESInputTag{"", data_label});
104  tokenC_ = collectorC.consumes<edmtest::Doodad>(edm::ESInputTag{"", data_label});
105  tokenD_ = collectorD.consumes<edmtest::Doodad>(edm::ESInputTag{"", data_label});
106  }
107 
109  // do anything here that needs to be done at desctruction time
110  // (e.g. close files, deallocate resources etc.)
111  }
112 
113  //
114  // member functions
115  //
116 
117  // ------------ method called to produce the data ------------
119  //This tests that the Service system is accessible from a ESProducer
121  tns->getProcessName();
122 
123  edm::ESHandle<Doodad> doodad = iRecord.getHandle(token_);
124  auto pWhatsIt = std::make_unique<WhatsIt>();
125  pWhatsIt->a = doodad->a;
126  return pWhatsIt;
127  }
128 
130  edm::ESHandle<Doodad> doodad = iRecord.getHandle(tokenA_);
131  auto pWhatsIt = std::make_unique<WhatsIt>();
132  pWhatsIt->a = doodad->a;
133  return pWhatsIt;
134  }
135 
137  edm::ESHandle<Doodad> doodad = iRecord.getHandle(tokenB_);
138  auto pWhatsIt = std::make_shared<WhatsIt>();
139  pWhatsIt->a = doodad->a;
140  return pWhatsIt;
141  }
142 
144  edm::ESHandle<Doodad> doodad = iRecord.getHandle(tokenC_);
145  auto pWhatsIt = std::make_shared<WhatsIt>();
146  pWhatsIt->a = doodad->a;
147  return pWhatsIt;
148  }
149 
151  edm::ESHandle<Doodad> doodad = iRecord.getHandle(tokenD_);
152  auto pWhatsIt = std::make_optional<WhatsIt>();
153  pWhatsIt->a = doodad->a;
154  return pWhatsIt;
155  }
156 
159  desc.addOptional<std::string>("doodadLabel");
160  desc.addUntracked<bool>("test", false)
161  ->setComment("This parameter exists only to test the parameter set validation for ESSources");
162  descriptions.add("WhatsItESProducer", desc);
163  }
164 } // namespace edmtest
165 using namespace edmtest;
166 //define this as a plug-in
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
edm::ESGetToken< edmtest::Doodad, GadgetRcd > tokenB_
std::shared_ptr< WhatsIt > ReturnTypeB
std::unique_ptr< const WhatsIt > ReturnTypeA
std::unique_ptr< WhatsIt > ReturnType
ReturnTypeD produceD(const GadgetRcd &)
edm::ESGetToken< edmtest::Doodad, GadgetRcd > token_
std::string const & getProcessName() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::shared_ptr< const WhatsIt > ReturnTypeC
edm::ESGetToken< edmtest::Doodad, GadgetRcd > tokenC_
ReturnTypeB produceB(const GadgetRcd &)
std::optional< WhatsIt > ReturnTypeD
WhatsItESProducer(edm::ParameterSet const &pset)
edm::ESGetToken< edmtest::Doodad, GadgetRcd > tokenA_
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:61
ReturnType produce(const GadgetRcd &)
ESHandle< PRODUCT > getHandle(ESGetToken< PRODUCT, T > const &iToken) const
edm::ESGetToken< edmtest::Doodad, GadgetRcd > tokenD_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
ReturnTypeC produceC(const GadgetRcd &)
ReturnTypeA produceA(const GadgetRcd &)