temporary bug fix (speed issues)
[u/mrichter/AliRoot.git] / TRD / AliTRDarraySignal.cxx
index be54014..8ad22d3 100644 (file)
 //                                                     //
 /////////////////////////////////////////////////////////
 
+#include <TArray.h>
+
 #include "AliTRDarraySignal.h"
-//#include "AliLog.h"
+#include "AliTRDfeeParam.h"
 
 ClassImp(AliTRDarraySignal)
 
+Short_t *AliTRDarraySignal::fgLutPadNumbering = 0x0;
+
 //_______________________________________________________________________
 AliTRDarraySignal::AliTRDarraySignal()
                   :TObject()
                   ,fNdet(0)
                   ,fNrow(0)
                   ,fNcol(0)
+                 ,fNumberOfChannels(0)
                   ,fNtime(0)
                   ,fNdim(0)  
                   ,fSignal(0)
@@ -43,6 +48,8 @@ AliTRDarraySignal::AliTRDarraySignal()
   //
   // AliTRDarraySignal default constructor
   //
+
+  CreateLut();
           
 }
 
@@ -52,6 +59,7 @@ AliTRDarraySignal::AliTRDarraySignal(Int_t nrow, Int_t ncol,Int_t ntime)
                   ,fNdet(0)
                   ,fNrow(0)
                   ,fNcol(0)
+                 ,fNumberOfChannels(0)
                   ,fNtime(0)
                   ,fNdim(0)
                   ,fSignal(0)
@@ -59,7 +67,8 @@ AliTRDarraySignal::AliTRDarraySignal(Int_t nrow, Int_t ncol,Int_t ntime)
   //
   // AliTRDarraySignal constructor
   //
+
+  CreateLut(); 
   Allocate(nrow,ncol,ntime);
 
 }
@@ -70,6 +79,7 @@ AliTRDarraySignal::AliTRDarraySignal(const AliTRDarraySignal &d)
                  ,fNdet(d.fNdet)
                  ,fNrow(d.fNrow)
                  ,fNcol(d.fNcol)
+                  ,fNumberOfChannels(d.fNumberOfChannels)
                  ,fNtime(d.fNtime)
                  ,fNdim(d.fNdim)
                  ,fSignal(0)
@@ -79,10 +89,7 @@ AliTRDarraySignal::AliTRDarraySignal(const AliTRDarraySignal &d)
   //
 
   fSignal = new Float_t[fNdim];
-  for(Int_t i=0; i<fNdim; i++)
-    {
-      fSignal[i]=d.fSignal[i];
-    }
+  memcpy(fSignal, d.fSignal, fNdim*sizeof(Float_t));
 
 }
 
@@ -120,14 +127,11 @@ AliTRDarraySignal &AliTRDarraySignal::operator=(const AliTRDarraySignal &d)
   fNdet=d.fNdet;
   fNrow=d.fNrow;
   fNcol=d.fNcol;
+  fNumberOfChannels = d.fNumberOfChannels;
   fNtime=d.fNtime;
   fNdim=d.fNdim;
   fSignal = new Float_t[fNdim];
-
-  for(Int_t i=0; i<fNdim; i++)
-    {
-      fSignal[i]=d.fSignal[i];
-    }
+  memcpy(fSignal,d.fSignal, fNdim*sizeof(Float_t));
 
   return *this;
 
@@ -138,27 +142,29 @@ void AliTRDarraySignal::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
 {
   //
   // Allocates memory for an AliTRDarraySignal object with dimensions 
-  // Row*Col*Time
+  // Row*NumberOfNecessaryMCMs*ADCchannelsInMCM*Time
+  // To be consistent with AliTRDarrayADC
   //
 
   fNrow=nrow;
   fNcol=ncol;
   fNtime=ntime;
-  fNdim = nrow*ncol*ntime;
+  Int_t adcchannelspermcm = AliTRDfeeParam::GetNadcMcm(); 
+  Int_t padspermcm = AliTRDfeeParam::GetNcolMcm(); 
+  Int_t numberofmcms = fNcol/padspermcm; 
+  fNumberOfChannels = numberofmcms*adcchannelspermcm;
+  fNdim = nrow*fNumberOfChannels*ntime;
   if (fSignal)   
     {
       delete [] fSignal;
     }
   fSignal = new Float_t[fNdim];
-  for(Int_t i=0; i<fNdim; i++)
-    {
-      fSignal[i]=0;
-    }
+  memset(fSignal,0,sizeof(Float_t)*fNdim);
 
 }
 
 //_______________________________________________________________________
-Int_t AliTRDarraySignal::GetOverThreshold(Float_t threshold)
+Int_t AliTRDarraySignal::GetOverThreshold(Float_t threshold) const
 {
   //
   // Get the number of entries over the threshold 
@@ -193,10 +199,7 @@ void AliTRDarraySignal::Compress(Float_t minval)
   Int_t k=0;
 
   //Initialize the array
-  for(Int_t i=0; i<fNdim;i++)
-    {
-      longArr[i]=0;
-    }
+  memset(longArr,0,sizeof(Int_t)*fNdim);
 
   for(Int_t i=0;i<fNdim; i++)
     {
@@ -305,10 +308,7 @@ void AliTRDarraySignal::Expand()
   Int_t *longArr; 
   longArr = new Int_t[fNdim];
   Int_t dimexp=0;
-  for(Int_t i=0; i<fNdim;i++)
-    {
-      longArr[i]=0;
-    }
+  memset(longArr,0,sizeof(Int_t)*fNdim);
 
   Int_t r2=0;
   for(Int_t i=0; i<fNdim;i++)
@@ -371,3 +371,67 @@ void AliTRDarraySignal::Expand()
   if(longArr) delete [] longArr;
 
 }
+//________________________________________________________________________________
+void AliTRDarraySignal::Reset()
+{
+  //
+  // Reset the array, the old contents are deleted
+  // The array keeps the same dimensions as before
+  //
+
+  memset(fSignal,0,sizeof(Float_t)*fNdim);
+
+}
+//________________________________________________________________________________
+Float_t AliTRDarraySignal::GetData(Int_t nrow, Int_t ncol, Int_t ntime) const
+{
+  //
+  // Get the data using the pad numbering.
+  // To access data using the mcm scheme use instead
+  // the method GetDataByAdcCol
+  //
+
+  Int_t corrcolumn = fgLutPadNumbering[ncol];
+
+  return fSignal[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime];
+
+}
+//________________________________________________________________________________
+void AliTRDarraySignal::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Float_t value)
+{
+  //
+  // Set the data using the pad numbering.
+  // To write data using the mcm scheme use instead
+  // the method SetDataByAdcCol
+  //
+
+  Int_t colnumb = fgLutPadNumbering[ncol];
+
+  fSignal[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime]=value;
+
+}
+
+//________________________________________________________________________________
+void AliTRDarraySignal::CreateLut()
+{
+  //
+  // Initializes the Look Up Table to relate
+  // pad numbering and mcm channel numbering
+  //
+
+  if(fgLutPadNumbering)  return;
+  
+   fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
+   memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
+
+  for(Int_t mcm=0; mcm<8; mcm++)
+    {
+      Int_t lowerlimit=0+mcm*18;
+      Int_t upperlimit=18+mcm*18;
+      Int_t shiftposition = 1+3*mcm;
+      for(Int_t index=lowerlimit;index<upperlimit;index++)
+       {
+         fgLutPadNumbering[index]=index+shiftposition;
+       }
+    }
+}