CMS 3D CMS Logo

CollectionMerger.h
Go to the documentation of this file.
1 
12 #ifndef TauAnalysis_MCEmbeddingTools_CollectionMerger_H
13 #define TauAnalysis_MCEmbeddingTools_CollectionMerger_H
14 
22 
26 
32 
33 //#include "TauAnalysis/MCEmbeddingTools/interface/embeddingAuxFunctions.h"
34 #include <string>
35 #include <iostream>
36 #include <map>
37 
38 template <typename T1, typename T2>
40 public:
41  explicit CollectionMerger(const edm::ParameterSet &);
42  ~CollectionMerger() override;
43 
44 private:
45  void produce(edm::Event &, const edm::EventSetup &) override;
46 
47  typedef T1 MergeCollection;
48  typedef T2 BaseHit;
49  std::map<std::string, std::vector<edm::EDGetTokenT<MergeCollection> > > inputs_;
50 
51  void fill_output_obj(std::unique_ptr<MergeCollection> &output,
52  std::vector<edm::Handle<MergeCollection> > &inputCollections);
53  void fill_output_obj_tracker(std::unique_ptr<MergeCollection> &output,
54  std::vector<edm::Handle<MergeCollection> > &inputCollections,
55  bool print_pixel = false);
56  void fill_output_obj_calo(std::unique_ptr<MergeCollection> &output,
57  std::vector<edm::Handle<MergeCollection> > &inputCollections);
58  void fill_output_obj_muonchamber(std::unique_ptr<MergeCollection> &output,
59  std::vector<edm::Handle<MergeCollection> > &inputCollections);
60 };
61 
62 template <typename T1, typename T2>
64  std::vector<edm::InputTag> inCollections = iConfig.getParameter<std::vector<edm::InputTag> >("mergCollections");
65  for (auto const &inCollection : inCollections) {
66  inputs_[inCollection.instance()].push_back(consumes<MergeCollection>(inCollection));
67  }
68  for (const auto &toproduce : inputs_) {
69  // std::cout<<toproduce.first<<"\t"<<toproduce.second.size()<<std::endl;
70  produces<MergeCollection>(toproduce.first);
71  }
72 }
73 
74 template <typename T1, typename T2>
76  // nothing to be done yet...
77 }
78 
79 template <typename T1, typename T2>
81  for (auto input_ : inputs_) {
82  std::unique_ptr<MergeCollection> output(new MergeCollection());
83  std::vector<edm::Handle<MergeCollection> > inputCollections;
84  inputCollections.resize(input_.second.size());
85  for (unsigned id = 0; id < input_.second.size(); id++) {
86  iEvent.getByToken(input_.second[id], inputCollections[id]);
87  }
88  fill_output_obj(output, inputCollections);
89  iEvent.put(std::move(output), input_.first);
90  }
91 }
92 #endif
std::map< std::string, std::vector< edm::EDGetTokenT< MergeCollection > > > inputs_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
~CollectionMerger() override
int iEvent
Definition: GenABIO.cc:224
void produce(edm::Event &, const edm::EventSetup &) override
void fill_output_obj_muonchamber(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
void fill_output_obj_calo(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
void fill_output_obj(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections)
Definition: output.py:1
CollectionMerger(const edm::ParameterSet &)
void fill_output_obj_tracker(std::unique_ptr< MergeCollection > &output, std::vector< edm::Handle< MergeCollection > > &inputCollections, bool print_pixel=false)
def move(src, dest)
Definition: eostools.py:511