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 
17  struct DefaultComponentTag { };
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 ) return T();
30  return (dc->*F)();
31  }
32  };
33 
34  template<typename C, typename T, T (C::*F)( size_t ) const , size_t (C::*S)() const>
36  static size_t numberOf( const Candidate & c ) {
37  const C * dc = dynamic_cast<const C *>( & c );
38  if ( dc == 0 ) return 0;
39  return (dc->*S)();
40  }
41  static T get( const Candidate & c, size_t i ) {
42  const C * dc = dynamic_cast<const C *>( & c );
43  if ( dc == 0 ) return T();
44  if ( i < (dc->*S)() ) return (dc->*F)( i );
45  else throw cms::Exception( "Error" ) << "index " << i << " out ot range";
46  }
47  };
48 
49  }
50 
51  template<typename T, typename M, typename Tag = DefaultComponentTag>
52  struct component { };
53 
54  template<typename T>
55  inline T get( const Candidate & c ) {
57  }
58 
59  template<typename T, typename Tag>
60  inline T get( const Candidate & c ) {
62  }
63 
64  template<typename T>
65  inline T get( const Candidate & c, size_t i ) {
67  }
68 
69  template<typename T, typename Tag>
70  inline T get( const Candidate & c, size_t i ) {
72  }
73 
74  template<typename T>
75  inline size_t numberOf( const Candidate & c ) {
77  }
78 
79  template<typename T, typename Tag>
80  inline size_t numberOf( const Candidate & c ) {
82  }
83 
84 }
85 
86 #define GET_CANDIDATE_COMPONENT( CAND, TYPE, FUN, TAG ) \
87  template<> \
88  struct component<TYPE, componenthelper::SingleComponentTag, TAG> { \
89  typedef componenthelper::SingleComponent<CAND, TYPE, & CAND::FUN> type; \
90  }
91 
92 #define GET_DEFAULT_CANDIDATE_COMPONENT( CAND, TYPE, FUN ) \
93  template<> \
94  struct component<TYPE, componenthelper::SingleComponentTag, DefaultComponentTag> { \
95  typedef componenthelper::SingleComponent<CAND, TYPE, & CAND::FUN> type; \
96  }
97 
98 #define GET_CANDIDATE_MULTIPLECOMPONENTS( CAND, TYPE, FUN, SIZE, TAG ) \
99  template<> \
100  struct component<TYPE, componenthelper::MultipleComponentsTag, TAG> { \
101  typedef componenthelper::MultipleComponents<CAND, TYPE, & CAND::FUN, & CAND::SIZE> type; \
102  }
103 
104 #define GET_DEFAULT_CANDIDATE_MULTIPLECOMPONENTS( CAND, TYPE, FUN, SIZE ) \
105  template<> \
106  struct component<TYPE, componenthelper::MultipleComponentsTag, DefaultComponentTag> { \
107  typedef componenthelper::MultipleComponents<CAND, TYPE, & CAND::FUN, & CAND::SIZE> type; \
108  }
109 
110 #endif
size_t numberOf(const Candidate &c)
Definition: component.h:80
size_t numberOf(const Candidate &c)
Definition: component.h:75
static size_t numberOf(const Candidate &c)
Definition: component.h:36
T get(const Candidate &c, size_t i)
Definition: component.h:70
fixed size matrix
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
long double T