Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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::EDGetToken thingToken_;
0028     edm::EDPutToken putToken_;
0029     bool useRefs_;
0030     bool refsAreTransient_;
0031   };
0032 
0033   OtherThingProducer::OtherThingProducer(edm::ParameterSet const& pset) : alg_(), refsAreTransient_(false) {
0034     putToken_ = produces<OtherThingCollection>("testUserTag");
0035     useRefs_ = pset.getUntrackedParameter<bool>("useRefs");
0036     if (useRefs_) {
0037       thingToken_ = consumes<ThingCollection>(pset.getParameter<edm::InputTag>("thingTag"));
0038     }
0039     refsAreTransient_ = pset.getUntrackedParameter<bool>("transient");
0040   }
0041 
0042   // Virtual destructor needed.
0043   OtherThingProducer::~OtherThingProducer() {}
0044 
0045   // Functions that gets called by framework every event
0046   void OtherThingProducer::produce(edm::StreamID, edm::Event& e, edm::EventSetup const&) const {
0047     // Step A: Get Inputs
0048 
0049     // Step B: Create empty output
0050     auto result = std::make_unique<OtherThingCollection>();  //Empty
0051 
0052     // Step C: Get data for algorithm
0053     edm::Handle<ThingCollection> parentHandle;
0054     if (useRefs_) {
0055       bool succeeded = e.getByToken(thingToken_, parentHandle);
0056       assert(succeeded);
0057       assert(parentHandle.isValid());
0058     }
0059 
0060     // Step D: Invoke the algorithm, passing in inputs (NONE) and getting back outputs.
0061     alg_.run(parentHandle, *result, useRefs_, refsAreTransient_);
0062 
0063     // Step E: Put outputs into event
0064     e.put(putToken_, std::move(result));
0065   }
0066 
0067   void OtherThingProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0068     edm::ParameterSetDescription desc;
0069     desc.add<edm::InputTag>("thingTag", edm::InputTag("Thing"))->setComment("Where to get the ThingCollection");
0070     desc.addUntracked<bool>("useRefs", true)
0071         ->setComment("Actually get the ThingCollection and build edm::Refs to the contained items.");
0072     desc.addUntracked<bool>("transient", false)
0073         ->setComment("If true, then the Refs constructed by the ThingCollection can not be persisted");
0074     descriptions.add("otherThingProd", desc);
0075   }
0076 
0077 }  // namespace edmtest
0078 using edmtest::OtherThingProducer;
0079 DEFINE_FWK_MODULE(OtherThingProducer);