Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-16 00:32:49

0001 #ifndef PhysicsTools_UtilAlgos_CollectionAdder_h
0002 #define PhysicsTools_UtilAlgos_CollectionAdder_h
0003 /* \class CollectionAdder<C>
0004  *
0005  * \author Luca Lista, INFN
0006  *
0007  * \version $Id: CollectionAdder.h,v 1.3 2010/02/20 20:55:17 wmtan Exp $
0008  */
0009 #include "FWCore/Framework/interface/global/EDProducer.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/Utilities/interface/transform.h"
0012 #include "FWCore/Utilities/interface/InputTag.h"
0013 #include "FWCore/Framework/interface/Event.h"
0014 #include "DataFormats/Common/interface/Handle.h"
0015 
0016 template <typename C>
0017 class CollectionAdder : public edm::global::EDProducer<> {
0018 public:
0019   typedef C collection;
0020   CollectionAdder(const edm::ParameterSet& cfg)
0021       : srcTokens_(edm::vector_transform(cfg.template getParameter<std::vector<edm::InputTag>>("src"),
0022                                          [this](edm::InputTag const& tag) { return consumes<collection>(tag); })) {
0023     produces<collection>();
0024   }
0025 
0026 private:
0027   std::vector<edm::EDGetTokenT<collection>> srcTokens_;
0028   void produce(edm::StreamID, edm::Event& evt, const edm::EventSetup&) const override {
0029     std::unique_ptr<collection> coll(new collection);
0030     typename collection::Filler filler(*coll);
0031     for (size_t i = 0; i < srcTokens_.size(); ++i) {
0032       edm::Handle<collection> src;
0033       evt.getByToken(srcTokens_[i], src);
0034       *coll += *src;
0035     }
0036     evt.put(std::move(coll));
0037   }
0038 };
0039 
0040 #endif