CP3-llbb Framework
Identifiable.h
1 #pragma once
2 
3 #include <FWCore/ParameterSet/interface/ParameterSet.h>
4 #include <FWCore/Framework/interface/Event.h>
5 #include <FWCore/Framework/interface/EventSetup.h>
6 #include <FWCore/Framework/interface/ConsumesCollector.h>
7 #include <FWCore/Utilities/interface/InputTag.h>
8 #include <DataFormats/Common/interface/ValueMap.h>
9 #include <DataFormats/Common/interface/Ref.h>
10 
11 #include <cp3_llbb/TreeWrapper/interface/TreeWrapper.h>
12 
13 
14 class Identifiable {
15 
16  public:
17  Identifiable(ROOT::TreeGroup& tree):
18  ids(tree["ids"].write<std::vector<std::map<std::string, bool>>>()) {
19  // Empty
20  }
21 
22  template <class T> void produce_id(const edm::Ref<T>& ref) {
23  std::map<std::string, bool> ids_;
24  for (auto& handle: m_id_maps) {
25  ids_.emplace(handle.first, (*(handle.second))[ref]);
26  }
27  ids.push_back(ids_);
28  }
29 
30  virtual void consumes_id_tokens(const edm::ParameterSet&, edm::ConsumesCollector&& collector) final;
31  virtual void retrieves_id_tokens(const edm::Event& event, const edm::EventSetup& eventSetup) final;
32  virtual void clean() final {
33  m_id_maps.clear();
34  }
35  std::vector<std::map<std::string, bool>>& ids;
36 
37  protected:
38  std::vector<std::pair<std::string, edm::EDGetTokenT<edm::ValueMap<bool>>>> m_id_tokens;
39  std::vector<std::pair<std::string, edm::Handle<edm::ValueMap<bool>>>> m_id_maps;
40 };
Definition: Identifiable.h:14