]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUON2DMapIteratorByI.cxx
Generation of generic AOD by the test script of MUON
[u/mrichter/AliRoot.git] / MUON / AliMUON2DMapIteratorByI.cxx
CommitLineData
5fc43f28 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
3d1463c8 18//-----------------------------------------------------------------------------
5fc43f28 19/// \class AliMUON2DMapIteratorByI
20///
21/// Implementation of TIterator for 2D maps
22///
23/// An implementation of TIterator for 2D maps, which can iterate
24/// on a range of i values (i being the first element of the couple
25/// (i,j) used to index values in the map).
26///
27/// \author Laurent Aphecetche
3d1463c8 28//-----------------------------------------------------------------------------
5fc43f28 29
30#include "AliMUON2DMapIteratorByI.h"
31
32#include "AliMpExMap.h"
33
34/// \cond CLASSIMP
35ClassImp(AliMUON2DMapIteratorByI)
36/// \endcond
37
38//_____________________________________________________________________________
39AliMUON2DMapIteratorByI::AliMUON2DMapIteratorByI(const AliMpExMap& theMap,
40 Int_t firstI,
41 Int_t lastI)
42: TIterator(),
43fMap(&theMap),
44fIter2(0x0),
45fCurrentI(-1),
46fCurrentJ(-1),
47fFirstI(firstI),
48fLastI(lastI)
49{
50 /// default ctor
51 Reset();
52}
53
54//_____________________________________________________________________________
55AliMUON2DMapIteratorByI::AliMUON2DMapIteratorByI(const AliMUON2DMapIteratorByI& rhs)
56:TIterator(rhs),
57fMap(rhs.fMap),
58fIter2(0x0),
59fCurrentI(rhs.fCurrentI),
60fCurrentJ(rhs.fCurrentJ),
61fFirstI(rhs.fFirstI),
62fLastI(rhs.fLastI)
63{
64 /// copy ctor
65 if ( rhs.fIter2 ) fIter2 = new TExMapIter(*(rhs.fIter2));
66}
67
68//_____________________________________________________________________________
69AliMUON2DMapIteratorByI&
70AliMUON2DMapIteratorByI::operator=(const AliMUON2DMapIteratorByI& rhs)
71{
72 /// assignment operator
73 if ( this != &rhs )
74 {
75 fMap = rhs.fMap;
76 fIter2 = 0x0;
77 if ( rhs.fIter2 ) fIter2 = new TExMapIter(*(rhs.fIter2));
78 fCurrentI = rhs.fCurrentI;
79 fCurrentJ = rhs.fCurrentJ;
80 fFirstI = rhs.fFirstI;
81 fLastI = rhs.fLastI;
82 }
83 return *this;
84}
85
86//_____________________________________________________________________________
87TIterator&
88AliMUON2DMapIteratorByI::operator=(const TIterator& rhs)
89{
90 /// overriden assigment operator (imposed by Root's declaration of TIterator ?)
91 if ( this != &rhs )
92 {
93 const AliMUON2DMapIteratorByI& rhs1 = static_cast<const AliMUON2DMapIteratorByI&>(rhs);
94 fMap = rhs1.fMap;
95 fIter2 = 0x0;
96 if ( rhs1.fIter2 ) fIter2 = new TExMapIter(*(rhs1.fIter2));
97 fCurrentI = rhs1.fCurrentI;
98 fCurrentJ = rhs1.fCurrentJ;
99 fFirstI = rhs1.fFirstI;
100 fLastI = rhs1.fLastI;
101 }
102 return *this;
103}
104
105//_____________________________________________________________________________
106AliMUON2DMapIteratorByI::~AliMUON2DMapIteratorByI()
107{
108 /// dtor
109 delete fIter2;
110}
111
112//_____________________________________________________________________________
113const TCollection*
114AliMUON2DMapIteratorByI::GetCollection() const
115{
116 /// Not implemented
117 return 0x0;
118}
119
120//_____________________________________________________________________________
121TObject*
122AliMUON2DMapIteratorByI::GetValue(TExMapIter& iter, Int_t& theKey) const
123{
124 /// return the value corresponding to theKey in iterator iter
125 theKey = -1;
126 Long_t key, value;
127 Bool_t ok = iter.Next(key,value);
128 if (!ok) return 0x0;
129 theKey = (Int_t)(key & 0xFFFF);
130 return reinterpret_cast<TObject*>(value);
131}
132
133//_____________________________________________________________________________
134TObject*
135AliMUON2DMapIteratorByI::Next()
136{
137 /// logic :
138 /// get TObject* from fIter2
139 /// if null, increment fIter2 by getting next map from fMap
140
141 if (!fIter2) return 0x0;
142
143 TObject* o = GetValue(*fIter2,fCurrentJ);
144 if (!o)
145 {
146 // fIter2 exhausted, try to get the next one
147 delete fIter2;
148 fIter2 = 0x0;
149 AliMpExMap* m(0x0);
150 while ( !m && fCurrentI < fLastI )
151 {
152 ++fCurrentI;
153 m = static_cast<AliMpExMap*>(fMap->GetValue(fCurrentI));
154 }
155 if (!m) return 0x0; // we are done
156 fIter2 = new TExMapIter(m->GetIterator());
157 o = GetValue(*fIter2,fCurrentJ);
158 }
159
160 return o;
161}
162
163//_____________________________________________________________________________
164void
165AliMUON2DMapIteratorByI::Reset()
166{
167 /// rewind the iterator
168 delete fIter2;
169 fIter2 = 0x0;
170 fCurrentI = fFirstI;
171 AliMpExMap* m;
172
173 while ( !( m = static_cast<AliMpExMap*>(fMap->GetValue(fCurrentI) ) ) &&
174 fCurrentI < fLastI )
175 {
176 ++fCurrentI;
177 }
178
179 if ( m )
180 {
181 fIter2 = new TExMapIter(m->GetIterator());
182 }
183}