1 #ifndef UserCode_ICHiggsTauTau_Merge_h
2 #define UserCode_ICHiggsTauTau_Merge_h
7 #include "FWCore/Framework/interface/EDProducer.h"
8 #include "FWCore/Framework/interface/Event.h"
9 #include "FWCore/Framework/interface/EventSetup.h"
10 #include "FWCore/ParameterSet/interface/ParameterSet.h"
11 #include "FWCore/Utilities/interface/InputTag.h"
12 #include "DataFormats/Common/interface/Handle.h"
13 #include "DataFormats/Common/interface/View.h"
14 #include "DataFormats/Common/interface/Ref.h"
15 #include "DataFormats/Common/interface/RefVector.h"
45 class Merge :
public edm::EDProducer {
47 explicit Merge(
const edm::ParameterSet &);
51 virtual void beginJob();
52 virtual void produce(edm::Event &,
const edm::EventSetup &);
53 virtual void endJob();
55 typedef std::vector<T> Vec;
56 typedef edm::RefVector<Vec> RefVectorVec;
57 typedef edm::Ref<Vec> RefVec;
58 typedef std::vector<edm::InputTag> VInputTag;
60 std::vector<edm::InputTag> merge_inputs_;
68 : merge_inputs_(config.getParameter<VInputTag>(
"merge")) {
69 for(
unsigned i = 0; i < merge_inputs_.size(); ++i){
70 consumes<edm::View<T>>(merge_inputs_[i]);
72 produces<RefVectorVec>();
82 void Merge<T>::endJob() {}
85 void Merge<T>::produce(edm::Event &event,
86 const edm::EventSetup &setup) {
87 std::auto_ptr<RefVectorVec> product(
new RefVectorVec());
88 std::set<T const *> ptr_set;
89 for (
unsigned i = 0; i < merge_inputs_.size(); ++i) {
90 edm::Handle<edm::View<T> > view;
91 event.getByLabel(merge_inputs_[i], view);
92 for (
unsigned j = 0; j < view->size(); ++j) {
93 if (!ptr_set.count(&(view->at(j)))) {
94 product->push_back(view->refAt(j).template castTo<RefVec>());
95 ptr_set.insert(&(view->at(j)));
Merge(const edm::ParameterSet &)
Merge several collections into one, removing any duplicates in the process.