CMS 3D CMS Logo

BPHAnalyzerTokenWrapper.h
Go to the documentation of this file.
1 #ifndef HeavyFlavorAnalysis_RecoDecay_BPHAnalyzerTokenWrapper_h
2 #define HeavyFlavorAnalysis_RecoDecay_BPHAnalyzerTokenWrapper_h
3 
14 //----------------------
15 // Base Class Headers --
16 //----------------------
17 
18 //------------------------------------
19 // Collaborating Class Declarations --
20 //------------------------------------
30 
31 //---------------
32 // C++ Headers --
33 //---------------
34 #include <string>
35 #include <map>
36 #include <memory>
37 
38 // ---------------------
39 // -- Class Interface --
40 // ---------------------
41 
43 public:
48 };
49 
50 template <class Obj>
52 public:
54  bool get(const edm::Event& ev, edm::Handle<Obj>& obj) { return ev.getByToken(token, obj); }
56 };
57 
58 template <class Obj, class Rec>
60 public:
62  bool get(const edm::EventSetup& es, edm::ESHandle<Obj>& obj) {
63  obj = es.get<Rec>().getHandle(token);
64  return obj.isValid();
65  }
67 };
68 
69 template <class T>
70 class BPHAnalyzerWrapper : public T {
71 protected:
72  template <class Obj>
75  tw.token = this->template consumes<Obj>(tag);
76  return;
77  }
78  template <class Obj>
80  tw.token = this->template consumes<Obj>(tag);
81  return;
82  }
83  template <class Obj, class Rec>
85  tw.token = this->template esConsumes<Obj, Rec>();
86  return;
87  }
88  template <class Obj, class Rec>
90  tw.token = this->template esConsumes<Obj, Rec>(edm::ESInputTag("", label));
91  return;
92  }
93  template <class Obj, class Rec>
95  tw.token = this->template esConsumes<Obj>(tag);
96  return;
97  }
98 };
99 
101 public:
103  : ep(&es), twMap(new std::map<BPHRecoCandidate::esType, void*>) {}
105  : BPHEventSetupWrapper(es) {
106  (*twMap)[type] = token;
107  }
108  BPHEventSetupWrapper(const edm::EventSetup& es, std::map<BPHRecoCandidate::esType, void*> tokenMap)
109  : BPHEventSetupWrapper(es) {
110  twMap->insert(tokenMap.begin(), tokenMap.end());
111  }
112  BPHEventSetupWrapper(const BPHEventSetupWrapper& es) = default;
115  : BPHEventSetupWrapper(es) {
116  (*twMap)[type] = token;
117  }
118  BPHEventSetupWrapper(BPHEventSetupWrapper& es, std::map<BPHRecoCandidate::esType, void*> tokenMap)
119  : BPHEventSetupWrapper(es) {
120  twMap->insert(tokenMap.begin(), tokenMap.end());
121  }
122  const edm::EventSetup* get() const { return ep; }
123  operator const edm::EventSetup&() const { return *ep; }
124  template <class Obj, class Rec>
126  const auto& iter = twMap->find(type);
127  return (iter == twMap->end() ? nullptr : static_cast<BPHESTokenWrapper<Obj, Rec>*>(iter->second));
128  }
129 
130 private:
132  std::shared_ptr<std::map<BPHRecoCandidate::esType, void*>> twMap;
133 };
134 
135 #endif
void consume(BPHTokenWrapper< Obj > &tw, const edm::InputTag &tag)
edm::one::EDProducer one_producer
edm::EDGetTokenT< Obj > type
void consume(BPHTokenWrapper< Obj > &tw, const std::string &label)
BPHEventSetupWrapper(const BPHEventSetupWrapper *es)
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
void esConsume(BPHESTokenWrapper< Obj, Rec > &tw)
char const * label
BPHEventSetupWrapper(const BPHEventSetupWrapper &es, BPHRecoCandidate::esType type, void *token)
void esConsume(BPHESTokenWrapper< Obj, Rec > &tw, const edm::ESInputTag &tag)
const edm::EventSetup * ep
edm::one::EDAnalyzer one_analyzer
edm::stream::EDProducer stream_producer
edm::stream::EDAnalyzer stream_analyzer
BPHEventSetupWrapper(const edm::EventSetup &es, std::map< BPHRecoCandidate::esType, void *> tokenMap)
BPHEventSetupWrapper(BPHEventSetupWrapper &es, std::map< BPHRecoCandidate::esType, void *> tokenMap)
void esConsume(BPHESTokenWrapper< Obj, Rec > &tw, const std::string &label)
edm::ESGetToken< Obj, Rec > type
std::shared_ptr< std::map< BPHRecoCandidate::esType, void * > > twMap
BPHEventSetupWrapper(const edm::EventSetup &es, BPHRecoCandidate::esType type, void *token)
long double T
BPHEventSetupWrapper(const edm::EventSetup &es)