CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoTauTag/TauTagTools/interface/CopyProducer.h

Go to the documentation of this file.
00001 #ifndef RecoTauTag_TauTagTools_CopyProducer_h
00002 #define RecoTauTag_TauTagTools_CopyProducer_h
00003 
00004 /*
00005  * Generic template class to take a View of C::value_type and produce an
00006  * output collection (type C) of clones.
00007  *
00008  * Author: Evan K. Friis (UC Davis)
00009  *
00010  */
00011 
00012 #include "FWCore/Framework/interface/EDProducer.h"
00013 #include "FWCore/Framework/interface/Event.h"
00014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00015 #include "FWCore/Utilities/interface/InputTag.h"
00016 #include "DataFormats/Common/interface/View.h"
00017 #include "DataFormats/Common/interface/Ref.h"
00018 #include "DataFormats/Common/interface/RefToBaseVector.h"
00019 
00020 #include <algorithm>
00021 
00022 namespace reco { namespace tautools {
00023 
00024 template<typename Collection>
00025 class CopyProducer : public edm::EDProducer {
00026   public:
00028     explicit CopyProducer( const edm::ParameterSet& pset)
00029         :src_(pset.template getParameter<edm::InputTag>("src")) {
00030           produces<Collection>();
00031         }
00033     ~CopyProducer(){};
00035     virtual void produce(edm::Event& evt, const edm::EventSetup& es) {
00036       // Output collection
00037       std::auto_ptr<Collection> coll(new Collection());
00038       typedef edm::View<typename Collection::value_type> CView;
00039       // Get input
00040       edm::Handle<CView> input;
00041       evt.getByLabel(src_, input);
00042       // Reserve space
00043       coll->reserve(input->size());
00044       // Copy the input to the output
00045       std::copy(input->begin(), input->end(), std::back_inserter(*coll));
00046       evt.put( coll );
00047     }
00048   private:
00050     edm::InputTag src_;
00051 };
00052 
00053 }}
00054 
00055 #endif