CMS 3D CMS Logo

component.h
Go to the documentation of this file.
1 #ifndef Candidate_component_h
2 #define Candidate_component_h
3 
12 
13 namespace reco {
14 
15  class Candidate;
16 
18 
19  namespace componenthelper {
20 
21  struct SingleComponentTag {};
22 
24 
25  template <typename C, typename T, T (C::*F)() const>
26  struct SingleComponent {
27  static T get(const Candidate &c) {
28  const C *dc = dynamic_cast<const C *>(&c);
29  if (dc == nullptr)
30  return T();
31  return (dc->*F)();
32  }
33  };
34 
35  template <typename C, typename T, T (C::*F)(size_t) const, size_t (C::*S)() const>
37  static size_t numberOf(const Candidate &c) {
38  const C *dc = dynamic_cast<const C *>(&c);
39  if (dc == nullptr)
40  return 0;
41  return (dc->*S)();
42  }
43  static T get(const Candidate &c, size_t i) {
44  const C *dc = dynamic_cast<const C *>(&c);
45  if (dc == nullptr)
46  return T();
47  if (i < (dc->*S)())
48  return (dc->*F)(i);
49  else
50  throw cms::Exception("Error") << "index " << i << " out ot range";
51  }
52  };
53 
54  } // namespace componenthelper
55 
56  template <typename T, typename M, typename Tag = DefaultComponentTag>
57  struct component {};
58 
59  template <typename T>
60  inline T get(const Candidate &c) {
62  }
63 
64  template <typename T, typename Tag>
65  inline T get(const Candidate &c) {
67  }
68 
69  template <typename T>
70  inline T get(const Candidate &c, size_t i) {
72  }
73 
74  template <typename T, typename Tag>
75  inline T get(const Candidate &c, size_t i) {
77  }
78 
79  template <typename T>
80  inline size_t numberOf(const Candidate &c) {
82  }
83 
84  template <typename T, typename Tag>
85  inline size_t numberOf(const Candidate &c) {
87  }
88 
89 } // namespace reco
90 
91 #define GET_CANDIDATE_COMPONENT(CAND, TYPE, FUN, TAG) \
92  template <> \
93  struct component<TYPE, componenthelper::SingleComponentTag, TAG> { \
94  typedef componenthelper::SingleComponent<CAND, TYPE, &CAND::FUN> type; \
95  }
96 
97 #define GET_DEFAULT_CANDIDATE_COMPONENT(CAND, TYPE, FUN) \
98  template <> \
99  struct component<TYPE, componenthelper::SingleComponentTag, DefaultComponentTag> { \
100  typedef componenthelper::SingleComponent<CAND, TYPE, &CAND::FUN> type; \
101  }
102 
103 #define GET_CANDIDATE_MULTIPLECOMPONENTS(CAND, TYPE, FUN, SIZE, TAG) \
104  template <> \
105  struct component<TYPE, componenthelper::MultipleComponentsTag, TAG> { \
106  typedef componenthelper::MultipleComponents<CAND, TYPE, &CAND::FUN, &CAND::SIZE> type; \
107  }
108 
109 #define GET_DEFAULT_CANDIDATE_MULTIPLECOMPONENTS(CAND, TYPE, FUN, SIZE) \
110  template <> \
111  struct component<TYPE, componenthelper::MultipleComponentsTag, DefaultComponentTag> { \
112  typedef componenthelper::MultipleComponents<CAND, TYPE, &CAND::FUN, &CAND::SIZE> type; \
113  }
114 
115 #endif
mps_fire.i
i
Definition: mps_fire.py:428
configurableAnalysis::Candidate
char Candidate[]
Definition: modules.cc:20
reco::componenthelper::SingleComponentTag
Definition: component.h:21
reco::componenthelper::MultipleComponents::numberOf
static size_t numberOf(const Candidate &c)
Definition: component.h:37
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
reco::componenthelper::SingleComponent::get
static T get(const Candidate &c)
Definition: component.h:27
F
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
reco::DefaultComponentTag
Definition: component.h:17
reco::numberOf
size_t numberOf(const Candidate &c)
Definition: component.h:80
reco::componenthelper::SingleComponent
Definition: component.h:26
get
#define get
reco::get
T get(const Candidate &c)
Definition: component.h:60
reco::Candidate
Definition: Candidate.h:27
gen::C
C
Definition: PomwigHadronizer.cc:78
T
long double T
Definition: Basic3DVectorLD.h:48
Exception
Definition: hltDiff.cc:245
Exception.h
S
Definition: CSCDBL1TPParametersExtended.h:16
reco::componenthelper::MultipleComponents
Definition: component.h:36
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
reco::component
Definition: component.h:57
reco::componenthelper::MultipleComponents::get
static T get(const Candidate &c, size_t i)
Definition: component.h:43
reco::componenthelper::MultipleComponentsTag
Definition: component.h:23
reco::numberOf
size_t numberOf(const Candidate &c)
Definition: component.h:85