CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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&);
33 
34 private:
35  virtual void produce(edm::Event&, const edm::EventSetup&);
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  std::auto_ptr<Collection> merged(new 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(merged);
64 }
65 
66 
67 #endif
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
std::vector< edm::EDGetTokenT< Collection > > collectionTokens
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
virtual void produce(edm::Event &, const edm::EventSetup &)
tuple handle
Definition: patZpeak.py:22
CollectionCombiner(const edm::ParameterSet &)
std::vector< edm::InputTag > labels