DataFormats
Common
interface
traits.h
Go to the documentation of this file.
1
#ifndef DataFormats_Common_traits_h
2
#define DataFormats_Common_traits_h
3
4
/*----------------------------------------------------------------------
5
6
Definition of traits templates used in the EDM.
7
8
9
----------------------------------------------------------------------*/
10
11
#include <deque>
12
#include <limits>
13
#include <list>
14
#include <set>
15
#include <string>
16
#include <utility>
17
#include <vector>
18
19
namespace
edm
{
20
//------------------------------------------------------------
21
//
22
// The trait struct template key_traits<K> is used to carry
23
// information relevant to the type K when used as a 'key' in
24
// RefVector and its related classes and templates.
25
//
26
// The general case works only for integral types K; for more
27
// 'esoteric' types, one must introduce an explicit specialization.
28
// That specialization must initialize the static data member
29
// 'value'.
30
31
template
<
class
K>
32
struct
key_traits
{
33
typedef
K
key_type
;
34
static
const
key_type
value
;
35
};
36
37
template
<
class
K>
38
typename
key_traits<K>::key_type
const
key_traits<K>::value
=
39
std::numeric_limits<typename key_traits<K>::key_type>
::max
();
40
41
// Partial specialization for std::pair
42
43
template
<
class
U,
class
V>
44
struct
key_traits
<
std
::pair<U, V> > {
45
typedef
std::pair<U, V>
key_type
;
46
static
const
key_type
value
;
47
};
48
49
template
<
class
U,
class
V>
50
typename
key_traits<std::pair<U, V>
>::key_type
const
key_traits<std::pair<U, V>
>
::value
=
51
std::make_pair(
key_traits<U>::value
,
key_traits<V>::value
);
52
53
// If we ever need to support instantiations of std::basic_string
54
// other than std::string, this is the place to do it.
55
56
// For value, we make a 1-character long string that contains an
57
// unprintable character; we are hoping nobody ever uses such a
58
// string as a legal key.
59
template
<>
60
struct
key_traits
<
std
::
string
> {
61
typedef
std::string
key_type
;
62
static
const
key_type
value
;
63
};
64
65
//------------------------------------------------------------
66
//
67
// DoNotSortUponInsertion is a base class. Derive your own class X
68
// from DoNotSortUponInsertion when:
69
//
70
// 1. You want to use DetSetVector<X> as an EDProduct, but
71
//
72
// 2. You do *not* want the Event::put member template to cause the
73
// DetSet<X> instances within the DetSetVector<X> to be sorted.
74
//
75
// DoNotSortUponInsertion has no behavior; it is used at compile
76
// time to influence the behavior of Event::put.
77
//
78
// Usage:
79
// class MyClass : public edm::DoNotSortUponInsertion { ... }
80
//
81
struct
DoNotSortUponInsertion
{};
82
83
//------------------------------------------------------------
84
//
85
// DoNotRecordParents is a base class. Derive your own (EDProduct)
86
// class X from DoNotRecordParents when your class already keeps all
87
// data that are relevant to parentage internally, and the
88
// information kept by the event model would thus be redundant.
89
//
90
// DoNotRecordParents has no behavior; it is used at compile time to
91
// influence the behavior of Event::put.
92
//
93
// Usage:
94
// class MyClass : public edm::DoNotRecordParents { ... }
95
struct
DoNotRecordParents
{};
96
97
// Other is a base class. NEVER USE IT. It is for the
98
// core of the event model only.
99
struct
Other
{};
100
101
//------------------------------------------------------------
102
//
103
// The trait struct template has_fillView<T> is used to
104
// indicate whether or not the type T has a member function
105
//
106
// void T::fillView(std::vector<void const*>&) const
107
//
108
// We assume the 'general case' for T is to not support fillView.
109
// Classes which do support fillView must specialize this trait.
110
//
111
//------------------------------------------------------------
112
113
template
<
class
T>
114
struct
has_fillView
{
115
static
bool
const
value
=
false
;
116
};
117
118
template
<
class
T,
class
A>
119
struct
has_fillView
<
std
::
vector
<T, A> > {
120
static
bool
const
value
=
true
;
121
};
122
123
template
<
class
A>
124
struct
has_fillView
<
std
::
vector
<bool, A> > {
125
static
bool
const
value
=
false
;
126
};
127
128
template
<
class
T,
class
A>
129
struct
has_fillView
<
std
::list<T, A> > {
130
static
bool
const
value
=
true
;
131
};
132
133
template
<
class
T,
class
A>
134
struct
has_fillView
<
std
::deque<T, A> > {
135
static
bool
const
value
=
true
;
136
};
137
138
template
<
class
T,
class
A>
139
struct
has_fillView
<
std
::set<T, A> > {
140
static
bool
const
value
=
true
;
141
};
142
143
//------------------------------------------------------------
144
//
145
// The trait struct template has_setPtr<T> is used to
146
// indicate whether or not the type T has a member function
147
//
148
// void T::setPtr(const std::type_info&, void const*&) const
149
//
150
// We assume the 'general case' for T is to not support setPtr.
151
// Classes which do support setPtr must specialize this trait.
152
//
153
//------------------------------------------------------------
154
155
template
<
class
T>
156
struct
has_setPtr
{
157
static
bool
const
value
=
false
;
158
};
159
160
template
<
class
T,
class
A>
161
struct
has_setPtr
<
std
::
vector
<T, A> > {
162
static
bool
const
value
=
true
;
163
};
164
165
template
<
class
A>
166
struct
has_setPtr
<
std
::
vector
<bool, A> > {
167
static
bool
const
value
=
false
;
168
};
169
170
template
<
class
T,
class
A>
171
struct
has_setPtr
<
std
::list<T, A> > {
172
static
bool
const
value
=
true
;
173
};
174
175
template
<
class
T,
class
A>
176
struct
has_setPtr
<
std
::deque<T, A> > {
177
static
bool
const
value
=
true
;
178
};
179
180
template
<
class
T,
class
A>
181
struct
has_setPtr
<
std
::set<T, A> > {
182
static
bool
const
value
=
true
;
183
};
184
}
// namespace edm
185
186
#endif
edm::key_traits< std::string >::value
static const key_type value
Definition:
traits.h:62
edm
HLT enums.
Definition:
AlignableModifier.h:19
edm::max
EventID const & max(EventID const &lh, EventID const &rh)
Definition:
EventID.h:118
edm::key_traits< std::pair< U, V > >::key_type
std::pair< U, V > key_type
Definition:
traits.h:45
edm::has_setPtr
Definition:
traits.h:156
edm::key_traits
Definition:
traits.h:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
edm::key_traits::value
static const key_type value
Definition:
traits.h:34
value
Definition:
value.py:1
trackerHitRTTI::vector
Definition:
trackerHitRTTI.h:21
edm::key_traits< std::string >::key_type
std::string key_type
Definition:
traits.h:61
edm::DoNotRecordParents
Definition:
traits.h:95
edm::key_traits::key_type
K key_type
Definition:
traits.h:33
std
Definition:
JetResolutionObject.h:76
relativeConstraints.value
value
Definition:
relativeConstraints.py:53
edm::DoNotSortUponInsertion
Definition:
traits.h:81
edm::Other
Definition:
traits.h:99
edm::has_fillView
Definition:
traits.h:114
edm::key_traits< std::pair< U, V > >::value
static const key_type value
Definition:
traits.h:46
Generated for CMSSW Reference Manual by
1.8.16