CMS 3D CMS Logo

ClassifierMerger.cc
Go to the documentation of this file.
3 
8 
9 #include <vector>
10 #include <memory>
11 
12 namespace {
13  class ClassifierMerger final : public edm::global::EDProducer<> {
14  public:
15  explicit ClassifierMerger(const edm::ParameterSet& conf) {
16  for (auto const& it : conf.getParameter<std::vector<std::string>>("inputClassifiers")) {
17  srcMVAs.push_back(consumes<MVACollection>(edm::InputTag(it, "MVAValues")));
18  srcQuals.push_back(consumes<QualityMaskCollection>(edm::InputTag(it, "QualityMasks")));
19  }
20 
21  produces<MVACollection>("MVAValues");
22  produces<QualityMaskCollection>("QualityMasks");
23  }
24 
25  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
27  desc.add<std::vector<std::string>>("inputClassifiers", std::vector<std::string>());
28  descriptions.add("ClassifierMerger", desc);
29  }
30 
31  private:
32  using MVACollection = std::vector<float>;
33  using QualityMaskCollection = std::vector<unsigned char>;
34 
35  void produce(edm::StreamID, edm::Event& evt, const edm::EventSetup&) const override {
36  // get Master
38  evt.getByToken(srcMVAs[0], hmva);
39  auto size = (*hmva).size();
40 
42  evt.getByToken(srcQuals[0], hqual);
43 
44  // products
45  auto mvas = std::make_unique<MVACollection>(*hmva);
46  auto quals = std::make_unique<QualityMaskCollection>(*hqual);
47 
48  for (auto i = 1U; i < srcQuals.size(); ++i) {
49  evt.getByToken(srcQuals[i], hqual);
50  auto const& iq = *hqual;
51  assert(iq.size() == size);
52  for (auto j = 0U; j != size; ++j)
53  (*quals)[j] |= iq[j];
54  }
55 
56  evt.put(std::move(mvas), "MVAValues");
57  evt.put(std::move(quals), "QualityMasks");
58  }
59 
60  std::vector<edm::EDGetTokenT<MVACollection>> srcMVAs;
61  std::vector<edm::EDGetTokenT<QualityMaskCollection>> srcQuals;
62  };
63 } // namespace
64 
67 
68 DEFINE_FWK_MODULE(ClassifierMerger);
size
Write out results.
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:540
assert(be >=bs)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(ConfigurationDescriptions &descriptions)
virtual void produce(StreamID, Event &, EventSetup const &) const =0
def move(src, dest)
Definition: eostools.py:511