1 |
yiiyama |
1.1 |
// -*- C++ -*-
|
2 |
|
|
//
|
3 |
|
|
// Package: CollectionMerger
|
4 |
|
|
// Class: CollectionMerger
|
5 |
|
|
//
|
6 |
|
|
/**\class CollectionMerger CollectionMerger.cc Toolset/CollectionMerger/src/CollectionMerger.cc
|
7 |
|
|
|
8 |
|
|
Description: [one line class summary]
|
9 |
|
|
|
10 |
|
|
Implementation:
|
11 |
|
|
[Notes on implementation]
|
12 |
|
|
*/
|
13 |
|
|
//
|
14 |
|
|
// Original Author: Yutaro Iiyama,512 1-005,+41227670489,
|
15 |
|
|
// Created: Thu Jun 21 16:48:38 CEST 2012
|
16 |
|
|
// $Id$
|
17 |
|
|
//
|
18 |
|
|
//
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
// system include files
|
22 |
|
|
#include <memory>
|
23 |
|
|
|
24 |
|
|
// user include files
|
25 |
|
|
#include "FWCore/Framework/interface/Frameworkfwd.h"
|
26 |
|
|
#include "FWCore/Framework/interface/EDProducer.h"
|
27 |
|
|
|
28 |
|
|
#include "FWCore/Framework/interface/Event.h"
|
29 |
|
|
#include "FWCore/Framework/interface/MakerMacros.h"
|
30 |
|
|
|
31 |
|
|
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
32 |
|
|
|
33 |
|
|
#include "FWCore/Utilities/interface/Exception.h"
|
34 |
|
|
#include "FWCore/Utilities/interface/InputTag.h"
|
35 |
|
|
|
36 |
|
|
#include "DataFormats/Common/interface/Handle.h"
|
37 |
|
|
#include "DataFormats/Common/interface/RefToBaseVector.h"
|
38 |
|
|
|
39 |
|
|
#include "DataFormats/Candidate/interface/Candidate.h"
|
40 |
|
|
#include "DataFormats/Candidate/interface/CandidateFwd.h"
|
41 |
|
|
#include "DataFormats/EgammaCandidates/interface/Photon.h"
|
42 |
|
|
#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
|
43 |
|
|
#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
|
44 |
|
|
#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
|
45 |
|
|
#include "DataFormats/MuonReco/interface/Muon.h"
|
46 |
|
|
#include "DataFormats/MuonReco/interface/MuonFwd.h"
|
47 |
|
|
|
48 |
|
|
//
|
49 |
|
|
// class declaration
|
50 |
|
|
//
|
51 |
|
|
|
52 |
|
|
class CollectionMerger : public edm::EDProducer {
|
53 |
|
|
public:
|
54 |
|
|
explicit CollectionMerger(const edm::ParameterSet&);
|
55 |
|
|
~CollectionMerger();
|
56 |
|
|
|
57 |
|
|
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
|
58 |
|
|
|
59 |
|
|
private:
|
60 |
|
|
virtual void beginJob() ;
|
61 |
|
|
virtual void produce(edm::Event&, const edm::EventSetup&);
|
62 |
|
|
virtual void endJob() ;
|
63 |
|
|
|
64 |
|
|
virtual void beginRun(edm::Run&, edm::EventSetup const&);
|
65 |
|
|
virtual void endRun(edm::Run&, edm::EventSetup const&);
|
66 |
|
|
virtual void beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);
|
67 |
|
|
virtual void endLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);
|
68 |
|
|
|
69 |
|
|
// ----------member data ---------------------------
|
70 |
|
|
|
71 |
|
|
std::vector<edm::InputTag> src_;
|
72 |
|
|
std::string colType_;
|
73 |
|
|
// bool clone_;
|
74 |
|
|
unsigned maxOutputSize_;
|
75 |
|
|
};
|
76 |
|
|
|
77 |
|
|
//
|
78 |
|
|
// constants, enums and typedefs
|
79 |
|
|
//
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
//
|
83 |
|
|
// static data member definitions
|
84 |
|
|
//
|
85 |
|
|
|
86 |
|
|
//
|
87 |
|
|
// constructors and destructor
|
88 |
|
|
//
|
89 |
|
|
CollectionMerger::CollectionMerger(const edm::ParameterSet& iConfig) :
|
90 |
|
|
src_(iConfig.getParameter<std::vector<edm::InputTag> >("src")),
|
91 |
|
|
colType_(iConfig.getParameter<std::string>("type")),
|
92 |
|
|
// clone_(false),
|
93 |
|
|
maxOutputSize_(-1)
|
94 |
|
|
{
|
95 |
|
|
|
96 |
|
|
// if(iConfig.existsAs<bool>("clone"))
|
97 |
|
|
// clone_ = iConfig.getParameter<bool>("clone");
|
98 |
|
|
|
99 |
|
|
if(iConfig.existsAs<int>("maxOutputSize"))
|
100 |
|
|
maxOutputSize_ = iConfig.getParameter<int>("maxOutputSize");
|
101 |
|
|
|
102 |
|
|
if(colType_ == "Photon"){
|
103 |
|
|
// if(clone_)
|
104 |
|
|
produces<reco::PhotonCollection>();
|
105 |
|
|
// else
|
106 |
|
|
// produces<edm::RefToBaseVector<reco::Photon> >();
|
107 |
|
|
}
|
108 |
|
|
else if(colType_ == "Electron"){
|
109 |
|
|
// if(clone_)
|
110 |
|
|
produces<reco::GsfElectronCollection>();
|
111 |
|
|
// else
|
112 |
|
|
// produces<reco::GsfElectronRefVector>();
|
113 |
|
|
}
|
114 |
|
|
else if(colType_ == "Muon"){
|
115 |
|
|
// if(clone_)
|
116 |
|
|
produces<reco::MuonCollection>();
|
117 |
|
|
// else
|
118 |
|
|
// produces<reco::MuonRefVector>();
|
119 |
|
|
}
|
120 |
|
|
else
|
121 |
|
|
throw cms::Exception("Configuration") << colType_;
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
CollectionMerger::~CollectionMerger()
|
126 |
|
|
{
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
//
|
131 |
|
|
// member functions
|
132 |
|
|
//
|
133 |
|
|
|
134 |
|
|
// ------------ method called to produce the data ------------
|
135 |
|
|
void
|
136 |
|
|
CollectionMerger::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
|
137 |
|
|
{
|
138 |
|
|
using namespace edm;
|
139 |
|
|
|
140 |
|
|
RefToBaseVector<reco::Candidate> merged;
|
141 |
|
|
|
142 |
|
|
for(unsigned iS(0); iS < src_.size(); iS++){
|
143 |
|
|
RefToBaseVector<reco::Candidate> const* vSrc(0);
|
144 |
|
|
|
145 |
|
|
Handle<View<reco::Candidate> > srcHndl;
|
146 |
|
|
if(iEvent.getByLabel(src_[iS], srcHndl))
|
147 |
|
|
vSrc = &(srcHndl->refVector());
|
148 |
|
|
else{
|
149 |
|
|
Handle<RefToBaseVector<reco::Candidate> > bsrcHndl;
|
150 |
|
|
if(iEvent.getByLabel(src_[iS], bsrcHndl))
|
151 |
|
|
vSrc = bsrcHndl.product();
|
152 |
|
|
else
|
153 |
|
|
throw cms::Exception("ProductNotFound") << src_[iS];
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
for(RefToBaseVector<reco::Candidate>::const_iterator cItr(vSrc->begin()); cItr != vSrc->end(); ++cItr){
|
157 |
|
|
bool counted(false);
|
158 |
|
|
for(RefToBaseVector<reco::Candidate>::const_iterator it(merged.begin()); it != merged.end(); ++it){
|
159 |
|
|
if(it->get() == cItr->get()){
|
160 |
|
|
counted = true;
|
161 |
|
|
break;
|
162 |
|
|
}
|
163 |
|
|
}
|
164 |
|
|
if(counted) continue;
|
165 |
|
|
|
166 |
|
|
merged.push_back(*cItr);
|
167 |
|
|
}
|
168 |
|
|
}
|
169 |
|
|
|
170 |
|
|
if(colType_ == "Photon"){
|
171 |
|
|
// if(clone_){
|
172 |
|
|
std::auto_ptr<reco::PhotonCollection> output(new reco::PhotonCollection);
|
173 |
|
|
unsigned iOut(0);
|
174 |
|
|
for(RefToBaseVector<reco::Candidate>::const_iterator eItr(merged.begin()); eItr != merged.end() && iOut != maxOutputSize_; ++eItr, iOut++)
|
175 |
|
|
output->push_back(*(static_cast<reco::Photon const*>(eItr->get())));
|
176 |
|
|
iEvent.put(output);
|
177 |
|
|
// }
|
178 |
|
|
// else{
|
179 |
|
|
// std::auto_ptr<RefToBaseVector<reco::Photon> > output(new RefToBaseVector<>);
|
180 |
|
|
// unsigned iOut(0);
|
181 |
|
|
// for(reco::PhotonRefVector::const_iterator eItr(merged.begin()); eItr != merged.end() && iOut != maxOutputSize_; ++eItr, iOut++)
|
182 |
|
|
// output->push_back(*eItr);
|
183 |
|
|
// iEvent.put(output);
|
184 |
|
|
|
185 |
|
|
// std::auto_
|
186 |
|
|
// produces<reco::PhotonCollection>();
|
187 |
|
|
// else
|
188 |
|
|
// produces<edm::RefToBaseVector<reco::Photon> >();
|
189 |
|
|
}
|
190 |
|
|
else if(colType_ == "Electron"){
|
191 |
|
|
std::auto_ptr<reco::GsfElectronCollection> output(new reco::GsfElectronCollection);
|
192 |
|
|
unsigned iOut(0);
|
193 |
|
|
for(RefToBaseVector<reco::Candidate>::const_iterator eItr(merged.begin()); eItr != merged.end() && iOut != maxOutputSize_; ++eItr, iOut++)
|
194 |
|
|
output->push_back(*(static_cast<reco::GsfElectron const*>(eItr->get())));
|
195 |
|
|
iEvent.put(output);
|
196 |
|
|
}
|
197 |
|
|
else if(colType_ == "Muon"){
|
198 |
|
|
std::auto_ptr<reco::MuonCollection> output(new reco::MuonCollection);
|
199 |
|
|
unsigned iOut(0);
|
200 |
|
|
for(RefToBaseVector<reco::Candidate>::const_iterator eItr(merged.begin()); eItr != merged.end() && iOut != maxOutputSize_; ++eItr, iOut++)
|
201 |
|
|
output->push_back(*(static_cast<reco::Muon const*>(eItr->get())));
|
202 |
|
|
iEvent.put(output);
|
203 |
|
|
}
|
204 |
|
|
}
|
205 |
|
|
|
206 |
|
|
// ------------ method called once each job just before starting event loop ------------
|
207 |
|
|
void
|
208 |
|
|
CollectionMerger::beginJob()
|
209 |
|
|
{
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
// ------------ method called once each job just after ending the event loop ------------
|
213 |
|
|
void
|
214 |
|
|
CollectionMerger::endJob() {
|
215 |
|
|
}
|
216 |
|
|
|
217 |
|
|
// ------------ method called when starting to processes a run ------------
|
218 |
|
|
void
|
219 |
|
|
CollectionMerger::beginRun(edm::Run&, edm::EventSetup const&)
|
220 |
|
|
{
|
221 |
|
|
}
|
222 |
|
|
|
223 |
|
|
// ------------ method called when ending the processing of a run ------------
|
224 |
|
|
void
|
225 |
|
|
CollectionMerger::endRun(edm::Run&, edm::EventSetup const&)
|
226 |
|
|
{
|
227 |
|
|
}
|
228 |
|
|
|
229 |
|
|
// ------------ method called when starting to processes a luminosity block ------------
|
230 |
|
|
void
|
231 |
|
|
CollectionMerger::beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&)
|
232 |
|
|
{
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
// ------------ method called when ending the processing of a luminosity block ------------
|
236 |
|
|
void
|
237 |
|
|
CollectionMerger::endLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&)
|
238 |
|
|
{
|
239 |
|
|
}
|
240 |
|
|
|
241 |
|
|
// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
|
242 |
|
|
void
|
243 |
|
|
CollectionMerger::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
|
244 |
|
|
//The following says we do not know what parameters are allowed so do no validation
|
245 |
|
|
// Please change this to state exactly what you do use, even if it is no parameters
|
246 |
|
|
edm::ParameterSetDescription desc;
|
247 |
|
|
desc.setUnknown();
|
248 |
|
|
descriptions.addDefault(desc);
|
249 |
|
|
}
|
250 |
|
|
|
251 |
|
|
//define this as a plug-in
|
252 |
|
|
DEFINE_FWK_MODULE(CollectionMerger);
|