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