]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpDEIterator.cxx
Fixing part of the Coding violation
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpDEIterator.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: AliMpDEIterator.cxx,v 1.6 2006/05/24 13:58:34 ivana Exp $
18 // Category: management
19
20 //-----------------------------------------------------------------------------
21 // Class AliMpDEIterator
22 // ------------------------
23 // The iterator over valid detection elements
24 // Author: Ivana Hrivnacova, IPN Orsay
25 //-----------------------------------------------------------------------------
26
27 #include "AliMpDEIterator.h"
28 #include "AliMpDEStore.h"
29 #include "AliMpDetElement.h"
30 #include "AliMpDEManager.h"
31 #include "AliMpFiles.h"
32
33 #include "AliLog.h"
34
35 #include <Riostream.h>
36 #include <TSystem.h>
37
38 /// \cond CLASSIMP
39 ClassImp(AliMpDEIterator)
40 /// \endcond
41
42 //______________________________________________________________________________
43 AliMpDEIterator::AliMpDEIterator()
44     : TObject(),
45       fDEStore(AliMpDEStore::Instance()),
46       fIndex(-1),
47       fChamberId(-1)
48 {  
49 /// Standard and default constructor
50 }
51
52 //______________________________________________________________________________
53 AliMpDEIterator::AliMpDEIterator(const AliMpDEIterator& rhs)
54  : TObject(rhs),
55    fDEStore(rhs.fDEStore),
56    fIndex(rhs.fIndex),
57    fChamberId(rhs.fChamberId)
58 {
59 /// Copy constructor
60 }
61
62 //______________________________________________________________________________
63
64 AliMpDEIterator::~AliMpDEIterator()
65 {
66 /// Destructor
67 }
68
69 //______________________________________________________________________________
70 AliMpDEIterator&  AliMpDEIterator::operator=(const AliMpDEIterator& rhs)
71 {
72 /// Assignement operator
73
74   // check assignment to self
75   if (this == &rhs) return *this;
76
77   // base class assignment
78   TObject::operator=(rhs);
79
80   fDEStore = rhs.fDEStore;
81   fIndex = rhs.fIndex;
82   fChamberId = rhs.fChamberId;
83
84   return *this;
85
86
87 //
88 // private methods
89 //
90
91 //______________________________________________________________________________
92 AliMpDetElement*  AliMpDEIterator::GetDetElement(Int_t index) const
93 {
94 /// Return the detection element from the map via index
95
96   return static_cast<AliMpDetElement*>(fDEStore->fDetElements.GetObject(index));
97 }
98
99 //
100 // public methods
101 //
102
103 //______________________________________________________________________________
104 void AliMpDEIterator::First()
105 {
106 /// Set iterator to the first DE Id defined 
107
108   fIndex = 0;
109   fChamberId = -1;
110 }  
111
112 //______________________________________________________________________________
113 void AliMpDEIterator::First(Int_t chamberId)
114 {
115 /// Reset the iterator, so that it points to the first DE
116  
117   fChamberId = -1;
118   fIndex = -1;  
119   if ( ! AliMpDEManager::IsValidChamberId(chamberId) ) {
120     AliErrorStream() << "Invalid chamber Id " << chamberId << endl;
121     return;
122   }    
123
124   Int_t i=0;
125   while ( i < fDEStore->fDetElements.GetSize() && fChamberId < 0 ) {
126     Int_t detElemId = GetDetElement(i)->GetId();
127     if ( AliMpDEManager::GetChamberId(detElemId) == chamberId ) {
128       fChamberId = chamberId;
129       fIndex = i;
130     } 
131     i++; 
132   }
133
134   if ( fChamberId < 0 ) {
135     AliErrorStream() 
136       << "No DEs of Chamber Id " << chamberId << " found" << endl;
137     return;
138   }    
139
140 }
141
142 //______________________________________________________________________________
143 void AliMpDEIterator::Next()
144 {
145 /// Increment iterator to next DE
146
147   fIndex++;
148
149   // Invalidate if at the end
150   if ( ( fIndex == fDEStore->fDetElements.GetSize() ) ||
151        ( fChamberId >= 0 &&    
152          AliMpDEManager::GetChamberId(CurrentDEId()) != fChamberId ) ) {
153     fIndex = -1;
154   }   
155 }
156
157 //______________________________________________________________________________
158 Bool_t AliMpDEIterator::IsDone() const
159 {
160 /// Is the iterator in the end?
161
162   return ( fIndex < 0 );
163 }   
164
165 //______________________________________________________________________________
166 AliMpDetElement* AliMpDEIterator::CurrentDE() const
167 {
168 /// Current DE Id
169
170   if ( ! IsDone() )
171     return GetDetElement(fIndex);
172   else {   
173     AliErrorStream()
174       << "Not in valid position - returning invalid DE." << endl;
175     return 0;
176   }  
177 }
178     
179 //______________________________________________________________________________
180 Int_t AliMpDEIterator::CurrentDEId() const
181 {
182 /// Current DE Id
183
184   if ( ! IsDone() )
185     return GetDetElement(fIndex)->GetId();
186   else {   
187     AliErrorStream()
188       << "Not in valid position - returning invalid DE." << endl;
189     return 0;
190   }  
191 }
192