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