1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
#ifndef Fireworks_Core_FWItemRandomAccessor_h
#define Fireworks_Core_FWItemRandomAccessor_h
// -*- C++ -*-
//
// Package: Core
// Class : FWItemRandomAccessor
//
// Original Author: Giulio Eulisse
// Created: Thu Feb 18 15:19:44 EDT 2008
//
// system include files
#include "FWCore/Reflection/interface/ObjectWithDict.h"
// user include files
#include "Fireworks/Core/interface/FWItemAccessorBase.h"
#include "Fireworks/Core/interface/FWItemAccessorRegistry.h"
// forward declarations
/** Non templated part of the generic FWItemRandomAccessor<T>
class.
Notice that the constructor is protected, so that it is
impossible to instanciate this baseclass directly.
*/
class FWItemRandomAccessorBase : public FWItemAccessorBase {
public:
~FWItemRandomAccessorBase() override;
const void *data() const override;
const TClass *type() const override;
const TClass *modelType() const override;
bool isCollection() const override;
void setData(const edm::ObjectWithDict &) override;
void reset() override;
protected:
void *getDataPtr() const;
FWItemRandomAccessorBase(const TClass *type, const std::type_info &modelTypeName);
const TClass *m_type;
const TClass *m_modelType;
mutable void *m_data;
public:
FWItemRandomAccessorBase(const FWItemRandomAccessorBase &) = delete; // stop default
const FWItemRandomAccessorBase &operator=(const FWItemRandomAccessorBase &) = delete; // stop default
};
/** A generic helper class which can be used to create
a specialized FWItemAccessorBase plugin for
all the classes that expose a std::vector like interface.
The template argument T is the actual type of the
container you want to have an accessor for and it must
satisty the following:
- It must have a random access operator (i.e. operator[]()).
- It must have a size() method which returns the amount of
objects contained in the collection.
- It must contain a value_type typedef which indicates
the type of the contained objects. If this is not the
case, you must specify the extra template argument V.
Notice that most of the work is actually done by the baseclass.
*/
template <class C, class V = typename C::value_type>
class FWItemRandomAccessor : public FWItemRandomAccessorBase {
typedef C container_type;
typedef V container_value_type;
public:
FWItemRandomAccessor(const TClass *iClass) : FWItemRandomAccessorBase(iClass, typeid(container_value_type)) {}
REGISTER_FWITEMACCESSOR_METHODS();
// ---------- const member functions ---------------------
const void *modelData(int iIndex) const override {
if (!getDataPtr())
return nullptr;
return &(reinterpret_cast<container_type *>(getDataPtr())->operator[](iIndex));
}
unsigned int size() const override {
if (!getDataPtr())
return 0;
return reinterpret_cast<const container_type *>(getDataPtr())->size();
}
};
/** Generic class for creating accessors for containers which
are implemented as a container of containers. This for example includes
`DetSetVector` hence the name. Both the outer and the inner containers
must follow the Random Access Container model and in particular
must have a size() method. The outer collection must be iterable, while
the inner collections must have an array subscript operator.
*/
template <class C, class COLL = typename C::value_type, class V = typename COLL::value_type>
class FWItemDetSetAccessor : public FWItemRandomAccessorBase {
public:
typedef C container_type;
typedef COLL collection_type;
typedef V collection_value_type;
FWItemDetSetAccessor(const TClass *iClass) : FWItemRandomAccessorBase(iClass, typeid(collection_value_type)) {}
REGISTER_FWITEMACCESSOR_METHODS();
const void *modelData(int iIndex) const override {
if (!getDataPtr())
return nullptr;
const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
size_t collectionOffset = 0;
for (typename container_type::const_iterator ci = c->begin(), ce = c->end(); ci != ce; ++ci) {
size_t i = iIndex - collectionOffset;
if (i < ci->size())
return &(ci->operator[](i));
collectionOffset += ci->size();
}
return nullptr;
}
unsigned int size() const override {
if (!getDataPtr())
return 0;
const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
size_t finalSize = 0;
for (typename container_type::const_iterator i = c->begin(), e = c->end(); i != e; ++i)
finalSize += i->size();
return finalSize;
}
};
/** Specialized accessor for the new edmNew::DetSetVector classes.
*/
template <class C, class COLL = typename C::value_type, class V = typename COLL::value_type>
class FWItemNewDetSetAccessor : public FWItemRandomAccessorBase {
public:
typedef C container_type;
typedef COLL collection_type;
typedef V collection_value_type;
FWItemNewDetSetAccessor(const TClass *iClass) : FWItemRandomAccessorBase(iClass, typeid(collection_value_type)) {}
REGISTER_FWITEMACCESSOR_METHODS();
const void *modelData(int iIndex) const override {
if (!getDataPtr())
return nullptr;
const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
if (iIndex < 0)
return nullptr;
return &(c->data().operator[](iIndex));
}
unsigned int size() const override {
if (!getDataPtr())
return 0;
const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
return c->dataSize();
}
};
template <class C, class R = typename C::Range, class V = typename R::value_type>
class FWItemRangeAccessor : public FWItemRandomAccessorBase {
public:
typedef C container_type;
typedef R range_type;
typedef V value_type;
FWItemRangeAccessor(const TClass *iClass) : FWItemRandomAccessorBase(iClass, typeid(value_type)) {}
REGISTER_FWITEMACCESSOR_METHODS();
const void *modelData(int iIndex) const override {
if (!getDataPtr())
return nullptr;
const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
size_t collectionOffset = 0;
for (typename container_type::const_iterator ci = c->begin(), ce = c->end(); ci != ce; ++ci) {
size_t i = iIndex - collectionOffset;
if (i < std::distance(ci->first, ci->second))
return &(*(ci + i));
collectionOffset += ci->size();
}
return nullptr;
}
unsigned int size() const override {
if (!getDataPtr())
return 0;
const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
size_t finalSize = 0;
for (typename range_type::const_iterator ci = c->begin(), ce = c->end(); ci != ce; ++ci)
finalSize += std::distance(ci->first, ci->second);
return finalSize;
}
};
template <class C, class V>
class FWItemMuonDigiAccessor : public FWItemRandomAccessorBase {
public:
typedef C container_type;
typedef V value_type;
FWItemMuonDigiAccessor(const TClass *iClass) : FWItemRandomAccessorBase(iClass, typeid(value_type)) {}
REGISTER_FWITEMACCESSOR_METHODS();
const void *modelData(int iIndex) const override {
if (!getDataPtr())
return nullptr;
const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
size_t collectionOffset = 0;
for (typename container_type::DigiRangeIterator ci = c->begin(), ce = c->end(); ci != ce; ++ci) {
int i = iIndex - collectionOffset;
typename container_type::DigiRangeIterator::value_type vt = *ci;
if (i < std::distance(vt.second.first, vt.second.second))
return &(*(vt.second.first + i));
collectionOffset += std::distance(vt.second.first, vt.second.second);
}
return nullptr;
}
unsigned int size() const override {
if (!getDataPtr())
return 0;
const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
size_t finalSize = 0;
for (typename container_type::DigiRangeIterator ci = c->begin(), ce = c->end(); ci != ce; ++ci) {
typename container_type::DigiRangeIterator::value_type vt = *ci;
finalSize += std::distance(vt.second.first, vt.second.second);
}
return finalSize;
}
};
template <class C>
class BXVectorAccessor : public FWItemRandomAccessorBase {
public:
typedef C container_type;
BXVectorAccessor(const TClass *iClass) : FWItemRandomAccessorBase(iClass, typeid(typename C::value_type)) {}
REGISTER_FWITEMACCESSOR_METHODS();
const void *modelData(int iIndex) const override {
if (!getDataPtr())
return nullptr;
const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
return &(c->at(0, iIndex));
}
unsigned int size() const override {
if (!getDataPtr())
return 0;
const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
return c->size(0);
}
};
#endif
|