AliPhysics  1e965c0 (1e965c0)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliEmcalIterableContainer.h
Go to the documentation of this file.
1 #ifndef ALIEMCALITERABLECONTAINER_H
2 #define ALIEMCALITERABLECONTAINER_H
3 /* Copyright(c) 1998-2016, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice */
5 
6 #include <iterator>
7 
8 #include <TArrayI.h>
9 
10 class AliEmcalContainer;
11 
52 template <class T>
54 public:
72  class iterator : public std::iterator<std::bidirectional_iterator_tag,
73  TObject,std::ptrdiff_t,
74  TObject **, TObject *>{
75  public:
76  iterator(const AliEmcalIterableContainerT<T> *cont, int currentpos, bool forward = true);
77  iterator(const iterator &ref);
78  iterator &operator=(const iterator &ref);
79  virtual ~iterator(){}
80 
81  bool operator!=(const iterator &ref) const;
82 
84  iterator operator++(int);
86  iterator operator--(int);
87 
88  T *operator*() const;
89 
90  private:
91  iterator();
92 
94  int fCurrent;
95  bool fForward;
96  };
97 
99  AliEmcalIterableContainerT(const AliEmcalContainer *cont, bool useAccept);
102 
107 
108  T *operator[](int index) const;
109 
114  operator int() const { return GetEntries(); }
115 
120  const AliEmcalContainer *GetContainer() const { return fkContainer; }
121 
122  int GetEntries() const;
123 
129  iterator begin() const { return iterator(this, 0, true); }
130 
136  iterator end() const { return iterator(this, GetEntries(), true); }
137 
143  iterator rbegin() const { return iterator(this, GetEntries()-1, false); }
144 
150  iterator rend() const { return iterator(this, -1, false); }
151 
152 protected:
153  void BuildAcceptIndices();
154 
155 private:
156  const AliEmcalContainer *fkContainer;
157  TArrayI fAcceptIndices;
158  Bool_t fUseAccepted;
159 };
160 
161 #include "AliEmcalContainer.h"
162 
166 template <class T>
168  fkContainer(NULL),
169  fAcceptIndices(),
170  fUseAccepted(kFALSE)
171 {
172 
173 }
174 
181 template <class T>
182 AliEmcalIterableContainerT<T>::AliEmcalIterableContainerT(const AliEmcalContainer *cont, bool useAccept):
183  fkContainer(cont),
184  fAcceptIndices(),
185  fUseAccepted(useAccept)
186 {
188 }
189 
195 template <class T>
197  fkContainer(ref.fkContainer),
198  fAcceptIndices(ref.fAcceptIndices),
199  fUseAccepted(ref.fUseAccepted)
200 {
201 
202 }
203 
210 template <class T>
212  if(this != &ref){
213  fkContainer = ref.fkContainer;
214  fAcceptIndices = ref.fAcceptIndices;
215  fUseAccepted = ref.fUseAccepted;
216  }
217  return *this;
218 }
219 
225 template <class T>
227  return fUseAccepted ? fAcceptIndices.GetSize() : fkContainer->GetNEntries();
228 }
229 
245 template <class T>
247  if(index < 0 || index >= GetEntries()) return NULL;
248  const AliEmcalContainer &contref = *fkContainer;
249  return static_cast<T*>(fUseAccepted ? contref[fAcceptIndices[index]] : contref[index]);
250 }
251 
257 template <class T>
259  fAcceptIndices.Set(fkContainer->GetNAcceptEntries());
260  int acceptCounter = 0;
261  for(int index = 0; index < fkContainer->GetNEntries(); index++){
262  UInt_t rejectionReason = 0;
263  if(fkContainer->AcceptObject(index, rejectionReason)) fAcceptIndices[acceptCounter++] = index;
264  }
265 }
266 
270 
283 template <class T>
285 fkData(cont),
286 fCurrent(currentpos),
287 fForward(forward)
288 {
289 
290 }
291 
297 template <class T>
299  fkData(ref.fkData),
300  fCurrent(ref.fCurrent),
301  fForward(ref.fForward)
302 {
303 
304 }
305 
312 template <class T>
314  if(this != &ref){
315  fkData = ref.fkData;
316  fCurrent = ref.fCurrent;
317  fForward = ref.fForward;
318  }
319  return *this;
320 }
321 
327 template <class T>
329  return fCurrent != ref.fCurrent;
330 }
331 
337 template <class T>
339  if(fForward) fCurrent++;
340  else fCurrent--;
341  return *this;
342 }
343 
349 template <class T>
351  if(fForward) fCurrent--;
352  else fCurrent++;
353  return *this;
354 }
355 
363 template <class T>
366  operator++();
367  return tmp;
368 }
369 
377 template <class T>
380  operator--();
381  return tmp;
382 }
383 
389 template <class T>
391  return (*fkData)[fCurrent];
392 }
393 
394 #endif /* ALIEMCALITERABLECONTAINER_H */
const AliEmcalContainer * GetContainer() const
bool operator!=(const iterator &ref) const
TArrayI fAcceptIndices
Array of accepted indices.
bool fForward
use forward or backward direction
bidirectional stl iterator over the EMCAL iterable container
const AliEmcalContainer * fkContainer
Container to be iterated over.
const AliEmcalIterableContainerT< T > * fkData
container with data
Bool_t fUseAccepted
Switch between accepted and all objects.
int fCurrent
current index in the container
iterator & operator=(const iterator &ref)
AliEmcalIterableContainerT< T > & operator=(const AliEmcalIterableContainerT< T > &ref)