#include "AliMpMotifTypePadIterator.h"
#include "AliMpMotifType.h"
+#include "AliMpEncodePair.h"
/// \cond CLASSIMP
ClassImp(AliMpMotifTypePadIterator)
//______________________________________________________________________________
AliMpMotifTypePadIterator::AliMpMotifTypePadIterator():
AliMpVPadIterator(),
- fMotifType(0),
- fCurrentPosition(AliMpIntPair::Invalid())
+ fkMotifType(0),
+ fCurrentIx(-1),
+ fCurrentIy(-1)
{
/// Default constructor, set the current position to "invalid"
}
AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
const AliMpMotifType* motifType)
: AliMpVPadIterator(),
- fMotifType(motifType),
- fCurrentPosition(AliMpIntPair::Invalid())
+ fkMotifType(motifType),
+ fCurrentIx(-1),
+ fCurrentIy(-1)
{
/// Standard constructor, let *this to invalid position
}
AliMpMotifTypePadIterator::AliMpMotifTypePadIterator(
const AliMpMotifTypePadIterator& right)
: AliMpVPadIterator(right),
- fMotifType(right.fMotifType),
- fCurrentPosition(right.fCurrentPosition)
+ fkMotifType(right.fkMotifType),
+ fCurrentIx(right.fCurrentIx),
+ fCurrentIy(right.fCurrentIy)
{
/// Copy constructor
// base class assignment
AliMpVPadIterator::operator=(right);
- fMotifType = right.fMotifType;
- fCurrentPosition = right.fCurrentPosition;
+ fkMotifType = right.fkMotifType;
+ fCurrentIx = right.fCurrentIx;
+ fCurrentIy = right.fCurrentIy;
return *this;
}
//
//______________________________________________________________________________
-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;
}
//______________________________________________________________________________
{
/// Is the iterator in a valid position?
- return fMotifType!=0 && fCurrentPosition.IsValid();
+ return fkMotifType!=0 && fCurrentIx >=0 && fCurrentIy >=0;
}
//
/// 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
{
/// 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...
{
/// Is the iterator in the end ?
- return !IsValid();
+ return ! IsValid();
}
//______________________________________________________________________________
{
/// 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.);
}
//______________________________________________________________________________
{
/// Let the iterator point to the invalid position
- fCurrentPosition = AliMpIntPair::Invalid();
-
+ fCurrentIx = -1;
+ fCurrentIy = -1;
}