CMS 3D CMS Logo

CollectionCombiner.h
Go to the documentation of this file.
1 #ifndef CollectionCombiner_H
2 #define CollectionCombiner_H
3 
4 
16 // system include files
17 #include <memory>
18 
19 // user include files
22 
25 
27 
28 template <typename Collection>
30 public:
31  explicit CollectionCombiner(const edm::ParameterSet&);
32  ~CollectionCombiner() override;
33 
34 private:
35  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
36 
37  // ----------member data ---------------------------
38  std::vector<edm::InputTag> labels;
39  std::vector<edm::EDGetTokenT<Collection> > collectionTokens;
40 
41 };
42 
43 template <typename Collection>
45  labels = iConfig.getParameter<std::vector<edm::InputTag> >("labels");
46  produces<Collection>();
47  for (unsigned int i=0;i<labels.size();++i)
48  collectionTokens.push_back(consumes<Collection>(labels.at(i)));
49 }
50 template <typename Collection>
52 
53 template <typename Collection>
55 {
56  unsigned int i=0,i_max=labels.size();
58  auto merged = std::make_unique<Collection>();
59  for (;i!=i_max;++i){
60  iEvent.getByToken(collectionTokens[i], handle);
61  merged->insert(merged->end(), handle->begin(), handle->end());
62  }
63  iEvent.put(std::move(merged));
64 }
65 
66 
67 #endif
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::vector< edm::EDGetTokenT< Collection > > collectionTokens
int iEvent
Definition: GenABIO.cc:224
~CollectionCombiner() override
CollectionCombiner(const edm::ParameterSet &)
std::vector< edm::InputTag > labels
def move(src, dest)
Definition: eostools.py:511
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override