1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
/*----------------------------------------------------------------------
Toy EDProducers and EDProducts for testing purposes only.
----------------------------------------------------------------------*/
#include "DataFormats/Common/interface/DetSetVector.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/RefProd.h"
#include "DataFormats/Common/interface/View.h"
#include "DataFormats/TestObjects/interface/ToyProducts.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/global/EDFilter.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include <cassert>
#include <stdexcept>
#include <string>
#include <vector>
namespace edmtest {
//--------------------------------------------------------------------
//
// Toy producers
//
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//
// Produces and SCSimpleProduct product instance.
//
class SCSimpleProducer : public edm::stream::EDProducer<> {
public:
explicit SCSimpleProducer(edm::ParameterSet const& p) : size_(p.getParameter<int>("size")) {
produces<SCSimpleProduct>();
assert(size_ > 1);
}
explicit SCSimpleProducer(int i) : size_(i) {
produces<SCSimpleProduct>();
assert(size_ > 1);
}
virtual ~SCSimpleProducer() {}
virtual void produce(edm::Event& e, edm::EventSetup const& c) override;
private:
int size_; // number of Simples to put in the collection
};
void SCSimpleProducer::produce(edm::Event& e, edm::EventSetup const& /* unused */) {
// Fill up a collection so that it is sorted *backwards*.
std::vector<Simple> guts(size_);
for (int i = 0; i < size_; ++i) {
guts[i].key = size_ - i;
guts[i].value = 1.5 * i;
}
// Verify that the vector is not sorted -- in fact, it is sorted
// backwards!
for (int i = 1; i < size_; ++i) {
assert(guts[i - 1].id() > guts[i].id());
}
// Put the product into the Event, thus sorting it.
e.put(std::make_unique<SCSimpleProduct>(guts));
}
//--------------------------------------------------------------------
//
// Produces and OVSimpleProduct product instance.
//
class OVSimpleProducer : public edm::stream::EDProducer<> {
public:
explicit OVSimpleProducer(edm::ParameterSet const& p) : size_(p.getParameter<int>("size")) {
produces<OVSimpleProduct>();
produces<OVSimpleDerivedProduct>("derived");
assert(size_ > 1);
}
explicit OVSimpleProducer(int i) : size_(i) {
produces<OVSimpleProduct>();
produces<OVSimpleDerivedProduct>("derived");
assert(size_ > 1);
}
virtual ~OVSimpleProducer() {}
virtual void produce(edm::Event& e, edm::EventSetup const& c) override;
private:
int size_; // number of Simples to put in the collection
};
void OVSimpleProducer::produce(edm::Event& e, edm::EventSetup const& /* unused */) {
// Fill up a collection
auto p = std::make_unique<OVSimpleProduct>();
for (int i = 0; i < size_; ++i) {
auto simple = std::make_unique<Simple>();
simple->key = size_ - i;
simple->value = 1.5 * i;
p->push_back(std::move(simple));
}
// Put the product into the Event
e.put(std::move(p));
// Fill up a collection of SimpleDerived objects
auto pd = std::make_unique<OVSimpleDerivedProduct>();
for (int i = 0; i < size_; ++i) {
auto simpleDerived = std::make_unique<SimpleDerived>();
simpleDerived->key = size_ - i;
simpleDerived->value = 1.5 * i + 100.0;
simpleDerived->dummy = 0.0;
pd->push_back(std::move(simpleDerived));
}
// Put the product into the Event
e.put(std::move(pd), "derived");
}
//--------------------------------------------------------------------
//
// Produces and OVSimpleProduct product instance.
//
class VSimpleProducer : public edm::stream::EDProducer<> {
public:
explicit VSimpleProducer(edm::ParameterSet const& p) : size_(p.getParameter<int>("size")) {
produces<VSimpleProduct>();
assert(size_ > 1);
}
explicit VSimpleProducer(int i) : size_(i) {
produces<VSimpleProduct>();
assert(size_ > 1);
}
virtual ~VSimpleProducer() {}
virtual void produce(edm::Event& e, edm::EventSetup const& c) override;
private:
int size_; // number of Simples to put in the collection
};
void VSimpleProducer::produce(edm::Event& e, edm::EventSetup const& /* unused */) {
// Fill up a collection
auto p = std::make_unique<VSimpleProduct>();
for (int i = 0; i < size_; ++i) {
Simple simple;
simple.key = size_ - i;
simple.value = 1.5 * i + e.id().event();
p->push_back(simple);
}
// Put the product into the Event
e.put(std::move(p));
}
//--------------------------------------------------------------------
//
// Produces AssociationVector<vector<Simple>, vector<Simple> > object
// This is used to test a View of an AssociationVector
//
class AVSimpleProducer : public edm::stream::EDProducer<> {
public:
explicit AVSimpleProducer(edm::ParameterSet const& p) : src_(p.getParameter<edm::InputTag>("src")) {
produces<AVSimpleProduct>();
consumes<std::vector<edmtest::Simple>>(src_);
}
virtual void produce(edm::Event& e, edm::EventSetup const& c) override;
private:
edm::InputTag src_;
};
void AVSimpleProducer::produce(edm::Event& e, edm::EventSetup const& /* unused */) {
edm::Handle<std::vector<edmtest::Simple>> vs;
e.getByLabel(src_, vs);
// Fill up a collection
auto p = std::make_unique<AVSimpleProduct>(edm::RefProd<std::vector<edmtest::Simple>>(vs));
for (unsigned int i = 0; i < vs->size(); ++i) {
edmtest::Simple simple;
simple.key = 100 + i; // just some arbitrary number for testing
simple.value = .1 * e.id().event();
p->setValue(i, simple);
}
// Put the product into the Event
e.put(std::move(p));
}
//--------------------------------------------------------------------
//
// Produces two products:
// DSVSimpleProduct
// DSVWeirdProduct
//
class DSVProducer : public edm::stream::EDProducer<> {
public:
explicit DSVProducer(edm::ParameterSet const& p) : size_(p.getParameter<int>("size")) {
produces<DSVSimpleProduct>();
produces<DSVWeirdProduct>();
assert(size_ > 1);
}
explicit DSVProducer(int i) : size_(i) {
produces<DSVSimpleProduct>();
produces<DSVWeirdProduct>();
assert(size_ > 1);
}
virtual ~DSVProducer() {}
virtual void produce(edm::Event& e, edm::EventSetup const&) override;
private:
template <typename PROD>
void make_a_product(edm::Event& e);
int size_;
};
void DSVProducer::produce(edm::Event& e, edm::EventSetup const& /* unused */) {
this->make_a_product<DSVSimpleProduct>(e);
this->make_a_product<DSVWeirdProduct>(e);
}
template <typename PROD>
void DSVProducer::make_a_product(edm::Event& e) {
typedef PROD product_type;
typedef typename product_type::value_type detset;
typedef typename detset::value_type value_type;
// Fill up a collection so that it is sorted *backwards*.
std::vector<value_type> guts(size_);
for (int i = 0; i < size_; ++i) {
guts[i].data = size_ - i;
}
// Verify that the vector is not sorted -- in fact, it is sorted
// backwards!
for (int i = 1; i < size_; ++i) {
assert(guts[i - 1].data > guts[i].data);
}
auto p = std::make_unique<product_type>();
int n = 0;
for (int id = 1; id < size_; ++id) {
++n;
detset item(id); // this will get DetID id
item.data.insert(item.data.end(), guts.begin(), guts.begin() + n);
p->insert(item);
}
// Put the product into the Event, thus sorting it ... or not,
// depending upon the product type.
e.put(std::move(p));
}
//--------------------------------------------------------------------
//
// Produces two products: (new DataSetVector)
// DSTVSimpleProduct
// DSTVSimpleDerivedProduct
//
class DSTVProducer : public edm::stream::EDProducer<> {
public:
explicit DSTVProducer(edm::ParameterSet const& p) : size_(p.getParameter<int>("size")) {
produces<DSTVSimpleProduct>();
produces<DSTVSimpleDerivedProduct>();
assert(size_ > 1);
}
explicit DSTVProducer(int i) : size_(i) {
produces<DSTVSimpleProduct>();
produces<DSTVSimpleDerivedProduct>();
assert(size_ > 1);
}
virtual ~DSTVProducer() {}
virtual void produce(edm::Event& e, edm::EventSetup const&) override;
private:
template <typename PROD>
void make_a_product(edm::Event& e);
void fill_a_data(DSTVSimpleProduct::data_type& d, unsigned int i);
void fill_a_data(DSTVSimpleDerivedProduct::data_type& d, unsigned int i);
int size_;
};
void DSTVProducer::produce(edm::Event& e, edm::EventSetup const& /* unused */) {
this->make_a_product<DSTVSimpleProduct>(e);
this->make_a_product<DSTVSimpleDerivedProduct>(e);
}
void DSTVProducer::fill_a_data(DSTVSimpleDerivedProduct::data_type& d, unsigned int i) {
d.key = size_ - i;
d.value = 1.5 * i;
}
void DSTVProducer::fill_a_data(DSTVSimpleProduct::data_type& d, unsigned int i) { d.data = size_ - i; }
template <typename PROD>
void DSTVProducer::make_a_product(edm::Event& e) {
typedef PROD product_type;
//FIXME
typedef typename product_type::FastFiller detset;
typedef typename detset::id_type id_type;
auto p = std::make_unique<product_type>();
product_type& v = *p;
unsigned int n = 0;
for (id_type id = 1; id < static_cast<id_type>(size_); ++id) {
++n;
detset item(v, id); // this will get DetID id
item.resize(n);
for (unsigned int i = 0; i < n; ++i)
fill_a_data(item[i], i);
}
// Put the product into the Event, thus sorting is not done by magic,
// up to one user-line
e.put(std::move(p));
}
//--------------------------------------------------------------------
//
// Produces an Prodigal instance.
//
class ProdigalProducer : public edm::stream::EDProducer<> {
public:
explicit ProdigalProducer(edm::ParameterSet const& p) : label_(p.getParameter<std::string>("label")) {
produces<Prodigal>();
consumes<IntProduct>(edm::InputTag{label_});
}
virtual ~ProdigalProducer() {}
virtual void produce(edm::Event& e, edm::EventSetup const& c) override;
private:
std::string label_;
};
void ProdigalProducer::produce(edm::Event& e, edm::EventSetup const&) {
// EventSetup is not used.
// The purpose of Prodigal is testing of *not* keeping
// parentage. So we need to get a product...
edm::Handle<IntProduct> parent;
e.getByLabel(label_, parent);
e.put(std::make_unique<Prodigal>(parent->value));
}
class IntProductFilter : public edm::global::EDFilter<> {
public:
explicit IntProductFilter(edm::ParameterSet const& p)
: token_(consumes(p.getParameter<edm::InputTag>("label"))),
threshold_(p.getParameter<int>("threshold")),
shouldProduce_(p.getParameter<bool>("shouldProduce")) {
if (shouldProduce_) {
putToken_ = produces<edmtest::IntProduct>();
}
}
bool filter(edm::StreamID, edm::Event& iEvent, edm::EventSetup const&) const {
auto const& product = iEvent.get(token_);
if (product.value < threshold_) {
return false;
}
if (shouldProduce_) {
iEvent.emplace(putToken_, product);
}
return true;
}
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("label");
desc.add<int>("threshold", 0);
desc.add<bool>("shouldProduce", false);
descriptions.addDefault(desc);
}
private:
const edm::EDGetTokenT<edmtest::IntProduct> token_;
edm::EDPutTokenT<edmtest::IntProduct> putToken_;
const int threshold_;
const bool shouldProduce_;
};
} // namespace edmtest
using edmtest::AVSimpleProducer;
using edmtest::DSTVProducer;
using edmtest::DSVProducer;
using edmtest::IntProductFilter;
using edmtest::OVSimpleProducer;
using edmtest::ProdigalProducer;
using edmtest::SCSimpleProducer;
using edmtest::VSimpleProducer;
DEFINE_FWK_MODULE(SCSimpleProducer);
DEFINE_FWK_MODULE(OVSimpleProducer);
DEFINE_FWK_MODULE(VSimpleProducer);
DEFINE_FWK_MODULE(AVSimpleProducer);
DEFINE_FWK_MODULE(DSVProducer);
DEFINE_FWK_MODULE(DSTVProducer);
DEFINE_FWK_MODULE(ProdigalProducer);
DEFINE_FWK_MODULE(IntProductFilter);
|