test
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 //
11 
12 // system include files
14 
15 // user include files
18 
19 // forward declarations
20 
29 {
30 public:
31  virtual ~FWItemRandomAccessorBase();
32 
33  const void* data() const;
34  const TClass* type() const;
35  const TClass* modelType() const;
36 
37  bool isCollection() const;
38 
39  void setData(const edm::ObjectWithDict&);
40  virtual void reset();
41 
42 protected:
43  void *getDataPtr() const;
44  FWItemRandomAccessorBase(const TClass *type, const 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&); // stop default
51 
52  const FWItemRandomAccessorBase& operator=(const FWItemRandomAccessorBase&); // 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)
80  {}
81 
83 
84  // ---------- const member functions ---------------------
85  const void* modelData(int iIndex) const
86  {
87  if (!getDataPtr())
88  return 0;
89  return &(reinterpret_cast<container_type *>(getDataPtr())->operator[](iIndex));
90  }
91 
92  unsigned int size() const
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)
117  {}
118 
120 
121  const void* modelData(int iIndex) const
122  {
123  if (!getDataPtr())
124  return 0;
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 0;
136  }
137 
138  unsigned int size() const
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)
164  {}
165 
167 
168  const void* modelData(int iIndex) const
169  {
170  if (!getDataPtr())
171  return 0;
172  const container_type *c = reinterpret_cast<const container_type*>(getDataPtr());
173  if (iIndex < 0)
174  return 0;
175 
176  return &(c->data().operator[](iIndex));
177  }
178 
179  unsigned int size() const
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
203  {
204  if (!getDataPtr())
205  return 0;
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 0;
217  }
218 
219  unsigned int size() const
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
247  {
248  if (!getDataPtr())
249  return 0;
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 0;
266  }
267 
268  unsigned int size() const
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()
int i
Definition: DBlmapReader.cc:9
const TClass * type() const
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
FWItemNewDetSetAccessor(const TClass *iClass)
void setData(const edm::ObjectWithDict &)
override if id of an object should be different than the index
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)