]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSectorPadIterator.cxx
Adding option for ownership of objects in the map
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSectorPadIterator.cxx
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
16 // $Id$
17 // $MpId: AliMpSectorPadIterator.cxx,v 1.6 2006/05/24 13:58:46 ivana Exp $
18 // Category: sector
19 //
20 // Class AliMpSectorPadIterator
21 // ----------------------------
22 // Class, which defines an iterator over the pads of a sector
23 // Included in AliRoot: 2003/05/02
24 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
25
26 #include "AliMpSectorPadIterator.h"
27 #include "AliMpIntPair.h"
28 #include "AliMpSector.h"
29 #include "AliMpMotifType.h"
30
31 #include "AliMpRow.h"
32 #include "AliMpVRowSegment.h"
33 #include "AliMpMotifMap.h"
34 #include "AliMpMotifPosition.h"
35
36 /// \cond CLASSIMP
37 ClassImp(AliMpSectorPadIterator)
38 /// \endcond
39
40 //______________________________________________________________________________
41 AliMpSectorPadIterator::AliMpSectorPadIterator()
42   : AliMpVPadIterator(),
43     fkSector(0),
44     fCurrentRow(0),
45     fCurrentSeg(0),
46     fCurrentMotif(0),
47     fMotifPos(0),
48     fIterator()
49 {
50 /// Default constructor, set the current position to "invalid"
51 }
52
53 //______________________________________________________________________________
54 AliMpSectorPadIterator::AliMpSectorPadIterator(const AliMpSector* const sector)
55   : AliMpVPadIterator(),
56     fkSector(sector),
57     fCurrentRow(0),
58     fCurrentSeg(0),
59     fCurrentMotif(0),
60     fMotifPos(0),
61     fIterator()
62 {
63 /// Standard constructor, set *this to invalid position  
64 }
65
66 //______________________________________________________________________________
67 AliMpSectorPadIterator::AliMpSectorPadIterator(const AliMpSectorPadIterator& right)
68   : AliMpVPadIterator(right),
69     fkSector(0),
70     fCurrentRow(0),
71     fCurrentSeg(0),
72     fCurrentMotif(0),
73     fMotifPos(0),
74     fIterator()
75 {
76 /// Copy constructor
77  
78   *this = right;
79 }
80
81 //______________________________________________________________________________
82 AliMpSectorPadIterator::~AliMpSectorPadIterator()
83 {
84 /// Destructor
85 }
86
87 //
88 // operators
89 //
90
91 //______________________________________________________________________________
92 AliMpSectorPadIterator& 
93 AliMpSectorPadIterator::operator = (const AliMpSectorPadIterator& right)
94 {
95 /// Assignment operator
96
97   // check assignment to self
98   if (this == &right) return *this;
99
100   // base class assignment
101   AliMpVPadIterator::operator=(right);
102
103   fkSector      = right.fkSector;
104   fCurrentRow   = right.fCurrentRow;
105   fCurrentSeg   = right.fCurrentSeg;
106   fCurrentMotif = right.fCurrentMotif;
107   fIterator     = right.fIterator;
108
109   return *this;
110
111
112 //private methods
113
114 //______________________________________________________________________________
115 AliMpMotifPosition* AliMpSectorPadIterator::ResetToCurrentMotifPosition()
116 {
117 /// Find the AliMpMotifType object associated with the triplet
118 /// (fCurrentRow, fCurrentSeg, fCurrentMotif),
119 /// place it in the private fMotifType member and return it.
120   
121   fMotifPos =0;
122   
123   if (fkSector){
124     AliMpRow* row;
125     if ((fCurrentRow >= 0) && (fCurrentRow < fkSector->GetNofRows())){
126       row= fkSector->GetRow(fCurrentRow);
127
128       AliMpVRowSegment* seg;
129       if (fCurrentSeg<row->GetNofRowSegments()){
130         seg = row->GetRowSegment(fCurrentSeg);
131
132         if (fCurrentMotif<seg->GetNofMotifs()){
133           fMotifPos = 
134            fkSector->GetMotifMap()->FindMotifPosition(
135                 seg->GetMotifPositionId(fCurrentMotif));
136         }
137       }
138     }
139   }
140   
141   if (fMotifPos) {
142     fIterator = AliMpMotifPositionPadIterator(fMotifPos);
143     fIterator.First();
144   }
145   else
146     Invalidate();
147
148   return fMotifPos;
149 }
150
151 //______________________________________________________________________________
152 Bool_t AliMpSectorPadIterator::IsValid() const
153 {
154 /// Is the iterator in a valid position?
155
156     return (fkSector!=0) && (fMotifPos!=0);
157
158
159 //
160 //public methods
161 //
162
163 //______________________________________________________________________________
164 void AliMpSectorPadIterator::First()
165 {
166 /// Reset the iterator, so that it points to the first available
167 /// pad in the sector
168
169     if (!fkSector) {
170         Invalidate();
171         return;
172     }
173     fCurrentRow =0;
174     fCurrentSeg=0;
175     fCurrentMotif=0;
176     
177     ResetToCurrentMotifPosition();
178
179     return;
180 }
181
182 //______________________________________________________________________________
183 void AliMpSectorPadIterator::Next()
184 {
185 /// Move the iterator to the next valid pad.
186
187   //if (!IsValid()) return *this;
188   if (!IsValid()) return;
189
190   fIterator.Next();
191   
192   if (!fIterator.IsDone()) return;
193   
194
195   // Go to ne next motif, in the current segment
196   ++fCurrentMotif;
197   if (ResetToCurrentMotifPosition()) return;
198
199
200   // if motif number is too big, set it to 0 and pass to the next row segment
201   fCurrentMotif=0;
202   ++fCurrentSeg;
203   if (ResetToCurrentMotifPosition()) return;
204
205
206   // if row segment number is too big, pass to the next row
207   fCurrentSeg=0;
208   ++fCurrentRow;
209   if (ResetToCurrentMotifPosition()) return;
210   
211   // if row number is too big, the invalidate the iterator (==End())
212   Invalidate();
213   return;
214
215 }
216
217 //______________________________________________________________________________
218 Bool_t AliMpSectorPadIterator::IsDone() const
219 {
220 /// Is the iterator in the end? 
221
222   return !IsValid();
223 }
224
225 //______________________________________________________________________________
226 AliMpPad AliMpSectorPadIterator::CurrentItem () const 
227 {
228 /// Return current pad.
229
230   if (!IsValid())
231     return AliMpPad::Invalid();
232       
233
234   // no more verification, since IsValid() is TRUE here.
235
236   return fIterator.CurrentItem();
237 }
238
239 //______________________________________________________________________________
240 void AliMpSectorPadIterator::Invalidate()
241 {
242 /// Let the iterator point to the invalid position
243     fMotifPos = 0;
244     fIterator.Invalidate();
245
246