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