Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/Framework/interface/global/EDProducer.h"
0002 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0003 #include "DataFormats/TestObjects/interface/Thing.h"
0004 #include "DataFormats/TestObjects/interface/TrackOfDSVThings.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/Utilities/interface/EDGetToken.h"
0008 #include "FWCore/Utilities/interface/InputTag.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 
0011 namespace edm {
0012   class EventSetup;
0013 }
0014 
0015 namespace edmtest {
0016 
0017   class TrackOfDSVThingsProducer : public edm::global::EDProducer<> {
0018   public:
0019     explicit TrackOfDSVThingsProducer(edm::ParameterSet const&);
0020 
0021     void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
0022 
0023   private:
0024     void incrementKey(std::vector<unsigned int>::const_iterator& key) const;
0025 
0026     const edm::EDGetTokenT<edmNew::DetSetVector<Thing>> inputToken_;
0027     const edm::EDPutTokenT<TrackOfDSVThingsCollection> outputToken_;
0028     const std::vector<unsigned int> keysToReference_;
0029     const unsigned int nTracks_;
0030   };
0031 
0032   TrackOfDSVThingsProducer::TrackOfDSVThingsProducer(edm::ParameterSet const& pset)
0033       : inputToken_(consumes<edmNew::DetSetVector<Thing>>(pset.getParameter<edm::InputTag>("inputTag"))),
0034         outputToken_(produces<TrackOfDSVThingsCollection>()),
0035         keysToReference_(pset.getParameter<std::vector<unsigned int>>("keysToReference")),
0036         nTracks_(pset.getParameter<unsigned int>("nTracks")) {}
0037 
0038   void TrackOfDSVThingsProducer::incrementKey(std::vector<unsigned int>::const_iterator& key) const {
0039     ++key;
0040     if (key == keysToReference_.end())
0041       key = keysToReference_.begin();
0042   }
0043 
0044   void TrackOfDSVThingsProducer::produce(edm::StreamID, edm::Event& event, edm::EventSetup const&) const {
0045     edm::Handle<edmNew::DetSetVector<Thing>> inputCollection = event.getHandle(inputToken_);
0046 
0047     TrackOfDSVThingsCollection result;
0048 
0049     // Arbitrarily fabricate some fake data with TrackOfThings pointing to
0050     // Thing objects in products written to the event by a different module.
0051     // The numbers in the keys here are made up, passed in via the configuration
0052     // and have no meaning other than that we will later check that we can
0053     // read out what we put in here.
0054     std::vector<unsigned int>::const_iterator key = keysToReference_.begin();
0055     for (unsigned int i = 0; i < nTracks_; ++i) {
0056       edmtest::TrackOfDSVThings trackOfThings;
0057 
0058       trackOfThings.ref1 = edm::Ref<edmNew::DetSetVector<Thing>, Thing>(inputCollection, *key);
0059       incrementKey(key);
0060 
0061       trackOfThings.ref2 = edm::Ref<edmNew::DetSetVector<Thing>, Thing>(inputCollection, *key);
0062       incrementKey(key);
0063 
0064       for (auto iKey : keysToReference_) {
0065         trackOfThings.refVector1.push_back(edm::Ref<edmNew::DetSetVector<Thing>, Thing>(inputCollection, iKey));
0066       }
0067 
0068       result.push_back(trackOfThings);
0069     }
0070 
0071     event.emplace(outputToken_, std::move(result));
0072   }
0073 }  // namespace edmtest
0074 using edmtest::TrackOfDSVThingsProducer;
0075 DEFINE_FWK_MODULE(TrackOfDSVThingsProducer);