CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/CommonTools/UtilAlgos/interface/ProductFromFwdPtrProducer.h

Go to the documentation of this file.
00001 #ifndef CommonTools_UtilAlgos_ProductFromFwdPtrProducer_h
00002 #define CommonTools_UtilAlgos_ProductFromFwdPtrProducer_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 
00027   template < class T, class H = ProductFromFwdPtrFactory<T> > 
00028   class ProductFromFwdPtrProducer : public edm::EDProducer {
00029   public :
00030     explicit ProductFromFwdPtrProducer( edm::ParameterSet const & params ) :
00031       src_   ( params.getParameter<edm::InputTag>("src") )
00032     {
00033       produces< std::vector<T> > ();
00034     }
00035     
00036     ~ProductFromFwdPtrProducer() {}
00037 
00038     virtual void produce(edm::Event & iEvent, const edm::EventSetup& iSetup) override {
00039 
00040       edm::Handle< std::vector<edm::FwdPtr<T> > > hSrc;
00041       iEvent.getByLabel( src_, hSrc );
00042       
00043       std::auto_ptr< std::vector<T> > pOutput ( new std::vector<T> );
00044       
00045       for ( typename std::vector< edm::FwdPtr<T> >::const_iterator ibegin = hSrc->begin(),
00046               iend = hSrc->end(),
00047               i = ibegin; i!= iend; ++i ) {
00048         H factory;
00049         T t = factory(*i);
00050         pOutput->push_back( t );
00051       }
00052       
00053       
00054       iEvent.put( pOutput );      
00055     }
00056     
00057   protected :
00058     edm::InputTag src_;
00059   };
00060 }
00061 
00062 #endif