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