CMS 3D CMS Logo

L1TEGMultiMerger.cc
Go to the documentation of this file.
6 
14 #include <vector>
15 #include <iostream>
16 
18 public:
19  explicit L1TEGMultiMerger(const edm::ParameterSet&);
20  ~L1TEGMultiMerger() override;
21  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
22 
23 private:
24  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
25 
26  struct RefRemapper {
28  std::map<edm::Ref<BXVector<l1t::EGamma>>, edm::Ref<BXVector<l1t::EGamma>>> old2newRefMap;
29  };
30 
31  template <class T>
33  public:
35  : instanceLabel_(conf.getParameter<std::string>("instance")) {
36  for (const auto& producer_tag : conf.getParameter<std::vector<edm::InputTag>>("pfProducers")) {
37  tokens_.push_back(
38  prod->consumes<T>(edm::InputTag(producer_tag.label(), producer_tag.instance(), producer_tag.process())));
39  }
40  // FIXME: move this outside
41  prod->produces<T>(instanceLabel_);
42  }
43 
44  void produce(edm::Event& iEvent, RefRemapper& refRemapper) const {
46  auto out = std::make_unique<T>();
47  for (const auto& token : tokens_) {
48  iEvent.getByToken(token, handle);
49  populate(out, handle, refRemapper);
50  }
51  remapRefs(iEvent, out, refRemapper);
53  }
54 
55  private:
56  template <class TT>
57  void remapRefs(edm::Event& iEvent, std::unique_ptr<TT>& out, RefRemapper& refRemapper) const {
58  for (auto& egobj : *out) {
59  auto newref = refRemapper.old2newRefMap.find(egobj.EGRef());
60  if (newref != refRemapper.old2newRefMap.end()) {
61  egobj.setEGRef(newref->second);
62  }
63  }
64  }
65 
68  edm::Ref<BXVector<l1t::EGamma>>::key_type idx = 0;
69  for (std::size_t ix = 0; ix < out->size(); ix++) {
70  refRemapper.old2newRefMap[refRemapper.oldRefs[ix]] = edm::Ref<BXVector<l1t::EGamma>>(ref_egs, idx++);
71  }
72  }
73 
74  template <class TT>
75  void populate(std::unique_ptr<TT>& out, const edm::Handle<TT>& in, RefRemapper& refRemapper) const {
76  out->insert(out->end(), in->begin(), in->end());
77  }
78 
81  RefRemapper& refRemapper) const {
82  edm::Ref<BXVector<l1t::EGamma>>::key_type idx = 0;
83  for (int bx = in->getFirstBX(); bx <= in->getLastBX(); bx++) {
84  for (auto egee_itr = in->begin(bx); egee_itr != in->end(bx); egee_itr++) {
85  out->push_back(bx, *egee_itr);
86  // this to ensure that the old ref and the new object have the same index in the BXVector collection so that we can still match them
87  // no matter which BX we will insert next
89  }
90  }
91  }
92 
93  std::vector<edm::EDGetTokenT<T>> tokens_;
95  };
96 
97  std::vector<InstanceMerger<l1t::TkElectronCollection>> tkEleMerger;
98  std::vector<InstanceMerger<l1t::TkEmCollection>> tkEmMerger;
99  std::vector<InstanceMerger<BXVector<l1t::EGamma>>> tkEGMerger;
100 };
101 
103  for (const auto& config : conf.getParameter<std::vector<edm::ParameterSet>>("tkEgs")) {
105  }
106  for (const auto& config : conf.getParameter<std::vector<edm::ParameterSet>>("tkElectrons")) {
108  }
109  for (const auto& config : conf.getParameter<std::vector<edm::ParameterSet>>("tkEms")) {
111  }
112 }
113 
115 
117  RefRemapper refmapper;
118  for (const auto& egMerger : tkEGMerger)
119  egMerger.produce(iEvent, refmapper);
120  for (const auto& eleMerger : tkEleMerger)
121  eleMerger.produce(iEvent, refmapper);
122  for (const auto& emMerger : tkEmMerger)
123  emMerger.produce(iEvent, refmapper);
124 }
125 
128  psetDesc.add<std::string>("instance");
129  psetDesc.add<std::vector<edm::InputTag>>("pfProducers");
131  desc.addVPSet("tkElectrons", psetDesc);
132  desc.addVPSet("tkEms", psetDesc);
133  desc.addVPSet("tkEgs", psetDesc);
134  descriptions.addWithDefaultLabel(desc);
135 }
136 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::vector< InstanceMerger< BXVector< l1t::EGamma > > > tkEGMerger
void produce(edm::Event &iEvent, RefRemapper &refRemapper) const
InstanceMerger(L1TEGMultiMerger *prod, const edm::ParameterSet &conf)
std::vector< InstanceMerger< l1t::TkEmCollection > > tkEmMerger
Definition: config.py:1
std::map< edm::Ref< BXVector< l1t::EGamma > >, edm::Ref< BXVector< l1t::EGamma > > > old2newRefMap
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
void populate(std::unique_ptr< TT > &out, const edm::Handle< TT > &in, RefRemapper &refRemapper) const
int iEvent
Definition: GenABIO.cc:224
std::vector< InstanceMerger< l1t::TkElectronCollection > > tkEleMerger
L1TEGMultiMerger(const edm::ParameterSet &)
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< edm::EDGetTokenT< T > > tokens_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void remapRefs(edm::Event &iEvent, std::unique_ptr< TT > &out, RefRemapper &refRemapper) const
void populate(std::unique_ptr< BXVector< l1t::EGamma >> &out, const edm::Handle< BXVector< l1t::EGamma >> &in, RefRemapper &refRemapper) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
long double T
BXVector< edm::Ref< BXVector< l1t::EGamma > > > oldRefs
~L1TEGMultiMerger() override
def move(src, dest)
Definition: eostools.py:511
void push_back(int bx, T object)
void remapRefs(edm::Event &iEvent, std::unique_ptr< BXVector< l1t::EGamma >> &out, RefRemapper &refRemapper) const