]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliDigits.cxx
Fixes for coding violations
[u/mrichter/AliRoot.git] / TPC / AliDigits.cxx
index d28a4a538a57fb1b2017a90918f4b430be3c8f46..710097e7f5b615db2e99531d6783c0cda07192f8 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.1.4.2  2000/04/10 11:37:42  kowal2
+/* $Id$ */
 
-Digits handling in a new data structure
-
-*/
+/*MI change -- for Rule checker
+          -- added copy constructor and assignmet operator 
+         -- new GetSize return size of object in Bytes
+          -- added GetDigitSize and GetOverTh function
+         -- added GetNRows, GetNCols function
+          -- for Marek -I had it in my code  
+*/ 
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -31,12 +33,12 @@ Digits handling in a new data structure
 
 
 #include "TClass.h"
-#include <iostream.h>
+#include <Riostream.h>
 #include "TError.h"
 #include "AliSegmentID.h"
 #include "AliH2F.h"
-#include "AliArrayI.h"
-#include "AliArrayS.h"
+#include <TArrayI.h>
+#include <TArrayS.h>
 #include "AliDigits.h"
 
 
@@ -47,20 +49,76 @@ Digits handling in a new data structure
 ClassImp(AliDigits)
 
 
-AliDigits::AliDigits()
+ AliDigits::AliDigits()
+           :AliSegmentID(),
+            fNrows(0),
+            fNcols(0),
+           fElements(0),
+            fIndex(0),
+            fBufType(0),
+            fThreshold(0),
+            fNelems(0),
+            fCurrentRow(0),
+            fCurrentCol(0),
+            fCurrentIndex(0) 
 {
-  fIndex = 0;
-  fElements = 0;
-  fThreshold =0;
+  // 
+  //default constructor
+  //
   Invalidate();
 }
 
+AliDigits::AliDigits(const AliDigits& digits)
+          :AliSegmentID(digits),
+            fNrows(0),
+            fNcols(0),
+           fElements(0),
+            fIndex(0),
+            fBufType(0),
+            fThreshold(0),
+            fNelems(0),
+            fCurrentRow(0),
+            fCurrentCol(0),
+            fCurrentIndex(0)
+{
+  //
+  //copy constructor
+  //
+  fNrows = digits.fNrows;
+  fNcols = digits.fNcols;
+  fElements = new TArrayS(*(digits.fElements));
+  fIndex = new TArrayI(*(digits.fIndex));
+  fBufType = digits.fBufType;
+  fThreshold = digits.fThreshold;
+  fNelems    = digits.fNelems;
+}
+
+AliDigits & AliDigits::operator =(const AliDigits & digits)
+{
+ //assignment operator
+  fNrows = digits.fNrows;
+  fNcols = digits.fNcols;
+  if (fElements) delete fElements;
+  fElements = new TArrayS(*(digits.fElements));
+  if (fIndex) delete fIndex;
+  fIndex = new TArrayI(*(digits.fIndex));
+  fBufType = digits.fBufType;
+  fThreshold = digits.fThreshold;
+  fNelems    = digits.fNelems; 
+  return (*this);
+}
+
 AliDigits::~AliDigits()
 {
   //
-  //defaulta destructor
-  if (fIndex !=0 ) fIndex->Delete();;
-  if (fElements != 0) fElements->Delete();
+  //default destructor
+  if (fIndex !=0 ) {
+    delete fIndex;
+  }
+  if (fElements != 0) {
+    delete fElements;
+  }
+  
   
 }
 
@@ -68,8 +126,8 @@ AliDigits::~AliDigits()
 Bool_t AliDigits::OutOfBoundsError(const char *where, Int_t row, Int_t column) 
 {
    // Generate an out-of-bounds error. Always returns false.
-   ::Error(where, "row %d  col %d out of bounds (size: %d x %d, this: 0x%08x)", 
-          row, column, fNrows, fNcols, this);
+   ::Error(where, "row %d  col %d out of bounds (size: %d x %d, this: 0x%08lx)", 
+          row, column, fNrows, fNcols, (ULong_t) this);
    return kFALSE;
 }
 
@@ -79,11 +137,11 @@ void AliDigits::Invalidate()
   //
   //set default (invalid parameters)
   if (fIndex != 0)  delete  fIndex;
-  fIndex = new AliArrayI;
+  fIndex = new TArrayI;
   
   if (fElements!= 0)     delete  fElements;
   
-  fElements = new AliArrayS;
+  fElements = new TArrayS;
   
   fNrows = fNcols =fNelems= -1; 
   fElements->Set(0); 
@@ -115,8 +173,59 @@ void AliDigits::Allocate(Int_t rows, Int_t columns)
 }
 
 
+Int_t AliDigits::GetSize()
+{
+  //
+  //return size of object as represented in the memory
+  //
+  //  Int_t size = sizeof(this);
+  Int_t size = 0;   // COVERITY consider the previous statment as bug 
+                    // 
+  if (fIndex!=0) size+= sizeof(fIndex)+fIndex->GetSize()*sizeof(Int_t);
+  if (fElements!=0) size+= sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
+  return size;
+}
+
+Int_t AliDigits::GetDigitSize() //return total size of pure digit
+{
+  //
+  //return size of PURE DIGITS
+  //
+  if (fElements==0) return 0;
+  else return sizeof(fElements)+fElements->GetSize()*sizeof(Short_t);
+}
+
+Int_t AliDigits::GetOverTh(Float_t threshold,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
+{
+  //
+  //return number of digits over threshold
+  // 
+ if ( (fElements==0) || (fElements->GetSize()<=0)) return 0;
+ if (x1<=x2) {
+    x1=0;
+    x2=fNrows;
+  }
+  if (y1<=y2) {
+     y1=0;
+     y2=fNcols;
+  }
+  Int_t over=0;
+
+  Bool_t cont=First();
+  for ( cont=First(); cont==kTRUE;cont=Next()) {
+    if ( (CurrentRow()<x1) || (CurrentRow()>x2)) continue;
+    if ( (CurrentColumn()<y1) || (CurrentColumn()>y2)) continue;
+    if (CurrentDigit()>threshold) over++;
+  }
+  return over;
+}
+
+
 Short_t AliDigits::GetDigit(Int_t row, Int_t column)
 {
+  //
+  // return digit for given row and collumn
   if (fBufType ==0) return GetDigitFast(row,column);
   if (fBufType ==1) return GetDigit1(row,column);
 
@@ -202,7 +311,7 @@ AliH2F *  AliDigits::GenerHisto()
   //
   //make digits histo 
   char ch[30];
-  sprintf(ch,"Segment_%d ",GetID());
+  snprintf(ch,30, "Segment_%d ",GetID());
   if ( (fNrows<1)|| (fNcols<1)) {
     return 0;
   }
@@ -215,7 +324,7 @@ AliH2F *  AliDigits::GenerHisto()
   return his;
 }
 
-AliH2F *  AliDigits::Draw(const char *option,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
+AliH2F *AliDigits::DrawDigits(const char *option,Float_t x1, Float_t x2, Float_t y1, Float_t y2)
 {
   //
   //draw digits in given array
@@ -239,12 +348,13 @@ void AliDigits::ExpandBuffer1()
   Int_t i,k;
   fNelems = fNrows*fNcols;
   Short_t * buf = new Short_t[fNelems];
+  memset(buf,0,fNelems*sizeof(Short_t)); //MI change - 4.12.2000
   fIndex->Set(fNcols);
   for (i =0,k=0 ;i<fNcols;i++,k+=fNrows) (*fIndex)[i]=k;
   Int_t col=0;
   Int_t row = 0;
-  Int_t N=fElements->fN;
-  for (i=0;i<N;i++){
+  Int_t n=fElements->fN;
+  for (i=0;i<n;i++){
     //oposite signa means how many unwrited (under threshold) values
     if ((*fElements)[i]<0) row-=fElements->At(i); 
     else {
@@ -257,48 +367,56 @@ void AliDigits::ExpandBuffer1()
     }else 
       if (row>fNrows){
        Invalidate();
+       delete [] buf;
        return;
       }      
   }
   fElements->Adopt(fNelems,buf);    
 }
+
 void AliDigits::CompresBuffer1()
 {
   //
   //compres buffer according  algorithm 1
   //
-  AliArrayS  buf;  //lets have the nearly the "worst case"
+  TArrayS  buf;  //lets have the nearly the "worst case"
   buf.Set(fNelems);
-  AliArrayI  index;
+  TArrayI  index;
   index.Set(fNcols);
   Int_t icurrent=-1;
   Int_t izero;
+  Short_t * cbuff = fElements->GetArray();  //MI change
+
   for (Int_t col = 0; col<fNcols; col++){      
     index[col]=icurrent+1;//set collumn pointer
     izero = 0;  //reset zer counter at the begining of the column
     for (Int_t row = 0; row< fNrows;row++){
       //if under threshold
-      if (GetDigitFast(row,col)<=fThreshold)  izero++;
+      //if (GetDigitFast(row,col)<=fThreshold)  izero++;
+      if (*cbuff<=fThreshold)  izero++;
+
       else{
        if (izero>0) {
          //if we have currently izero count under threshold
          icurrent++;     
-         if (icurrent>=buf.fN) buf.Expand(icurrent*2);
+         if (icurrent>=buf.fN) buf.Set(icurrent*2);
          buf[icurrent]= -izero;  //write how many under zero
          izero = 0;
        } //end of reseting izero
        icurrent++;
-       if (icurrent>=buf.fN) buf.Expand(icurrent*2);
-       buf[icurrent] = GetDigitFast(row,col);      
-      }//if signal bigger then threshold               
+       if (icurrent>=buf.fN) buf.Set(icurrent*2);
+       //buf[icurrent] = GetDigitFast(row,col);            
+       buf[icurrent] = *cbuff;     
+      }//if signal bigger then threshold       
+       cbuff++;
     } //end of loop over rows
     if (izero>0) {
       icurrent++;        
-      if (icurrent>=buf.fN) buf.Expand(icurrent*2);
+      if (icurrent>=buf.fN) buf.Set(icurrent*2);
       buf[icurrent]= -izero;  //write how many under zero
     }
   }//end of lopping over digits
-  buf.Expand(icurrent+1);
+  buf.Set(icurrent+1);
   (*fElements)=buf;
   fNelems = fElements->fN;
   fBufType = 1;
@@ -316,7 +434,7 @@ Bool_t AliDigits::First0()
   fCurrentCol = -1;
   fCurrentIndex = -1;
   Int_t i;
-  for (i=0; (( i<fNelems) && (fElements->At(i)<=fThreshold));i++)
+  for (i=0; (( i<fNelems) && (fElements->At(i)<=fThreshold));i++) {}  //MI1211
   if (i == fNelems) return kFALSE;
   fCurrentCol =i/fNrows;
   fCurrentRow =i%fNrows;
@@ -331,7 +449,7 @@ Bool_t AliDigits::Next0()
   //
   if (fCurrentIndex<0) return kFALSE;  // if we didn't adjust first 
   Int_t i;
-  for (i=fCurrentIndex+1; ( (i<fNelems) && (fElements->At(i)<=fThreshold) ) ;i++);
+  for (i=fCurrentIndex+1; ( (i<fNelems) && (fElements->At(i)<=fThreshold) ) ;i++) {}
   if (i >= fNelems)  {
     fCurrentIndex = -1;
     return kFALSE;
@@ -361,7 +479,7 @@ Bool_t AliDigits::First1()
     if (fElements->At(i)>fThreshold) break;
   }
   fCurrentIndex = i;
-  if (fCurrentIndex>=0) return kTRUE;
+  if (fCurrentIndex>=0&&i<fNelems) return kTRUE;
   fCurrentRow =-1;
   fCurrentCol =-1;
   return kFALSE;