00001 #ifndef CollectionCombiner_H 00002 #define CollectionCombiner_H 00003 00004 00016 // system include files 00017 #include <memory> 00018 00019 // user include files 00020 #include "FWCore/Framework/interface/Frameworkfwd.h" 00021 #include "FWCore/Framework/interface/EDProducer.h" 00022 00023 #include "FWCore/Framework/interface/Event.h" 00024 #include "FWCore/Framework/interface/MakerMacros.h" 00025 00026 #include "FWCore/ParameterSet/interface/ParameterSet.h" 00027 00028 template <typename Collection> 00029 class CollectionCombiner : public edm::EDProducer{ 00030 public: 00031 explicit CollectionCombiner(const edm::ParameterSet&); 00032 ~CollectionCombiner(); 00033 00034 private: 00035 virtual void beginJob(const edm::EventSetup&); 00036 virtual void produce(edm::Event&, const edm::EventSetup&); 00037 virtual void endJob(); 00038 00039 // ----------member data --------------------------- 00040 std::vector<edm::InputTag> labels; 00041 }; 00042 00043 template <typename Collection> 00044 CollectionCombiner<Collection>::CollectionCombiner(const edm::ParameterSet& iConfig){ 00045 labels = iConfig.getParameter<std::vector<edm::InputTag> >("labels"); 00046 produces<Collection>(); 00047 } 00048 template <typename Collection> 00049 CollectionCombiner<Collection>::~CollectionCombiner(){} 00050 template <typename Collection> 00051 void CollectionCombiner<Collection>::beginJob(const edm::EventSetup&){} 00052 template <typename Collection> 00053 void CollectionCombiner<Collection>::endJob(){} 00054 template <typename Collection> 00055 void CollectionCombiner<Collection>::produce(edm::Event& iEvent, const edm::EventSetup& es) 00056 { 00057 uint i=0,i_max=labels.size(); 00058 edm::Handle<Collection> handle; 00059 std::auto_ptr<Collection> merged(new Collection()); 00060 for (;i!=i_max;++i){ 00061 iEvent.getByLabel(labels[i], handle); 00062 merged->insert(merged->end(), handle->begin(), handle->end()); 00063 } 00064 iEvent.put(merged); 00065 } 00066 00067 00068 #endif