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