]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpMotifPositionPadIterator.cxx
Fix coverity defect
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifPositionPadIterator.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: AliMpMotifPositionPadIterator.cxx,v 1.6 2006/05/24 13:58:41 ivana Exp $
18 // Category: motif
19
20 //-----------------------------------------------------------------------------
21 // Class AliMpMotifPositionPadIterator
22 // -----------------------------------
23 // Class, which defines an iterator over the pads of a given motif type
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26 //-----------------------------------------------------------------------------
27
28 #include "AliMpMotifPositionPadIterator.h"
29 #include "AliMpMotifPosition.h"
30 #include "AliMpMotifType.h"
31 #include "AliMpConnection.h"
32 #include "AliMpEncodePair.h"
33
34 /// \cond CLASSIMP
35 ClassImp(AliMpMotifPositionPadIterator)
36 /// \endcond
37
38 //______________________________________________________________________________
39 AliMpMotifPositionPadIterator::AliMpMotifPositionPadIterator():
40     AliMpVPadIterator(),
41     fkMotifPos(0),
42     fIterator()
43 {
44 /// Default constructor, set the current position to "invalid"
45 }
46
47 //______________________________________________________________________________
48
49 AliMpMotifPositionPadIterator::AliMpMotifPositionPadIterator(
50                                     const AliMpMotifPosition* motifPos)
51   : AliMpVPadIterator(),
52     fkMotifPos(motifPos),
53     fIterator(motifPos->GetMotif()->GetMotifType())
54 {
55 /// Standard constructor, let *this to invalid position
56 }
57
58 //______________________________________________________________________________
59 AliMpMotifPositionPadIterator::AliMpMotifPositionPadIterator(
60                                     const AliMpMotifPositionPadIterator& right)
61   : AliMpVPadIterator(right),
62     fkMotifPos(right.fkMotifPos),
63     fIterator(right.fIterator)
64     
65 {
66 /// Copy constructor
67 }
68
69 //______________________________________________________________________________
70 AliMpMotifPositionPadIterator::~AliMpMotifPositionPadIterator()
71 {
72 /// Destructor
73 }
74
75 // operators
76
77 //______________________________________________________________________________
78 AliMpMotifPositionPadIterator& 
79 AliMpMotifPositionPadIterator::operator = (const AliMpMotifPositionPadIterator& right)
80 {
81 /// Assignment operator
82
83 // if the right hand iterator isn't of good type
84 // the current operator is invalidated
85
86   // check assignment to self
87   if (this == &right) return *this;
88
89   // base class assignment
90   AliMpVPadIterator::operator=(right);
91
92   fkMotifPos = right.fkMotifPos;
93   fIterator = right.fIterator;
94
95   return *this;
96 }  
97
98 //private methods
99
100
101 //______________________________________________________________________________
102 Bool_t AliMpMotifPositionPadIterator::IsValid() const
103 {
104 /// Is the iterator in a valid position?
105
106     return (fkMotifPos!=0) && (!fIterator.IsDone());
107
108
109 //
110 // public methods
111 //
112
113 //______________________________________________________________________________
114 void AliMpMotifPositionPadIterator::First()
115 {
116 /// Reset the iterator, so that it points to the first available
117 /// pad in the motif type
118
119     if (!fkMotifPos) {
120         Invalidate();
121         return ;
122     }
123
124     fIterator.First();
125     return;
126 }
127
128 //______________________________________________________________________________
129 void AliMpMotifPositionPadIterator::Next()
130 {
131 /// Move the iterator to the next valid pad.
132
133   fIterator.Next();
134 }
135
136 //______________________________________________________________________________
137 Bool_t AliMpMotifPositionPadIterator::IsDone() const
138 {
139 /// Is the iterator in the end? 
140
141   return !IsValid();
142 }
143
144 //______________________________________________________________________________
145 AliMpPad AliMpMotifPositionPadIterator::CurrentItem() const 
146 {
147 /// Return current pad.
148
149     if (!fkMotifPos)
150         return AliMpPad::Invalid();
151     else {
152       MpPair_t ind = fIterator.CurrentItem().GetIndices();
153       AliMpMotifType* mt = fkMotifPos->GetMotif()->GetMotifType();
154       AliMpConnection* connect = 
155         mt->FindConnectionByLocalIndices(ind);
156
157       Double_t posx, posy;
158       fkMotifPos->GetMotif()->PadPositionLocal(ind, posx, posy);
159       posx += fkMotifPos->GetPositionX();
160       posy += fkMotifPos->GetPositionY();
161         
162       Double_t dx, dy;
163       fkMotifPos->GetMotif()->GetPadDimensionsByIndices(ind, dx, dy);           
164
165       return AliMpPad(
166                   fkMotifPos->GetID(),connect->GetManuChannel(), 
167                   fkMotifPos->GlobalIndices(ind),
168                   posx, posy, dx, dy);
169     }
170 }
171
172 //______________________________________________________________________________
173 void AliMpMotifPositionPadIterator::Invalidate()
174 {
175 /// Let the iterator point to the invalid position
176
177   fIterator.Invalidate();
178
179