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 {
30 public:
31  ~FWItemRandomAccessorBase() override;
32 
33  const void* data() const override;
34  const TClass* type() const override;
35  const TClass* modelType() const override;
36 
37  bool isCollection() const override;
38 
39  void setData(const edm::ObjectWithDict&) override;
40  void reset() override;
41 
42 protected:
43  void *getDataPtr() const;
44  FWItemRandomAccessorBase(const TClass *type, const std::type_info &modelTypeName);
45  const TClass* m_type;
46  const TClass* m_modelType;
47  mutable void* m_data;
48 
49 private:
50  FWItemRandomAccessorBase(const FWItemRandomAccessorBase&) = delete; // stop default
51 
52  const FWItemRandomAccessorBase& operator=(const FWItemRandomAccessorBase&) = delete; // stop default
53 };
54 
72 template <class C, class V = typename C::value_type>
74 {
75  typedef C container_type;
77 public:
78  FWItemRandomAccessor(const TClass *iClass)
79  : FWItemRandomAccessorBase(iClass, typeid(container_value_type))
80  {}
81 
83 
84  // ---------- const member functions ---------------------
85  const void* modelData(int iIndex) const override
86  {
87  if (!getDataPtr())
88  return nullptr;
89  return &(reinterpret_cast<container_type *>(getDataPtr())->operator[](iIndex));
90  }
91 
92  unsigned int size() const override
93  {
94  if (!getDataPtr())
95  return 0;
96  return reinterpret_cast<const container_type*>(getDataPtr())->size();
97  }
98 };
99 
107 template <class C, class COLL = typename C::value_type, class V = typename COLL::value_type >
109 {
110 public:
111  typedef C container_type;
112  typedef COLL collection_type;
114 
115  FWItemDetSetAccessor(const TClass *iClass)
116  : FWItemRandomAccessorBase(iClass, typeid(collection_value_type))
117  {}
118 
120 
121  const void* modelData(int iIndex) const override
122  {
123  if (!getDataPtr())
124  return nullptr;
125  const container_type *c = reinterpret_cast<const container_type*>(getDataPtr());
126  size_t collectionOffset = 0;
127  for (typename container_type::const_iterator ci = c->begin(), ce = c->end(); ci != ce; ++ci)
128  {
129  size_t i = iIndex - collectionOffset;
130  if (i < ci->size())
131  return &(ci->operator[](i));
132  collectionOffset += ci->size();
133  }
134 
135  return nullptr;
136  }
137 
138  unsigned int size() const override
139  {
140  if (!getDataPtr())
141  return 0;
142  const container_type *c = reinterpret_cast<const container_type*>(getDataPtr());
143  size_t finalSize = 0;
144 
145  for (typename container_type::const_iterator i = c->begin(), e = c->end(); i != e; ++i)
146  finalSize += i->size();
147 
148  return finalSize;
149  }
150 };
151 
154 template <class C, class COLL = typename C::value_type, class V = typename COLL::value_type >
156 {
157 public:
158  typedef C container_type;
159  typedef COLL collection_type;
161 
162  FWItemNewDetSetAccessor(const TClass *iClass)
163  : FWItemRandomAccessorBase(iClass, typeid(collection_value_type))
164  {}
165 
167 
168  const void* modelData(int iIndex) const override
169  {
170  if (!getDataPtr())
171  return nullptr;
172  const container_type *c = reinterpret_cast<const container_type*>(getDataPtr());
173  if (iIndex < 0)
174  return nullptr;
175 
176  return &(c->data().operator[](iIndex));
177  }
178 
179  unsigned int size() const override
180  {
181  if (!getDataPtr())
182  return 0;
183  const container_type *c = reinterpret_cast<const container_type*>(getDataPtr());
184  return c->dataSize();
185  }
186 };
187 
188 template <class C, class R = typename C::Range, class V = typename R::value_type>
190 {
191 public:
192  typedef C container_type;
193  typedef R range_type;
194  typedef V value_type;
195 
196  FWItemRangeAccessor(const TClass *iClass)
197  : FWItemRandomAccessorBase(iClass, typeid(value_type))
198  {}
199 
201 
202  const void* modelData(int iIndex) const override
203  {
204  if (!getDataPtr())
205  return nullptr;
206  const container_type *c = reinterpret_cast<const container_type*>(getDataPtr());
207  size_t collectionOffset = 0;
208  for (typename container_type::const_iterator ci = c->begin(), ce = c->end(); ci != ce; ++ci)
209  {
210  size_t i = iIndex - collectionOffset;
211  if (i < std::distance(ci->first, ci->second))
212  return &(*(ci + i));
213  collectionOffset += ci->size();
214  }
215 
216  return nullptr;
217  }
218 
219  unsigned int size() const override
220  {
221  if (!getDataPtr())
222  return 0;
223  const container_type *c = reinterpret_cast<const container_type*>(getDataPtr());
224  size_t finalSize = 0;
225 
226  for (typename range_type::const_iterator ci = c->begin(), ce = c->end(); ci != ce; ++ci)
227  finalSize += std::distance(ci->first, ci->second);
228 
229  return finalSize;
230  }
231 };
232 
233 template <class C, class V>
235 {
236 public:
237  typedef C container_type;
238  typedef V value_type;
239 
240  FWItemMuonDigiAccessor(const TClass *iClass)
241  : FWItemRandomAccessorBase(iClass, typeid(value_type))
242  {}
243 
245 
246  const void* modelData(int iIndex) const override
247  {
248  if (!getDataPtr())
249  return nullptr;
250  const container_type *c = reinterpret_cast<const container_type*>(getDataPtr());
251  size_t collectionOffset = 0;
252 
253  for (typename container_type::DigiRangeIterator ci = c->begin(), ce = c->end(); ci != ce; ++ci)
254  {
255  int i = iIndex - collectionOffset;
256 
258 
259 
260  if (i < std::distance(vt.second.first, vt.second.second))
261  return &(*(vt.second.first + i));
262  collectionOffset += std::distance(vt.second.first, vt.second.second);
263  }
264 
265  return nullptr;
266  }
267 
268  unsigned int size() const override
269  {
270  if (!getDataPtr())
271  return 0;
272  const container_type *c = reinterpret_cast<const container_type*>(getDataPtr());
273  size_t finalSize = 0;
274 
275  for (typename container_type::DigiRangeIterator ci = c->begin(), ce = c->end(); ci != ce; ++ci)
276  {
278  finalSize += std::distance(vt.second.first, vt.second.second);
279  }
280 
281  return finalSize;
282  }
283 };
284 
285 #endif
#define REGISTER_FWITEMACCESSOR_METHODS()
const TClass * type() const override
const void * modelData(int iIndex) const override
const TClass * modelType() const override
FWItemDetSetAccessor(const TClass *iClass)
const void * modelData(int iIndex) const override
const FWItemRandomAccessorBase & operator=(const FWItemRandomAccessorBase &)=delete
FWItemRandomAccessor(const TClass *iClass)
const void * modelData(int iIndex) const override
const void * modelData(int iIndex) const override
const void * data() const override
FWItemMuonDigiAccessor(const TClass *iClass)
unsigned int size() const override
FWItemRandomAccessorBase(const TClass *type, const std::type_info &modelTypeName)
FWItemNewDetSetAccessor(const TClass *iClass)
unsigned int size() const override
unsigned int size() const override
unsigned int size() 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
bool isCollection() const override
virtual unsigned int size() const =0
FWItemRangeAccessor(const TClass *iClass)