CMS 3D CMS Logo

FWItemRandomAccessor.h
Go to the documentation of this file.
1 #ifndef Fireworks_Core_FWItemRandomAccessor_h
2 #define Fireworks_Core_FWItemRandomAccessor_h
3 // -*- C++ -*-
4 //
5 // Package: Core
6 // Class : FWItemRandomAccessor
7 //
8 // Original Author: Giulio Eulisse
9 // Created: Thu Feb 18 15:19:44 EDT 2008
10 //
11 
12 // system include files
14 
15 // user include files
18 
19 // forward declarations
20 
29 public:
30  ~FWItemRandomAccessorBase() override;
31 
32  const void *data() const override;
33  const TClass *type() const override;
34  const TClass *modelType() const override;
35 
36  bool isCollection() const override;
37 
38  void setData(const edm::ObjectWithDict &) override;
39  void reset() override;
40 
41 protected:
42  void *getDataPtr() const;
43  FWItemRandomAccessorBase(const TClass *type, const std::type_info &modelTypeName);
44  const TClass *m_type;
45  const TClass *m_modelType;
46  mutable void *m_data;
47 
48 public:
49  FWItemRandomAccessorBase(const FWItemRandomAccessorBase &) = delete; // stop default
50 
51  const FWItemRandomAccessorBase &operator=(const FWItemRandomAccessorBase &) = delete; // stop default
52 };
53 
71 template <class C, class V = typename C::value_type>
73  typedef C container_type;
75 
76 public:
77  FWItemRandomAccessor(const TClass *iClass) : FWItemRandomAccessorBase(iClass, typeid(container_value_type)) {}
78 
80 
81  // ---------- const member functions ---------------------
82  const void *modelData(int iIndex) const override {
83  if (!getDataPtr())
84  return nullptr;
85  return &(reinterpret_cast<container_type *>(getDataPtr())->operator[](iIndex));
86  }
87 
88  unsigned int size() const override {
89  if (!getDataPtr())
90  return 0;
91  return reinterpret_cast<const container_type *>(getDataPtr())->size();
92  }
93 };
94 
102 template <class C, class COLL = typename C::value_type, class V = typename COLL::value_type>
104 public:
105  typedef C container_type;
106  typedef COLL collection_type;
108 
109  FWItemDetSetAccessor(const TClass *iClass) : FWItemRandomAccessorBase(iClass, typeid(collection_value_type)) {}
110 
112 
113  const void *modelData(int iIndex) const override {
114  if (!getDataPtr())
115  return nullptr;
116  const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
117  size_t collectionOffset = 0;
118  for (typename container_type::const_iterator ci = c->begin(), ce = c->end(); ci != ce; ++ci) {
119  size_t i = iIndex - collectionOffset;
120  if (i < ci->size())
121  return &(ci->operator[](i));
122  collectionOffset += ci->size();
123  }
124 
125  return nullptr;
126  }
127 
128  unsigned int size() const override {
129  if (!getDataPtr())
130  return 0;
131  const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
132  size_t finalSize = 0;
133 
134  for (typename container_type::const_iterator i = c->begin(), e = c->end(); i != e; ++i)
135  finalSize += i->size();
136 
137  return finalSize;
138  }
139 };
140 
143 template <class C, class COLL = typename C::value_type, class V = typename COLL::value_type>
145 public:
146  typedef C container_type;
147  typedef COLL collection_type;
149 
150  FWItemNewDetSetAccessor(const TClass *iClass) : FWItemRandomAccessorBase(iClass, typeid(collection_value_type)) {}
151 
153 
154  const void *modelData(int iIndex) const override {
155  if (!getDataPtr())
156  return nullptr;
157  const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
158  if (iIndex < 0)
159  return nullptr;
160 
161  return &(c->data().operator[](iIndex));
162  }
163 
164  unsigned int size() const override {
165  if (!getDataPtr())
166  return 0;
167  const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
168  return c->dataSize();
169  }
170 };
171 
172 template <class C, class R = typename C::Range, class V = typename R::value_type>
174 public:
175  typedef C container_type;
176  typedef R range_type;
177  typedef V value_type;
178 
179  FWItemRangeAccessor(const TClass *iClass) : FWItemRandomAccessorBase(iClass, typeid(value_type)) {}
180 
182 
183  const void *modelData(int iIndex) const override {
184  if (!getDataPtr())
185  return nullptr;
186  const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
187  size_t collectionOffset = 0;
188  for (typename container_type::const_iterator ci = c->begin(), ce = c->end(); ci != ce; ++ci) {
189  size_t i = iIndex - collectionOffset;
190  if (i < std::distance(ci->first, ci->second))
191  return &(*(ci + i));
192  collectionOffset += ci->size();
193  }
194 
195  return nullptr;
196  }
197 
198  unsigned int size() const override {
199  if (!getDataPtr())
200  return 0;
201  const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
202  size_t finalSize = 0;
203 
204  for (typename range_type::const_iterator ci = c->begin(), ce = c->end(); ci != ce; ++ci)
205  finalSize += std::distance(ci->first, ci->second);
206 
207  return finalSize;
208  }
209 };
210 
211 template <class C, class V>
213 public:
214  typedef C container_type;
215  typedef V value_type;
216 
217  FWItemMuonDigiAccessor(const TClass *iClass) : FWItemRandomAccessorBase(iClass, typeid(value_type)) {}
218 
220 
221  const void *modelData(int iIndex) const override {
222  if (!getDataPtr())
223  return nullptr;
224  const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
225  size_t collectionOffset = 0;
226 
227  for (typename container_type::DigiRangeIterator ci = c->begin(), ce = c->end(); ci != ce; ++ci) {
228  int i = iIndex - collectionOffset;
229 
231 
232  if (i < std::distance(vt.second.first, vt.second.second))
233  return &(*(vt.second.first + i));
234  collectionOffset += std::distance(vt.second.first, vt.second.second);
235  }
236 
237  return nullptr;
238  }
239 
240  unsigned int size() const override {
241  if (!getDataPtr())
242  return 0;
243  const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
244  size_t finalSize = 0;
245 
246  for (typename container_type::DigiRangeIterator ci = c->begin(), ce = c->end(); ci != ce; ++ci) {
248  finalSize += std::distance(vt.second.first, vt.second.second);
249  }
250 
251  return finalSize;
252  }
253 };
254 
255 template <class C>
257 public:
258  typedef C container_type;
259 
260  BXVectorAccessor(const TClass *iClass) : FWItemRandomAccessorBase(iClass, typeid(typename C::value_type)) {}
261 
263 
264  const void *modelData(int iIndex) const override {
265  if (!getDataPtr())
266  return nullptr;
267 
268  const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
269 
270  return &(c->at(0, iIndex));
271  }
272 
273  unsigned int size() const override {
274  if (!getDataPtr())
275  return 0;
276 
277  const container_type *c = reinterpret_cast<const container_type *>(getDataPtr());
278 
279  return c->size(0);
280  }
281 };
282 
283 #endif
#define REGISTER_FWITEMACCESSOR_METHODS()
unsigned int size() const override
const void * modelData(int iIndex) const override
FWItemDetSetAccessor(const TClass *iClass)
const void * modelData(int iIndex) const override
const void * data() const override
const FWItemRandomAccessorBase & operator=(const FWItemRandomAccessorBase &)=delete
unsigned int size() const override
FWItemRandomAccessor(const TClass *iClass)
bool isCollection() const override
const void * modelData(int iIndex) const override
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t V
unsigned int size() const override
unsigned int size() const override
const TClass * type() const override
FWItemMuonDigiAccessor(const TClass *iClass)
FWItemRandomAccessorBase(const TClass *type, const std::type_info &modelTypeName)
FWItemNewDetSetAccessor(const TClass *iClass)
BXVectorAccessor(const TClass *iClass)
unsigned int size() const override
const TClass * modelType() const override
const void * modelData(int iIndex) const override
const void * modelData(int iIndex) const override
unsigned int size() const override
void setData(const edm::ObjectWithDict &) override
override if id of an object should be different than the index
const void * modelData(int iIndex) const override
FWItemRangeAccessor(const TClass *iClass)