From: ivana Date: Wed, 17 Oct 2007 12:58:58 +0000 (+0000) Subject: Small optimizations X-Git-Url: http://git.uio.no/git/?p=u%2Fmrichter%2FAliRoot.git;a=commitdiff_plain;h=47a48067c48726e4b5cb58b4357a532177493eb7;hp=f0195aa5ac47b102ac348c4e4c8b1f2a5d45570d Small optimizations --- diff --git a/MUON/AliMUON2DMapIterator.cxx b/MUON/AliMUON2DMapIterator.cxx index 7ffffcfd447..b6b3fc333df 100644 --- a/MUON/AliMUON2DMapIterator.cxx +++ b/MUON/AliMUON2DMapIterator.cxx @@ -33,12 +33,12 @@ ClassImp(AliMUON2DMapIterator) /// \endcond //_____________________________________________________________________________ -AliMUON2DMapIterator::AliMUON2DMapIterator(const AliMpExMap& theMap) +AliMUON2DMapIterator::AliMUON2DMapIterator(AliMpExMap* theMap) : TIterator(), -fIter(theMap.GetIterator()), -fIter2(0x0), -fCurrentI(-1), -fCurrentJ(-1) +fMap(theMap), +fCurrentMap(0x0), +fI(-1), +fJ(-1) { /// default ctor Reset(); @@ -47,15 +47,14 @@ fCurrentJ(-1) //_____________________________________________________________________________ AliMUON2DMapIterator::AliMUON2DMapIterator(const AliMUON2DMapIterator& rhs) : TIterator(rhs), -fIter(rhs.fIter), -fIter2(0x0), -fCurrentI(rhs.fCurrentI), -fCurrentJ(rhs.fCurrentJ) +fMap(rhs.fMap), +fCurrentMap(rhs.fCurrentMap), +fI(rhs.fI), +fJ(rhs.fI) { /// copy ctor - if ( rhs.fIter2 ) fIter2 = new TExMapIter(*rhs.fIter2); - } + //_____________________________________________________________________________ AliMUON2DMapIterator& AliMUON2DMapIterator::operator=(const AliMUON2DMapIterator& rhs) @@ -63,11 +62,10 @@ AliMUON2DMapIterator::operator=(const AliMUON2DMapIterator& rhs) /// assignment operator if ( this != &rhs ) { - fIter = rhs.fIter; - fIter2 = 0x0; - if ( rhs.fIter2 ) fIter2 = new TExMapIter(*rhs.fIter2); - fCurrentI = rhs.fCurrentI; - fCurrentJ = rhs.fCurrentJ; + fMap = rhs.fMap; + fCurrentMap = rhs.fCurrentMap; + fI = rhs.fI; + fJ = rhs.fJ; } return *this; } @@ -81,12 +79,10 @@ AliMUON2DMapIterator::operator=(const TIterator& rhs) if ( this != &rhs && rhs.IsA() == AliMUON2DMapIterator::Class() ) { const AliMUON2DMapIterator& rhs1 = static_cast(rhs); - - fIter = rhs1.fIter; - fIter2 = 0x0; - if ( rhs1.fIter2 ) fIter2 = new TExMapIter(*rhs1.fIter2); - fCurrentI = rhs1.fCurrentI; - fCurrentJ = rhs1.fCurrentJ; + fMap = rhs1.fMap; + fCurrentMap = rhs1.fCurrentMap; + fI = rhs1.fI; + fJ = rhs1.fJ; } return *this; } @@ -95,7 +91,6 @@ AliMUON2DMapIterator::operator=(const TIterator& rhs) AliMUON2DMapIterator::~AliMUON2DMapIterator() { /// dtor - delete fIter2; } //_____________________________________________________________________________ @@ -106,59 +101,39 @@ AliMUON2DMapIterator::GetCollection() const return 0x0; } -//_____________________________________________________________________________ -TObject* -AliMUON2DMapIterator::GetValue(TExMapIter& iter, Int_t& theKey) const -{ - /// 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); -} - //_____________________________________________________________________________ AliMpExMap* -AliMUON2DMapIterator::GetMap(TExMapIter& iter, Int_t& key) const +AliMUON2DMapIterator::Map(Int_t i) const { - /// get the map corresponding to key - AliMpExMap* rv(0x0); - TObject* o = GetValue(iter,key); - if (o) - { - rv = dynamic_cast(o); - } - return rv; + /// 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 (!fCurrentMap) return 0x0; - if (!fIter2) return 0x0; + ++fJ; - TObject* o = GetValue(*fIter2,fCurrentJ); - if (!o) + 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 o; } //_____________________________________________________________________________ @@ -166,11 +141,15 @@ void AliMUON2DMapIterator::Reset() { /// rewind the iterator - delete fIter2; - fIter.Reset(); - AliMpExMap* m = GetMap(fIter,fCurrentI); - if (m) + fI = -1; + fJ = -1; + fCurrentMap = 0x0; + + if ( fMap->GetSize() > 0 ) { - fIter2 = new TExMapIter(m->GetIterator()); - } + fI = 0; + fCurrentMap = Map(fI); + fJ = -1; + } } + diff --git a/MUON/AliMUON2DMapIterator.h b/MUON/AliMUON2DMapIterator.h index de10eb0e491..6061444f292 100644 --- a/MUON/AliMUON2DMapIterator.h +++ b/MUON/AliMUON2DMapIterator.h @@ -12,9 +12,6 @@ /// // Author Laurent Aphecetche -#ifndef ROOT_TExMap -# include "TExMap.h" -#endif #ifndef ROOT_TIterator # include "TIterator.h" #endif @@ -25,7 +22,7 @@ class AliMpExMap; class AliMUON2DMapIterator : public TIterator { public: - AliMUON2DMapIterator(const AliMpExMap& theMap); + AliMUON2DMapIterator(AliMpExMap* theMap); AliMUON2DMapIterator(const AliMUON2DMapIterator& rhs); AliMUON2DMapIterator& operator=(const AliMUON2DMapIterator& rhs); TIterator& operator=(const TIterator& rhs); @@ -40,15 +37,15 @@ public: virtual const TCollection* GetCollection() const; private: - TObject* GetValue(TExMapIter& iter, Int_t& key) const; - AliMpExMap* GetMap(TExMapIter& iter, Int_t& key) const; + + AliMpExMap* Map(Int_t i) const; private: - TExMapIter fIter; //!< first iterator - TExMapIter* fIter2; //!< second iterator - Int_t fCurrentI; //!< current index in direction i - Int_t fCurrentJ; //!< current index in direction j - + AliMpExMap* fMap; ///< Top map we iterate upon + AliMpExMap* fCurrentMap; ///< Current map (inside top map) we are iterating upon + Int_t fI; ///< Map(fI) is fCurrentMap + Int_t fJ; ///< Current position in fCurrentMap + ClassDef(AliMUON2DMapIterator,0) // VDataIterator for 2D maps };