CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: FWItemRandomAccessor.h,v 1.7 2010/06/09 13:21:00 mccauley Exp $
11 //
12 
13 // system include files
14 #include "Reflex/Object.h"
15 
16 // user include files
19 
20 // forward declarations
21 
30 {
31 public:
32  virtual ~FWItemRandomAccessorBase();
33 
34  const void* data() const;
35  const TClass* type() const;
36  const TClass* modelType() const;
37 
38  bool isCollection() const;
39 
40  void setData(const ROOT::Reflex::Object&);
41  virtual void reset();
42 
43 protected:
44  void *getDataPtr() const;
45  FWItemRandomAccessorBase(const TClass *type, const type_info &modelTypeName);
46  const TClass* m_type;
47  const TClass* m_modelType;
48  mutable void* m_data;
49 
50 private:
51  FWItemRandomAccessorBase(const FWItemRandomAccessorBase&); // stop default
52 
53  const FWItemRandomAccessorBase& operator=(const FWItemRandomAccessorBase&); // stop default
54 };
55 
73 template <class C, class V = typename C::value_type>
75 {
76  typedef C container_type;
78 public:
79  FWItemRandomAccessor(const TClass *iClass)
81  {}
82 
84 
85  // ---------- const member functions ---------------------
86  const void* modelData(int iIndex) const
87  {
88  if (!getDataPtr())
89  return 0;
90  return &(reinterpret_cast<container_type *>(getDataPtr())->operator[](iIndex));
91  }
92 
93  unsigned int size() const
94  {
95  if (!getDataPtr())
96  return 0;
97  return reinterpret_cast<const container_type*>(getDataPtr())->size();
98  }
99 };
100 
108 template <class C, class COLL = typename C::value_type, class V = typename COLL::value_type >
110 {
111 public:
112  typedef C container_type;
113  typedef COLL collection_type;
115 
116  FWItemDetSetAccessor(const TClass *iClass)
118  {}
119 
121 
122  const void* modelData(int iIndex) const
123  {
124  if (!getDataPtr())
125  return 0;
126  const container_type *c = reinterpret_cast<const container_type*>(getDataPtr());
127  size_t collectionOffset = 0;
128  for (typename container_type::const_iterator ci = c->begin(), ce = c->end(); ci != ce; ++ci)
129  {
130  size_t i = iIndex - collectionOffset;
131  if (i < ci->size())
132  return &(ci->operator[](i));
133  collectionOffset += ci->size();
134  }
135 
136  return 0;
137  }
138 
139  unsigned int size() const
140  {
141  if (!getDataPtr())
142  return 0;
143  const container_type *c = reinterpret_cast<const container_type*>(getDataPtr());
144  size_t finalSize = 0;
145 
146  for (typename container_type::const_iterator i = c->begin(), e = c->end(); i != e; ++i)
147  finalSize += i->size();
148 
149  return finalSize;
150  }
151 };
152 
155 template <class C, class COLL = typename C::value_type, class V = typename COLL::value_type >
157 {
158 public:
159  typedef C container_type;
160  typedef COLL collection_type;
162 
163  FWItemNewDetSetAccessor(const TClass *iClass)
165  {}
166 
168 
169  const void* modelData(int iIndex) const
170  {
171  if (!getDataPtr())
172  return 0;
173  const container_type *c = reinterpret_cast<const container_type*>(getDataPtr());
174  if (iIndex < 0)
175  return 0;
176 
177  return &(c->data().operator[](iIndex));
178  }
179 
180  unsigned int size() const
181  {
182  if (!getDataPtr())
183  return 0;
184  const container_type *c = reinterpret_cast<const container_type*>(getDataPtr());
185  return c->dataSize();
186  }
187 };
188 
189 template <class C, class R = typename C::Range, class V = typename R::value_type>
191 {
192 public:
193  typedef C container_type;
194  typedef R range_type;
195  typedef V value_type;
196 
197  FWItemRangeAccessor(const TClass *iClass)
198  : FWItemRandomAccessorBase(iClass, typeid(value_type))
199  {}
200 
202 
203  const void* modelData(int iIndex) const
204  {
205  if (!getDataPtr())
206  return 0;
207  const container_type *c = reinterpret_cast<const container_type*>(getDataPtr());
208  size_t collectionOffset = 0;
209  for (typename container_type::const_iterator ci = c->begin(), ce = c->end(); ci != ce; ++ci)
210  {
211  size_t i = iIndex - collectionOffset;
212  if (i < std::distance(ci->first, ci->second))
213  return &(*(ci + i));
214  collectionOffset += ci->size();
215  }
216 
217  return 0;
218  }
219 
220  unsigned int size() const
221  {
222  if (!getDataPtr())
223  return 0;
224  const container_type *c = reinterpret_cast<const container_type*>(getDataPtr());
225  size_t finalSize = 0;
226 
227  for (typename range_type::const_iterator ci = c->begin(), ce = c->end(); ci != ce; ++ci)
228  finalSize += std::distance(ci->first, ci->second);
229 
230  return finalSize;
231  }
232 };
233 
234 template <class C, class V>
236 {
237 public:
238  typedef C container_type;
239  typedef V value_type;
240 
241  FWItemMuonDigiAccessor(const TClass *iClass)
242  : FWItemRandomAccessorBase(iClass, typeid(value_type))
243  {}
244 
246 
247  const void* modelData(int iIndex) const
248  {
249  if (!getDataPtr())
250  return 0;
251  const container_type *c = reinterpret_cast<const container_type*>(getDataPtr());
252  size_t collectionOffset = 0;
253 
254  for (typename container_type::DigiRangeIterator ci = c->begin(), ce = c->end(); ci != ce; ++ci)
255  {
256  int i = iIndex - collectionOffset;
257 
259 
260 
261  if (i < std::distance(vt.second.first, vt.second.second))
262  return &(*(vt.second.first + i));
263  collectionOffset += std::distance(vt.second.first, vt.second.second);
264  }
265 
266  return 0;
267  }
268 
269  unsigned int size() const
270  {
271  if (!getDataPtr())
272  return 0;
273  const container_type *c = reinterpret_cast<const container_type*>(getDataPtr());
274  size_t finalSize = 0;
275 
276  for (typename container_type::DigiRangeIterator ci = c->begin(), ce = c->end(); ci != ce; ++ci)
277  {
279  finalSize += std::distance(vt.second.first, vt.second.second);
280  }
281 
282  return finalSize;
283  }
284 };
285 
286 #endif
int i
Definition: DBlmapReader.cc:9
const TClass * type() const
void setData(const ROOT::Reflex::Object &)
FWItemDetSetAccessor(const TClass *iClass)
const void * data() const
const FWItemRandomAccessorBase & operator=(const FWItemRandomAccessorBase &)
FWItemRandomAccessorBase(const TClass *type, const type_info &modelTypeName)
FWItemRandomAccessor(const TClass *iClass)
const void * modelData(int iIndex) const
unsigned int size() const
unsigned int size() const
const void * modelData(int iIndex) const
FWItemMuonDigiAccessor(const TClass *iClass)
const void * modelData(int iIndex) const
Container::value_type value_type
FWItemNewDetSetAccessor(const TClass *iClass)
const void * modelData(int iIndex) const
unsigned int size() const
unsigned int size() const
unsigned int size() const
const void * modelData(int iIndex) const
const TClass * modelType() const
FWItemRangeAccessor(const TClass *iClass)