]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpDEIterator.cxx
- Adding fgkNofGeomModules static data member and its getter
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpDEIterator.cxx
CommitLineData
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
36ClassImp(AliMpDEIterator)
37/// \endcond
38
73250182 39const Int_t AliMpDEIterator::fgkMaxNofDetElements = 250;
40TArrayI AliMpDEIterator::fgDetElemIds(fgkMaxNofDetElements);
41Int_t AliMpDEIterator::fgNofDetElemIds = 0;
42
43//
44// static private methods
45//
46
47//______________________________________________________________________________
48Bool_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);
81 AliDebugClassStream(1)
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//______________________________________________________________________________
95void AliMpDEIterator::ReadData()
96{
97/// Fill DE Ids array from DE names files
98/// Return true if all data were read ok
99
100 Bool_t result1 = ReadDEIds(kStation1);
101 Bool_t result2 = ReadDEIds(kStation2);
102 Bool_t result3 = ReadDEIds(kStation345);
103 Bool_t result4 = ReadDEIds(kStationTrigger);
104
105 Bool_t result = result1 && result2 && result3 && result4;
106 if ( ! result ) {
107 AliErrorClassStream() << "Error in reading DE names files" << endl;
108 }
109}
110
111//
112// constructors, destructor
113//
114
115//______________________________________________________________________________
116AliMpDEIterator::AliMpDEIterator()
117 : TObject(),
118 fIndex(-1),
119 fModuleId(-1)
120{
121/// Standard and default constructor
122
123 if (! fgNofDetElemIds ) ReadData();
124}
125
126//______________________________________________________________________________
127AliMpDEIterator::AliMpDEIterator(const AliMpDEIterator& rhs)
128 : TObject(rhs),
129 fIndex(rhs.fIndex),
130 fModuleId(rhs.fModuleId)
131{
132/// Copy constructor
133}
134
135//______________________________________________________________________________
136
137AliMpDEIterator::~AliMpDEIterator()
138{
139/// Destructor
140}
141
142//______________________________________________________________________________
143AliMpDEIterator& AliMpDEIterator::operator=(const AliMpDEIterator& rhs)
144{
145/// Assignement operator
146
147 // check assignment to self
148 if (this == &rhs) return *this;
149
150 // base class assignment
151 TObject::operator=(rhs);
152
153 fIndex = rhs.fIndex;
154 fModuleId = rhs.fModuleId;
155
156 return *this;
157}
158
159//
160// public methods
161//
162
163//______________________________________________________________________________
164void AliMpDEIterator::First()
165{
166/// Set iterator to the first DE Id defined
167
168 fIndex = 0;
169 fModuleId = -1;
170}
171
172//______________________________________________________________________________
173void AliMpDEIterator::First(Int_t moduleId)
174{
490da820 175/// Reset the iterator, so that it points to the first DE
73250182 176
177 fModuleId = -1;
178 fIndex = -1;
179 if ( ! AliMpDEManager::IsValidModuleId(moduleId) ) {
180 AliErrorStream() << "Invalid module Id " << moduleId << endl;
181 return;
182 }
183
184 Int_t i=0;
185 while ( i < fgNofDetElemIds && fModuleId < 0 ) {
186 Int_t detElemId = fgDetElemIds.At(i);
187 if ( AliMpDEManager::GetModuleId(detElemId) == moduleId ) {
188 fModuleId = moduleId;
189 fIndex = i;
190 }
191 i++;
192 }
193
194 if ( fModuleId < 0 ) {
195 AliErrorStream()
2c605e66 196 << "No DEs of Module Id " << moduleId << " found" << endl;
73250182 197 return;
198 }
199
200}
201
202//______________________________________________________________________________
203void AliMpDEIterator::Next()
204{
490da820 205/// Increment iterator to next DE
206
73250182 207 fIndex++;
208
209 // Invalidate if at the end
210 if ( ( fIndex == fgNofDetElemIds ) ||
211 ( fModuleId >= 0 &&
212 AliMpDEManager::GetModuleId(CurrentDE()) != fModuleId ) ) {
213 fIndex = -1;
214 }
215}
216
217//______________________________________________________________________________
218Bool_t AliMpDEIterator::IsDone() const
219{
490da820 220/// Is the iterator in the end?
221
73250182 222 return ( fIndex < 0 );
223}
224
225//______________________________________________________________________________
226Int_t AliMpDEIterator::CurrentDE() const
227{
490da820 228/// Current DE Id
229
73250182 230 if ( ! IsDone() )
231 return fgDetElemIds.At(fIndex);
232 else {
233 AliErrorStream()
234 << "Not in valid position - returning invalid DE." << endl;
235 return 0;
236 }
237}
238