]>
Commit | Line | Data |
---|---|---|
dee1d5f1 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
5f91c9e8 | 16 | // $Id$ |
13985652 | 17 | // $MpId: AliMpMotifTypePadIterator.cxx,v 1.6 2006/05/24 13:58:41 ivana Exp $ |
5f91c9e8 | 18 | // Category: motif |
3d1463c8 | 19 | |
20 | //----------------------------------------------------------------------------- | |
5f91c9e8 | 21 | // Class AliMpMotifTypePadIterator |
22 | // ------------------------------- | |
23 | // Class, which defines an iterator over the pads of a given motif type | |
dbe945cc | 24 | // Included in AliRoot: 2003/05/02 |
5f91c9e8 | 25 | // Authors: David Guez, Ivana Hrivnacova; IPN Orsay |
3d1463c8 | 26 | //----------------------------------------------------------------------------- |
5f91c9e8 | 27 | |
28 | #include "AliMpMotifTypePadIterator.h" | |
29 | #include "AliMpMotifType.h" | |
30 | ||
13985652 | 31 | /// \cond CLASSIMP |
5f91c9e8 | 32 | ClassImp(AliMpMotifTypePadIterator) |
13985652 | 33 | /// \endcond |
5f91c9e8 | 34 | |
35 | //______________________________________________________________________________ | |
36 | AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(): | |
37 | AliMpVPadIterator(), | |
7d5d0cc5 | 38 | fkMotifType(0), |
5f91c9e8 | 39 | fCurrentPosition(AliMpIntPair::Invalid()) |
40 | { | |
dee1d5f1 | 41 | /// Default constructor, set the current position to "invalid" |
5f91c9e8 | 42 | } |
43 | ||
44 | //______________________________________________________________________________ | |
45 | AliMpMotifTypePadIterator::AliMpMotifTypePadIterator( | |
46 | const AliMpMotifType* motifType) | |
47 | : AliMpVPadIterator(), | |
7d5d0cc5 | 48 | fkMotifType(motifType), |
5f91c9e8 | 49 | fCurrentPosition(AliMpIntPair::Invalid()) |
50 | { | |
dee1d5f1 | 51 | /// Standard constructor, let *this to invalid position |
5f91c9e8 | 52 | } |
53 | ||
54 | //______________________________________________________________________________ | |
55 | AliMpMotifTypePadIterator::AliMpMotifTypePadIterator( | |
56 | const AliMpMotifTypePadIterator& right) | |
57 | : AliMpVPadIterator(right), | |
7d5d0cc5 | 58 | fkMotifType(right.fkMotifType), |
5f91c9e8 | 59 | fCurrentPosition(right.fCurrentPosition) |
60 | ||
61 | { | |
dee1d5f1 | 62 | /// Copy constructor |
5f91c9e8 | 63 | } |
64 | ||
65 | //______________________________________________________________________________ | |
66 | AliMpMotifTypePadIterator::~AliMpMotifTypePadIterator() | |
67 | { | |
dee1d5f1 | 68 | /// Destructor |
5f91c9e8 | 69 | } |
70 | ||
71 | // operators | |
72 | ||
73 | //______________________________________________________________________________ | |
74 | AliMpMotifTypePadIterator& | |
75 | AliMpMotifTypePadIterator::operator = (const AliMpMotifTypePadIterator& right) | |
76 | { | |
dee1d5f1 | 77 | /// Assignment operator. \n |
78 | /// If the right hand iterator isn't of good type | |
79 | /// the current operator is invalidated | |
5f91c9e8 | 80 | |
dee1d5f1 | 81 | // check assignment to self |
5f91c9e8 | 82 | if (this == &right) return *this; |
83 | ||
dee1d5f1 | 84 | // base class assignment |
5f91c9e8 | 85 | AliMpVPadIterator::operator=(right); |
86 | ||
7d5d0cc5 | 87 | fkMotifType = right.fkMotifType; |
5f91c9e8 | 88 | fCurrentPosition = right.fCurrentPosition; |
89 | ||
90 | return *this; | |
91 | } | |
92 | ||
93 | // | |
94 | //private methods | |
95 | // | |
96 | ||
97 | //______________________________________________________________________________ | |
98 | AliMpIntPair | |
99 | AliMpMotifTypePadIterator::FindFirstPadInLine(AliMpIntPair indices) const | |
100 | { | |
dee1d5f1 | 101 | /// Find the indices of the first pad in the same line |
13985652 | 102 | /// as the \a indices, and in column, at least equal, to the |
103 | /// one of \a indices | |
5f91c9e8 | 104 | |
7d5d0cc5 | 105 | if (!fkMotifType) return AliMpIntPair::Invalid(); |
5f91c9e8 | 106 | |
7d5d0cc5 | 107 | while (indices.GetFirst() < fkMotifType->GetNofPadsX()) { |
3635f34f | 108 | if (fkMotifType->HasPadByLocalIndices(indices)) return indices; |
5f91c9e8 | 109 | indices += AliMpIntPair(1,0); |
110 | } | |
111 | return AliMpIntPair::Invalid(); | |
112 | } | |
113 | ||
114 | //______________________________________________________________________________ | |
115 | Bool_t AliMpMotifTypePadIterator::IsValid() const | |
116 | { | |
dee1d5f1 | 117 | /// Is the iterator in a valid position? |
5f91c9e8 | 118 | |
7d5d0cc5 | 119 | return fkMotifType!=0 && fCurrentPosition.IsValid(); |
5f91c9e8 | 120 | } |
121 | ||
122 | // | |
123 | //public methods | |
124 | // | |
125 | ||
126 | //______________________________________________________________________________ | |
127 | void AliMpMotifTypePadIterator::First() | |
128 | { | |
dee1d5f1 | 129 | /// Reset the iterator, so that it points to the first available |
130 | /// pad in the motif type | |
5f91c9e8 | 131 | |
7d5d0cc5 | 132 | if (!fkMotifType) { |
5f91c9e8 | 133 | Invalidate(); |
134 | return ; | |
135 | } | |
136 | fCurrentPosition = AliMpIntPair(0,0); | |
3635f34f | 137 | if (fkMotifType->HasPadByLocalIndices(fCurrentPosition)) return; |
5f91c9e8 | 138 | |
139 | ||
140 | // if (0,0) is not available | |
141 | // place itself to the first avalable motif after (0,0) (if exists) | |
142 | // ++(*this); | |
143 | Next(); | |
144 | ||
145 | return; | |
146 | } | |
147 | ||
148 | //______________________________________________________________________________ | |
149 | void AliMpMotifTypePadIterator::Next() | |
150 | { | |
dee1d5f1 | 151 | /// Move the iterator to the next valid pad. |
5f91c9e8 | 152 | |
153 | //if (!IsValid()) return *this; | |
154 | if (!IsValid()) return; | |
155 | ||
7d5d0cc5 | 156 | while (fCurrentPosition.GetSecond() < fkMotifType->GetNofPadsY()){ |
5f91c9e8 | 157 | AliMpIntPair nextTry |
158 | = FindFirstPadInLine(fCurrentPosition + AliMpIntPair(1,0)); | |
159 | if (nextTry.IsValid()){ | |
160 | fCurrentPosition = nextTry; | |
161 | return; | |
162 | } | |
163 | fCurrentPosition.SetFirst(-1); | |
164 | fCurrentPosition.SetSecond(fCurrentPosition.GetSecond()+1); | |
165 | } | |
166 | ||
167 | // if the loop is finished, there's not available pads at all... | |
168 | Invalidate(); | |
169 | return; | |
170 | } | |
171 | ||
172 | //______________________________________________________________________________ | |
173 | Bool_t AliMpMotifTypePadIterator::IsDone() const | |
174 | { | |
dee1d5f1 | 175 | /// Is the iterator in the end ? |
176 | ||
5f91c9e8 | 177 | return !IsValid(); |
178 | } | |
179 | ||
180 | //______________________________________________________________________________ | |
181 | AliMpPad AliMpMotifTypePadIterator::CurrentItem() const | |
182 | { | |
dee1d5f1 | 183 | /// Return current pad. |
5f91c9e8 | 184 | |
7d5d0cc5 | 185 | if (!fkMotifType) |
5f91c9e8 | 186 | return AliMpPad::Invalid(); |
187 | else | |
188 | return AliMpPad(AliMpIntPair::Invalid(), | |
189 | fCurrentPosition,TVector2(),TVector2()); | |
190 | } | |
191 | ||
192 | //______________________________________________________________________________ | |
193 | void AliMpMotifTypePadIterator::Invalidate() | |
194 | { | |
dee1d5f1 | 195 | /// Let the iterator point to the invalid position |
196 | ||
5f91c9e8 | 197 | fCurrentPosition = AliMpIntPair::Invalid(); |
198 | ||
199 | } | |
200 |