Update HFE v2 analyses
[u/mrichter/AliRoot.git] / MUON / AliMUON2DMapIterator.cxx
index f4f69ad..2bb027e 100644 (file)
@@ -27,6 +27,8 @@
 //-----------------------------------------------------------------------------
 
 #include "AliMpExMap.h"
+#include "AliMpExMapIterator.h"
+#include "AliLog.h"
 
 /// \cond CLASSIMP
 ClassImp(AliMUON2DMapIterator)
@@ -36,54 +38,20 @@ ClassImp(AliMUON2DMapIterator)
 AliMUON2DMapIterator::AliMUON2DMapIterator(const AliMpExMap& theMap)
 : TIterator(),
 fkMap(&theMap),
-fCurrentMap(0x0),
-fI(-1),
-fJ(-1)
+fIter1(theMap.CreateIterator()),
+fIter2(NextIterator())
 {
   /// default ctor
   Reset();
 }
 
 //_____________________________________________________________________________
-AliMUON2DMapIterator::AliMUON2DMapIterator(const AliMUON2DMapIterator& rhs)
-: TIterator(rhs),
-fkMap(rhs.fkMap),
-fCurrentMap(rhs.fCurrentMap),
-fI(rhs.fI),
-fJ(rhs.fI)
-{
-  /// copy ctor
-}
-
-//_____________________________________________________________________________
 AliMUON2DMapIterator& 
-AliMUON2DMapIterator::operator=(const AliMUON2DMapIterator& rhs)
-{
-  /// assignment operator
-  if ( this != &rhs ) 
-  {
-    fkMap = rhs.fkMap;
-    fCurrentMap = rhs.fCurrentMap;
-    fI = rhs.fI;
-    fJ = rhs.fJ;
-  }
-  return *this;
-}
-
-//_____________________________________________________________________________
-TIterator& 
-AliMUON2DMapIterator::operator=(const TIterator& rhs)
+AliMUON2DMapIterator::operator=(const TIterator& /*rhs*/)
 {
-  /// overriden operator= (imposed by Root's definition of TIterator::operator= ?)
+  // overriden operator= (imposed by Root's definition of TIterator::operator= ?)
   
-  if ( this != &rhs && rhs.IsA() == AliMUON2DMapIterator::Class() ) 
-  {
-    const AliMUON2DMapIterator& rhs1 = static_cast<const AliMUON2DMapIterator&>(rhs);
-    fkMap = rhs1.fkMap;
-    fCurrentMap = rhs1.fCurrentMap;
-    fI = rhs1.fI;
-    fJ = rhs1.fJ;
-  }
+  AliFatalGeneral("operator=(TIterator&)",""); // as in copy ctor
   return *this;
 }
 
@@ -91,6 +59,8 @@ AliMUON2DMapIterator::operator=(const TIterator& rhs)
 AliMUON2DMapIterator::~AliMUON2DMapIterator()
 {
   /// dtor
+  delete fIter1;
+  delete fIter2;
 }
 
 //_____________________________________________________________________________
@@ -102,11 +72,16 @@ AliMUON2DMapIterator::GetCollection() const
 }
 
 //_____________________________________________________________________________
-AliMpExMap*
-AliMUON2DMapIterator::Map(Int_t i) const
+TIterator*
+AliMUON2DMapIterator::NextIterator()
 {
-  /// Get the map at a given index
-  return static_cast<AliMpExMap*>(fkMap->GetObjectFast(i));
+  /// Get next map (from fIter1) and create an iterator to it
+  
+  AliMpExMap* m = static_cast<AliMpExMap*>(fIter1->Next());
+
+  if (!m) return 0x0;
+  
+  return m->CreateIterator();
 }
 
 //_____________________________________________________________________________
@@ -115,25 +90,18 @@ AliMUON2DMapIterator::Next()
 {
   /// return next object
   
-  if (!fCurrentMap) return 0x0;
-  
-  ++fJ;
+  if (!fIter2) return 0x0;
+
+  TObject* o = fIter2->Next();
   
-  if ( fJ < fCurrentMap->GetSize() ) 
+  if (!o)
   {
-    return fCurrentMap->GetObjectFast(fJ);
-  }
-  else
-  {
-    ++fI;
-    if ( fI < fkMap->GetSize() )
-    {
-      fCurrentMap = Map(fI);
-      fJ = -1;
-      return Next();
-    }
-    return 0x0;
+    delete fIter2;
+    fIter2 = NextIterator();
+    return Next();
   }
+  
+  return o;
 }
 
 //_____________________________________________________________________________
@@ -141,15 +109,9 @@ void
 AliMUON2DMapIterator::Reset()
 {
   /// rewind the iterator
-  fI = -1;
-  fJ = -1;
-  fCurrentMap = 0x0;
   
-  if ( fkMap->GetSize() > 0 )
-  {
-    fI = 0;
-    fCurrentMap = Map(fI);
-    fJ = -1;
-  }
+  delete fIter2;
+  fIter1->Reset();
+  fIter2 = NextIterator();
 }