]>
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: AliMpNeighboursPadIterator.cxx,v 1.12 2006/05/24 13:58:46 ivana Exp $ |
5f91c9e8 | 18 | // Category: sector |
3d1463c8 | 19 | |
20 | //----------------------------------------------------------------------------- | |
5f91c9e8 | 21 | // Class AliMpNeighboursPadIterator |
22 | // -------------------------------- | |
23 | // Class, which defines an iterator over the pads surrounding a given pad | |
dbe945cc | 24 | // Included in AliRoot: 2003/05/02 |
5f91c9e8 | 25 | // Authors: David Guez, Ivana Hrivnacova; IPN Orsay |
3d1463c8 | 26 | //----------------------------------------------------------------------------- |
5f91c9e8 | 27 | |
5f91c9e8 | 28 | #include "AliMpNeighboursPadIterator.h" |
29 | #include "AliMpIntPair.h" | |
0fef3734 | 30 | #include "AliMpVSegmentation.h" |
5f91c9e8 | 31 | #include "AliMpRow.h" |
32 | #include "AliMpConstants.h" | |
33 | ||
97186a3f | 34 | #include "AliLog.h" |
35 | ||
63ed9c6b | 36 | #include <TVector2.h> |
5f91c9e8 | 37 | |
13985652 | 38 | /// \cond CLASSIMP |
39 | ClassImp(AliMpNeighboursPadIterator) | |
40 | /// \endcond | |
41 | ||
5f91c9e8 | 42 | const UInt_t AliMpNeighboursPadIterator::fgkInvalidIndex = 9999; |
43 | //never so much neighbours... | |
44 | ||
45 | //______________________________________________________________________________ | |
46 | AliMpNeighboursPadIterator::AliMpNeighboursPadIterator() | |
47 | : AliMpVPadIterator(), | |
48 | fkSegmentation(0), | |
49 | fCenterPad(AliMpPad::Invalid()), | |
50 | fPads(), | |
51 | fIndex(fgkInvalidIndex) | |
52 | { | |
dee1d5f1 | 53 | /// Default constructor, set the current position to "invalid" |
5f91c9e8 | 54 | } |
55 | ||
56 | //______________________________________________________________________________ | |
57 | AliMpNeighboursPadIterator::AliMpNeighboursPadIterator( | |
0fef3734 | 58 | const AliMpVSegmentation* segmentation, |
5f91c9e8 | 59 | const AliMpPad& centerPad, |
60 | Bool_t includeCenter) | |
61 | : AliMpVPadIterator(), | |
62 | fkSegmentation(segmentation), | |
63 | fCenterPad(centerPad), | |
0471c97b | 64 | fPads(), |
5f91c9e8 | 65 | fIndex(fgkInvalidIndex) |
66 | { | |
dee1d5f1 | 67 | /// Standard constructor, set *this to invalid position |
5f91c9e8 | 68 | |
69 | FillPadsVector(includeCenter); | |
70 | } | |
71 | ||
72 | //______________________________________________________________________________ | |
73 | AliMpNeighboursPadIterator::AliMpNeighboursPadIterator( | |
74 | const AliMpNeighboursPadIterator& right) | |
0471c97b | 75 | : AliMpVPadIterator(right), |
76 | fkSegmentation(0), | |
77 | fCenterPad(AliMpPad::Invalid()), | |
78 | fPads(), | |
79 | fIndex(fgkInvalidIndex) | |
5f91c9e8 | 80 | { |
dee1d5f1 | 81 | /// Copy constructor |
5f91c9e8 | 82 | |
83 | *this = right; | |
84 | } | |
85 | ||
86 | //______________________________________________________________________________ | |
87 | AliMpNeighboursPadIterator::~AliMpNeighboursPadIterator() | |
88 | { | |
dee1d5f1 | 89 | /// Destructor |
f79c58a5 | 90 | |
f79c58a5 | 91 | fPads.Delete(); |
5f91c9e8 | 92 | } |
93 | ||
94 | // operators | |
95 | ||
96 | //______________________________________________________________________________ | |
97 | AliMpNeighboursPadIterator& | |
98 | AliMpNeighboursPadIterator::operator = (const AliMpNeighboursPadIterator& right) | |
99 | { | |
dee1d5f1 | 100 | /// Assignment operator. \n |
101 | /// If the right hand iterator isn't of a good type | |
102 | /// the current operator is invalidated \n | |
5f91c9e8 | 103 | |
dee1d5f1 | 104 | // check assignment to self |
5f91c9e8 | 105 | if (this == &right) return *this; |
106 | ||
dee1d5f1 | 107 | // base class assignment |
5f91c9e8 | 108 | AliMpVPadIterator::operator=(right); |
109 | ||
0471c97b | 110 | AliFatal("Not allowed assignment for TObjArray"); |
5f91c9e8 | 111 | |
112 | return *this; | |
113 | } | |
114 | ||
dee1d5f1 | 115 | // |
116 | // private methods | |
117 | // | |
5f91c9e8 | 118 | |
119 | //______________________________________________________________________________ | |
b9dbf8ab | 120 | Bool_t AliMpNeighboursPadIterator::IsNeighbour(const AliMpPad& pad) const |
5f91c9e8 | 121 | { |
13985652 | 122 | /// Return true if the pad located by \a pad is a neighbour of those |
123 | /// located at a\ fCenterPad | |
5f91c9e8 | 124 | |
b9dbf8ab | 125 | if ( !pad.IsValid() ) return kFALSE; |
126 | ||
5f91c9e8 | 127 | TVector2 relPos = pad.Position() - fCenterPad.Position(); |
128 | TVector2 bounds = pad.Dimensions() + fCenterPad.Dimensions(); | |
129 | return (TMath::Abs(relPos.X())- bounds.X()<AliMpConstants::LengthTolerance()) && | |
130 | (TMath::Abs(relPos.Y())- bounds.Y()<AliMpConstants::LengthTolerance()); | |
131 | ||
132 | } | |
133 | ||
134 | //______________________________________________________________________________ | |
2294822d | 135 | TObjArray* |
5006ec94 | 136 | AliMpNeighboursPadIterator::PadVectorLine(const AliMpPad& from, |
137 | const AliMpIntPair& direction) const | |
5f91c9e8 | 138 | { |
dee1d5f1 | 139 | /// Fill a new vector with all pads which have common |
13985652 | 140 | /// parts with the pad located at \a fCenterPad, in a given line |
141 | /// starting from \a from and moving by \a direction | |
5f91c9e8 | 142 | |
143 | AliMpPad current = from; | |
2294822d | 144 | TObjArray* ans = new TObjArray(); |
f79c58a5 | 145 | Bool_t cont=kTRUE; |
146 | do { | |
b9dbf8ab | 147 | if (IsNeighbour(current)) |
f79c58a5 | 148 | ans->Add(new AliMpPad(current)); |
149 | else | |
150 | cont=kFALSE; | |
151 | TVector2 nextPos = current.Position() + TVector2( | |
152 | current.Dimensions().X()*(AliMpConstants::LengthStep()+1.)*direction.GetFirst(), | |
153 | current.Dimensions().Y()*(AliMpConstants::LengthStep()+1.)*direction.GetSecond()); | |
b9dbf8ab | 154 | current = fkSegmentation->PadByPosition(nextPos, false); |
f79c58a5 | 155 | } while (cont); |
156 | return ans; | |
157 | } | |
158 | ||
159 | //______________________________________________________________________________ | |
2294822d | 160 | void AliMpNeighboursPadIterator::UpdateTotalSet(TObjArray& setTotal, |
161 | TObjArray* from) const | |
f79c58a5 | 162 | { |
dee1d5f1 | 163 | /// Add pads from pad vector to the total set |
164 | /// only if they are not yet included and deletes the pad vector | |
f79c58a5 | 165 | |
166 | for (Int_t i=0; i<from->GetEntriesFast(); i++) { | |
167 | AliMpPad* candidate = (AliMpPad*)from->At(i); | |
168 | ||
169 | Bool_t isInSetTotal = false; | |
170 | for (Int_t j=0; j<setTotal.GetEntriesFast(); j++) { | |
171 | AliMpPad* pad = (AliMpPad*)setTotal.At(j); | |
172 | ||
173 | if (pad->GetIndices() == candidate->GetIndices()) { | |
174 | isInSetTotal = true; | |
175 | break; | |
176 | } | |
177 | } | |
178 | if (!isInSetTotal) | |
179 | setTotal.Add(candidate); | |
180 | else | |
181 | delete candidate; | |
182 | } | |
183 | delete from; | |
184 | } | |
185 | ||
5f91c9e8 | 186 | //______________________________________________________________________________ |
187 | void AliMpNeighboursPadIterator::FillPadsVector(Bool_t includeCenter) | |
188 | { | |
dee1d5f1 | 189 | /// Fill the indices vector with all indices of pads which have common |
13985652 | 190 | /// parts with the pad located at \a fCenterPad |
5f91c9e8 | 191 | |
192 | if (!fkSegmentation || !fCenterPad.IsValid()) return; | |
193 | ||
194 | ||
195 | AliMpPad from; | |
196 | AliMpIntPair direction; | |
2294822d | 197 | TObjArray* found; |
5f91c9e8 | 198 | |
199 | // repare a unique simple associative container | |
200 | // --> no doublons, rapid insersion | |
2294822d | 201 | TObjArray setTotal; |
5f91c9e8 | 202 | |
203 | ///////////// Left side | |
204 | ||
205 | ////////////////// up direction | |
206 | ||
207 | from = fkSegmentation->PadsLeft(fCenterPad).GetFirst(); | |
208 | direction = AliMpIntPair(0,1); | |
209 | found = PadVectorLine(from,direction); | |
f79c58a5 | 210 | UpdateTotalSet(setTotal, found); |
5f91c9e8 | 211 | |
212 | ////////////////// down direction | |
213 | ||
214 | from = fkSegmentation->PadsDown(from).GetFirst(); // the Pad down is already added | |
215 | direction = AliMpIntPair(0,-1); | |
216 | found = PadVectorLine(from,direction); | |
f79c58a5 | 217 | UpdateTotalSet(setTotal, found); |
5f91c9e8 | 218 | |
219 | ///////////// Up side | |
220 | ||
221 | ////////////////// right direction | |
222 | ||
223 | from = fkSegmentation->PadsUp(fCenterPad).GetFirst(); | |
224 | direction = AliMpIntPair(1,0); | |
225 | found = PadVectorLine(from,direction); | |
f79c58a5 | 226 | UpdateTotalSet(setTotal, found); |
5f91c9e8 | 227 | |
228 | ////////////////// left direction | |
229 | ||
230 | from = fkSegmentation->PadsLeft(from).GetFirst(); // the pad up is already added | |
231 | direction = AliMpIntPair(-1,0); | |
232 | found = PadVectorLine(from,direction); | |
f79c58a5 | 233 | UpdateTotalSet(setTotal, found); |
5f91c9e8 | 234 | |
235 | ///////////// Right side | |
236 | ||
237 | ////////////////// Up direction | |
238 | ||
239 | from = fkSegmentation->PadsRight(fCenterPad).GetFirst(); | |
240 | direction = AliMpIntPair(0,1); | |
241 | found = PadVectorLine(from,direction); | |
f79c58a5 | 242 | UpdateTotalSet(setTotal, found); |
5f91c9e8 | 243 | |
244 | ////////////////// down direction | |
245 | ||
246 | from = fkSegmentation->PadsDown(from).GetFirst(); // the pad right is already added | |
247 | direction = AliMpIntPair(0,-1); | |
248 | found = PadVectorLine(from,direction); | |
f79c58a5 | 249 | UpdateTotalSet(setTotal, found); |
5f91c9e8 | 250 | |
251 | ///////////// Down side | |
252 | ||
253 | ////////////////// Right direction | |
254 | ||
255 | from = fkSegmentation->PadsDown(fCenterPad).GetFirst(); | |
256 | direction = AliMpIntPair(1,0); | |
257 | found = PadVectorLine(from,direction); | |
f79c58a5 | 258 | UpdateTotalSet(setTotal, found); |
5f91c9e8 | 259 | |
260 | ////////////////// left direction | |
261 | ||
262 | from = fkSegmentation->PadsLeft(from).GetFirst(); // the pad down is already added | |
263 | direction = AliMpIntPair(-1,0); | |
264 | found = PadVectorLine(from,direction); | |
f79c58a5 | 265 | UpdateTotalSet(setTotal, found); |
5f91c9e8 | 266 | |
267 | // fill the fIndices vector with the set (-->pass from a rapid insertion, | |
268 | // to rapid and indexed access, for the rest of the job) | |
269 | ||
f79c58a5 | 270 | fPads.Delete(); |
271 | // include the center pad if requiered | |
272 | if (includeCenter) fPads.Add(new AliMpPad(fCenterPad)); | |
273 | ||
274 | for (Int_t i = 0; i<setTotal.GetEntriesFast(); i++) | |
275 | fPads.Add(setTotal.At(i)); | |
5f91c9e8 | 276 | } |
277 | ||
278 | //______________________________________________________________________________ | |
279 | Bool_t AliMpNeighboursPadIterator::IsValid() const | |
280 | { | |
dee1d5f1 | 281 | /// Is the iterator in a valid position? |
282 | ||
5f91c9e8 | 283 | return (fkSegmentation!=0 && fIndex!=fgkInvalidIndex); |
284 | } | |
285 | ||
286 | //public methods | |
287 | ||
288 | //______________________________________________________________________________ | |
289 | void AliMpNeighboursPadIterator::First() | |
290 | { | |
dee1d5f1 | 291 | /// Reset the iterator, so that it points to the first available |
292 | /// pad in the sector | |
5f91c9e8 | 293 | |
f79c58a5 | 294 | if ((fkSegmentation != 0) && (fPads.GetEntriesFast() != 0)) |
5f91c9e8 | 295 | fIndex=0; |
296 | else | |
297 | fIndex=fgkInvalidIndex; | |
298 | ||
299 | } | |
300 | ||
301 | //______________________________________________________________________________ | |
302 | void AliMpNeighboursPadIterator::Next() | |
303 | { | |
dee1d5f1 | 304 | /// Pre-increment operator. Should be used by default for iterating over |
305 | /// pads | |
5f91c9e8 | 306 | |
307 | ||
308 | if (!IsValid()) return; | |
309 | ||
f79c58a5 | 310 | if (Int_t(fIndex) < fPads.GetEntriesFast()-1) |
5f91c9e8 | 311 | fIndex++; |
312 | else | |
313 | Invalidate(); | |
314 | } | |
315 | ||
316 | //______________________________________________________________________________ | |
317 | Bool_t AliMpNeighboursPadIterator::IsDone() const | |
318 | { | |
dee1d5f1 | 319 | /// Is the iterator in the end? |
320 | ||
5f91c9e8 | 321 | return !IsValid(); |
322 | } | |
323 | ||
324 | //______________________________________________________________________________ | |
325 | AliMpPad AliMpNeighboursPadIterator::CurrentItem() const | |
326 | { | |
dee1d5f1 | 327 | /// Dereferencement function |
328 | ||
5f91c9e8 | 329 | if (!IsValid()) |
330 | return AliMpPad::Invalid(); | |
331 | else | |
f79c58a5 | 332 | return *((AliMpPad*)fPads[fIndex]); |
5f91c9e8 | 333 | } |
334 | ||
335 | //______________________________________________________________________________ | |
336 | void AliMpNeighboursPadIterator::Invalidate() | |
337 | { | |
dee1d5f1 | 338 | /// Let the iterator point to the invalid position |
339 | ||
5f91c9e8 | 340 | fIndex=fgkInvalidIndex; |
341 | } | |
342 |