]>
Commit | Line | Data |
---|---|---|
73250182 | 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 | ||
490da820 | 16 | // $Id$ |
13985652 | 17 | // $MpId: AliMpDEIterator.cxx,v 1.6 2006/05/24 13:58:34 ivana Exp $ |
700013f0 | 18 | // Category: management |
490da820 | 19 | |
20 | // ------------------------ | |
21 | // Class AliMpDEIterator | |
22 | // ------------------------ | |
38956661 | 23 | // The iterator over valid detection elements |
490da820 | 24 | // Author: Ivana Hrivnacova, IPN Orsay |
73250182 | 25 | |
26 | #include "AliMpDEIterator.h" | |
38956661 | 27 | #include "AliMpDEStore.h" |
28 | #include "AliMpDetElement.h" | |
73250182 | 29 | #include "AliMpDEManager.h" |
30 | #include "AliMpFiles.h" | |
31 | ||
32 | #include "AliLog.h" | |
33 | ||
34 | #include <Riostream.h> | |
35 | #include <TSystem.h> | |
36 | ||
13985652 | 37 | /// \cond CLASSIMP |
38 | ClassImp(AliMpDEIterator) | |
39 | /// \endcond | |
40 | ||
73250182 | 41 | //______________________________________________________________________________ |
42 | AliMpDEIterator::AliMpDEIterator() | |
43 | : TObject(), | |
38956661 | 44 | fDEStore(AliMpDEStore::Instance()), |
73250182 | 45 | fIndex(-1), |
0a478fb1 | 46 | fChamberId(-1) |
73250182 | 47 | { |
48 | /// Standard and default constructor | |
73250182 | 49 | } |
50 | ||
51 | //______________________________________________________________________________ | |
52 | AliMpDEIterator::AliMpDEIterator(const AliMpDEIterator& rhs) | |
53 | : TObject(rhs), | |
38956661 | 54 | fDEStore(rhs.fDEStore), |
73250182 | 55 | fIndex(rhs.fIndex), |
0a478fb1 | 56 | fChamberId(rhs.fChamberId) |
73250182 | 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 | ||
38956661 | 79 | fDEStore = rhs.fDEStore; |
0a478fb1 | 80 | fIndex = rhs.fIndex; |
81 | fChamberId = rhs.fChamberId; | |
73250182 | 82 | |
83 | return *this; | |
84 | } | |
85 | ||
38956661 | 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 | ||
73250182 | 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; | |
0a478fb1 | 108 | fChamberId = -1; |
73250182 | 109 | } |
110 | ||
111 | //______________________________________________________________________________ | |
0a478fb1 | 112 | void AliMpDEIterator::First(Int_t chamberId) |
73250182 | 113 | { |
490da820 | 114 | /// Reset the iterator, so that it points to the first DE |
73250182 | 115 | |
0a478fb1 | 116 | fChamberId = -1; |
73250182 | 117 | fIndex = -1; |
0a478fb1 | 118 | if ( ! AliMpDEManager::IsValidChamberId(chamberId) ) { |
119 | AliErrorStream() << "Invalid chamber Id " << chamberId << endl; | |
73250182 | 120 | return; |
121 | } | |
122 | ||
123 | Int_t i=0; | |
38956661 | 124 | while ( i < fDEStore->fDetElements.GetSize() && fChamberId < 0 ) { |
125 | Int_t detElemId = GetDetElement(i)->GetId(); | |
0a478fb1 | 126 | if ( AliMpDEManager::GetChamberId(detElemId) == chamberId ) { |
127 | fChamberId = chamberId; | |
73250182 | 128 | fIndex = i; |
129 | } | |
130 | i++; | |
131 | } | |
132 | ||
0a478fb1 | 133 | if ( fChamberId < 0 ) { |
73250182 | 134 | AliErrorStream() |
0a478fb1 | 135 | << "No DEs of Chamber Id " << chamberId << " found" << endl; |
73250182 | 136 | return; |
137 | } | |
138 | ||
139 | } | |
140 | ||
141 | //______________________________________________________________________________ | |
142 | void AliMpDEIterator::Next() | |
143 | { | |
490da820 | 144 | /// Increment iterator to next DE |
145 | ||
73250182 | 146 | fIndex++; |
147 | ||
148 | // Invalidate if at the end | |
38956661 | 149 | if ( ( fIndex == fDEStore->fDetElements.GetSize() ) || |
0a478fb1 | 150 | ( fChamberId >= 0 && |
38956661 | 151 | AliMpDEManager::GetChamberId(CurrentDEId()) != fChamberId ) ) { |
73250182 | 152 | fIndex = -1; |
153 | } | |
154 | } | |
155 | ||
156 | //______________________________________________________________________________ | |
157 | Bool_t AliMpDEIterator::IsDone() const | |
158 | { | |
490da820 | 159 | /// Is the iterator in the end? |
160 | ||
73250182 | 161 | return ( fIndex < 0 ); |
162 | } | |
163 | ||
164 | //______________________________________________________________________________ | |
38956661 | 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 | |
73250182 | 180 | { |
490da820 | 181 | /// Current DE Id |
182 | ||
73250182 | 183 | if ( ! IsDone() ) |
38956661 | 184 | return GetDetElement(fIndex)->GetId(); |
73250182 | 185 | else { |
186 | AliErrorStream() | |
187 | << "Not in valid position - returning invalid DE." << endl; | |
188 | return 0; | |
189 | } | |
190 | } | |
191 |