X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=MUON%2FAliMUON2DMapIterator.cxx;h=b6b3fc333df4f0d1482c7299b4edf11fdc4feef9;hb=e29a165da3598f5021996a6968b79fdff2f51975;hp=507b82f80e02bcb71d87a3cf8038dee6666d5b56;hpb=f246123b1321692dcd7ef8aa12c6cab84e911cf4;p=u%2Fmrichter%2FAliRoot.git diff --git a/MUON/AliMUON2DMapIterator.cxx b/MUON/AliMUON2DMapIterator.cxx index 507b82f80e0..b6b3fc333df 100644 --- a/MUON/AliMUON2DMapIterator.cxx +++ b/MUON/AliMUON2DMapIterator.cxx @@ -16,118 +16,140 @@ // $Id$ #include "AliMUON2DMapIterator.h" -#include "AliMpExMap.h" -#include "TMap.h" -#include "AliLog.h" -#include "AliMpIntPair.h" +//----------------------------------------------------------------------------- /// \class AliMUON2DMapIterator -/// \brief Implementation of AliMUONVDataIterator for 2Dmaps +/// Implementation of TIterator for 2Dmaps /// /// A simple implementation of VDataIterator for 2Dmaps. /// /// \author Laurent Aphecetche +//----------------------------------------------------------------------------- + +#include "AliMpExMap.h" /// \cond CLASSIMP ClassImp(AliMUON2DMapIterator) /// \endcond //_____________________________________________________________________________ -AliMUON2DMapIterator::AliMUON2DMapIterator(AliMpExMap& theMap) -: AliMUONVDataIterator(), -fIter(theMap.GetIterator()), -fIter2(0x0), -fCurrentI(-1), -fCurrentJ(-1) +AliMUON2DMapIterator::AliMUON2DMapIterator(AliMpExMap* theMap) +: TIterator(), +fMap(theMap), +fCurrentMap(0x0), +fI(-1), +fJ(-1) { - // default ctor + /// default ctor Reset(); } //_____________________________________________________________________________ -AliMUON2DMapIterator::~AliMUON2DMapIterator() +AliMUON2DMapIterator::AliMUON2DMapIterator(const AliMUON2DMapIterator& rhs) +: TIterator(rhs), +fMap(rhs.fMap), +fCurrentMap(rhs.fCurrentMap), +fI(rhs.fI), +fJ(rhs.fI) { - // dtor - delete fIter2; + /// copy ctor } //_____________________________________________________________________________ -TObject* -AliMUON2DMapIterator::GetValue(TExMapIter& iter, Int_t& theKey) const +AliMUON2DMapIterator& +AliMUON2DMapIterator::operator=(const AliMUON2DMapIterator& rhs) { - // return the value corresponding to theKey in iterator iter - theKey = -1; - Long_t key, value; - Bool_t ok = iter.Next(key,value); - if (!ok) return 0x0; - theKey = (Int_t)(key & 0xFFFF); - return reinterpret_cast(value); + /// assignment operator + if ( this != &rhs ) + { + fMap = rhs.fMap; + fCurrentMap = rhs.fCurrentMap; + fI = rhs.fI; + fJ = rhs.fJ; + } + return *this; } //_____________________________________________________________________________ -AliMpExMap* -AliMUON2DMapIterator::GetMap(TExMapIter& iter, Int_t& key) +TIterator& +AliMUON2DMapIterator::operator=(const TIterator& rhs) { - // get the map corresponding to key - AliMpExMap* rv(0x0); - TObject* o = GetValue(iter,key); - if (o) + /// overriden operator= (imposed by Root's definition of TIterator::operator= ?) + + if ( this != &rhs && rhs.IsA() == AliMUON2DMapIterator::Class() ) { - rv = dynamic_cast(o); - if (!rv) - { - AliFatal("boom"); - } + const AliMUON2DMapIterator& rhs1 = static_cast(rhs); + fMap = rhs1.fMap; + fCurrentMap = rhs1.fCurrentMap; + fI = rhs1.fI; + fJ = rhs1.fJ; } - return rv; + return *this; +} + +//_____________________________________________________________________________ +AliMUON2DMapIterator::~AliMUON2DMapIterator() +{ + /// dtor +} + +//_____________________________________________________________________________ +const TCollection* +AliMUON2DMapIterator::GetCollection() const +{ + /// Return 0 as we're not really dealing with a Root TCollection... + return 0x0; +} + +//_____________________________________________________________________________ +AliMpExMap* +AliMUON2DMapIterator::Map(Int_t i) const +{ + /// Get the map at a given index + return static_cast(fMap->GetObjectFast(i)); } //_____________________________________________________________________________ TObject* AliMUON2DMapIterator::Next() { - // logic : - // get TObject* from fIter2 - // if null, increment fIter2 by getting next on fIter + /// return next object - if (!fIter2) return 0x0; + if (!fCurrentMap) return 0x0; - TObject* o = GetValue(*fIter2,fCurrentJ); - if (!o) + ++fJ; + + if ( fJ < fCurrentMap->GetSize() ) + { + return fCurrentMap->GetObjectFast(fJ); + } + else { - // fIter2 exhausted, try to get the next one - AliMpExMap* m = GetMap(fIter,fCurrentI); - if (!m) + ++fI; + if ( fI < fMap->GetSize() ) { - // nothing left, we are done. - return 0x0; + fCurrentMap = Map(fI); + fJ = -1; + return Next(); } - delete fIter2; - fIter2 = new TExMapIter(m->GetIterator()); - o = GetValue(*fIter2,fCurrentJ); + return 0x0; } - return new TPair(new AliMpIntPair(fCurrentI,fCurrentJ),o); } //_____________________________________________________________________________ void AliMUON2DMapIterator::Reset() { - // rewind the iterator - delete fIter2; - fIter.Reset(); - AliMpExMap* m = GetMap(fIter,fCurrentI); - if (m) + /// rewind the iterator + fI = -1; + fJ = -1; + fCurrentMap = 0x0; + + if ( fMap->GetSize() > 0 ) { - fIter2 = new TExMapIter(m->GetIterator()); - } + fI = 0; + fCurrentMap = Map(fI); + fJ = -1; + } } -//_____________________________________________________________________________ -Bool_t -AliMUON2DMapIterator::Remove() -{ - // to be implemented if needed - AliInfo("Not supported yet"); - return kFALSE; -}