]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpPCBPadIterator.cxx
The description of changes:
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpPCBPadIterator.cxx
index 20599b7531d231289a37f9e4a59eecf2734579bc..4160d376061b49d4520b35c8f90f6576945746bb 100644 (file)
 #include "AliMpPCB.h"
 #include "AliMpSlat.h"
 #include "AliMpSlatSegmentation.h"
+#include "AliMpEncodePair.h"
 
 #include "Riostream.h"
 #include "TMath.h"
 
-/// 
+
+//-----------------------------------------------------------------------------
 /// \class AliMpPCBPadIterator
 /// 
 /// Iterates over slat pads within a region of constant pad size.
 /// 
 /// \author Laurent Aphecetche
+//-----------------------------------------------------------------------------
 
 /// \cond CLASSIMP
 ClassImp(AliMpPCBPadIterator)
@@ -41,20 +44,20 @@ ClassImp(AliMpPCBPadIterator)
 
 //_____________________________________________________________________________
 AliMpPCBPadIterator::AliMpPCBPadIterator(const AliMpSlat* slat,
-                                                     const AliMpArea& area)
+                                         const AliMpArea& area)
 : AliMpVPadIterator(),
 fkSlat(slat),
 fSlatSegmentation(new AliMpSlatSegmentation(slat)),
-fMinIndices(),
-fMaxIndices(),
-fOffset(0,0),
+fMinIndices(0),
+fMaxIndices(0),
+fOffset(0),
 fCurrentPad(),
 fIsDone(kTRUE)
 {
-  //
-  // Normal ctor.
-  // Iteration will be done on the slat, over the crop of (area,slat_area)
-  //
+  ///
+  /// Normal ctor.
+  /// Iteration will be done on the slat, over the crop of (area,slat_area)
+  ///
   if (!CropArea(area)) 
   {
     AliError(Form("Could not crop area : (x,y)min=(%e,%e) ; max=(%e,%e) for slat %s",
@@ -67,9 +70,9 @@ fIsDone(kTRUE)
 //_____________________________________________________________________________
 AliMpPCBPadIterator::~AliMpPCBPadIterator()
 {
-  //
-  // Dtor.
-  //
+  ///
+  /// Dtor.
+  ///
   delete fSlatSegmentation;
 }
 
@@ -77,9 +80,9 @@ AliMpPCBPadIterator::~AliMpPCBPadIterator()
 Bool_t
 AliMpPCBPadIterator::CropArea(const AliMpArea& area)
 {
-  //
-  // Checks the area is correct, and truncate it
-  // if it goes outside the slat.
+  ///
+  /// Checks the area is correct, and truncate it
+  /// if it goes outside the slat.
   
   AliDebug(3,Form("Input area (%7.2f,%7.2f)->(%7.2f,%7.2f)",
                   area.LeftBorder(),area.DownBorder(),
@@ -129,24 +132,24 @@ AliMpPCBPadIterator::CropArea(const AliMpArea& area)
   Int_t iymax = first->Iymin() + TMath::CeilNint((ymax-first->Ymin())/first->PadSizeY()) - 1;
   
   
-  fMinIndices.Set(ixmin,iymin);
-  fMaxIndices.Set(ixmax,iymax);
+  fMinIndices = AliMp::Pair(ixmin,iymin);
+  fMaxIndices = AliMp::Pair(ixmax,iymax);
   
   AliDebug(3,Form("Paddified cropped area (%d,%d)->(%d,%d) %d,%d ; %d,%d",
                   ixmin,iymin,ixmax,iymax,
-                  fMinIndices.GetFirst(),fMinIndices.GetSecond(),
-                  fMaxIndices.GetFirst(),fMaxIndices.GetSecond()));
+                  AliMp::PairFirst(fMinIndices),AliMp::PairSecond(fMinIndices),
+                  AliMp::PairFirst(fMaxIndices),AliMp::PairSecond(fMaxIndices)));
   
-  return fMinIndices.IsValid() && fMaxIndices.IsValid();
+  return fMinIndices >= 0 && fMaxIndices >= 0;
 }
 
 //_____________________________________________________________________________
 AliMpPad
 AliMpPCBPadIterator::CurrentItem() const
 {
-  //
-  // Returns the current iteration position (i.e. a pad)
-  //
+  ///
+  /// Returns the current iteration position (i.e. a pad)
+  ///
   return fCurrentPad;
 }
 
@@ -154,28 +157,26 @@ AliMpPCBPadIterator::CurrentItem() const
 void
 AliMpPCBPadIterator::First()
 {
-  //
-  // (re)Starts the iteration.
-  //
+  ///
+  /// (re)Starts the iteration.
+  ///
   
   AliDebug(3,Form("area = (%d,%d)->(%d,%d)",
-                  fMinIndices.GetFirst(),fMinIndices.GetSecond(),
-                  fMaxIndices.GetFirst(),fMaxIndices.GetSecond()));
+                  AliMp::PairFirst(fMinIndices),AliMp::PairSecond(fMinIndices),
+                  AliMp::PairFirst(fMaxIndices),AliMp::PairSecond(fMaxIndices)));
   fOffset = fMinIndices;
   fIsDone = kFALSE;
-  SetPad(fCurrentPad,fOffset);
-  if (!fCurrentPad.IsValid()) Next();
-  if ( !fCurrentPad.IsValid() ) 
+  SetPad(fCurrentPad,AliMp::PairFirst(fOffset),AliMp::PairSecond(fOffset));
+  if ( ! fCurrentPad.IsValid() ) Next();
+  if ( ! fCurrentPad.IsValid() ) 
   {
     // did not find any valid pad in there, bailing out.
     fIsDone = kTRUE;
     AliError(Form("Could not initiate iterator for slat %s. "
                   " Please check the area you gave : %d,%d to %d,%d",
                   fkSlat->GetName(),
-                  fMinIndices.GetFirst(),
-                  fMinIndices.GetSecond(),
-                  fMaxIndices.GetFirst(),
-                  fMaxIndices.GetSecond()));
+                  AliMp::PairFirst(fMinIndices),AliMp::PairSecond(fMinIndices),
+                  AliMp::PairFirst(fMaxIndices),AliMp::PairSecond(fMaxIndices)));
     return;
   }
 }
@@ -184,19 +185,19 @@ AliMpPCBPadIterator::First()
 Bool_t
 AliMpPCBPadIterator::GetNextPosition(Int_t& ix, Int_t& iy)
 {
-  // Get the next iteration position. 
-  // On input, fOffset must be a valid position (i.e. within iteration
-  // area already).
+  /// Get the next iteration position. 
+  /// On input, fOffset must be a valid position (i.e. within iteration
+  /// area already).
   
   ++ix;
   
-  if ( ix > fMaxIndices.GetFirst() )
+  if ( ix > AliMp::PairFirst(fMaxIndices) )
   {
     // Go back leftmost position...
-    ix = fMinIndices.GetFirst();
+    ix = AliMp::PairFirst(fMinIndices);
     // ... and up
     ++iy;
-    if ( iy > fMaxIndices.GetSecond() )
+    if ( iy > AliMp::PairSecond(fMaxIndices) )
     {
       return false;
     }
@@ -209,10 +210,10 @@ AliMpPCBPadIterator::GetNextPosition(Int_t& ix, Int_t& iy)
 void
 AliMpPCBPadIterator::Invalidate()
 {
-  //
-  // Invalidate the iterator.
-  //
-  fOffset = AliMpIntPair::Invalid();
+  ///
+  /// Invalidate the iterator.
+  ///
+  fOffset = 0;
   fCurrentPad = AliMpPad::Invalid();
   fIsDone = kTRUE;
 }
@@ -221,9 +222,9 @@ AliMpPCBPadIterator::Invalidate()
 Bool_t
 AliMpPCBPadIterator::IsDone() const
 {
-  //
-  // Whether the iteration is finished or not.
-  //
+  ///
+  /// Whether the iteration is finished or not.
+  ///
   return fIsDone;
 }
 
@@ -231,22 +232,22 @@ AliMpPCBPadIterator::IsDone() const
 void
 AliMpPCBPadIterator::Next()
 {
-  // This one is the meat of the class.
-  // We're iterating in x-direction mainly, starting from 
-  // lower-left of the iteration area, and proceeding right,
-  // until we reach right border, in which case we increment y
-  // and go back to leftmost position.
-  // End of iteration occurs when both x and y are outside the iteration
-  // window.
+  /// This one is the meat of the class.
+  /// We're iterating in x-direction mainly, starting from 
+  /// lower-left of the iteration area, and proceeding right,
+  /// until we reach right border, in which case we increment y
+  /// and go back to leftmost position.
+  /// End of iteration occurs when both x and y are outside the iteration
+  /// window.
   
   if (IsDone()) return;
   
   AliMpPad pad(fCurrentPad);
   int n = 0;
-  Int_t ix(fOffset.GetFirst());
-  Int_t iy(fOffset.GetSecond());
+  Int_t ix(AliMp::PairFirst(fOffset));
+  Int_t iy(AliMp::PairSecond(fOffset));
   
-  while ( ( pad == fCurrentPad || !pad.IsValid() ) && n<100 )
+  while ( ( pad == fCurrentPad || ! pad.IsValid() ) && n<100 )
   {
     ++n;
     if (GetNextPosition(ix,iy)==kFALSE) 
@@ -254,7 +255,7 @@ AliMpPCBPadIterator::Next()
       Invalidate();
       return;
     } 
-    SetPad(pad,AliMpIntPair(ix,iy));
+    SetPad(pad,ix,iy);
   }
   if ( n>=100 )
   {
@@ -271,23 +272,23 @@ AliMpPCBPadIterator::Print(Option_t*) const
   cout << Form("fkSlat=%p fSlatSegmentation=%p (%s)",fkSlat,fSlatSegmentation,
                fkSlat->GetName()) << endl
   << Form("minIndices=(%d,%d) maxIndices=(%d,%d)",
-          fMinIndices.GetFirst(),fMinIndices.GetSecond(),
-          fMaxIndices.GetFirst(),fMaxIndices.GetSecond()) << endl
+          AliMp::PairFirst(fMinIndices),AliMp::PairSecond(fMinIndices),
+          AliMp::PairFirst(fMaxIndices),AliMp::PairSecond(fMaxIndices)) << endl
   << Form("currentOffset=(%d,%d) isdone=%d currentpad=",
-          fOffset.GetFirst(),fOffset.GetSecond(),IsDone()) << endl;
+          AliMp::PairFirst(fOffset),AliMp::PairSecond(fOffset)) << endl;
   fCurrentPad.Print();
 }
 
 //_____________________________________________________________________________
 void
-AliMpPCBPadIterator::SetPad(AliMpPad& pad, const AliMpIntPair& indices)
+AliMpPCBPadIterator::SetPad(AliMpPad& pad, Int_t ix, Int_t iy)
 {
-  //
-  // Sets the current pad.
-  //
-  pad = fSlatSegmentation->PadByIndices(indices,kFALSE);
+  ///
+  /// Sets the current pad.
+  ///
+  pad = fSlatSegmentation->PadByIndices(ix, iy,kFALSE);
   if (pad.IsValid())
   {
-    fOffset = indices;
+    fOffset = AliMp::Pair(ix,iy);
   }
 }