AliPhysics  b24dc27 (b24dc27)
 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 #include <TObject.h>
10 
11 class AliEmcalContainer;
12 
53 template <class T>
54 class AliEmcalIterableContainerT : public TObject {
55 public:
73  class iterator : public std::iterator<std::bidirectional_iterator_tag,
74  TObject,std::ptrdiff_t,
75  TObject **, TObject *>{
76  public:
77  iterator(const AliEmcalIterableContainerT<T> *cont, int currentpos, bool forward = true);
78  iterator(const iterator &ref);
79  iterator &operator=(const iterator &ref);
80  virtual ~iterator(){}
81 
82  bool operator!=(const iterator &ref) const;
83 
85  iterator operator++(int);
87  iterator operator--(int);
88 
89  T *operator*() const;
90 
91  private:
92  iterator();
93 
95  int fCurrent;
96  bool fForward;
97  };
98 
100  AliEmcalIterableContainerT(const AliEmcalContainer *cont, bool useAccept);
103 
108 
109  T *operator[](int index) const;
110 
115  operator int() const { return GetEntries(); }
116 
121  const AliEmcalContainer *GetContainer() const { return fkContainer; }
122 
123  int GetEntries() const;
124 
130  iterator begin() const { return iterator(this, 0, true); }
131 
137  iterator end() const { return iterator(this, GetEntries(), true); }
138 
144  iterator rbegin() const { return iterator(this, GetEntries()-1, false); }
145 
151  iterator rend() const { return iterator(this, -1, false); }
152 
153 protected:
154  void BuildAcceptIndices();
155 
156 private:
157  const AliEmcalContainer *fkContainer;
158  TArrayI fAcceptIndices;
159  Bool_t fUseAccepted;
160 };
161 
162 #include "AliEmcalContainer.h"
163 
167 template <class T>
169  TObject(),
170  fkContainer(NULL),
171  fAcceptIndices(),
172  fUseAccepted(kFALSE)
173 {
174 
175 }
176 
183 template <class T>
184 AliEmcalIterableContainerT<T>::AliEmcalIterableContainerT(const AliEmcalContainer *cont, bool useAccept):
185  TObject(),
186  fkContainer(cont),
187  fAcceptIndices(),
188  fUseAccepted(useAccept)
189 {
191 }
192 
198 template <class T>
200  TObject(ref),
201  fkContainer(ref.fkContainer),
202  fAcceptIndices(ref.fAcceptIndices),
203  fUseAccepted(ref.fUseAccepted)
204 {
205 
206 }
207 
214 template <class T>
216  TObject::operator=(ref);
217  if(this != &ref){
218  fkContainer = ref.fkContainer;
219  fAcceptIndices = ref.fAcceptIndices;
220  fUseAccepted = ref.fUseAccepted;
221  }
222  return *this;
223 }
224 
230 template <class T>
232  return fUseAccepted ? fAcceptIndices.GetSize() : fkContainer->GetNEntries();
233 }
234 
250 template <class T>
252  if(index < 0 || index >= GetEntries()) return NULL;
253  const AliEmcalContainer &contref = *fkContainer;
254  return static_cast<T*>(fUseAccepted ? contref[fAcceptIndices[index]] : contref[index]);
255 }
256 
262 template <class T>
264  fAcceptIndices.Set(fkContainer->GetNAcceptEntries());
265  int acceptCounter = 0;
266  for(int index = 0; index < fkContainer->GetNEntries(); index++){
267  UInt_t rejectionReason = 0;
268  if(fkContainer->AcceptObject(index, rejectionReason)) fAcceptIndices[acceptCounter++] = index;
269  }
270 }
271 
275 
288 template <class T>
290 fkData(cont),
291 fCurrent(currentpos),
292 fForward(forward)
293 {
294 
295 }
296 
302 template <class T>
304  fkData(ref.fkData),
305  fCurrent(ref.fCurrent),
306  fForward(ref.fForward)
307 {
308 
309 }
310 
317 template <class T>
319  if(this != &ref){
320  fkData = ref.fkData;
321  fCurrent = ref.fCurrent;
322  fForward = ref.fForward;
323  }
324  return *this;
325 }
326 
332 template <class T>
334  return fCurrent != ref.fCurrent;
335 }
336 
342 template <class T>
344  if(fForward) fCurrent++;
345  else fCurrent--;
346  return *this;
347 }
348 
354 template <class T>
356  if(fForward) fCurrent--;
357  else fCurrent++;
358  return *this;
359 }
360 
368 template <class T>
371  operator++();
372  return tmp;
373 }
374 
382 template <class T>
385  operator--();
386  return tmp;
387 }
388 
394 template <class T>
396  return (*fkData)[fCurrent];
397 }
398 
399 #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)