]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpDEIterator.cxx
- Added class for Global Crate object
[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
3d1463c8 20//-----------------------------------------------------------------------------
490da820 21// Class AliMpDEIterator
22// ------------------------
38956661 23// The iterator over valid detection elements
490da820 24// Author: Ivana Hrivnacova, IPN Orsay
3d1463c8 25//-----------------------------------------------------------------------------
73250182 26
27#include "AliMpDEIterator.h"
38956661 28#include "AliMpDEStore.h"
29#include "AliMpDetElement.h"
73250182 30#include "AliMpDEManager.h"
31#include "AliMpFiles.h"
32
33#include "AliLog.h"
34
35#include <Riostream.h>
36#include <TSystem.h>
37
13985652 38/// \cond CLASSIMP
39ClassImp(AliMpDEIterator)
40/// \endcond
41
73250182 42//______________________________________________________________________________
43AliMpDEIterator::AliMpDEIterator()
44 : TObject(),
38956661 45 fDEStore(AliMpDEStore::Instance()),
73250182 46 fIndex(-1),
0a478fb1 47 fChamberId(-1)
73250182 48{
49/// Standard and default constructor
73250182 50}
51
52//______________________________________________________________________________
53AliMpDEIterator::AliMpDEIterator(const AliMpDEIterator& rhs)
54 : TObject(rhs),
38956661 55 fDEStore(rhs.fDEStore),
73250182 56 fIndex(rhs.fIndex),
0a478fb1 57 fChamberId(rhs.fChamberId)
73250182 58{
59/// Copy constructor
60}
61
62//______________________________________________________________________________
63
64AliMpDEIterator::~AliMpDEIterator()
65{
66/// Destructor
67}
68
69//______________________________________________________________________________
70AliMpDEIterator& AliMpDEIterator::operator=(const AliMpDEIterator& rhs)
71{
72/// Assignement operator
73
74 // check assignment to self
75 if (this == &rhs) return *this;
76
77 // base class assignment
78 TObject::operator=(rhs);
79
38956661 80 fDEStore = rhs.fDEStore;
0a478fb1 81 fIndex = rhs.fIndex;
82 fChamberId = rhs.fChamberId;
73250182 83
84 return *this;
85}
86
38956661 87//
88// private methods
89//
90
91//______________________________________________________________________________
92AliMpDetElement* AliMpDEIterator::GetDetElement(Int_t index) const
93{
94/// Return the detection element from the map via index
95
96 return static_cast<AliMpDetElement*>(fDEStore->fDetElements.GetObject(index));
97}
98
73250182 99//
100// public methods
101//
102
103//______________________________________________________________________________
104void AliMpDEIterator::First()
105{
106/// Set iterator to the first DE Id defined
107
108 fIndex = 0;
0a478fb1 109 fChamberId = -1;
73250182 110}
111
112//______________________________________________________________________________
0a478fb1 113void AliMpDEIterator::First(Int_t chamberId)
73250182 114{
490da820 115/// Reset the iterator, so that it points to the first DE
73250182 116
0a478fb1 117 fChamberId = -1;
73250182 118 fIndex = -1;
0a478fb1 119 if ( ! AliMpDEManager::IsValidChamberId(chamberId) ) {
120 AliErrorStream() << "Invalid chamber Id " << chamberId << endl;
73250182 121 return;
122 }
123
124 Int_t i=0;
38956661 125 while ( i < fDEStore->fDetElements.GetSize() && fChamberId < 0 ) {
126 Int_t detElemId = GetDetElement(i)->GetId();
0a478fb1 127 if ( AliMpDEManager::GetChamberId(detElemId) == chamberId ) {
128 fChamberId = chamberId;
73250182 129 fIndex = i;
130 }
131 i++;
132 }
133
0a478fb1 134 if ( fChamberId < 0 ) {
73250182 135 AliErrorStream()
0a478fb1 136 << "No DEs of Chamber Id " << chamberId << " found" << endl;
73250182 137 return;
138 }
139
140}
141
142//______________________________________________________________________________
143void AliMpDEIterator::Next()
144{
490da820 145/// Increment iterator to next DE
146
73250182 147 fIndex++;
148
149 // Invalidate if at the end
38956661 150 if ( ( fIndex == fDEStore->fDetElements.GetSize() ) ||
0a478fb1 151 ( fChamberId >= 0 &&
38956661 152 AliMpDEManager::GetChamberId(CurrentDEId()) != fChamberId ) ) {
73250182 153 fIndex = -1;
154 }
155}
156
157//______________________________________________________________________________
158Bool_t AliMpDEIterator::IsDone() const
159{
490da820 160/// Is the iterator in the end?
161
73250182 162 return ( fIndex < 0 );
163}
164
165//______________________________________________________________________________
38956661 166AliMpDetElement* AliMpDEIterator::CurrentDE() const
167{
168/// Current DE Id
169
170 if ( ! IsDone() )
171 return GetDetElement(fIndex);
172 else {
173 AliErrorStream()
174 << "Not in valid position - returning invalid DE." << endl;
175 return 0;
176 }
177}
178
179//______________________________________________________________________________
180Int_t AliMpDEIterator::CurrentDEId() const
73250182 181{
490da820 182/// Current DE Id
183
73250182 184 if ( ! IsDone() )
38956661 185 return GetDetElement(fIndex)->GetId();
73250182 186 else {
187 AliErrorStream()
188 << "Not in valid position - returning invalid DE." << endl;
189 return 0;
190 }
191}
192