CMS 3D CMS Logo

CollectionCombiner.h
Go to the documentation of this file.
1 #ifndef CollectionCombiner_H
2 #define CollectionCombiner_H
3 
14 // system include files
15 #include <memory>
16 
17 // user include files
20 
23 
25 
26 template <typename Collection>
28 public:
29  explicit CollectionCombiner(const edm::ParameterSet&);
30  ~CollectionCombiner() override;
31 
32 private:
33  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
34 
35  // ----------member data ---------------------------
36  std::vector<edm::InputTag> labels;
37  std::vector<edm::EDGetTokenT<Collection> > collectionTokens;
38 };
39 
40 template <typename Collection>
42  labels = iConfig.getParameter<std::vector<edm::InputTag> >("labels");
43  produces<Collection>();
44  for (unsigned int i = 0; i < labels.size(); ++i)
45  collectionTokens.push_back(consumes<Collection>(labels.at(i)));
46 }
47 template <typename Collection>
49 
50 template <typename Collection>
52  unsigned int i = 0, i_max = labels.size();
54  auto merged = std::make_unique<Collection>();
55  for (; i != i_max; ++i) {
56  iEvent.getByToken(collectionTokens[i], handle);
57  merged->insert(merged->end(), handle->begin(), handle->end());
58  }
59  iEvent.put(std::move(merged));
60 }
61 
62 #endif
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::vector< edm::EDGetTokenT< Collection > > collectionTokens
int iEvent
Definition: GenABIO.cc:224
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
~CollectionCombiner() override
CollectionCombiner(const edm::ParameterSet &)
std::vector< edm::InputTag > labels
def move(src, dest)
Definition: eostools.py:511