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
|
#include "DataFormats/Common/interface/DetSetVectorNew.h"
#include "DataFormats/TestObjects/interface/ThingCollection.h"
#include "ThingAlgorithm.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/EDPutToken.h"
namespace edmtest {
class DetSetVectorThingProducer : public edm::global::EDProducer<> {
public:
explicit DetSetVectorThingProducer(edm::ParameterSet const& iConfig)
: detSets_(iConfig.getParameter<std::vector<int>>("detSets")),
nPerDetSet_(iConfig.getParameter<int>("nThings")),
alg_(iConfig.getParameter<int>("offsetDelta"),
nPerDetSet_ * detSets_.size(),
iConfig.getParameter<bool>("grow")),
evToken_(produces<edmNew::DetSetVector<Thing>>()) {}
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<int>("offsetDelta", 0)
->setComment(
"How much extra to increment the value used when creating Things for a new container. E.g. the last "
"value "
"used to create Thing from the previous event is incremented by 'offsetDelta' to compute the value to "
"use "
"of the first Thing created in the next Event.");
desc.add<std::vector<int>>("detSets", std::vector<int>{1, 2, 3})->setComment("Vector of DetSet ids");
desc.add<int>("nThings", 20)->setComment("How many Things to put in each DetSet.");
desc.add<bool>("grow", false)
->setComment("If true, multiply 'nThings' by the value of offset for each run of the algorithm.");
descriptions.addWithDefaultLabel(desc);
}
void produce(edm::StreamID, edm::Event& e, edm::EventSetup const& c) const override {
edmNew::DetSetVector<Thing> ret(2);
ThingCollection tmp;
alg_.run(tmp);
assert(tmp.end() == tmp.begin() + nPerDetSet_ * detSets_.size());
auto begin = tmp.begin();
auto end = begin + nPerDetSet_;
for (int detSetID : detSets_) {
edmNew::DetSetVector<Thing>::FastFiller filler(ret, detSetID);
std::copy(begin, end, std::back_inserter(filler));
begin = end;
std::advance(end, nPerDetSet_);
}
e.emplace(evToken_, std::move(ret));
}
private:
std::vector<int> detSets_;
unsigned int nPerDetSet_;
ThingAlgorithm alg_;
edm::EDPutTokenT<edmNew::DetSetVector<Thing>> evToken_;
};
} // namespace edmtest
using edmtest::DetSetVectorThingProducer;
DEFINE_FWK_MODULE(DetSetVectorThingProducer);
|