StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StiSortedHitIterator.h
1 #ifndef StiSortedHitIterator_HH
2 #define StiSortedHitIterator_HH
3 #ifdef GNU_GCC
4  #if __GNUC__<3
5  #define HACK_forward_iterator
6  #endif
7 #endif
8 #include <vector>
9 #include <iterator>
10 using namespace std;
11 #include "StiHit.h"
12 typedef StiHit Hit_t;
13 #include "StiDetector.h"
14 #include "StiHitContainer.h"
15 
22 #ifndef HACK_forward_iterator
23 : public iterator<forward_iterator_tag, Hit_t, ptrdiff_t, Hit_t*, Hit_t&>
24 #else
25  : public forward_iterator<Hit_t, int>
26 #endif
27 {
28 public:
33  vector<StiDetector*>::iterator firstDet,
34  vector<StiDetector*>::iterator lastDet);
38  const StiSortedHitIterator& operator=(const StiSortedHitIterator&iter);
41 
43  bool operator==(const StiSortedHitIterator& rhs);
45  bool operator!=(const StiSortedHitIterator& rhs);
47  StiHit& operator*();
49  StiSortedHitIterator& operator++();
51  StiSortedHitIterator operator++(int);
53  //StiSortedHitIterator end();
54 
55 private:
57  StiHit * _currentHit;
59  StiHitContainer * _hitContainer;
61  vector<StiDetector*>::iterator _currentDet;
63  vector<StiDetector*>::iterator _firstDet;
65  vector<StiDetector*>::iterator _lastDet;
67  vector<StiHit*>::iterator _currentDetHit;
69  vector<StiHit*>::iterator _lastDetHit;
70 };
71 
72 
73 
76 {
77  _currentHit = iter._currentHit;
78  _hitContainer = iter._hitContainer;
79  _currentDet = iter._currentDet;
80  _firstDet = iter._firstDet;
81  _lastDet = iter._lastDet;
82  _currentDetHit = iter._currentDetHit;
83  _lastDetHit = iter._lastDetHit;
84  return *this;
85 }
86 
87 
91 {
92  return _currentHit==rhs._currentHit;
93 }
94 
98 {
99  return _currentHit!=rhs._currentHit;
100 }
101 
105 {
106  assert(_currentHit);
107  return *_currentHit;
108 }
109 
115 {
116  // if this iterator points to a null hit, return because there is nothing to do.
117  // This guarantees the end() iterator will behave properly.
118  if (_currentHit==0)
119  return *this;
120 
121  ++_currentDetHit;
122  if (_currentDetHit<_lastDetHit)
123  {
124  _currentHit = *_currentDetHit;
125  }
126  else
127  {
128  // Reached end of current detector hits
129  // Must go to next detector with hits.
130  if (_currentDet<_lastDet)
131  {
132  // Still have detectors to traverse, find next one which
133  // has hits.
134  bool go = true;
135  while (_currentDet<_lastDet && go )
136  {
137  ++_currentDet;
138  if (_currentDet<_lastDet )
139  {
140  // valid detector
141  if (_hitContainer->hasDetector(*_currentDet)) {
142 
143  _currentDetHit = _hitContainer->hitsBegin(*_currentDet);
144  _lastDetHit = _hitContainer->hitsEnd(*_currentDet);
145  if (_currentDetHit < _lastDetHit)
146  {
147  // current detector has hits
148  // done for now.
149  _currentHit = *_currentDetHit;
150  go = false;
151  }
152  }
153  }
154  else
155  {
156  // reached past the last detector
157  // no more hits to serve
158  _currentHit = 0;
159  _currentDet = _lastDet;
160  _currentDetHit = _lastDetHit;
161  }
162  }
163  }
164  else // !(_currentDet<_lastDet)
165  {
166  _currentHit = 0;
167  _currentDet = _lastDet;
168  _currentDetHit = _lastDetHit;
169  }
170  }
171  return *this;
172 }
173 
174 
180 {
181  StiSortedHitIterator temp = *this;
182  ++(*this);
183  return temp;
184 }
185 
186 #endif
StiSortedHitIterator & operator++()
prefix
Definition: StiHit.h:51
bool operator==(const StiSortedHitIterator &rhs)
equality:
~StiSortedHitIterator()
Destructor.
bool operator!=(const StiSortedHitIterator &rhs)
inequlity
const StiSortedHitIterator & operator=(const StiSortedHitIterator &iter)
Asignment operator.