X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=TRD%2FAliTRDSignalIndex.cxx;h=5433f303965bd825f56047857f88ebe5ed80186a;hb=7c7b461cac701623563550bbcb8c4592818365c5;hp=d95628c1dd648815ad4e9f6eadc6459c96cde37e;hpb=ecf394168509e8d1edcae0a32f0c70d3c93cf668;p=u%2Fmrichter%2FAliRoot.git diff --git a/TRD/AliTRDSignalIndex.cxx b/TRD/AliTRDSignalIndex.cxx index d95628c1dd6..5433f303965 100644 --- a/TRD/AliTRDSignalIndex.cxx +++ b/TRD/AliTRDSignalIndex.cxx @@ -20,104 +20,122 @@ // General container for data from TRD detector segments // // Adapted from AliDigits, origin M.Ivanov // // // -// Author: M. Ploskon (ploskon@ikf.uni-frankfurt.de) // +// Author: // +// Mateusz Ploskon (ploskon@ikf.uni-frankfurt.de) // // // /////////////////////////////////////////////////////////////////////////////// -#include "AliTRDSignalIndex.h" - -#include "TArrayI.h" +#include +#include "TObject.h" #include "AliLog.h" +#include "AliTRDSignalIndex.h" ClassImp(AliTRDSignalIndex) //_____________________________________________________________________________ AliTRDSignalIndex::AliTRDSignalIndex() - : TObject() - , fDet(-1) - , fLayer(-1) - , fStack(-1) - , fSM(-1) - , fIndex(NULL) - , fPositionRow(0) - , fPositionCol(0) - , fPositionTbin(0) - , fLastRow(0) - , fLastCol(0) - , fLastTbin(0) - , fNrows(0) - , fNcols(0) - , fNtbins(0) - , fMaxLimit(0) - , fResetCounters(kTRUE) - , fHasEntry(kFALSE) + :TObject() + ,fDet(-1) + ,fLayer(-1) + ,fStack(-1) + ,fSM(-1) + ,fBoolIndex(NULL) + ,fSortedIndex(NULL) + ,fMaxLimit(0) + ,fPositionRC(0) + ,fCountRC(1) + ,fSortedWasInit(kFALSE) + ,fCurrRow(0) + ,fCurrCol(0) + ,fCurrTbin(0) + ,fNrows(0) + ,fNcols(0) + ,fNtbins(0) { // - // default contructor + // Default contructor // + ResetCounters(); + } //_____________________________________________________________________________ AliTRDSignalIndex::AliTRDSignalIndex(Int_t nrow, Int_t ncol,Int_t ntime) - : TObject() - , fDet(-1) - , fLayer(-1) - , fStack(-1) - , fSM(-1) - , fIndex(NULL) - , fPositionRow(0) - , fPositionCol(0) - , fPositionTbin(0) - , fLastRow(0) - , fLastCol(0) - , fLastTbin(0) - , fNrows(0) - , fNcols(0) - , fNtbins(0) - , fMaxLimit(0) - , fResetCounters(kTRUE) - , fHasEntry(kFALSE) + :TObject() + ,fDet(-1) + ,fLayer(-1) + ,fStack(-1) + ,fSM(-1) + ,fBoolIndex(NULL) + ,fSortedIndex(NULL) + ,fMaxLimit(0) + ,fPositionRC(0) + ,fCountRC(1) + ,fSortedWasInit(kFALSE) + ,fCurrRow(0) + ,fCurrCol(0) + ,fCurrTbin(0) + ,fNrows(0) + ,fNcols(0) + ,fNtbins(0) { - // not the default contructor... hmmm... + // + // Not the default contructor... hmmm... + // + Allocate(nrow, ncol, ntime); + } //_____________________________________________________________________________ -AliTRDSignalIndex::~AliTRDSignalIndex() +AliTRDSignalIndex::AliTRDSignalIndex(const AliTRDSignalIndex &a) + :TObject(a) + ,fDet(a.fDet) + ,fLayer(a.fLayer) + ,fStack(a.fStack) + ,fSM(a.fSM) + ,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) { // - // Destructor + // Copy constructor // - delete fIndex; - fIndex = NULL; + 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)); } //_____________________________________________________________________________ -AliTRDSignalIndex::AliTRDSignalIndex(const AliTRDSignalIndex &a) - : TObject(a) - , fDet(a.fDet) - , 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) - , fNrows(a.fNrows) - , fNcols(a.fNcols) - , fNtbins(a.fNtbins) - , fMaxLimit(a.fMaxLimit) - , fResetCounters(a.fResetCounters) - , fHasEntry(a.fHasEntry) +AliTRDSignalIndex::~AliTRDSignalIndex() { // - // Copy constructor + // Destructor // + + if (fBoolIndex) { + delete [] fBoolIndex; + fBoolIndex = NULL; + } + +if (fSortedIndex) { + delete [] fSortedIndex; + fSortedIndex = NULL; + } + } //_____________________________________________________________________________ @@ -127,22 +145,35 @@ void AliTRDSignalIndex::Copy(TObject &a) const // Copy function // - ((AliTRDSignalIndex &)a).fDet = fDet; - ((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).fNrows = fNrows; - ((AliTRDSignalIndex &)a).fNcols = fNcols; - ((AliTRDSignalIndex &)a).fNtbins = fNtbins; - ((AliTRDSignalIndex &)a).fMaxLimit = fMaxLimit; - ((AliTRDSignalIndex &)a).fResetCounters = fResetCounters; - ((AliTRDSignalIndex &)a).fHasEntry = fHasEntry; + ((AliTRDSignalIndex &)a).fDet = fDet; + ((AliTRDSignalIndex &)a).fLayer = fLayer; + ((AliTRDSignalIndex &)a).fStack = fStack; + ((AliTRDSignalIndex &)a).fSM = fSM; + ((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; + + 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)); + } //_____________________________________________________________________________ @@ -152,33 +183,85 @@ AliTRDSignalIndex& AliTRDSignalIndex::operator = (const AliTRDSignalIndex& a) // 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 + // Create the arrays // fNrows = nrow; fNcols = ncol; fNtbins = ntime; - fMaxLimit = nrow * ncol * ntime + nrow * ncol * 2; - if (fIndex) - { - delete fIndex; - fIndex = NULL; - } + fMaxLimit = nrow * ncol + 1; - fIndex = new TArrayI(fMaxLimit); - //fIndex->Set(fMaxLimit); - fIndex->Reset(-1); + if (fBoolIndex) { + delete [] fBoolIndex; + fBoolIndex = NULL; + } + if (fSortedIndex) { + delete [] fSortedIndex; + fSortedIndex = NULL; + } + + fBoolIndex = new Bool_t[fMaxLimit]; + fSortedIndex = new RowCol[fMaxLimit+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; } //_____________________________________________________________________________ @@ -188,13 +271,14 @@ void AliTRDSignalIndex::Reset() // Reset the array but keep the size - realloc // - fDet = -1; + fDet = -1; fLayer = -1; fStack = -1; - fSM = -1; + fSM = -1; - // all will be lost + // All will be lost Allocate(fNrows, fNcols, fNtbins); + } //_____________________________________________________________________________ @@ -204,36 +288,43 @@ void AliTRDSignalIndex::ResetContent() // 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 // - fDet = -1; + fDet = -1; fLayer = -1; fStack = -1; - fSM = -1; + fSM = -1; + + if ((nrow > fNrows) || + (ncol > fNcols) || + (ntime > fNtbins)) { + Allocate(nrow, ncol, ntime); + } + else { + ResetArrays(); + ResetCounters(); + fCountRC = 1; + } - if (nrow > fNrows || ncol > fNcols || ntime > fNtbins) - { - Allocate(nrow, ncol, ntime); - } - else - { - fIndex->Reset(-1); - ResetCounters(); - fHasEntry = kFALSE; - } } - //_____________________________________________________________________________ void AliTRDSignalIndex::ClearAll() { @@ -241,242 +332,115 @@ void AliTRDSignalIndex::ClearAll() // Reset the values - clear all! // - fDet = -1; - fLayer = -1; - fStack = -1; - fSM = -1; + fDet = -1; + fLayer = -1; + fStack = -1; + fSM = -1; - fNrows = -1; - fNcols = -1; + fNrows = -1; + fNcols = -1; fNtbins = -1; - if (fIndex) - { - delete fIndex; - fIndex = NULL; - } - fIndex = new TArrayI(); + if (fBoolIndex) { + delete [] fBoolIndex; + fBoolIndex = NULL; + } + + if (fSortedIndex) { + delete [] fSortedIndex; + fSortedIndex = NULL; + } + ResetCounters(); - fHasEntry = kFALSE; + + fCountRC = 1; + fSortedWasInit = kFALSE; + fMaxLimit = 0; + } //_____________________________________________________________________________ -void AliTRDSignalIndex::AddIndexTBin(Int_t row, Int_t col, Int_t tbin) +Bool_t AliTRDSignalIndex::CheckSorting(Int_t &row, Int_t &col) { - // 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 (fPositionCol + fNtbins >= fMaxLimit) - if (row * col * tbin + row * col * 2 >= fMaxLimit) - { - AliError(Form("Out-of-limits fPositionCol + fNtbins %d. Limit is: %d", fPositionCol + fNtbins, fMaxLimit)); - return; - } + // + // Check whether array was read to end or it was not sorted until now + // - 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; - //AliInfo(Form("x1: fPositionCol + fPositionTbin = %d", fPositionCol + fPositionTbin)); - ++fPositionTbin; + if(fSortedWasInit || fCountRC==1) + { //we already reached the end of the array + ResetCounters(); + row = fCurrRow; + col = fCurrCol; + return kFALSE; } else - { - // same RCT combination ? - // if (fLastTbin == tbin) - // { - // AliWarning(Form("Same RCT? %d %d %d", row, col, tbin)); - // } - - (*fIndex)[fPositionCol + fPositionTbin] = tbin; - //AliInfo(Form("x2: fPositionCol + fPositionTbin = %d", fPositionCol + fPositionTbin)); - ++fPositionTbin; + { //we have not sorted the array up to now, let's do so + InitSortedIndex(); + return NextRCIndex(row, col); } - - fLastRow = row; - fLastCol = col; - fLastTbin = tbin; - - fHasEntry = kTRUE; } //_____________________________________________________________________________ -Bool_t AliTRDSignalIndex::NextRCIndex(Int_t &row, Int_t &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 pad - - if (fResetCounters == kTRUE) - { - fPositionRow = 0; - fPositionCol = 1; - - fResetCounters = kFALSE; - //AliDebug(2, "Reset counters"); - } - else - { - fPositionRow += fNtbins + 2; - fPositionCol += fNtbins + 2; - } + // + // Returns the next tbin, or if there is no next time bin, it returns the + // next used RC combination. + // - if (fPositionRow >= fMaxLimit) - { - //AliDebug(8, "Out of index range"); - return kFALSE; + if (NextTbinIndex(tbin)) { + row = fCurrRow; + col = fCurrCol; + return kTRUE; + } + else { + if (NextRCIndex(row, col)) { + return NextRCTbinIndex(row, col, tbin); } + } - //AliDebug(8, Form("Next RC %d", fPositionRow / (fNtbins + 2))); - - fPositionTbin = 1; - - row = (*fIndex)[fPositionRow]; - col = (*fIndex)[fPositionCol]; - - if (row > -1 && col > -1) - return kTRUE; - return kFALSE; + } //_____________________________________________________________________________ -Bool_t AliTRDSignalIndex::NextRCTbinIndex(Int_t &row, Int_t &col, Int_t &tbin) +Bool_t AliTRDSignalIndex::NextTbinIndex(Int_t &tbin) { - // return the position (index in the data array) of the next available tbin - // within the current pad - - if (fPositionRow >= fMaxLimit) - { - //AliDebug(8, "Out of index range"); - return kFALSE; - } - - if (NextTbinIndex(tbin)) + // + // Returns the next tbin of the current RC combination + // + + if(fCurrTbin= fMaxLimit || fPositionTbin > fNtbins) - { - //AliDebug(8, "Out of index range"); - return kFALSE; - } + fSortedWasInit = kTRUE; + std::sort((UShort_t*)fSortedIndex, ((UShort_t*)fSortedIndex) + fCountRC); - tbin = (*fIndex)[fPositionCol + fPositionTbin]; +} - if (tbin > -1) - { - ++fPositionTbin; - return kTRUE; - } +//_____________________________________________________________________________ +void AliTRDSignalIndex::ResetCounters() +{ + // + // Reset the counters/iterators + // - return kFALSE; + fCurrRow = -1; + fCurrCol = -1; + fCurrTbin = -1; + fPositionRC = 0; } - -// void AliTRDSignalIndex::Dump() -// { -// AliInfo("R C T..."); -// Int_t i = 0; -// Int_t rcok = 0; -// while ( i < fMaxLimit ) -// { -// if (i % (fNtbins + 2) == 0) -// { -// if ((*(*fIndex))[i] > -1) -// { -// rcok = 1; -// printf("\n RC : "); -// } -// else -// rcok = 0; -// } -// if (rcok) -// if ((*(*fIndex))[i] > -1) -// printf("[%d] = %d \t", i, (*(*fIndex))[i]); -// i++; -// } -// } - -// //_____________________________________________________________________________ -// void AliTRDSignalIndex::Dump() -// { -// // -// // Dump the data -// // - -// AliInfo("R C T..."); -// Int_t i = 0; -// Int_t rcok = 0; -// while ( i < fMaxLimit ) -// { -// if (i % (fNtbins + 2) == 0) -// { -// if ((*fIndex)[i] > -1) -// { -// rcok = 1; -// printf("\n RC : "); -// } -// else -// rcok = 0; -// } -// if (rcok) -// if ((*fIndex)[i] > -1) -// printf("[%d] = %d \t", i, (*fIndex)[i]); -// i++; -// } -// } - -// //_____________________________________________________________________________ -// void AliTRDSignalIndex::Dump2() -// { -// // -// // Dump the data -// // - -// AliInfo("R C T..."); -// Int_t ir, ic, it; -// ResetCounters(); -// while (NextRCIndex(ir, ic)) -// { -// printf("\nR %d C %d t : ", ir, ic); -// while (NextTbinIndex(it)) -// printf("%d ", it); -// } -// printf("\n"); -// }