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 
23 
27 
33 
34 
35 //#include "TauAnalysis/MCEmbeddingTools/interface/embeddingAuxFunctions.h"
36 #include <string>
37 #include <iostream>
38 #include <map>
39 
40 
41 
42 template <typename T1, typename T2>
44 {
45  public:
46  explicit CollectionMerger(const edm::ParameterSet&);
47  ~CollectionMerger() override;
48 
49  private:
50  void produce(edm::Event&, const edm::EventSetup&) override;
51 
52  typedef T1 MergeCollection;
53  typedef T2 BaseHit;
54  std::map<std::string, std::vector<edm::EDGetTokenT<MergeCollection > > > inputs_;
55 
56 
57  void fill_output_obj(std::unique_ptr<MergeCollection > & output, std::vector<edm::Handle<MergeCollection> > &inputCollections);
58  void fill_output_obj_tracker(std::unique_ptr<MergeCollection > & output, std::vector<edm::Handle<MergeCollection> > &inputCollections, bool print_pixel=false);
59  void fill_output_obj_calo(std::unique_ptr<MergeCollection > & output, std::vector<edm::Handle<MergeCollection> > &inputCollections);
60  void fill_output_obj_muonchamber(std::unique_ptr<MergeCollection > & output, std::vector<edm::Handle<MergeCollection> > &inputCollections);
61 
62 
63 
64 
65 };
66 
67 template <typename T1, typename T2>
69 {
70  std::vector<edm::InputTag> inCollections = iConfig.getParameter<std::vector<edm::InputTag> >("mergCollections");
71  for (auto const & inCollection : inCollections){
72  inputs_[inCollection.instance()].push_back(consumes<MergeCollection >(inCollection));
73  }
74  for (auto toproduce : inputs_){
75  // std::cout<<toproduce.first<<"\t"<<toproduce.second.size()<<std::endl;
76  produces<MergeCollection>(toproduce.first);
77 
78  }
79 }
80 
81 template <typename T1, typename T2>
83 {
84 // nothing to be done yet...
85 }
86 
87 
88 template <typename T1, typename T2>
90 {
91 
92  for (auto input_ : inputs_){
93  std::unique_ptr<MergeCollection > output(new MergeCollection());
94  std::vector<edm::Handle<MergeCollection> > inputCollections;
95  inputCollections.resize(input_.second.size());
96  for (unsigned id = 0; id<input_.second.size(); id++){
97  iEvent.getByToken(input_.second[id], inputCollections[id]);
98  }
99  fill_output_obj(output,inputCollections);
100  iEvent.put(std::move(output),input_.first);
101 
102  }
103 }
104 #endif
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
~CollectionMerger() override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
std::map< std::string, std::vector< edm::EDGetTokenT< MergeCollection > > > inputs_
int iEvent
Definition: GenABIO.cc:230
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)
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:510