File indexing completed on 2025-01-21 01:39:47
0001 #include <string>
0002
0003 #include "DataFormats/TestObjects/interface/OtherThingCollection.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 #include "FWCore/Framework/interface/global/EDProducer.h"
0008
0009 #include "OtherThingAlgorithm.h"
0010 #include "FWCore/Utilities/interface/EDGetToken.h"
0011 #include "FWCore/Utilities/interface/EDPutToken.h"
0012 #include "FWCore/Utilities/interface/InputTag.h"
0013
0014 namespace edmtest {
0015 class OtherThingProducer : public edm::global::EDProducer<> {
0016 public:
0017 explicit OtherThingProducer(edm::ParameterSet const& ps);
0018
0019 ~OtherThingProducer() override;
0020
0021 void produce(edm::StreamID, edm::Event& e, edm::EventSetup const& c) const override;
0022
0023 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0024
0025 private:
0026 OtherThingAlgorithm alg_;
0027 edm::EDGetTokenT<ThingCollection> thingToken_;
0028 edm::EDPutTokenT<OtherThingCollection> putToken_;
0029 bool useRefs_;
0030 bool refsAreTransient_;
0031 bool thingMissing_;
0032 };
0033
0034 OtherThingProducer::OtherThingProducer(edm::ParameterSet const& pset) : alg_(), refsAreTransient_(false) {
0035 putToken_ = produces<OtherThingCollection>("testUserTag");
0036 useRefs_ = pset.getUntrackedParameter<bool>("useRefs");
0037 thingMissing_ = pset.getUntrackedParameter<bool>("thingMissing");
0038 if (useRefs_ or thingMissing_) {
0039 thingToken_ = consumes<ThingCollection>(pset.getParameter<edm::InputTag>("thingTag"));
0040 }
0041 refsAreTransient_ = pset.getUntrackedParameter<bool>("transient");
0042 }
0043
0044
0045 OtherThingProducer::~OtherThingProducer() {}
0046
0047
0048 void OtherThingProducer::produce(edm::StreamID, edm::Event& e, edm::EventSetup const&) const {
0049
0050
0051
0052 auto result = std::make_unique<OtherThingCollection>();
0053
0054
0055 edm::Handle<ThingCollection> parentHandle;
0056 if (useRefs_ or thingMissing_) {
0057 parentHandle = e.getHandle(thingToken_);
0058
0059 if (thingMissing_) {
0060 if (parentHandle.isValid()) {
0061 throw cms::Exception("TestFailure")
0062 << "The ThingCollection is available when it was expected to not be available";
0063 }
0064 } else {
0065 *parentHandle;
0066 }
0067 }
0068
0069
0070 alg_.run(parentHandle, *result, useRefs_, refsAreTransient_);
0071
0072
0073 e.put(putToken_, std::move(result));
0074 }
0075
0076 void OtherThingProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0077 edm::ParameterSetDescription desc;
0078 desc.add<edm::InputTag>("thingTag", edm::InputTag("Thing"))->setComment("Where to get the ThingCollection");
0079 desc.addUntracked<bool>("useRefs", true)
0080 ->setComment("Actually get the ThingCollection and build edm::Refs to the contained items.");
0081 desc.addUntracked<bool>("transient", false)
0082 ->setComment("If true, then the Refs constructed by the ThingCollection can not be persisted");
0083 desc.addUntracked<bool>("thingMissing", false)->setComment("If true, expect that thing collection is missing");
0084 descriptions.add("otherThingProd", desc);
0085 }
0086
0087 }
0088 using edmtest::OtherThingProducer;
0089 DEFINE_FWK_MODULE(OtherThingProducer);