Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:15

0001 #ifndef CommonTools_UtilAlgos_FwdPtrProducer_h
0002 #define CommonTools_UtilAlgos_FwdPtrProducer_h
0003 
0004 /**
0005   \class    edm::FwdPtrProducer FwdPtrProducer.h "CommonTools/UtilAlgos/interface/FwdPtrProducer.h"
0006   \brief    Produces a list of FwdPtr's to an input collection.
0007 
0008 
0009   \author   Salvatore Rappoccio
0010 */
0011 
0012 #include "FWCore/Framework/interface/stream/EDProducer.h"
0013 #include "FWCore/Framework/interface/Event.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/Utilities/interface/InputTag.h"
0016 #include "DataFormats/Common/interface/View.h"
0017 #include "DataFormats/Common/interface/FwdPtr.h"
0018 #include "CommonTools/UtilAlgos/interface/FwdPtrConversionFactory.h"
0019 #include <vector>
0020 
0021 namespace edm {
0022 
0023   template <class T, class H = FwdPtrFromProductFactory<T> >
0024   class FwdPtrProducer : public edm::stream::EDProducer<> {
0025   public:
0026     explicit FwdPtrProducer(edm::ParameterSet const& params)
0027         : srcToken_(consumes<edm::View<T> >(params.getParameter<edm::InputTag>("src"))) {
0028       produces<std::vector<edm::FwdPtr<T> > >();
0029     }
0030 
0031     ~FwdPtrProducer() override {}
0032 
0033     void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override {
0034       edm::Handle<edm::View<T> > hSrc;
0035       iEvent.getByToken(srcToken_, hSrc);
0036 
0037       std::unique_ptr<std::vector<edm::FwdPtr<T> > > pOutputFwdPtr(new std::vector<edm::FwdPtr<T> >);
0038 
0039       for (typename edm::View<T>::const_iterator ibegin = hSrc->begin(), iend = hSrc->end(), i = ibegin; i != iend;
0040            ++i) {
0041         H factory;
0042         FwdPtr<T> ptr = factory(*hSrc, i - ibegin);
0043         pOutputFwdPtr->push_back(ptr);
0044       }
0045 
0046       iEvent.put(std::move(pOutputFwdPtr));
0047     }
0048 
0049   protected:
0050     edm::EDGetTokenT<edm::View<T> > srcToken_;
0051   };
0052 }  // namespace edm
0053 
0054 #endif