// //
///////////////////////////////////////////////////////////////////////////////
-#include "TArrayI.h"
-
+#include <algorithm>
+#include "TObject.h"
#include "AliLog.h"
-
#include "AliTRDSignalIndex.h"
ClassImp(AliTRDSignalIndex)
,fLayer(-1)
,fStack(-1)
,fSM(-1)
- ,fIndex(NULL)
- ,fPositionRow(0)
- ,fPositionCol(0)
- ,fPositionTbin(0)
- ,fLastRow(0)
- ,fLastCol(0)
- ,fLastTbin(0)
+ ,fBoolIndex(NULL)
+ ,fSortedIndex(NULL)
+ ,fMaxLimit(0)
+ ,fPositionRC(0)
+ ,fCountRC(1)
+ ,fSortedWasInit(kFALSE)
+ ,fCurrRow(0)
+ ,fCurrCol(0)
+ ,fCurrTbin(0)
,fNrows(0)
,fNcols(0)
,fNtbins(0)
- ,fMaxLimit(0)
- ,fResetCounters(kTRUE)
- ,fHasEntry(kFALSE)
{
//
// Default contructor
,fLayer(-1)
,fStack(-1)
,fSM(-1)
- ,fIndex(NULL)
- ,fPositionRow(0)
- ,fPositionCol(0)
- ,fPositionTbin(0)
- ,fLastRow(0)
- ,fLastCol(0)
- ,fLastTbin(0)
+ ,fBoolIndex(NULL)
+ ,fSortedIndex(NULL)
+ ,fMaxLimit(0)
+ ,fPositionRC(0)
+ ,fCountRC(1)
+ ,fSortedWasInit(kFALSE)
+ ,fCurrRow(0)
+ ,fCurrCol(0)
+ ,fCurrTbin(0)
,fNrows(0)
,fNcols(0)
,fNtbins(0)
- ,fMaxLimit(0)
- ,fResetCounters(kTRUE)
- ,fHasEntry(kFALSE)
{
//
// Not the default contructor... hmmm...
,fLayer(a.fLayer)
,fStack(a.fStack)
,fSM(a.fSM)
- ,fIndex(a.fIndex)
- ,fPositionRow(a.fPositionRow)
- ,fPositionCol(a.fPositionCol)
- ,fPositionTbin(a.fPositionTbin)
- ,fLastRow(a.fLastRow)
- ,fLastCol(a.fLastCol)
- ,fLastTbin(a.fLastTbin)
+ ,fBoolIndex(NULL)
+ ,fSortedIndex(NULL)
+ ,fMaxLimit(a.fMaxLimit)
+ ,fPositionRC(a.fPositionRC)
+ ,fCountRC(a.fCountRC)
+ ,fSortedWasInit(a.fSortedWasInit)
+ ,fCurrRow(a.fCurrRow)
+ ,fCurrCol(a.fCurrCol)
+ ,fCurrTbin(a.fCurrTbin)
,fNrows(a.fNrows)
,fNcols(a.fNcols)
,fNtbins(a.fNtbins)
- ,fMaxLimit(a.fMaxLimit)
- ,fResetCounters(a.fResetCounters)
- ,fHasEntry(a.fHasEntry)
{
//
// Copy constructor
//
+ fBoolIndex = new Bool_t[fMaxLimit];
+ memcpy(fBoolIndex, a.fBoolIndex, fMaxLimit*sizeof(Bool_t));
+
+ fSortedIndex = new RowCol[fMaxLimit+1];
+ memcpy(fSortedIndex, a.fSortedIndex, (fMaxLimit+1)*sizeof(RowCol));
}
//_____________________________________________________________________________
// Destructor
//
- if (fIndex) {
- delete fIndex;
- fIndex = NULL;
+ if (fBoolIndex) {
+ delete [] fBoolIndex;
+ fBoolIndex = NULL;
+ }
+
+if (fSortedIndex) {
+ delete [] fSortedIndex;
+ fSortedIndex = NULL;
}
}
((AliTRDSignalIndex &)a).fLayer = fLayer;
((AliTRDSignalIndex &)a).fStack = fStack;
((AliTRDSignalIndex &)a).fSM = fSM;
- ((AliTRDSignalIndex &)a).fIndex = fIndex;
- ((AliTRDSignalIndex &)a).fPositionRow = fPositionRow;
- ((AliTRDSignalIndex &)a).fPositionTbin = fPositionTbin;
- ((AliTRDSignalIndex &)a).fLastRow = fLastRow;
- ((AliTRDSignalIndex &)a).fLastCol = fLastCol;
- ((AliTRDSignalIndex &)a).fLastTbin = fLastTbin;
+ ((AliTRDSignalIndex &)a).fMaxLimit = fMaxLimit;
+ ((AliTRDSignalIndex &)a).fPositionRC = fPositionRC;
+ ((AliTRDSignalIndex &)a).fCountRC = fCountRC;
+ ((AliTRDSignalIndex &)a).fSortedWasInit = fSortedWasInit;
+ ((AliTRDSignalIndex &)a).fCurrRow = fCurrRow;
+ ((AliTRDSignalIndex &)a).fCurrCol = fCurrCol;
+ ((AliTRDSignalIndex &)a).fCurrTbin = fCurrTbin;
((AliTRDSignalIndex &)a).fNrows = fNrows;
((AliTRDSignalIndex &)a).fNcols = fNcols;
((AliTRDSignalIndex &)a).fNtbins = fNtbins;
- ((AliTRDSignalIndex &)a).fMaxLimit = fMaxLimit;
- ((AliTRDSignalIndex &)a).fResetCounters = fResetCounters;
- ((AliTRDSignalIndex &)a).fHasEntry = fHasEntry;
+
+ if(((AliTRDSignalIndex &)a).fBoolIndex)
+ {
+ delete [] ((AliTRDSignalIndex &)a).fBoolIndex;
+ }
+ ((AliTRDSignalIndex &)a).fBoolIndex = new Bool_t[fMaxLimit];
+ memcpy(((AliTRDSignalIndex &)a).fBoolIndex, fBoolIndex, fMaxLimit*sizeof(Bool_t));
+
+ if(((AliTRDSignalIndex &)a).fSortedIndex)
+ {
+ delete [] ((AliTRDSignalIndex &)a).fSortedIndex;
+ }
+ ((AliTRDSignalIndex &)a).fSortedIndex = new RowCol[fMaxLimit+1];
+ memcpy(((AliTRDSignalIndex &)a).fSortedIndex, fSortedIndex, (fMaxLimit+1)*sizeof(RowCol));
}
// Assignment operator
//
- if (this != &a) ((AliTRDSignalIndex &) a).Copy(*this);
+ if (this == &a) {
+ return *this;
+ }
+
+ fDet = a.fDet;
+ fLayer = a.fLayer;
+ fStack = a.fStack;
+ fSM = a.fSM;
+ fMaxLimit = a.fMaxLimit;
+ fPositionRC = a.fPositionRC;
+ fCountRC = a.fCountRC;
+ fSortedWasInit = a.fSortedWasInit;
+ fCurrRow = a.fCurrRow;
+ fCurrCol = a.fCurrCol;
+ fCurrTbin = a.fCurrTbin;
+ fNrows = a.fNrows;
+ fNcols = a.fNcols;
+ fNtbins = a.fNtbins;
+
+ if (fBoolIndex) {
+ delete [] fBoolIndex;
+ }
+ fBoolIndex = new Bool_t[fMaxLimit];
+ memcpy(fBoolIndex, fBoolIndex, fMaxLimit*sizeof(Bool_t));
+
+ if (fSortedIndex) {
+ delete [] fSortedIndex;
+ }
+ fSortedIndex = new RowCol[fMaxLimit+1];
+ memcpy(fSortedIndex, fSortedIndex, (fMaxLimit+1)*sizeof(RowCol));
+
+ ResetCounters();
+
return *this;
}
//_____________________________________________________________________________
-void AliTRDSignalIndex::Allocate(Int_t nrow, Int_t ncol,Int_t ntime)
+void AliTRDSignalIndex::Allocate(const Int_t nrow, const Int_t ncol, const Int_t ntime)
{
//
// Create the arrays
fNcols = ncol;
fNtbins = ntime;
- fMaxLimit = nrow * ncol * ntime + nrow * ncol * 2;
- if (fIndex) {
- delete fIndex;
- fIndex = NULL;
+ fMaxLimit = nrow * ncol + 1;
+
+ if (fBoolIndex) {
+ delete [] fBoolIndex;
+ fBoolIndex = NULL;
}
+ if (fSortedIndex) {
+ delete [] fSortedIndex;
+ fSortedIndex = NULL;
+ }
+
+ fBoolIndex = new Bool_t[fMaxLimit];
+ fSortedIndex = new RowCol[fMaxLimit+1];
- fIndex = new TArrayI(fMaxLimit);
- fIndex->Reset(-1);
+ fCountRC = fMaxLimit+1;
+ ResetArrays();
ResetCounters();
- fHasEntry = kFALSE;
+ fCountRC = 1;
+
+}
+//_____________________________________________________________________________
+void AliTRDSignalIndex::ResetArrays()
+{
+ if (!IsAllocated())
+ return;
+ memset(fBoolIndex,0x00,sizeof(Bool_t)*fMaxLimit);
+ memset(fSortedIndex,0xFF,sizeof(RowCol)*fCountRC);
+ fSortedWasInit = kFALSE;
}
//_____________________________________________________________________________
// Reset the array but keep the size - no realloc
//
- fIndex->Reset(-1);
+ fDet = -1;
+ fLayer = -1;
+ fStack = -1;
+ fSM = -1;
+
+ ResetArrays();
ResetCounters();
- fHasEntry = kFALSE;
+ fCountRC = 1;
}
//_____________________________________________________________________________
-void AliTRDSignalIndex::ResetContentConditional(Int_t nrow, Int_t ncol,Int_t ntime)
+void AliTRDSignalIndex::ResetContentConditional(const Int_t nrow, const Int_t ncol, const Int_t ntime)
{
//
// Reset the array but keep the size if no need to enlarge - no realloc
Allocate(nrow, ncol, ntime);
}
else {
- fIndex->Reset(-1);
+ ResetArrays();
ResetCounters();
- fHasEntry = kFALSE;
+ fCountRC = 1;
}
}
fNcols = -1;
fNtbins = -1;
- if (fIndex) {
- delete fIndex;
- fIndex = NULL;
- }
- fIndex = new TArrayI();
- ResetCounters();
-
- fHasEntry = kFALSE;
-
-}
-
-//_____________________________________________________________________________
-void AliTRDSignalIndex::AddIndexTBin(Int_t row, Int_t col, Int_t tbin)
-{
- //
- // Store the index row-column-tbin as an interesting one
- // The RC index is updated to!!!
- // This is to be used in the TRD clusterizer!
- //
-
- if (row * col * tbin + row * col * 2 >= fMaxLimit) {
- AliError(Form("Out-of-limits fPositionCol + fNtbins %d. Limit is: %d"
- ,fPositionCol + fNtbins
- ,fMaxLimit));
- return;
+ if (fBoolIndex) {
+ delete [] fBoolIndex;
+ fBoolIndex = NULL;
}
- if ((row != fLastRow) ||
- (col != fLastCol)) {
-
- // New RC combination
- if (fResetCounters == kTRUE) {
- fPositionRow = 0;
- fPositionCol = 1;
- fResetCounters = kFALSE;
- }
- else {
- fPositionRow += fNtbins + 2;
- fPositionCol += fNtbins + 2;
- }
-
- fPositionTbin = 1;
-
- (*fIndex)[fPositionRow] = row;
- (*fIndex)[fPositionCol] = col;
- (*fIndex)[fPositionCol + fPositionTbin] = tbin;
- ++fPositionTbin;
-
+ if (fSortedIndex) {
+ delete [] fSortedIndex;
+ fSortedIndex = NULL;
}
- else {
-
- // Same RCT combination ?
-
- (*fIndex)[fPositionCol + fPositionTbin] = tbin;
- ++fPositionTbin;
- }
-
- fLastRow = row;
- fLastCol = col;
- fLastTbin = tbin;
+ ResetCounters();
- fHasEntry = kTRUE;
+ fCountRC = 1;
+ fSortedWasInit = kFALSE;
+ fMaxLimit = 0;
}
//_____________________________________________________________________________
-Bool_t AliTRDSignalIndex::NextRCIndex(Int_t &row, Int_t &col)
+Bool_t AliTRDSignalIndex::CheckSorting(Int_t &row, Int_t &col)
{
//
- // Return the position (index in the data array) of the next available pad
+ // Check whether array was read to end or it was not sorted until now
//
- if (fResetCounters == kTRUE) {
- fPositionRow = 0;
- fPositionCol = 1;
- fResetCounters = kFALSE;
- }
- else {
- fPositionRow += fNtbins + 2;
- fPositionCol += fNtbins + 2;
- }
-
- if (fPositionRow >= fMaxLimit) {
- return kFALSE;
- }
-
- fPositionTbin = 1;
-
- row = (*fIndex)[fPositionRow];
- col = (*fIndex)[fPositionCol];
-
- if ((row > -1) &&
- (col > -1)) {
- return kTRUE;
- }
-
- return kFALSE;
-
+ if(fSortedWasInit || fCountRC==1)
+ { //we already reached the end of the array
+ ResetCounters();
+ row = fCurrRow;
+ col = fCurrCol;
+ return kFALSE;
+ }
+ else
+ { //we have not sorted the array up to now, let's do so
+ InitSortedIndex();
+ return NextRCIndex(row, col);
+ }
}
//_____________________________________________________________________________
Bool_t AliTRDSignalIndex::NextRCTbinIndex(Int_t &row, Int_t &col, Int_t &tbin)
{
//
- // Return the position (index in the data array) of the next available tbin
- // within the current pad
- //
-
- if (fPositionRow >= fMaxLimit) {
- return kFALSE;
- }
+ // Returns the next tbin, or if there is no next time bin, it returns the
+ // next used RC combination.
+ //
if (NextTbinIndex(tbin)) {
- row = (*fIndex)[fPositionRow];
- col = (*fIndex)[fPositionCol];
- fResetCounters = kFALSE;
+ row = fCurrRow;
+ col = fCurrCol;
return kTRUE;
}
else {
Bool_t AliTRDSignalIndex::NextTbinIndex(Int_t &tbin)
{
//
- // Return the position (index in the data array) of the next available tbin
- // within the current pad
+ // Returns the next tbin of the current RC combination
//
+
+ if(fCurrTbin<fNtbins)
+ {
+ tbin = fCurrTbin++;
+ return kTRUE;
+ }
- if ((fPositionCol + fPositionTbin >= fMaxLimit) ||
- (fPositionTbin > fNtbins )) {
- return kFALSE;
- }
+ return kFALSE;
- tbin = (*fIndex)[fPositionCol + fPositionTbin];
+}
- if (tbin > -1) {
- ++fPositionTbin;
- return kTRUE;
- }
+//_____________________________________________________________________________
+void AliTRDSignalIndex::InitSortedIndex()
+{
+ //
+ // Creates the SortedIndex
+ //
- return kFALSE;
+ fSortedWasInit = kTRUE;
+ std::sort((UShort_t*)fSortedIndex, ((UShort_t*)fSortedIndex) + fCountRC);
}
// Reset the counters/iterators
//
- fPositionRow = 0;
- fPositionCol = fPositionRow + 1;
- fPositionTbin = 1;
- fLastRow = -1;
- fLastCol = -1;
- fLastTbin = -1;
- fResetCounters = kTRUE;
-
+ fCurrRow = -1;
+ fCurrCol = -1;
+ fCurrTbin = -1;
+ fPositionRC = 0;
}