]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpMotifTypePadIterator.cxx
Previous commit had the bad side-effect of changing the behaviour of Raw QA to comput...
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifTypePadIterator.cxx
index 0398d1afdb8fbfd8b61023736918bcd1f28256ec..6aeb6e5ee64e6d1a398759b8c95a7d36e2258701 100755 (executable)
@@ -27,6 +27,7 @@
 
 #include "AliMpMotifTypePadIterator.h"
 #include "AliMpMotifType.h"
+#include "AliMpEncodePair.h"
 
 /// \cond CLASSIMP
 ClassImp(AliMpMotifTypePadIterator)
@@ -35,8 +36,9 @@ ClassImp(AliMpMotifTypePadIterator)
 //______________________________________________________________________________
 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator():
     AliMpVPadIterator(),
-    fMotifType(0),
-    fCurrentPosition(AliMpIntPair::Invalid())
+    fkMotifType(0),
+    fCurrentIx(-1),
+    fCurrentIy(-1)
 {
 /// Default constructor, set the current position to "invalid"
 }
@@ -45,8 +47,9 @@ AliMpMotifTypePadIterator::AliMpMotifTypePadIterator():
 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator( 
                                 const AliMpMotifType* motifType)
   : AliMpVPadIterator(),
-    fMotifType(motifType),
-    fCurrentPosition(AliMpIntPair::Invalid())
+    fkMotifType(motifType),
+    fCurrentIx(-1),
+    fCurrentIy(-1)
 {
 /// Standard constructor, let *this to invalid position
 }
@@ -55,8 +58,9 @@ AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
 AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
                                 const AliMpMotifTypePadIterator& right)
   : AliMpVPadIterator(right),
-    fMotifType(right.fMotifType),
-    fCurrentPosition(right.fCurrentPosition)
+    fkMotifType(right.fkMotifType),
+    fCurrentIx(right.fCurrentIx),
+    fCurrentIy(right.fCurrentIy)
     
 {
 /// Copy constructor
@@ -84,8 +88,9 @@ AliMpMotifTypePadIterator::operator = (const AliMpMotifTypePadIterator& right)
   // base class assignment
   AliMpVPadIterator::operator=(right);
 
-  fMotifType = right.fMotifType;
-  fCurrentPosition = right.fCurrentPosition;
+  fkMotifType = right.fkMotifType;
+  fCurrentIx = right.fCurrentIx;
+  fCurrentIy = right.fCurrentIy;
 
   return *this;
 }  
@@ -95,20 +100,32 @@ AliMpMotifTypePadIterator::operator = (const AliMpMotifTypePadIterator& right)
 //
 
 //______________________________________________________________________________
-AliMpIntPair 
-AliMpMotifTypePadIterator::FindFirstPadInLine(AliMpIntPair indices) const
+Bool_t
+AliMpMotifTypePadIterator::FindFirstPadInLine(Int_t ix, Int_t iy, 
+                                              Int_t& newIx, Int_t& newIy) const
 {
 /// Find the indices of the first pad in the same line
 /// as the \a indices, and in column, at least equal, to the
 /// one of \a indices
 
-    if (!fMotifType) return AliMpIntPair::Invalid();
-
-    while (indices.GetFirst() < fMotifType->GetNofPadsX()) {
-        if (fMotifType->HasPad(indices)) return indices;
-        indices += AliMpIntPair(1,0);
+    if ( ! fkMotifType ) {
+      newIx = -1;
+      newIy = -1;
+      return false;
+    }  
+
+    while ( ix < fkMotifType->GetNofPadsX() ) {
+      if ( fkMotifType->HasPadByLocalIndices(ix, iy) ) {
+        newIx = ix;
+        newIy = iy;
+        return true;
+      }  
+      ix++;
     }
-    return AliMpIntPair::Invalid();
+    
+    newIx = -1;
+    newIy = -1;
+    return false;
 } 
 
 //______________________________________________________________________________
@@ -116,7 +133,7 @@ Bool_t AliMpMotifTypePadIterator::IsValid() const
 {
 /// Is the iterator in a valid position?
 
-    return fMotifType!=0 && fCurrentPosition.IsValid();
+    return fkMotifType!=0 && fCurrentIx >=0 &&  fCurrentIy >=0;
 } 
 
 //
@@ -129,12 +146,14 @@ void AliMpMotifTypePadIterator::First()
 /// Reset the iterator, so that it points to the first available
 /// pad in the motif type
 
-    if (!fMotifType) {
-        Invalidate();
-        return ;
+    if ( ! fkMotifType ) {
+      Invalidate();
+      return ;
     }
-    fCurrentPosition = AliMpIntPair(0,0);
-    if (fMotifType->HasPad(fCurrentPosition)) return;
+    
+    fCurrentIx = 0;
+    fCurrentIy = 0;
+    if ( fkMotifType->HasPadByLocalIndices(fCurrentIx, fCurrentIy) ) return;
     
     
     // if (0,0) is not available
@@ -150,18 +169,20 @@ void AliMpMotifTypePadIterator::Next()
 {
 /// Move the iterator to the next valid pad.
 
-    //if (!IsValid()) return *this;
-    if (!IsValid()) return;
-
-    while (fCurrentPosition.GetSecond() < fMotifType->GetNofPadsY()){
-        AliMpIntPair nextTry 
-         = FindFirstPadInLine(fCurrentPosition + AliMpIntPair(1,0));
-        if (nextTry.IsValid()){
-            fCurrentPosition = nextTry;
-            return;
-        }
-        fCurrentPosition.SetFirst(-1);
-        fCurrentPosition.SetSecond(fCurrentPosition.GetSecond()+1);
+    if ( ! IsValid() ) return;
+
+    while ( fCurrentIy < fkMotifType->GetNofPadsY() ) {
+      Int_t nextTryIx, nextTryIy;
+      Bool_t result 
+        = FindFirstPadInLine(fCurrentIx+1, fCurrentIy, nextTryIx, nextTryIy);
+
+      if ( result ){
+        fCurrentIx = nextTryIx;
+        fCurrentIy = nextTryIy;
+        return;
+      }
+      fCurrentIx = -1;
+      fCurrentIy++;
     }
     
     // if the loop is finished, there's not available pads at all...
@@ -174,7 +195,7 @@ Bool_t AliMpMotifTypePadIterator::IsDone() const
 {
 /// Is the iterator in the end ?
  
-  return !IsValid();
+  return ! IsValid();
 }
 
 //______________________________________________________________________________
@@ -182,11 +203,12 @@ AliMpPad AliMpMotifTypePadIterator::CurrentItem() const
 {
 /// Return current pad.
 
-    if (!fMotifType)
-        return AliMpPad::Invalid();
+    if ( ! fkMotifType )
+      return AliMpPad::Invalid();
     else
-        return AliMpPad(AliMpIntPair::Invalid(),
-                       fCurrentPosition,TVector2(),TVector2());
+      return AliMpPad(0, 0,
+                     fCurrentIx, fCurrentIy,
+                      0., 0.,0., 0.);
 }
 
 //______________________________________________________________________________
@@ -194,7 +216,7 @@ void AliMpMotifTypePadIterator::Invalidate()
 {
 /// Let the iterator point to the invalid position
 
-    fCurrentPosition = AliMpIntPair::Invalid();
-
+    fCurrentIx = -1;
+    fCurrentIy = -1;
 }