]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpDEIterator.cxx
Updated comments for Doxygen - corrected warnings
[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 element IDs
24 // Author: Ivana Hrivnacova, IPN Orsay
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
35 /// \cond CLASSIMP
36 ClassImp(AliMpDEIterator)
37 /// \endcond
38
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);
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 //______________________________________________________________________________
95 void 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 //______________________________________________________________________________
116 AliMpDEIterator::AliMpDEIterator()
117     : TObject(),
118       fIndex(-1),
119       fModuleId(-1)
120 {  
121 /// Standard and default constructor
122
123   if (! fgNofDetElemIds ) ReadData();
124 }
125
126 //______________________________________________________________________________
127 AliMpDEIterator::AliMpDEIterator(const AliMpDEIterator& rhs)
128  : TObject(rhs),
129    fIndex(rhs.fIndex),
130    fModuleId(rhs.fModuleId)
131 {
132 /// Copy constructor
133 }
134
135 //______________________________________________________________________________
136
137 AliMpDEIterator::~AliMpDEIterator()
138 {
139 /// Destructor
140 }
141
142 //______________________________________________________________________________
143 AliMpDEIterator&  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 //______________________________________________________________________________
164 void AliMpDEIterator::First()
165 {
166 /// Set iterator to the first DE Id defined 
167
168   fIndex = 0;
169   fModuleId = -1;
170 }  
171
172 //______________________________________________________________________________
173 void AliMpDEIterator::First(Int_t moduleId)
174 {
175 /// Reset the iterator, so that it points to the first DE
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() 
196       << "No DEs of Module Id " << moduleId << " found" << endl;
197     return;
198   }    
199
200 }
201
202 //______________________________________________________________________________
203 void AliMpDEIterator::Next()
204 {
205 /// Increment iterator to next DE
206
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 //______________________________________________________________________________
218 Bool_t AliMpDEIterator::IsDone() const
219 {
220 /// Is the iterator in the end?
221
222   return ( fIndex < 0 );
223 }   
224
225 //______________________________________________________________________________
226 Int_t AliMpDEIterator::CurrentDE() const
227 {
228 /// Current DE Id
229
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