]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDdataArray.cxx
Additional protection in the destructor: when you have a chain of calls returning...
[u/mrichter/AliRoot.git] / TRD / AliTRDdataArray.cxx
index 0cd7633d4cb94320c7997a204de2b796b7873cda..e344751999423e8dab684918286c2c15fc844528 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.5  2000/06/08 18:32:58  cblume
-Make code compliant to coding conventions
-
-Revision 1.4  2000/06/07 16:27:01  cblume
-Try to remove compiler warnings on Sun and HP
-
-Revision 1.3  2000/05/18 07:56:44  cblume
-Added #include <stdlib.h>
-
-Revision 1.2  2000/05/08 16:17:27  cblume
-Merge TRD-develop
-
-Revision 1.1.4.1  2000/05/08 15:13:59  cblume
-Introduce boundary checking
-
-Revision 1.1  2000/02/28 18:59:19  cblume
-Add new TRD classes
-
-*/
+/* $Id$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -46,6 +26,9 @@ Add new TRD classes
 
 #include "TClass.h"
 #include "TError.h"
+
+#include "AliLog.h"
+
 #include "AliTRDsegmentID.h"
 #include "AliTRDarrayI.h"
 #include "AliTRDdataArray.h"
@@ -54,27 +37,37 @@ ClassImp(AliTRDdataArray)
 
 //_____________________________________________________________________________
 AliTRDdataArray::AliTRDdataArray()
+   :fNrow(0)
+   ,fNcol(0)
+   ,fNtime(0)
+   ,fNdim1(-1)
+   ,fNdim2(-1)
+   ,fIndex(0)
+   ,fBufType(-1)
+   ,fNelems(-1)
+   ,fCurrentIdx1(0)
+   ,fCurrentIdx2(0)
+   ,fCurrentIndex(0)
 {
   //
   // Default constructor
   //
 
-  fIndex   =  0;
-
-  fNdim1   = -1;
-  fNdim2   = -1;
-  fNelems  = -1; 
-
-  fBufType = -1;
-
-  fNrow    =  0;
-  fNcol    =  0;
-  fNtime   =  0;
-
 }
 
 //_____________________________________________________________________________
 AliTRDdataArray::AliTRDdataArray(Int_t nrow, Int_t ncol, Int_t ntime)
+   :fNrow(0)
+   ,fNcol(0)
+   ,fNtime(0)
+   ,fNdim1(-1)
+   ,fNdim2(-1)
+   ,fIndex(0)
+   ,fBufType(-1)
+   ,fNelems(-1)
+   ,fCurrentIdx1(0)
+   ,fCurrentIdx2(0)
+   ,fCurrentIndex(0)
 {
   //
   // Creates a AliTRDdataArray with the dimensions <nrow>, <ncol>, and <ntime>.
@@ -87,13 +80,23 @@ AliTRDdataArray::AliTRDdataArray(Int_t nrow, Int_t ncol, Int_t ntime)
 
 //_____________________________________________________________________________
 AliTRDdataArray::AliTRDdataArray(const AliTRDdataArray &d)
+   :AliTRDsegmentID(d)
+   ,fNrow(d.fNrow)
+   ,fNcol(d.fNcol)
+   ,fNtime(d.fNtime)
+   ,fNdim1(d.fNdim1)
+   ,fNdim2(d.fNdim2)
+   ,fIndex(d.fIndex)
+   ,fBufType(d.fBufType)
+   ,fNelems(d.fNelems)
+   ,fCurrentIdx1(0)
+   ,fCurrentIdx2(0)
+   ,fCurrentIndex(0)
 {
   //
   // AliTRDdataArray copy constructor
   //
 
-  ((AliTRDdataArray &) d).Copy(*this);
-
 }
 
 //_____________________________________________________________________________
@@ -103,7 +106,10 @@ AliTRDdataArray::~AliTRDdataArray()
   // AliTRDdataArray destructor
   //
 
-  if (fIndex) fIndex->Delete();
+  if (fIndex) {
+    delete fIndex;
+    fIndex = 0;
+  }
   
 }
 
@@ -120,7 +126,7 @@ AliTRDdataArray &AliTRDdataArray::operator=(const AliTRDdataArray &d)
 }
 
 //_____________________________________________________________________________
-void AliTRDdataArray::Copy(TObject &d)
+void AliTRDdataArray::Copy(TObject &d) const
 {
   //
   // Copy function
@@ -145,7 +151,7 @@ void AliTRDdataArray::Copy(TObject &d)
 }
 
 //_____________________________________________________________________________
-void AliTRDdataArray::Allocate(Int_t nrow, Int_t ncol,Int_t ntime)
+void AliTRDdataArray::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
 {
   //
   // Allocates memory for a AliTRDdataArray with the dimensions 
@@ -154,15 +160,15 @@ void AliTRDdataArray::Allocate(Int_t nrow, Int_t ncol,Int_t ntime)
   //
 
   if (nrow  <= 0) {
-    Error("AliTRDdataArray::Allocate","The number of rows has to be positive");
+    AliError("The number of rows has to be positive");
     exit(1);
   }
   if (ncol  <= 0) {
-    Error("AliTRDdataArray::Allocate","The number of columns has to be positive");
+    AliError("The number of columns has to be positive");
     exit(1);
   }
   if (ntime <= 0) {
-    Error("AliTRDdataArray::Allocate","The number of timebins has to be positive");
+    AliError("The number of timebins has to be positive");
     exit(1);
   }
 
@@ -172,13 +178,13 @@ void AliTRDdataArray::Allocate(Int_t nrow, Int_t ncol,Int_t ntime)
   fNdim1  = nrow * ncol;
   fNdim2  = ntime;
   fNelems = fNdim1 * fNdim2;
-
+  
   fNrow   = nrow;
   fNcol   = ncol;
   fNtime  = ntime;
 
   if (fIndex) delete fIndex;
-  fIndex = new AliTRDarrayI;
+  fIndex = new AliTRDarrayI();
   fIndex->Set(fNdim2);
   for (Int_t i = 0, k = 0; i < fNdim2; i++, k += fNdim1) { 
     (*fIndex)[i] = k;
@@ -189,32 +195,36 @@ void AliTRDdataArray::Allocate(Int_t nrow, Int_t ncol,Int_t ntime)
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDdataArray::CheckBounds(const char *where, Int_t idx1, Int_t idx2) 
+Bool_t AliTRDdataArray::CheckBounds(Int_t idx1, Int_t idx2) 
 {
   //
   // Does the boundary checking
   //
 
-  if ((idx2 >= fNdim2) || (idx2 < 0)) 
-    return OutOfBoundsError(where,idx1,idx2);
+  if ((idx2 >= fNdim2) || 
+      (idx2 <       0)) {
+    return OutOfBoundsError(idx1,idx2);
+  }
 
   Int_t index = (*fIndex).At(idx2) + idx1;
-  if ((index < 0) || (index > fNelems)) 
-    return OutOfBoundsError(where,idx1,idx2);
+  if ((index <       0) || 
+      (index > fNelems)) {
+    return OutOfBoundsError(idx1,idx2);
+  }
 
   return kTRUE;  
 
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDdataArray::OutOfBoundsError(const char *where, Int_t idx1, Int_t idx2) 
+Bool_t AliTRDdataArray::OutOfBoundsError(Int_t idx1, Int_t idx2) 
 {
   //
   // Generate an out-of-bounds error. Always returns false.
   //
 
-  TObject::Error(where, "idx1 %d  idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
-          ,idx1,idx2,fNdim1,fNdim2,this);
+  AliError(Form("idx1 %d  idx2 %d out of bounds (size: %d x %d, this: 0x%08x)"
+              ,idx1,idx2,fNdim1,fNdim2,this));
 
   return kFALSE;
 
@@ -227,8 +237,11 @@ void AliTRDdataArray::Reset()
   // Reset the array (old content gets deleted)
   //
 
-  if (fIndex) delete fIndex;
-  fIndex = new AliTRDarrayI;
+  if (fIndex) {
+    delete fIndex;
+  }
+
+  fIndex = new AliTRDarrayI();
   fIndex->Set(0); 
 
   fNdim1   = -1;
@@ -244,23 +257,19 @@ void AliTRDdataArray::Reset()
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDdataArray::GetIdx1(Int_t row, Int_t col)
+Int_t AliTRDdataArray::GetIdx1(Int_t row, Int_t col) const
 {
   //
   // Maps the two-dimensional row/column plane into an one-dimensional array.
   //
 
   if (row >= fNrow) {
-    TObject::Error("GetIdx1"
-                  ,"row %d out of bounds (size: %d, this: 0x%08x)"
-                  ,row,fNrow,this);
+    AliError(Form("row %d out of bounds (size: %d, this: 0x%08x)",row,fNrow,this));
     return -1;
   }  
 
   if (col >= fNcol) {
-    TObject::Error("GetIdx1"
-                  ,"col %d out of bounds (size: %d, this: 0x%08x)"
-                  ,col,fNcol,this);
+    AliError(Form("col %d out of bounds (size: %d, this: 0x%08x)",col,fNcol,this));
     return -1;
   }  
 
@@ -269,16 +278,14 @@ Int_t AliTRDdataArray::GetIdx1(Int_t row, Int_t col)
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDdataArray::GetIndex(Int_t row, Int_t col, Int_t time)
+Int_t AliTRDdataArray::GetIndex(Int_t row, Int_t col, Int_t time) const
 {
   //
   // Maps the row/column/time into one number
   // 
 
   if (time > fNtime) {
-    TObject::Error("GetIdx1"
-                  ,"time %d out of bounds (size: %d, this: 0x%08x)"
-                  ,time,fNtime,this);
+    AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)",time,fNtime,this));
     return -1;
   }