#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)
//_____________________________________________________________________________
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",
//_____________________________________________________________________________
AliMpPCBPadIterator::~AliMpPCBPadIterator()
{
- //
- // Dtor.
- //
+ ///
+ /// Dtor.
+ ///
delete fSlatSegmentation;
}
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(),
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;
}
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;
}
}
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;
}
void
AliMpPCBPadIterator::Invalidate()
{
- //
- // Invalidate the iterator.
- //
- fOffset = AliMpIntPair::Invalid();
+ ///
+ /// Invalidate the iterator.
+ ///
+ fOffset = 0;
fCurrentPad = AliMpPad::Invalid();
fIsDone = kTRUE;
}
Bool_t
AliMpPCBPadIterator::IsDone() const
{
- //
- // Whether the iteration is finished or not.
- //
+ ///
+ /// Whether the iteration is finished or not.
+ ///
return fIsDone;
}
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)
Invalidate();
return;
}
- SetPad(pad,AliMpIntPair(ix,iy));
+ SetPad(pad,ix,iy);
}
if ( n>=100 )
{
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);
}
}