X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=TRD%2FAliTRDdataArrayF.cxx;h=7c69bb7e4c696a12bf88dc5ec6b22f8463143a87;hb=fd3ef1361d8592c882ba4e000f6588d1acb17e76;hp=0f1c6060442e23229d58e529e7f2a92afd6db78b;hpb=6f1e466d6db177aa095cc30f57958d5e62389e1c;p=u%2Fmrichter%2FAliRoot.git diff --git a/TRD/AliTRDdataArrayF.cxx b/TRD/AliTRDdataArrayF.cxx index 0f1c6060442..7c69bb7e4c6 100644 --- a/TRD/AliTRDdataArrayF.cxx +++ b/TRD/AliTRDdataArrayF.cxx @@ -13,12 +13,7 @@ * provided "as is" without express or implied warranty. * **************************************************************************/ -/* -$Log$ -Revision 1.1.2.1 2000/05/08 15:14:34 cblume -Add new data array classes - -*/ +/* $Id$ */ /////////////////////////////////////////////////////////////////////////////// // // @@ -27,24 +22,31 @@ Add new data array classes // // /////////////////////////////////////////////////////////////////////////////// +#include "AliLog.h" + #include "AliTRDdataArrayF.h" +#include "AliTRDarrayI.h" +#include "AliTRDarrayF.h" ClassImp(AliTRDdataArrayF) //_____________________________________________________________________________ -AliTRDdataArrayF::AliTRDdataArrayF():AliTRDdataArray() +AliTRDdataArrayF::AliTRDdataArrayF() + :AliTRDdataArray() + ,fElements(0) + ,fThreshold(0) { // // Default constructor // - fElements = 0; - } //_____________________________________________________________________________ AliTRDdataArrayF::AliTRDdataArrayF(Int_t nrow, Int_t ncol, Int_t ntime) - :AliTRDdataArray(nrow,ncol,ntime) + :AliTRDdataArray(nrow,ncol,ntime) + ,fElements(0) + ,fThreshold(0) { // // Creates a AliTRDdataArrayF with the dimensions , , and . @@ -55,6 +57,18 @@ AliTRDdataArrayF::AliTRDdataArrayF(Int_t nrow, Int_t ncol, Int_t ntime) } +//_____________________________________________________________________________ +AliTRDdataArrayF::AliTRDdataArrayF(const AliTRDdataArrayF &a) + :AliTRDdataArray(a) + ,fElements(a.fElements) + ,fThreshold(a.fThreshold) +{ + // + // AliTRDdataArrayF copy constructor + // + +} + //_____________________________________________________________________________ AliTRDdataArrayF::~AliTRDdataArrayF() { @@ -62,7 +76,10 @@ AliTRDdataArrayF::~AliTRDdataArrayF() // Destructor // - if (fElements) fElements->Delete(); + if (fElements) { + delete fElements; + fElements = 0; + } } @@ -75,15 +92,34 @@ void AliTRDdataArrayF::Allocate(Int_t nrow, Int_t ncol, Int_t ntime) // The row- and column dimensions are compressible. // + if (fNelems < 0) { + AliTRDdataArray::Allocate(nrow,ncol,ntime); + } - if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime); + if (fElements) { + delete fElements; + } - if (fElements) delete fElements; - fElements = new AliTRDarrayF; + fElements = new AliTRDarrayF(); fElements->Set(fNelems); } +//_____________________________________________________________________________ +void AliTRDdataArrayF::Copy(TObject &a) const +{ + // + // Copy function + // + + fElements->Copy(*((AliTRDdataArrayF &) a).fElements); + + ((AliTRDdataArrayF &) a).fThreshold = fThreshold; + + AliTRDdataArray::Copy(a); + +} + //_____________________________________________________________________________ void AliTRDdataArrayF::Reset() { @@ -91,8 +127,11 @@ void AliTRDdataArrayF::Reset() // Reset the array (old content gets deleted) // - if (fElements) delete fElements; - fElements = new AliTRDarrayF; + if (fElements) { + delete fElements; + } + + fElements = new AliTRDarrayF(); fElements->Set(0); AliTRDdataArray::Reset(); @@ -100,7 +139,7 @@ void AliTRDdataArrayF::Reset() } //_____________________________________________________________________________ -Int_t AliTRDdataArrayF::GetSize() +Int_t AliTRDdataArrayF::GetSize() const { // // Returns the size of the complete object @@ -109,7 +148,7 @@ Int_t AliTRDdataArrayF::GetSize() Int_t size = sizeof(this); if (fIndex) size += sizeof(fIndex) - + fIndex->GetSize() * sizeof(Float_t); + + fIndex->GetSize() * sizeof(Int_t); if (fElements) size += sizeof(fElements) + fElements->GetSize() * sizeof(Float_t); @@ -118,7 +157,7 @@ Int_t AliTRDdataArrayF::GetSize() } //_____________________________________________________________________________ -Int_t AliTRDdataArrayF::GetDataSize() +Int_t AliTRDdataArrayF::GetDataSize() const { // // Returns the size of only the data part @@ -132,7 +171,7 @@ Int_t AliTRDdataArrayF::GetDataSize() } //_____________________________________________________________________________ -Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold) +Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold) { // // Returns the number of entries over threshold @@ -144,8 +183,8 @@ Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold) Int_t over = 0; for (Bool_t cont = First(); cont == kTRUE; cont = Next()) { - if ((fCurrentIdx1 < 0) || (fCurrentIdx1 > fNdim1)) continue; - if ((fCurrentIdx2 < 0) || (fCurrentIdx2 > fNdim2)) continue; + if ((fCurrentIdx1 < 0) || (fCurrentIdx1 >= fNdim1)) continue; + if ((fCurrentIdx2 < 0) || (fCurrentIdx2 >= fNdim2)) continue; if (fElements->At(fCurrentIndex) > threshold) over++; } @@ -154,7 +193,7 @@ Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold) } //_____________________________________________________________________________ -Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time) +Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time) const { // // Returns the data value at a given position of the array @@ -169,9 +208,8 @@ Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time) } else { if (idx1 >= 0) { - TObject::Error("GetData" - ,"time %d out of bounds (size: %d, this: 0x%08x)" - ,time,fNdim2,this); + AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)" + ,time,fNdim2,this)); } } } @@ -180,6 +218,18 @@ Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time) } +//_____________________________________________________________________________ +Float_t AliTRDdataArrayF::GetDataFast(Int_t idx1, Int_t idx2) const +{ + // + // Returns the data value at a given position of the array + // No boundary checking + // + + return fElements->At(fIndex->At(idx2)+idx1); + +} + //_____________________________________________________________________________ void AliTRDdataArrayF::Compress(Int_t bufferType, Float_t threshold) { @@ -200,7 +250,7 @@ void AliTRDdataArrayF::Compress(Int_t bufferType) // if (fBufType < 0) { - Error("AliTRDdataArrayF::Compress","Buffer does not exist"); + AliError("Buffer does not exist"); return; } if (fBufType == bufferType) { @@ -210,7 +260,7 @@ void AliTRDdataArrayF::Compress(Int_t bufferType) Expand(); } if (fBufType !=0) { - Error("AliTRDdataArrayF::Compress","Buffer does not exist"); + AliError("Buffer does not exist"); return; } @@ -229,7 +279,7 @@ void AliTRDdataArrayF::Expand() // if (fBufType < 0) { - Error("AliTRDdataArrayF::Expand","Buffer does not exist"); + AliError("Buffer does not exist"); return; } if (fBufType == 0) { @@ -244,7 +294,7 @@ void AliTRDdataArrayF::Expand() } //_____________________________________________________________________________ -Bool_t AliTRDdataArrayF::First() +Bool_t AliTRDdataArrayF::First() { // // Returns the position of the first valid data value @@ -281,6 +331,7 @@ void AliTRDdataArrayF::Expand1() fNelems = fNdim1 * fNdim2; Float_t *buf = new Float_t[fNelems]; + memset(buf,0,fNelems*sizeof(Float_t)); fIndex->Set(fNdim2); @@ -288,16 +339,16 @@ void AliTRDdataArrayF::Expand1() Int_t idx1 = 0; Int_t idx2 = 0; - Int_t N = fElements->fN; + Int_t n = fElements->fN; - for (i = 0; i < N; i++){ + for (i = 0; i < n; i++){ // Negative sign counts the unwritten values (under threshold) if ((*fElements)[i] < 0) { - idx1 -= (Int_t) fElements->At(i); + idx1 -= TMath::Nint(fElements->At(i)); } else { - buf[(*fIndex)[idx2] + idx1] = fElements->At(i); + buf[(*fIndex)[idx2] + idx1] = (*fElements)[i]; idx1++; } if (idx1 == fNdim1) { @@ -323,17 +374,17 @@ void AliTRDdataArrayF::Compress1() // Compress a buffer of type 1 // - AliTRDarrayF buf; - buf.Set(fNelems); - AliTRDarrayI index; - index.Set(fNdim2); + AliTRDarrayF *buf = new AliTRDarrayF(); + buf->Set(fNelems); + AliTRDarrayI *index = new AliTRDarrayI(); + index->Set(fNdim2); Int_t icurrent = -1; Int_t izero; for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){ // Set the idx2 pointer - index[idx2] = icurrent + 1; + (*index)[idx2] = icurrent + 1; // Reset the zero counter izero = 0; @@ -347,31 +398,33 @@ void AliTRDdataArrayF::Compress1() if (izero > 0) { // If we have currently izero counts under threshold icurrent++; - if (icurrent >= buf.fN) buf.Expand(icurrent*2); + if (icurrent >= buf->fN) buf->Expand(icurrent*2); // Store the number of entries below zero - buf[icurrent] = -izero; + (*buf)[icurrent] = -izero; izero = 0; } icurrent++; - if (icurrent >= buf.fN) buf.Expand(icurrent*2); - buf[icurrent] = GetDataFast(idx1,idx2); + if (icurrent >= buf->fN) buf->Expand(icurrent*2); + (*buf)[icurrent] = GetDataFast(idx1,idx2); } // If signal larger than threshold } // End of loop over idx1 if (izero > 0) { icurrent++; - if (icurrent >= buf.fN) buf.Expand(icurrent*2); + if (icurrent >= buf->fN) buf->Expand(icurrent*2); // Store the number of entries below zero - buf[icurrent] = -izero; + (*buf)[icurrent] = -izero; } } - buf.Expand(icurrent+1); - (*fElements) = buf; + buf->Expand(icurrent+1); + if (fElements) delete fElements; + fElements = buf; fNelems = fElements->fN; fBufType = 1; - (*fIndex) = index; + if (fIndex) delete fIndex; + fIndex = index; } @@ -383,7 +436,9 @@ void AliTRDdataArrayF::Expand2() // Int_t i, k; + Float_t *buf = new Float_t[fNelems]; + memset(buf,0,fNelems*sizeof(Float_t)); fNelems = fNdim1 * fNdim2; fIndex->Set(fNdim2); @@ -392,11 +447,12 @@ void AliTRDdataArrayF::Expand2() Int_t idx1 = 0; Int_t idx2 = 0; - Int_t N = fElements->fN; - for (i = 0; i < N; i++){ + Int_t n = fElements->fN; + for (i = 0; i < n; i++){ // Negative sign counts the unwritten values (under threshold) if ((*fElements)[i] < 0) { - idx1 -= (Int_t) fElements->At(i); + //idx1 -= (Int_t) fElements->At(i); + idx1 -= TMath::Nint(fElements->At(i)); } else { buf[(*fIndex)[idx2]+idx1] = fElements->At(i); @@ -421,11 +477,14 @@ void AliTRDdataArrayF::Expand2() //_____________________________________________________________________________ void AliTRDdataArrayF::Compress2() { + // + // Compress a buffer of type 2 - not implemented! + // } //_____________________________________________________________________________ -Bool_t AliTRDdataArrayF::First0() +Bool_t AliTRDdataArrayF::First0() { // // Returns the first entry for a buffer of type 0 @@ -472,7 +531,7 @@ Bool_t AliTRDdataArrayF::Next0() } //_____________________________________________________________________________ -Bool_t AliTRDdataArrayF::First1() +Bool_t AliTRDdataArrayF::First1() { // // Returns the first entry for a buffer of type 1 @@ -485,7 +544,8 @@ Bool_t AliTRDdataArrayF::First1() Int_t i; for (i = 0; i < fNelems; i++){ if (fElements->At(i) < 0) { - fCurrentIdx1 -= (Int_t) fElements->At(i); + //fCurrentIdx1 -= (Int_t) fElements->At(i); + fCurrentIdx1 -= TMath::Nint(fElements->At(i)); } else { fCurrentIdx1++; @@ -506,7 +566,7 @@ Bool_t AliTRDdataArrayF::First1() } //_____________________________________________________________________________ -Bool_t AliTRDdataArrayF::Next1() +Bool_t AliTRDdataArrayF::Next1() { // // Returns the next entry for a buffer of type 1 @@ -517,7 +577,8 @@ Bool_t AliTRDdataArrayF::Next1() Int_t i; for (i = fCurrentIndex + 1; i < fNelems; i++){ if (fElements->At(i) < 0) { - fCurrentIdx1 -= (Int_t) fElements->At(i); + //fCurrentIdx1 -= (Int_t) fElements->At(i); + fCurrentIdx1 -= TMath::Nint(fElements->At(i)); } else { fCurrentIdx1++; @@ -538,7 +599,7 @@ Bool_t AliTRDdataArrayF::Next1() } //_____________________________________________________________________________ -Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2) +Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2) const { // // Returns the value at a given position of the array @@ -558,7 +619,8 @@ Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2) for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){ if (fElements->At(i) < 0) { - curidx1 -= (Int_t) fElements->At(i); + //curidx1 -= (Int_t) fElements->At(i); + curidx1 -= TMath::Nint(fElements->At(i)); } else { curidx1++; @@ -574,3 +636,50 @@ Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2) } +//_____________________________________________________________________________ +void AliTRDdataArrayF::SetData(Int_t row, Int_t col, Int_t time, Float_t value) +{ + // + // Sets the data value at a given position of the array + // Includes boundary checking + // + + if ((row >= 0) && (col >= 0) && (time >= 0)) { + Int_t idx1 = GetIdx1(row,col); + if ((idx1 >= 0) && (time < fNdim2)) { + SetDataFast(idx1,time,value); + } + else { + if (idx1 >= 0) { + AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)" + ,time,fNdim2,this)); + } + } + } + +} + +//_____________________________________________________________________________ +void AliTRDdataArrayF::SetDataFast(Int_t idx1, Int_t idx2, Float_t value) +{ + // + // Sets the data value at a given position of the array + // No boundary checking + // + + (*fElements)[fIndex->fArray[idx2]+idx1] = value; + +} + +//_____________________________________________________________________________ +AliTRDdataArrayF &AliTRDdataArrayF::operator=(const AliTRDdataArrayF &a) +{ + // + // Assignment operator + // + + if (this != &a) ((AliTRDdataArrayF &) a).Copy(*this); + return *this; + +} +