Imperial Analysis
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Merge.h
Go to the documentation of this file.
1 #ifndef UserCode_ICHiggsTauTau_Merge_h
2 #define UserCode_ICHiggsTauTau_Merge_h
3 
4 #include <vector>
5 #include <set>
6 #include <memory>
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"
17 
18 namespace ic {
19 
44 template <class T>
45 class Merge : public edm::EDProducer {
46  public:
47  explicit Merge(const edm::ParameterSet &);
48  ~Merge();
49 
50  private:
51  virtual void beginJob();
52  virtual void produce(edm::Event &, const edm::EventSetup &);
53  virtual void endJob();
54 
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;
59 
60  std::vector<edm::InputTag> merge_inputs_;
61 };
62 
63 // =============================
64 // Template class implementation
65 // =============================
66 template <class T>
67 Merge<T>::Merge(const edm::ParameterSet &config)
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]);
71  }
72  produces<RefVectorVec>();
73 }
74 
75 template <class T>
77 
78 template <class T>
79 void Merge<T>::beginJob() {}
80 
81 template <class T>
82 void Merge<T>::endJob() {}
83 
84 template <class T>
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)));
96  }
97  }
98  }
99  event.put(product);
100 }
101 }
102 
103 #endif
Merge(const edm::ParameterSet &)
Definition: Merge.h:67
Definition: CaloJet.hh:9
Merge several collections into one, removing any duplicates in the process.
Definition: Merge.h:45
~Merge()
Definition: Merge.h:76