]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpNeighboursPadIterator.cxx
Work around for CINT bug in root 5.10/00, with gcc4.0.2
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpNeighboursPadIterator.cxx
CommitLineData
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$
63ed9c6b 17// $MpId: AliMpNeighboursPadIterator.cxx,v 1.11 2006/03/02 16:37:30 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
34const UInt_t AliMpNeighboursPadIterator::fgkInvalidIndex = 9999;
35 //never so much neighbours...
36
63ed9c6b 37ClassImp(AliMpNeighboursPadIterator)
38
5f91c9e8 39//______________________________________________________________________________
40AliMpNeighboursPadIterator::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//______________________________________________________________________________
51AliMpNeighboursPadIterator::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//______________________________________________________________________________
66AliMpNeighboursPadIterator::AliMpNeighboursPadIterator(
67 const AliMpNeighboursPadIterator& right)
68 : AliMpVPadIterator(right)
69{
dee1d5f1 70/// Copy constructor
5f91c9e8 71
72 *this = right;
73}
74
75//______________________________________________________________________________
76AliMpNeighboursPadIterator::~AliMpNeighboursPadIterator()
77{
dee1d5f1 78/// Destructor
f79c58a5 79
80#ifdef WITH_ROOT
81 fPads.Delete();
82#endif
5f91c9e8 83}
84
85// operators
86
87//______________________________________________________________________________
88AliMpNeighboursPadIterator&
89AliMpNeighboursPadIterator::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//______________________________________________________________________________
b9dbf8ab 120Bool_t AliMpNeighboursPadIterator::IsNeighbour(const AliMpPad& pad) const
5f91c9e8 121{
dee1d5f1 122/// Return true if the pad located by <padIndice> is a neighbour of those
123/// located at <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
f79c58a5 134#ifdef WITH_STL
5f91c9e8 135//______________________________________________________________________________
5006ec94 136AliMpNeighboursPadIterator::PadVector
137AliMpNeighboursPadIterator::PadVectorLine(const AliMpPad& from,
138 const AliMpIntPair& direction) const
5f91c9e8 139{
dee1d5f1 140/// Fill a new vector with all pads which have common
141/// parts with the pad located at <fCenterPad>, in a given line
142/// starting from <from> and moving by <direction>
5f91c9e8 143
144 AliMpPad current = from;
145 PadVector ans;
146 Bool_t cont=kTRUE;
147 do {
b9dbf8ab 148 if (IsNeighbour(current))
5f91c9e8 149 ans.push_back(current);
150 else
151 cont=kFALSE;
152 TVector2 nextPos = current.Position() + TVector2(
153 current.Dimensions().X()*(AliMpConstants::LengthStep()+1.)*direction.GetFirst(),
154 current.Dimensions().Y()*(AliMpConstants::LengthStep()+1.)*direction.GetSecond());
b9dbf8ab 155 current = fkSegmentation->PadByPosition(nextPos, false);
5f91c9e8 156 } while (cont);
157 return ans;
158}
159
f79c58a5 160//______________________________________________________________________________
161void AliMpNeighboursPadIterator::UpdateTotalSet(PadSet& setTotal,
162 const PadVector& from) const
163{
dee1d5f1 164/// Add pads from pad vector to the total set
165/// only if they are not yet included
f79c58a5 166
167 setTotal.insert(from.begin(),from.end());
168}
169
170#endif
171#ifdef WITH_ROOT
172//______________________________________________________________________________
5006ec94 173AliMpNeighboursPadIterator::PadVector*
174AliMpNeighboursPadIterator::PadVectorLine(const AliMpPad& from,
175 const AliMpIntPair& direction) const
f79c58a5 176{
dee1d5f1 177/// Fill a new vector with all pads which have common
178/// parts with the pad located at <fCenterPad>, in a given line
179/// starting from <from> and moving by <direction>
f79c58a5 180
181 AliMpPad current = from;
182 PadVector* ans = new PadVector();
183 Bool_t cont=kTRUE;
184 do {
b9dbf8ab 185 if (IsNeighbour(current))
f79c58a5 186 ans->Add(new AliMpPad(current));
187 else
188 cont=kFALSE;
189 TVector2 nextPos = current.Position() + TVector2(
190 current.Dimensions().X()*(AliMpConstants::LengthStep()+1.)*direction.GetFirst(),
191 current.Dimensions().Y()*(AliMpConstants::LengthStep()+1.)*direction.GetSecond());
b9dbf8ab 192 current = fkSegmentation->PadByPosition(nextPos, false);
f79c58a5 193 } while (cont);
194 return ans;
195}
196
197//______________________________________________________________________________
198void AliMpNeighboursPadIterator::UpdateTotalSet(PadSet& setTotal,
199 PadVector* from) const
200{
dee1d5f1 201/// Add pads from pad vector to the total set
202/// only if they are not yet included and deletes the pad vector
f79c58a5 203
204 for (Int_t i=0; i<from->GetEntriesFast(); i++) {
205 AliMpPad* candidate = (AliMpPad*)from->At(i);
206
207 Bool_t isInSetTotal = false;
208 for (Int_t j=0; j<setTotal.GetEntriesFast(); j++) {
209 AliMpPad* pad = (AliMpPad*)setTotal.At(j);
210
211 if (pad->GetIndices() == candidate->GetIndices()) {
212 isInSetTotal = true;
213 break;
214 }
215 }
216 if (!isInSetTotal)
217 setTotal.Add(candidate);
218 else
219 delete candidate;
220 }
221 delete from;
222}
223
224#endif
225
5f91c9e8 226//______________________________________________________________________________
227void AliMpNeighboursPadIterator::FillPadsVector(Bool_t includeCenter)
228{
dee1d5f1 229/// Fill the indices vector with all indices of pads which have common
230/// parts with the pad located at <fCenterPad>
5f91c9e8 231
232 if (!fkSegmentation || !fCenterPad.IsValid()) return;
233
234
235 AliMpPad from;
236 AliMpIntPair direction;
f79c58a5 237#ifdef WITH_STL
5f91c9e8 238 PadVector found;
f79c58a5 239#endif
240#ifdef WITH_ROOT
241 PadVector* found;
242#endif
5f91c9e8 243
244 // repare a unique simple associative container
245 // --> no doublons, rapid insersion
246 PadSet setTotal;
247
248 ///////////// Left side
249
250 ////////////////// up direction
251
252 from = fkSegmentation->PadsLeft(fCenterPad).GetFirst();
253 direction = AliMpIntPair(0,1);
254 found = PadVectorLine(from,direction);
f79c58a5 255 UpdateTotalSet(setTotal, found);
5f91c9e8 256
257 ////////////////// down direction
258
259 from = fkSegmentation->PadsDown(from).GetFirst(); // the Pad down is already added
260 direction = AliMpIntPair(0,-1);
261 found = PadVectorLine(from,direction);
f79c58a5 262 UpdateTotalSet(setTotal, found);
5f91c9e8 263
264 ///////////// Up side
265
266 ////////////////// right direction
267
268 from = fkSegmentation->PadsUp(fCenterPad).GetFirst();
269 direction = AliMpIntPair(1,0);
270 found = PadVectorLine(from,direction);
f79c58a5 271 UpdateTotalSet(setTotal, found);
5f91c9e8 272
273 ////////////////// left direction
274
275 from = fkSegmentation->PadsLeft(from).GetFirst(); // the pad up is already added
276 direction = AliMpIntPair(-1,0);
277 found = PadVectorLine(from,direction);
f79c58a5 278 UpdateTotalSet(setTotal, found);
5f91c9e8 279
280 ///////////// Right side
281
282 ////////////////// Up direction
283
284 from = fkSegmentation->PadsRight(fCenterPad).GetFirst();
285 direction = AliMpIntPair(0,1);
286 found = PadVectorLine(from,direction);
f79c58a5 287 UpdateTotalSet(setTotal, found);
5f91c9e8 288
289 ////////////////// down direction
290
291 from = fkSegmentation->PadsDown(from).GetFirst(); // the pad right is already added
292 direction = AliMpIntPair(0,-1);
293 found = PadVectorLine(from,direction);
f79c58a5 294 UpdateTotalSet(setTotal, found);
5f91c9e8 295
296 ///////////// Down side
297
298 ////////////////// Right direction
299
300 from = fkSegmentation->PadsDown(fCenterPad).GetFirst();
301 direction = AliMpIntPair(1,0);
302 found = PadVectorLine(from,direction);
f79c58a5 303 UpdateTotalSet(setTotal, found);
5f91c9e8 304
305 ////////////////// left direction
306
307 from = fkSegmentation->PadsLeft(from).GetFirst(); // the pad down is already added
308 direction = AliMpIntPair(-1,0);
309 found = PadVectorLine(from,direction);
f79c58a5 310 UpdateTotalSet(setTotal, found);
5f91c9e8 311
312 // fill the fIndices vector with the set (-->pass from a rapid insertion,
313 // to rapid and indexed access, for the rest of the job)
314
f79c58a5 315#ifdef WITH_STL
5f91c9e8 316 fPads.clear();
317 // include the center pad if requiered
318 if (includeCenter) fPads.push_back(fCenterPad);
319 //fPads.insert(fPads.end(),setTotal.begin(),setTotal.end());
320
5006ec94 321 PadSetCIterator it;
5f91c9e8 322 for (it = setTotal.begin(); it != setTotal.end(); it++)
323 fPads.push_back((*it));
f79c58a5 324#endif
325
326#ifdef WITH_ROOT
327 fPads.Delete();
328 // include the center pad if requiered
329 if (includeCenter) fPads.Add(new AliMpPad(fCenterPad));
330
331 for (Int_t i = 0; i<setTotal.GetEntriesFast(); i++)
332 fPads.Add(setTotal.At(i));
333#endif
5f91c9e8 334}
335
336//______________________________________________________________________________
337Bool_t AliMpNeighboursPadIterator::IsValid() const
338{
dee1d5f1 339/// Is the iterator in a valid position?
340
5f91c9e8 341 return (fkSegmentation!=0 && fIndex!=fgkInvalidIndex);
342}
343
344//public methods
345
346//______________________________________________________________________________
347void AliMpNeighboursPadIterator::First()
348{
dee1d5f1 349/// Reset the iterator, so that it points to the first available
350/// pad in the sector
5f91c9e8 351
f79c58a5 352#ifdef WITH_STL
5f91c9e8 353 if ((fkSegmentation != 0) && (fPads.size() != 0))
f79c58a5 354#endif
355#ifdef WITH_ROOT
356 if ((fkSegmentation != 0) && (fPads.GetEntriesFast() != 0))
357#endif
5f91c9e8 358 fIndex=0;
359 else
360 fIndex=fgkInvalidIndex;
361
362}
363
364//______________________________________________________________________________
365void AliMpNeighboursPadIterator::Next()
366{
dee1d5f1 367/// Pre-increment operator. Should be used by default for iterating over
368/// pads
5f91c9e8 369
370
371 if (!IsValid()) return;
372
f79c58a5 373#ifdef WITH_STL
5f91c9e8 374 if (fIndex < fPads.size()-1)
f79c58a5 375#endif
376#ifdef WITH_ROOT
377 if (Int_t(fIndex) < fPads.GetEntriesFast()-1)
378#endif
5f91c9e8 379 fIndex++;
380 else
381 Invalidate();
382}
383
384//______________________________________________________________________________
385Bool_t AliMpNeighboursPadIterator::IsDone() const
386{
dee1d5f1 387/// Is the iterator in the end?
388
5f91c9e8 389 return !IsValid();
390}
391
392//______________________________________________________________________________
393AliMpPad AliMpNeighboursPadIterator::CurrentItem() const
394{
dee1d5f1 395/// Dereferencement function
396
5f91c9e8 397 if (!IsValid())
398 return AliMpPad::Invalid();
399 else
f79c58a5 400#ifdef WITH_STL
5f91c9e8 401 return fPads[fIndex];
f79c58a5 402#endif
403#ifdef WITH_ROOT
404 return *((AliMpPad*)fPads[fIndex]);
405#endif
5f91c9e8 406}
407
408//______________________________________________________________________________
409void AliMpNeighboursPadIterator::Invalidate()
410{
dee1d5f1 411/// Let the iterator point to the invalid position
412
5f91c9e8 413 fIndex=fgkInvalidIndex;
414}
415