CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/CommonTools/UtilAlgos/interface/Merger.h

Go to the documentation of this file.
00001 #ifndef UtilAlgos_Merger_h
00002 #define UtilAlgos_Merger_h
00003 
00020 #include "FWCore/Framework/interface/EDProducer.h"
00021 #include "FWCore/Framework/interface/Event.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 #include "FWCore/Utilities/interface/InputTag.h"
00024 #include "DataFormats/Common/interface/CloneTrait.h"
00025 #include <vector>
00026 
00027 template<typename InputCollection, 
00028          typename OutputCollection = InputCollection,
00029          typename P = typename edm::clonehelper::CloneTrait<InputCollection>::type>
00030 class Merger : public edm::EDProducer {
00031 public:
00033   explicit Merger( const edm::ParameterSet& );
00035   ~Merger();
00036 
00037 private:
00039   virtual void produce( edm::Event&, const edm::EventSetup& );
00041   typedef std::vector<edm::InputTag> vtag;
00043   vtag src_;
00044 };
00045 
00046 template<typename InputCollection, typename OutputCollection, typename P>
00047 Merger<InputCollection, OutputCollection, P>::Merger( const edm::ParameterSet& par ) : 
00048   src_( par.template getParameter<vtag>( "src" ) ) {
00049   produces<OutputCollection>();
00050 }
00051 
00052 template<typename InputCollection, typename OutputCollection, typename P>
00053 Merger<InputCollection, OutputCollection, P>::~Merger() {
00054 }
00055 
00056 template<typename InputCollection, typename OutputCollection, typename P>
00057 void Merger<InputCollection, OutputCollection, P>::produce( edm::Event& evt, const edm::EventSetup& ) {
00058   std::auto_ptr<OutputCollection> coll( new OutputCollection );
00059   for( vtag::const_iterator s = src_.begin(); s != src_.end(); ++ s ) {
00060     edm::Handle<InputCollection> h;
00061     evt.getByLabel( * s, h );
00062     for( typename InputCollection::const_iterator c = h->begin(); c != h->end(); ++c ) {
00063       coll->push_back( P::clone( * c ) );
00064     }
00065   }
00066   evt.put( coll );
00067 }
00068 
00069 #endif