]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDdataArrayI.cxx
Added a commented out version with new digitizers.
[u/mrichter/AliRoot.git] / TRD / AliTRDdataArrayI.cxx
index 4d5dc91ca9f5de04724d5a935c74691634e60804..d9303617dcfa024404c4169da9bcbdb9e7704f52 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.2  2000/05/08 16:17:27  cblume
-Merge TRD-develop
-
-Revision 1.1.2.1  2000/05/08 15:14:34  cblume
-Add new data array classes
-
-*/
+/* $Id$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -31,6 +23,7 @@ Add new data array classes
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "AliTRDdataArrayI.h"
+#include "AliTRDarrayI.h"
 
 ClassImp(AliTRDdataArrayI)
 
@@ -54,18 +47,20 @@ AliTRDdataArrayI::AliTRDdataArrayI(Int_t nrow, Int_t ncol, Int_t ntime)
   // The row- and column dimensions are compressible.
   //
 
+  fElements = 0;
+
   Allocate(nrow,ncol,ntime);
   
 }
 
 //_____________________________________________________________________________
-AliTRDdataArrayI::AliTRDdataArrayI(AliTRDdataArrayI &a)
+AliTRDdataArrayI::AliTRDdataArrayI(const AliTRDdataArrayI &a):AliTRDdataArray(a)
 {
   //
   // AliTRDdataArrayI copy constructor
   //
 
-  a.Copy(*this);
+  ((AliTRDdataArrayI &) a).Copy(*this);
 
 }
 
@@ -76,7 +71,7 @@ AliTRDdataArrayI::~AliTRDdataArrayI()
   // Destructor
   //
 
-  if (fElements) fElements->Delete();
+  if (fElements) delete fElements;
   
 }
 
@@ -92,21 +87,21 @@ void AliTRDdataArrayI::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
   if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
 
   if (fElements) delete fElements;
-  fElements = new AliTRDarrayI;
+  fElements = new AliTRDarrayI();
   fElements->Set(fNelems);
 
 }
 
 //_____________________________________________________________________________
-void AliTRDdataArrayI::Copy(AliTRDdataArrayI &a)
+void AliTRDdataArrayI::Copy(TObject &a) const
 {
   //
   // Copy function
   //
 
-  fElements->Copy(*a.fElements);
+  fElements->Copy(*((AliTRDdataArrayI &) a).fElements);
 
-  a.fThreshold = fThreshold;
+  ((AliTRDdataArrayI &) a).fThreshold = fThreshold;
 
   AliTRDdataArray::Copy(a);
 
@@ -120,7 +115,7 @@ void AliTRDdataArrayI::Reset()
   //
 
   if (fElements) delete fElements;
-  fElements = new AliTRDarrayI;
+  fElements = new AliTRDarrayI();
   fElements->Set(0); 
 
   AliTRDdataArray::Reset();
@@ -129,7 +124,7 @@ void AliTRDdataArrayI::Reset()
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDdataArrayI::GetSize()
+Int_t AliTRDdataArrayI::GetSize() const
 {
   //
   // Returns the size of the complete object
@@ -147,7 +142,7 @@ Int_t AliTRDdataArrayI::GetSize()
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDdataArrayI::GetDataSize()
+Int_t AliTRDdataArrayI::GetDataSize() const
 {
   //
   // Returns the size of only the data part
@@ -173,8 +168,8 @@ Int_t AliTRDdataArrayI::GetOverThreshold(Int_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++;
   }
 
@@ -183,7 +178,7 @@ Int_t AliTRDdataArrayI::GetOverThreshold(Int_t threshold)
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time)
+Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time) const
 {
   //
   // Returns the data value at a given position of the array
@@ -208,6 +203,18 @@ Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time)
 
 }
 
+//_____________________________________________________________________________
+Int_t AliTRDdataArrayI::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 AliTRDdataArrayI::Compress(Int_t bufferType, Int_t threshold)
 {
@@ -309,6 +316,7 @@ void AliTRDdataArrayI::Expand1()
   fNelems = fNdim1 * fNdim2;
 
   Int_t *buf = new Int_t[fNelems];
+  memset(buf,0,fNelems*sizeof(Int_t));
 
   fIndex->Set(fNdim2);
 
@@ -322,10 +330,10 @@ void AliTRDdataArrayI::Expand1()
 
     // Negative sign counts the unwritten values (under threshold)
     if ((*fElements)[i] < 0) {
-      idx1 -= fElements->At(i);
+      idx1 -= (*fElements)[i];
     } 
     else {
-      buf[(*fIndex)[idx2] + idx1] = fElements->At(i);
+      buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
       idx1++;
     }
     if (idx1 == fNdim1) {
@@ -351,17 +359,17 @@ void AliTRDdataArrayI::Compress1()
   // Compress a buffer of type 1
   //
 
-  AliTRDarrayI  buf;  
-  buf.Set(fNelems);
-  AliTRDarrayI  index;
-  index.Set(fNdim2);
+  AliTRDarrayI *buf   = new AliTRDarrayI();  
+  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;  
@@ -375,31 +383,33 @@ void AliTRDdataArrayI::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;
 
 }
 
@@ -411,7 +421,9 @@ void AliTRDdataArrayI::Expand2()
   //
 
   Int_t i, k;
+
   Int_t *buf = new Int_t[fNelems];
+  memset(buf,0,fNelems*sizeof(Int_t)); 
 
   fNelems = fNdim1 * fNdim2;
   fIndex->Set(fNdim2);
@@ -478,7 +490,7 @@ Bool_t AliTRDdataArrayI::First0()
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDdataArrayI::Next0()
+Bool_t AliTRDdataArrayI::Next0() 
 {
   //
   // Returns the next entry for a buffer of type 0
@@ -503,7 +515,7 @@ Bool_t AliTRDdataArrayI::Next0()
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDdataArrayI::First1()
+Bool_t AliTRDdataArrayI::First1() 
 {
   //
   // Returns the first entry for a buffer of type 1
@@ -537,7 +549,7 @@ Bool_t AliTRDdataArrayI::First1()
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDdataArrayI::Next1()
+Bool_t AliTRDdataArrayI::Next1() 
 {
   //
   // Returns the next entry for a buffer of type 1
@@ -569,7 +581,7 @@ Bool_t AliTRDdataArrayI::Next1()
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2)
+Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2) const
 {
   //
   // Returns the value at a given position of the array
@@ -605,3 +617,50 @@ Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2)
 
 }
 
+//_____________________________________________________________________________
+void AliTRDdataArrayI::SetData(Int_t row, Int_t col, Int_t time, Int_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) {
+        TObject::Error("SetData"
+                      ,"time %d out of bounds (size: %d, this: 0x%08x)"
+                      ,time,fNdim2,this);
+      }
+    }
+  }
+
+}
+
+//_____________________________________________________________________________
+void AliTRDdataArrayI::SetDataFast(Int_t idx1, Int_t idx2, Int_t value)
+{
+  //
+  // Sets the data value at a given position of the array
+  // No boundary checking
+  //
+
+  (*fElements)[fIndex->fArray[idx2]+idx1] = value;
+
+}
+
+//_____________________________________________________________________________
+AliTRDdataArrayI &AliTRDdataArrayI::operator=(const AliTRDdataArrayI &a)
+{
+  //
+  // Assignment operator
+  //
+
+  if (this != &a) ((AliTRDdataArrayI &) a).Copy(*this);
+  return *this;
+
+}