1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpDEIterator.cxx,v 1.6 2006/05/24 13:58:34 ivana Exp $
18 // Category: management
20 // ------------------------
21 // Class AliMpDEIterator
22 // ------------------------
23 // The iterator over valid detection element IDs
24 // Author: Ivana Hrivnacova, IPN Orsay
26 #include "AliMpDEIterator.h"
27 #include "AliMpDEManager.h"
28 #include "AliMpFiles.h"
32 #include <Riostream.h>
36 ClassImp(AliMpDEIterator)
39 const Int_t AliMpDEIterator::fgkMaxNofDetElements = 250;
40 TArrayI AliMpDEIterator::fgDetElemIds(fgkMaxNofDetElements);
41 Int_t AliMpDEIterator::fgNofDetElemIds = 0;
44 // static private methods
47 //______________________________________________________________________________
48 Bool_t AliMpDEIterator::ReadDEIds(AliMpStationType station)
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
55 TString filePath = AliMpFiles::DENamesFilePath(station);
56 std::ifstream in(filePath);
58 AliErrorClassStream() << "Cannot open file " << filePath << endl;;
62 // Skip plane types per cathods + empty lines
74 while ( ! in.eof() ) {
75 if ( word[0] == '#' ) {
79 detElemId = word.Atoi();
81 AliDebugClassStream(1)
82 << "Adding " << fgNofDetElemIds << " " << detElemId << endl;
83 fgDetElemIds.AddAt(detElemId, fgNofDetElemIds++);
94 //______________________________________________________________________________
95 void AliMpDEIterator::ReadData()
97 /// Fill DE Ids array from DE names files
98 /// Return true if all data were read ok
100 Bool_t result1 = ReadDEIds(kStation1);
101 Bool_t result2 = ReadDEIds(kStation2);
102 Bool_t result3 = ReadDEIds(kStation345);
103 Bool_t result4 = ReadDEIds(kStationTrigger);
105 Bool_t result = result1 && result2 && result3 && result4;
107 AliErrorClassStream() << "Error in reading DE names files" << endl;
112 // constructors, destructor
115 //______________________________________________________________________________
116 AliMpDEIterator::AliMpDEIterator()
121 /// Standard and default constructor
123 if (! fgNofDetElemIds ) ReadData();
126 //______________________________________________________________________________
127 AliMpDEIterator::AliMpDEIterator(const AliMpDEIterator& rhs)
130 fModuleId(rhs.fModuleId)
135 //______________________________________________________________________________
137 AliMpDEIterator::~AliMpDEIterator()
142 //______________________________________________________________________________
143 AliMpDEIterator& AliMpDEIterator::operator=(const AliMpDEIterator& rhs)
145 /// Assignement operator
147 // check assignment to self
148 if (this == &rhs) return *this;
150 // base class assignment
151 TObject::operator=(rhs);
154 fModuleId = rhs.fModuleId;
163 //______________________________________________________________________________
164 void AliMpDEIterator::First()
166 /// Set iterator to the first DE Id defined
172 //______________________________________________________________________________
173 void AliMpDEIterator::First(Int_t moduleId)
175 /// Reset the iterator, so that it points to the first DE
179 if ( ! AliMpDEManager::IsValidModuleId(moduleId) ) {
180 AliErrorStream() << "Invalid module Id " << moduleId << endl;
185 while ( i < fgNofDetElemIds && fModuleId < 0 ) {
186 Int_t detElemId = fgDetElemIds.At(i);
187 if ( AliMpDEManager::GetModuleId(detElemId) == moduleId ) {
188 fModuleId = moduleId;
194 if ( fModuleId < 0 ) {
196 << "No DEs of Module Id " << moduleId << " found" << endl;
202 //______________________________________________________________________________
203 void AliMpDEIterator::Next()
205 /// Increment iterator to next DE
209 // Invalidate if at the end
210 if ( ( fIndex == fgNofDetElemIds ) ||
212 AliMpDEManager::GetModuleId(CurrentDE()) != fModuleId ) ) {
217 //______________________________________________________________________________
218 Bool_t AliMpDEIterator::IsDone() const
220 /// Is the iterator in the end?
222 return ( fIndex < 0 );
225 //______________________________________________________________________________
226 Int_t AliMpDEIterator::CurrentDE() const
231 return fgDetElemIds.At(fIndex);
234 << "Not in valid position - returning invalid DE." << endl;