Go to the documentation of this file.00001 #ifndef CommonTools_UtilAlgos_FwdPtrProducer_h
00002 #define CommonTools_UtilAlgos_FwdPtrProducer_h
00003
00004
00014 #include "FWCore/Framework/interface/EDProducer.h"
00015 #include "FWCore/Framework/interface/Event.h"
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017 #include "FWCore/Utilities/interface/InputTag.h"
00018 #include "DataFormats/Common/interface/View.h"
00019 #include "DataFormats/Common/interface/FwdPtr.h"
00020 #include "CommonTools/UtilAlgos/interface/FwdPtrConversionFactory.h"
00021 #include <vector>
00022
00023 namespace edm {
00024
00025
00026 template < class T, class H = FwdPtrFromProductFactory<T> >
00027 class FwdPtrProducer : public edm::EDProducer {
00028 public :
00029 explicit FwdPtrProducer( edm::ParameterSet const & params ) :
00030 src_( params.getParameter<edm::InputTag>("src") )
00031 {
00032 produces< std::vector< edm::FwdPtr<T> > > ();
00033 }
00034
00035 ~FwdPtrProducer() {}
00036
00037 virtual void produce(edm::Event & iEvent, const edm::EventSetup& iSetup) override {
00038
00039 edm::Handle< edm::View<T> > hSrc;
00040 iEvent.getByLabel( src_, hSrc );
00041
00042 std::auto_ptr< std::vector< edm::FwdPtr<T> > > pOutputFwdPtr ( new std::vector<edm::FwdPtr<T> > );
00043
00044 for ( typename edm::View<T>::const_iterator ibegin = hSrc->begin(),
00045 iend = hSrc->end(),
00046 i = ibegin; i!= iend; ++i ) {
00047 H factory;
00048 FwdPtr<T> ptr = factory( *hSrc, i - ibegin );
00049 pOutputFwdPtr->push_back( ptr );
00050 }
00051
00052
00053 iEvent.put( pOutputFwdPtr );
00054 }
00055
00056 protected :
00057 edm::InputTag src_;
00058 };
00059 }
00060
00061 #endif