Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:38

0001 /** \class edm::ThinningProducer
0002 \author W. David Dagenhart, created 11 June 2014
0003 */
0004 
0005 #include "FWCore/Framework/interface/one/EDProducer.h"
0006 #include "DataFormats/TestObjects/interface/ThingCollection.h"
0007 #include "DataFormats/TestObjects/interface/TrackOfThings.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/Utilities/interface/EDGetToken.h"
0011 #include "FWCore/Utilities/interface/InputTag.h"
0012 #include "FWCore/Framework/interface/MakerMacros.h"
0013 
0014 namespace edm {
0015   class EventSetup;
0016 }
0017 
0018 namespace edmtest {
0019 
0020   class TrackOfThingsProducer : public edm::one::EDProducer<> {
0021   public:
0022     explicit TrackOfThingsProducer(edm::ParameterSet const&);
0023     virtual ~TrackOfThingsProducer();
0024 
0025     void produce(edm::Event&, edm::EventSetup const&) override;
0026 
0027   private:
0028     void incrementKey(std::vector<unsigned int>::const_iterator& key) const;
0029 
0030     edm::EDGetTokenT<ThingCollection> inputToken_;
0031     std::vector<unsigned int> keysToReference_;
0032   };
0033 
0034   TrackOfThingsProducer::TrackOfThingsProducer(edm::ParameterSet const& pset) {
0035     inputToken_ = consumes<ThingCollection>(pset.getParameter<edm::InputTag>("inputTag"));
0036 
0037     keysToReference_ = pset.getParameter<std::vector<unsigned int> >("keysToReference");
0038 
0039     produces<TrackOfThingsCollection>();
0040   }
0041 
0042   TrackOfThingsProducer::~TrackOfThingsProducer() {}
0043 
0044   void TrackOfThingsProducer::incrementKey(std::vector<unsigned int>::const_iterator& key) const {
0045     ++key;
0046     if (key == keysToReference_.end())
0047       key = keysToReference_.begin();
0048   }
0049 
0050   void TrackOfThingsProducer::produce(edm::Event& event, edm::EventSetup const&) {
0051     edm::Handle<ThingCollection> inputCollection = event.getHandle(inputToken_);
0052 
0053     auto result = std::make_unique<TrackOfThingsCollection>();
0054 
0055     // Arbitrarily fabricate some fake data with TrackOfThings pointing to
0056     // Thing objects in products written to the event by a different module.
0057     // The numbers in the keys here are made up, passed in via the configuration
0058     // and have no meaning other than that we will later check that we can
0059     // read out what we put in here.
0060     std::vector<unsigned int>::const_iterator key = keysToReference_.begin();
0061     for (unsigned int i = 0; i < 5; ++i) {
0062       edmtest::TrackOfThings trackOfThings;
0063 
0064       trackOfThings.ref1 = edm::Ref<ThingCollection>(inputCollection, *key);
0065       incrementKey(key);
0066 
0067       trackOfThings.ref2 = edm::Ref<ThingCollection>(inputCollection, *key);
0068       incrementKey(key);
0069 
0070       trackOfThings.ptr1 = edm::Ptr<Thing>(inputCollection, *key);
0071       incrementKey(key);
0072 
0073       trackOfThings.ptr2 = edm::Ptr<Thing>(inputCollection, *key);
0074       incrementKey(key);
0075 
0076       trackOfThings.refToBase1 = edm::RefToBase<Thing>(trackOfThings.ref1);
0077 
0078       for (auto iKey : keysToReference_) {
0079         trackOfThings.refVector1.push_back(edm::Ref<ThingCollection>(inputCollection, iKey));
0080         trackOfThings.ptrVector1.push_back(edm::Ptr<Thing>(inputCollection, iKey));
0081         trackOfThings.refToBaseVector1.push_back(
0082             edm::RefToBase<Thing>(edm::Ref<ThingCollection>(inputCollection, iKey)));
0083       }
0084 
0085       result->push_back(trackOfThings);
0086     }
0087 
0088     event.put(std::move(result));
0089   }
0090 }  // namespace edmtest
0091 using edmtest::TrackOfThingsProducer;
0092 DEFINE_FWK_MODULE(TrackOfThingsProducer);