#ifndef ALIDIGITS_H
#define ALIDIGITS_H
#include <TArrayI.h>
#include <TArrayS.h>
#include "AliSegmentID.h"
class AliH2F;
class AliDigits: public AliSegmentID{
public:
AliDigits();
AliDigits(const AliDigits &digits);
AliDigits &operator = (const AliDigits & digits);
virtual ~AliDigits();
Short_t * GetDigits(){return fElements->GetArray();}
Short_t GetDigitFast(Int_t row, Int_t column);
Short_t GetDigitUnchecked(Int_t row, Int_t column);
void SetDigitFast(Short_t value,Int_t row, Int_t column);
Bool_t BoundsOK(const char *where, Int_t row, Int_t col) ;
Bool_t OutOfBoundsError(const char *where, Int_t row, Int_t column);
virtual void Allocate(Int_t rows, Int_t columns);
virtual Short_t GetDigit(Int_t row, Int_t column);
virtual void ExpandBuffer();
virtual void CompresBuffer(Int_t bufferType,Int_t threshold);
virtual Bool_t First();
virtual Bool_t Next();
void SetThreshold(Int_t th) {fThreshold = th;}
Int_t GetThreshold() {return fThreshold;}
Int_t GetNRows(){return fNrows;}
Int_t GetNCols(){return fNcols;}
Int_t CurrentRow(){ return fCurrentRow;}
Int_t CurrentColumn(){ return fCurrentCol;}
Int_t CurrentDigit() {return fElements->At(fCurrentIndex);}
void AcceptHisto(AliH2F * his);
AliH2F * GenerHisto();
AliH2F *DrawDigits( const char *option=0,Float_t x1=-1, Float_t x2=-1, Float_t y1=-1, Float_t y2=-1);
Int_t GetSize();
Int_t GetDigitSize();
Int_t GetOverTh(Float_t threshold,Float_t x1=-1, Float_t x2=-1, Float_t y1=-1, Float_t y2=-1);
inline Short_t * GetDigitsColumn(Int_t row);
protected:
virtual void Invalidate();
void ExpandBuffer1();
void CompresBuffer1();
Bool_t First0();
Bool_t Next0();
Bool_t First1();
Bool_t Next1();
Short_t GetDigit1(Int_t row, Int_t column);
Int_t fNrows;
Int_t fNcols;
private:
TArrayS *fElements;
TArrayI *fIndex;
Int_t fBufType;
Int_t fThreshold;
Int_t fNelems;
Int_t fCurrentRow;
Int_t fCurrentCol;
Int_t fCurrentIndex;
ClassDef(AliDigits,2)
};
inline Bool_t AliDigits::BoundsOK(const char *where, Int_t row, Int_t col)
{
if ( (col>=fNcols) || (col<0) ) return OutOfBoundsError(where,row,col);
Int_t index =(*fIndex).At(col)+row;
if ( (index<0) || (index>fNelems)) return OutOfBoundsError(where,row,col);
return kTRUE;
}
inline Short_t AliDigits::GetDigitFast(Int_t row, Int_t column)
{
return fElements->At(fIndex->At(column)+row);
}
inline Short_t AliDigits::GetDigitUnchecked(Int_t row, Int_t column)
{
return fElements->fArray[fIndex->fArray[column]+row];
}
inline Short_t * AliDigits::GetDigitsColumn(Int_t column){
return &(fElements->fArray[fIndex->fArray[column]]);
}
inline void AliDigits::SetDigitFast(Short_t value, Int_t row, Int_t column)
{
if ( (row<0) || (row>=fNrows) || (column<0) || (column>=fNcols) )
Error("AliDigits::SetDigitFast", "row %d col %d out of bounds (size: %d x %d, this: 0x%08lx)",
row, column, fNrows, fNcols, (ULong_t)this);
(*fElements)[fIndex->At(column)+row]=value;
}
#endif