]>
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 | // ------------------------ | |
23 | // The iterator over valid detection element IDs | |
24 | // Author: Ivana Hrivnacova, IPN Orsay | |
73250182 | 25 | |
26 | #include "AliMpDEIterator.h" | |
27 | #include "AliMpDEManager.h" | |
28 | #include "AliMpFiles.h" | |
29 | ||
30 | #include "AliLog.h" | |
31 | ||
32 | #include <Riostream.h> | |
33 | #include <TSystem.h> | |
34 | ||
13985652 | 35 | /// \cond CLASSIMP |
36 | ClassImp(AliMpDEIterator) | |
37 | /// \endcond | |
38 | ||
73250182 | 39 | const Int_t AliMpDEIterator::fgkMaxNofDetElements = 250; |
40 | TArrayI AliMpDEIterator::fgDetElemIds(fgkMaxNofDetElements); | |
41 | Int_t AliMpDEIterator::fgNofDetElemIds = 0; | |
42 | ||
43 | // | |
44 | // static private methods | |
45 | // | |
46 | ||
47 | //______________________________________________________________________________ | |
48 | Bool_t AliMpDEIterator::ReadDEIds(AliMpStationType station) | |
49 | { | |
50 | /// Read det element ids from the file specified by name | |
51 | /// and fill the map (the deNames are ignored) | |
52 | /// Return true if the data were read ok | |
53 | ||
54 | // Open file | |
55 | TString filePath = AliMpFiles::DENamesFilePath(station); | |
56 | std::ifstream in(filePath); | |
57 | if (!in.good()) { | |
58 | AliErrorClassStream() << "Cannot open file " << filePath << endl;; | |
59 | return false; | |
60 | } | |
61 | ||
62 | // Skip plane types per cathods + empty lines | |
63 | // | |
64 | char line[80]; | |
65 | in.getline(line, 80); | |
66 | in.getline(line, 80); | |
67 | in.getline(line, 80); | |
68 | ||
69 | // Read DE Ids | |
70 | // | |
71 | Int_t detElemId; | |
72 | TString word; | |
73 | in >> word; | |
74 | while ( ! in.eof() ) { | |
75 | if ( word[0] == '#' ) { | |
76 | in.getline(line, 80); | |
77 | } | |
78 | else { | |
79 | detElemId = word.Atoi(); | |
80 | in.getline(line, 80); | |
da3a1bb2 | 81 | AliDebugClassStream(3) |
73250182 | 82 | << "Adding " << fgNofDetElemIds << " " << detElemId << endl; |
83 | fgDetElemIds.AddAt(detElemId, fgNofDetElemIds++); | |
84 | } | |
85 | in >> word; | |
86 | } | |
87 | ||
88 | // Close file | |
89 | in.close(); | |
90 | ||
91 | return true; | |
92 | } | |
93 | ||
94 | //______________________________________________________________________________ | |
95 | void AliMpDEIterator::ReadData() | |
96 | { | |
97 | /// Fill DE Ids array from DE names files | |
98 | /// Return true if all data were read ok | |
99 | ||
da3a1bb2 | 100 | AliDebugClass(2,""); |
101 | ||
73250182 | 102 | Bool_t result1 = ReadDEIds(kStation1); |
103 | Bool_t result2 = ReadDEIds(kStation2); | |
104 | Bool_t result3 = ReadDEIds(kStation345); | |
105 | Bool_t result4 = ReadDEIds(kStationTrigger); | |
106 | ||
107 | Bool_t result = result1 && result2 && result3 && result4; | |
108 | if ( ! result ) { | |
109 | AliErrorClassStream() << "Error in reading DE names files" << endl; | |
110 | } | |
111 | } | |
112 | ||
113 | // | |
114 | // constructors, destructor | |
115 | // | |
116 | ||
117 | //______________________________________________________________________________ | |
118 | AliMpDEIterator::AliMpDEIterator() | |
119 | : TObject(), | |
120 | fIndex(-1), | |
0a478fb1 | 121 | fChamberId(-1) |
73250182 | 122 | { |
123 | /// Standard and default constructor | |
124 | ||
125 | if (! fgNofDetElemIds ) ReadData(); | |
126 | } | |
127 | ||
128 | //______________________________________________________________________________ | |
129 | AliMpDEIterator::AliMpDEIterator(const AliMpDEIterator& rhs) | |
130 | : TObject(rhs), | |
131 | fIndex(rhs.fIndex), | |
0a478fb1 | 132 | fChamberId(rhs.fChamberId) |
73250182 | 133 | { |
134 | /// Copy constructor | |
135 | } | |
136 | ||
137 | //______________________________________________________________________________ | |
138 | ||
139 | AliMpDEIterator::~AliMpDEIterator() | |
140 | { | |
141 | /// Destructor | |
142 | } | |
143 | ||
144 | //______________________________________________________________________________ | |
145 | AliMpDEIterator& AliMpDEIterator::operator=(const AliMpDEIterator& rhs) | |
146 | { | |
147 | /// Assignement operator | |
148 | ||
149 | // check assignment to self | |
150 | if (this == &rhs) return *this; | |
151 | ||
152 | // base class assignment | |
153 | TObject::operator=(rhs); | |
154 | ||
0a478fb1 | 155 | fIndex = rhs.fIndex; |
156 | fChamberId = rhs.fChamberId; | |
73250182 | 157 | |
158 | return *this; | |
159 | } | |
160 | ||
161 | // | |
162 | // public methods | |
163 | // | |
164 | ||
165 | //______________________________________________________________________________ | |
166 | void AliMpDEIterator::First() | |
167 | { | |
168 | /// Set iterator to the first DE Id defined | |
169 | ||
170 | fIndex = 0; | |
0a478fb1 | 171 | fChamberId = -1; |
73250182 | 172 | } |
173 | ||
174 | //______________________________________________________________________________ | |
0a478fb1 | 175 | void AliMpDEIterator::First(Int_t chamberId) |
73250182 | 176 | { |
490da820 | 177 | /// Reset the iterator, so that it points to the first DE |
73250182 | 178 | |
0a478fb1 | 179 | fChamberId = -1; |
73250182 | 180 | fIndex = -1; |
0a478fb1 | 181 | if ( ! AliMpDEManager::IsValidChamberId(chamberId) ) { |
182 | AliErrorStream() << "Invalid chamber Id " << chamberId << endl; | |
73250182 | 183 | return; |
184 | } | |
185 | ||
186 | Int_t i=0; | |
0a478fb1 | 187 | while ( i < fgNofDetElemIds && fChamberId < 0 ) { |
73250182 | 188 | Int_t detElemId = fgDetElemIds.At(i); |
0a478fb1 | 189 | if ( AliMpDEManager::GetChamberId(detElemId) == chamberId ) { |
190 | fChamberId = chamberId; | |
73250182 | 191 | fIndex = i; |
192 | } | |
193 | i++; | |
194 | } | |
195 | ||
0a478fb1 | 196 | if ( fChamberId < 0 ) { |
73250182 | 197 | AliErrorStream() |
0a478fb1 | 198 | << "No DEs of Chamber Id " << chamberId << " found" << endl; |
73250182 | 199 | return; |
200 | } | |
201 | ||
202 | } | |
203 | ||
204 | //______________________________________________________________________________ | |
205 | void AliMpDEIterator::Next() | |
206 | { | |
490da820 | 207 | /// Increment iterator to next DE |
208 | ||
73250182 | 209 | fIndex++; |
210 | ||
211 | // Invalidate if at the end | |
212 | if ( ( fIndex == fgNofDetElemIds ) || | |
0a478fb1 | 213 | ( fChamberId >= 0 && |
214 | AliMpDEManager::GetChamberId(CurrentDE()) != fChamberId ) ) { | |
73250182 | 215 | fIndex = -1; |
216 | } | |
217 | } | |
218 | ||
219 | //______________________________________________________________________________ | |
220 | Bool_t AliMpDEIterator::IsDone() const | |
221 | { | |
490da820 | 222 | /// Is the iterator in the end? |
223 | ||
73250182 | 224 | return ( fIndex < 0 ); |
225 | } | |
226 | ||
227 | //______________________________________________________________________________ | |
228 | Int_t AliMpDEIterator::CurrentDE() const | |
229 | { | |
490da820 | 230 | /// Current DE Id |
231 | ||
73250182 | 232 | if ( ! IsDone() ) |
233 | return fgDetElemIds.At(fIndex); | |
234 | else { | |
235 | AliErrorStream() | |
236 | << "Not in valid position - returning invalid DE." << endl; | |
237 | return 0; | |
238 | } | |
239 | } | |
240 |