]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDdataArrayI.cxx
running local for SP and LYZEP and new histograms for QC
[u/mrichter/AliRoot.git] / TRD / AliTRDdataArrayI.cxx
index 35887f545a2aca61c0cfb8f0843584ead23a3005..20f259d767e1fb9add669982fffe033c7580c904 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.1.2.3  2000/10/06 16:49:46  cblume
-Made Getters const
-
-Revision 1.1.2.2  2000/10/04 16:34:58  cblume
-Replace include files by forward declarations
-
-Revision 1.5  2000/06/27 13:08:50  cblume
-Changed to Copy(TObject &A) to appease the HP-compiler
-
-Revision 1.4  2000/06/09 11:10:07  cblume
-Compiler warnings and coding conventions, next round
-
-Revision 1.3  2000/06/08 18:32:58  cblume
-Make code compliant to coding conventions
-
-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$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -45,25 +22,30 @@ Add new data array classes
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
+#include "AliLog.h"
+
 #include "AliTRDdataArrayI.h"
 #include "AliTRDarrayI.h"
 
 ClassImp(AliTRDdataArrayI)
 
 //_____________________________________________________________________________
-AliTRDdataArrayI::AliTRDdataArrayI():AliTRDdataArray()
+AliTRDdataArrayI::AliTRDdataArrayI()
+   :AliTRDdataArray()
+   ,fElements(0)
+   ,fThreshold(0)
 {
   //
   // Default constructor
   //
 
-  fElements = 0;
-
 }
 
 //_____________________________________________________________________________
 AliTRDdataArrayI::AliTRDdataArrayI(Int_t nrow, Int_t ncol, Int_t ntime)
-                 :AliTRDdataArray(nrow,ncol,ntime)
+   :AliTRDdataArray(nrow,ncol,ntime)
+   ,fElements(0)
+   ,fThreshold(0)
 {
   //
   // Creates a AliTRDdataArrayI with the dimensions <nrow>, <ncol>, and <ntime>.
@@ -76,13 +58,14 @@ AliTRDdataArrayI::AliTRDdataArrayI(Int_t nrow, Int_t ncol, Int_t ntime)
 
 //_____________________________________________________________________________
 AliTRDdataArrayI::AliTRDdataArrayI(const AliTRDdataArrayI &a)
+   :AliTRDdataArray(a)
+   ,fElements(a.fElements)
+   ,fThreshold(a.fThreshold)
 {
   //
   // AliTRDdataArrayI copy constructor
   //
 
-  ((AliTRDdataArrayI &) a).Copy(*this);
-
 }
 
 //_____________________________________________________________________________
@@ -92,8 +75,10 @@ AliTRDdataArrayI::~AliTRDdataArrayI()
   // Destructor
   //
 
-  if (fElements) fElements->Delete();
-  delete fElements;
+  if (fElements) {
+    delete fElements;
+    fElements = 0;
+  }
   
 }
 
@@ -106,16 +91,21 @@ void AliTRDdataArrayI::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;
-  fElements = new AliTRDarrayI;
+  if (fElements) {
+    delete fElements;
+  }
+
+  fElements = new AliTRDarrayI();
   fElements->Set(fNelems);
 
 }
 
 //_____________________________________________________________________________
-void AliTRDdataArrayI::Copy(TObject &a)
+void AliTRDdataArrayI::Copy(TObject &a) const
 {
   //
   // Copy function
@@ -136,8 +126,12 @@ void AliTRDdataArrayI::Reset()
   // Reset the array (old content gets deleted)
   //
 
-  if (fElements) delete fElements;
-  fElements = new AliTRDarrayI;
+  if (fElements) {
+    delete fElements;
+  }
+
+
+  fElements = new AliTRDarrayI();
   fElements->Set(0); 
 
   AliTRDdataArray::Reset();
@@ -146,7 +140,7 @@ void AliTRDdataArrayI::Reset()
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDdataArrayI::GetSize()
+Int_t AliTRDdataArrayI::GetSize() const
 {
   //
   // Returns the size of the complete object
@@ -164,7 +158,7 @@ Int_t AliTRDdataArrayI::GetSize()
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDdataArrayI::GetDataSize()
+Int_t AliTRDdataArrayI::GetDataSize() const
 {
   //
   // Returns the size of only the data part
@@ -190,8 +184,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++;
   }
 
@@ -214,9 +208,8 @@ Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time) const
     }
     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));
       }
     }
   }
@@ -225,6 +218,18 @@ Int_t AliTRDdataArrayI::GetData(Int_t row, Int_t col, Int_t time) const
 
 }
 
+//_____________________________________________________________________________
+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)
 {
@@ -245,7 +250,7 @@ void AliTRDdataArrayI::Compress(Int_t bufferType)
   //
 
   if (fBufType  < 0) {
-    Error("AliTRDdataArrayI::Compress","Buffer does not exist");
+    AliError("Buffer does not exist");
     return;
   }
   if (fBufType == bufferType) {
@@ -255,7 +260,7 @@ void AliTRDdataArrayI::Compress(Int_t bufferType)
     Expand();
   }
   if (fBufType !=0)  {
-    Error("AliTRDdataArrayI::Compress","Buffer does not exist");
+    AliError("Buffer does not exist");
     return;
   }
 
@@ -274,7 +279,7 @@ void AliTRDdataArrayI::Expand()
   //
 
   if (fBufType  < 0) {
-    Error("AliTRDdataArrayI::Expand","Buffer does not exist");
+    AliError("Buffer does not exist");
     return;
   }
   if (fBufType == 0) {  
@@ -326,6 +331,7 @@ void AliTRDdataArrayI::Expand1()
   fNelems = fNdim1 * fNdim2;
 
   Int_t *buf = new Int_t[fNelems];
+  memset(buf,0,fNelems*sizeof(Int_t));
 
   fIndex->Set(fNdim2);
 
@@ -339,10 +345,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) {
@@ -368,17 +374,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;  
@@ -392,31 +398,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;
 
 }
 
@@ -428,7 +436,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);
@@ -506,7 +516,7 @@ Bool_t AliTRDdataArrayI::Next0()
   Int_t i;
   for (i = fCurrentIndex + 1; 
        ((i < fNelems) && (fElements->At(i) <= fThreshold)); 
-       i++);
+       i++) {}
   if (i >= fNelems)  {
     fCurrentIndex = -1;
     return kFALSE;
@@ -622,17 +632,6 @@ Int_t AliTRDdataArrayI::GetData1(Int_t idx1, Int_t idx2) const
 
 }
 
-//_____________________________________________________________________________
-Int_t AliTRDdataArrayI::GetDataFast(Int_t idx1, Int_t idx2) const
-{
-  //
-  // Returns the value at a given position in the array
-  //
-  
-  return fElements->At(fIndex->At(idx2) + idx1); 
-
-}
-
 //_____________________________________________________________________________
 void AliTRDdataArrayI::SetData(Int_t row, Int_t col, Int_t time, Int_t value)
 {
@@ -648,9 +647,8 @@ void AliTRDdataArrayI::SetData(Int_t row, Int_t col, Int_t time, Int_t value)
     }
     else {
       if (idx1 >= 0) {
-        TObject::Error("SetData"
-                      ,"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));
       }
     }
   }
@@ -658,20 +656,14 @@ void AliTRDdataArrayI::SetData(Int_t row, Int_t col, Int_t time, Int_t value)
 }
 
 //_____________________________________________________________________________
-void  AliTRDdataArrayI::SetDataFast(Int_t idx1, Int_t idx2, Int_t value)
+void AliTRDdataArrayI::SetDataFast(Int_t idx1, Int_t idx2, Int_t value)
 {
   //
-  // Set the value at a given position in the array
+  // Sets the data value at a given position of the array
+  // No boundary checking
   //
 
-  if ((idx1 < 0) || (idx1 >= fNdim1) || 
-      (idx2 < 0) || (idx2 >= fNdim2)) { 
-    TObject::Error("SetDataFast"
-                  ,"idx1 %d  idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
-                  ,idx1,idx2,fNdim1,fNdim2,this);
-  }
-
-  (*fElements)[fIndex->fArray[idx2] + idx1] = value; 
+  (*fElements)[fIndex->fArray[idx2]+idx1] = value;
 
 }