]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDdataArrayF.cxx
Revision of AliTRDmcmSim + coding rule violations
[u/mrichter/AliRoot.git] / TRD / AliTRDdataArrayF.cxx
index fbdee9bdee41896c59bf43ce37bc161a3edca502..dad99146e0d1749800f8ef50de76c3efe0318b6e 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.6  2000/11/01 14:53:20  cblume
-Merge with TRD-develop
-
-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$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -48,6 +22,8 @@ Add new data array classes
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
+#include "AliLog.h"
+
 #include "AliTRDdataArrayF.h"
 #include "AliTRDarrayI.h"
 #include "AliTRDarrayF.h"
@@ -55,40 +31,42 @@ Add new data array classes
 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 <nrow>, <ncol>, and <ntime>.
   // The row- and column dimensions are compressible.
   //
 
-  fElements = 0;
-
   Allocate(nrow,ncol,ntime);
   
 }
 
 //_____________________________________________________________________________
 AliTRDdataArrayF::AliTRDdataArrayF(const AliTRDdataArrayF &a)
+   :AliTRDdataArray(a)
+   ,fElements(a.fElements)
+   ,fThreshold(a.fThreshold)
 {
   //
   // AliTRDdataArrayF copy constructor
   //
 
-  ((AliTRDdataArrayF &) a).Copy(*this);
-
 }
 
 //_____________________________________________________________________________
@@ -98,7 +76,10 @@ AliTRDdataArrayF::~AliTRDdataArrayF()
   // Destructor
   //
 
-  if (fElements) delete fElements;
+  if (fElements) {
+    delete fElements;
+    fElements = 0;
+  }
   
 }
 
@@ -111,16 +92,21 @@ 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->Set(fNelems);
 
 }
 
 //_____________________________________________________________________________
-void AliTRDdataArrayF::Copy(TObject &a)
+void AliTRDdataArrayF::Copy(TObject &a) const
 {
   //
   // Copy function
@@ -141,7 +127,10 @@ void AliTRDdataArrayF::Reset()
   // Reset the array (old content gets deleted)
   //
   
-  if (fElements) delete fElements;
+  if (fElements) {
+    delete fElements;
+  }
+
   fElements = new AliTRDarrayF();
   fElements->Set(0); 
 
@@ -150,7 +139,7 @@ void AliTRDdataArrayF::Reset()
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDdataArrayF::GetSize()
+Int_t AliTRDdataArrayF::GetSize() const
 {
   //
   // Returns the size of the complete object
@@ -168,7 +157,7 @@ Int_t AliTRDdataArrayF::GetSize()
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDdataArrayF::GetDataSize() 
+Int_t AliTRDdataArrayF::GetDataSize() const 
 {
   //
   // Returns the size of only the data part
@@ -194,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++;
   }
 
@@ -219,9 +208,8 @@ Float_t AliTRDdataArrayF::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));
       }
     }
   }
@@ -230,6 +218,18 @@ Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time) const
 
 }
 
+//_____________________________________________________________________________
+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)
 {
@@ -250,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) {
@@ -260,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;
   }
 
@@ -279,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) {  
@@ -331,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);
 
@@ -344,11 +345,10 @@ void AliTRDdataArrayF::Expand1()
 
     // 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) {
@@ -374,10 +374,6 @@ 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();
@@ -388,7 +384,6 @@ void AliTRDdataArrayF::Compress1()
   for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){      
 
     // Set the idx2 pointer
-    //index[idx2] = icurrent + 1;
     (*index)[idx2] = icurrent + 1;
 
     // Reset the zero counter 
@@ -403,37 +398,26 @@ 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);
        if (icurrent >= buf->fN) buf->Expand(icurrent*2);
-       //buf[icurrent] = GetDataFast(idx1,idx2);           
        (*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;
-  //fNelems   = fElements->fN;
-  //fBufType  = 1;
-  //(*fIndex) = index;
   buf->Expand(icurrent+1);
   if (fElements) delete fElements;
   fElements = buf;
@@ -452,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);
@@ -531,7 +517,7 @@ Bool_t AliTRDdataArrayF::Next0()
   Int_t i;
   for (i = fCurrentIndex + 1; 
        ((i < fNelems) && (fElements->At(i) <= fThreshold)); 
-       i++);
+       i++) {}
   if (i >= fNelems)  {
     fCurrentIndex = -1;
     return kFALSE;
@@ -650,17 +636,6 @@ Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2) const
 
 }
 
-//____________________________________________________________________________
-Float_t AliTRDdataArrayF::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 AliTRDdataArrayF::SetData(Int_t row, Int_t col, Int_t time, Float_t value)
 {
@@ -676,9 +651,8 @@ void AliTRDdataArrayF::SetData(Int_t row, Int_t col, Int_t time, Float_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));
       }
     }
   }
@@ -686,20 +660,14 @@ void AliTRDdataArrayF::SetData(Int_t row, Int_t col, Int_t time, Float_t value)
 }
 
 //_____________________________________________________________________________
-void  AliTRDdataArrayF::SetDataFast(Int_t idx1, Int_t idx2, Float_t value)
+void AliTRDdataArrayF::SetDataFast(Int_t idx1, Int_t idx2, Float_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;
 
 }