]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDarrayDictionary.cxx
added slewing correction by data
[u/mrichter/AliRoot.git] / TRD / AliTRDarrayDictionary.cxx
index 335e212be6a71455f9dbcf1ed69af545cc83be34..3d5dfeeaed1329bf6ce9eb23fd83760e1e1424f0 100644 (file)
 //                                                     //
 /////////////////////////////////////////////////////////
 
+#include <TArray.h>
+
 #include "AliTRDarrayDictionary.h"
-#include "TArray.h"
+#include "AliTRDfeeParam.h"
+#include "AliLog.h"
 
 ClassImp(AliTRDarrayDictionary)
 
+Short_t *AliTRDarrayDictionary::fgLutPadNumbering = 0x0;
+
 //________________________________________________________________________________
 AliTRDarrayDictionary::AliTRDarrayDictionary()
                       :TObject()
                       ,fNdet(0)
                       ,fNrow(0)
                       ,fNcol(0)
+                     ,fNumberOfChannels(0)
                       ,fNtime(0)
                       ,fNDdim(0)
                       ,fDictionary(0)
+                      ,fFlag(kFALSE)
 {
   //
   // AliTRDarrayDictionary default contructor
   //
 
+  CreateLut();
+
 }
 
 //________________________________________________________________________________
@@ -51,15 +60,17 @@ AliTRDarrayDictionary::AliTRDarrayDictionary(Int_t nrow, Int_t ncol, Int_t ntime
                      ,fNdet(0)
                       ,fNrow(0)
                       ,fNcol(0)
+                     ,fNumberOfChannels(0)
                       ,fNtime(0)
                      ,fNDdim(0)
                      ,fDictionary(0)
-
+                      ,fFlag(kFALSE)
 {
   //
   // AliTRDarrayDictionary contructor
   //
 
+  CreateLut();
   Allocate(nrow,ncol,ntime);
 
 }
@@ -70,9 +81,11 @@ AliTRDarrayDictionary::AliTRDarrayDictionary(const AliTRDarrayDictionary &a)
                      ,fNdet(a.fNdet)
                       ,fNrow(a.fNrow)
                       ,fNcol(a.fNcol)
+                     ,fNumberOfChannels(a.fNumberOfChannels)
                       ,fNtime(a.fNtime)
                      ,fNDdim(a.fNDdim)
                      ,fDictionary(0)
+                      ,fFlag(a.fFlag)
 {
   //
   // AliTRDarrayDictionary copy constructor
@@ -93,11 +106,8 @@ AliTRDarrayDictionary::~AliTRDarrayDictionary()
   //   AliTRDarrayDictionary destructor
   //
 
-  if(fDictionary)
-    {
-      delete [] fDictionary;
-      fDictionary=0;
-    }
+  delete [] fDictionary;
+  fDictionary=0;
 
 }
 
@@ -121,12 +131,14 @@ AliTRDarrayDictionary &AliTRDarrayDictionary::operator=(const AliTRDarrayDiction
   fNDdim=a.fNDdim;
   fNrow=a.fNrow;
   fNcol=a.fNcol;
+  fNumberOfChannels = a.fNumberOfChannels;
   fNtime=a.fNtime;
   fDictionary = new Int_t[fNDdim];
   for(Int_t i=0; i<fNDdim; i++)
     {
       fDictionary[i]=a.fDictionary[i];
     }
+  fFlag=a.fFlag;
   return *this;
 
 }
@@ -136,24 +148,26 @@ void AliTRDarrayDictionary::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
 {
   //
   // Allocates memory for the dictionary array with dimensions
-  // Row*Col*Time
+  // Row*NumberOfNecessaryMCMs*ADCchannelsInMCM*Time
+  // To be consistent with AliTRDarrayADC
   // Object initialized to -1
   //
 
   fNrow=nrow;
   fNcol=ncol;
   fNtime=ntime;
-  fNDdim=nrow*ncol*ntime;
+  Int_t adcchannelspermcm = AliTRDfeeParam::GetNadcMcm(); 
+  Int_t padspermcm = AliTRDfeeParam::GetNcolMcm(); 
+  Int_t numberofmcms = fNcol/padspermcm;
+  fNumberOfChannels = numberofmcms*adcchannelspermcm;
+  fNDdim=nrow*fNumberOfChannels*ntime;
   if(fDictionary)
     {
       delete [] fDictionary;
       fDictionary=0;
     }
   fDictionary = new Int_t[fNDdim];
-  for(Int_t i=0; i<fNDdim; i++)
-    {
-      fDictionary[i] = -1; 
-    }
+  memset(fDictionary,-1,sizeof(Int_t)*fNDdim);
 
 }
 
@@ -170,89 +184,85 @@ void AliTRDarrayDictionary::Compress()
   Int_t newDim=0;
   Int_t j;                 
   Int_t r=0;
-  Int_t *longArr;            
-  longArr = new Int_t[fNDdim];  
   Int_t k=0;
-  for(Int_t i=0; i<fNDdim;i++)
-    {
-      longArr[i]=0;  
-    }
-  for(Int_t i=0;i<fNDdim; i++)
-    {
-      j=0;
-      if(fDictionary[i]==-1)
-       {
-         for(k=i;k<fNDdim;k++)
-           {
-             if(fDictionary[k]==-1)
-               {
-                 j=j+1;
-                 longArr[r]=j;
-               }
-             else
-               {
-                 break;
-               }
-           } 
-         r=r+1;    
-       }
-      i=i+j;
-    }
-  //Calculate the size of the compressed array
-  for(Int_t i=0; i<fNDdim;i++)
-    {
-      if(longArr[i]!=0)  
-       {
-         counter=counter+longArr[i]-1;
-       }
-    }
-  newDim=fNDdim-counter;   //Size of the compressed array
-  //Fill the buffer of the compressed array
-  Int_t* buffer;
-  buffer = new Int_t[newDim];
-  Int_t counterTwo=0;
-  Int_t g=0;
-  for(Int_t i=0; i<newDim; i++)
-    {
-      if(counterTwo<fNDdim)
-       {
-         if(fDictionary[counterTwo]!=-1)
-           {
-             buffer[i]=fDictionary[counterTwo];
-           }
-         if(fDictionary[counterTwo]==-1)
-           {
-             buffer[i]=-(longArr[g]);
-             counterTwo=counterTwo+longArr[g]-1;
-             g++;
-           }  
-         counterTwo++;
-       }
-    }
 
-  //Copy the buffer
-  if(fDictionary)
-    {
-      delete [] fDictionary;
-      fDictionary=0;
-    }
-  fDictionary = new Int_t[newDim];
-  fNDdim = newDim;
-  for(Int_t i=0; i<newDim; i++)
-    {
-      fDictionary[i] = buffer[i]; 
-    }
-  if(buffer)
-    {
-      delete [] buffer;
-      buffer=0;
-    }
+  Int_t *longArr = new Int_t[fNDdim];  
+
   if(longArr) 
     {
+
+      memset(longArr,0,sizeof(Int_t)*fNDdim);
+
+      for(Int_t i=0;i<fNDdim; i++)
+        {
+          j=0;
+          if(fDictionary[i]==-1)
+           {
+             for(k=i;k<fNDdim;k++)
+               {
+                 if(fDictionary[k]==-1)
+                   {
+                     j=j+1;
+                     longArr[r]=j;
+                   }
+                 else
+                   {
+                     break;
+                   }
+               } 
+             r=r+1;    
+           }
+          i=i+j;
+        }
+
+      //Calculate the size of the compressed array
+      for(Int_t i=0; i<fNDdim;i++)
+        {
+          if(longArr[i]!=0)  
+           {
+             counter=counter+longArr[i]-1;
+           }
+        }
+      newDim=fNDdim-counter;   //Size of the compressed array
+
+      //Fill the buffer of the compressed array
+      Int_t* buffer = new Int_t[newDim];
+      Int_t counterTwo=0;
+      Int_t g=0;
+      if(buffer)
+        {
+          for(Int_t i=0; i<newDim; i++)
+            {
+              if(counterTwo<fNDdim)
+               {
+                 if(fDictionary[counterTwo]!=-1)
+                   {
+                     buffer[i]=fDictionary[counterTwo];
+                   }
+                 if(fDictionary[counterTwo]==-1)
+                   {
+                     buffer[i]=-(longArr[g]);
+                     counterTwo=counterTwo+longArr[g]-1;
+                     g++;
+                   }  
+                 counterTwo++;
+               }
+            }
+
+          //Copy the buffer
+          if(fDictionary)
+            {
+              delete [] fDictionary;
+              fDictionary=0;
+            }
+         fDictionary = buffer;
+          fNDdim = newDim;
+        }
+    
       delete [] longArr;
       longArr=0;
     }
-
+  fFlag=kFALSE; // This way it can be expanded afterwards
 }
 
 //________________________________________________________________________________
@@ -262,71 +272,93 @@ void AliTRDarrayDictionary::Expand()
   //  Expand the array
   //  
 
-  Int_t *longArr;
-  longArr = new Int_t[fNDdim];
-  Int_t dimexp=0;
-  for(Int_t i=0; i<fNDdim;i++)
-    {
-      longArr[i]=0;
-    }
-  Int_t r2=0;
-  for(Int_t i=0; i<fNDdim;i++)
+  if(fNDdim==0)
     {
-      if((fDictionary[i]<0)&&(fDictionary[i]!=-1))  
-       {
-         longArr[r2]=-fDictionary[i]; 
-         r2++;
-       }
+      AliError("Called expand with dimension zero");
+      return;    
     }
 
-  //Calculate new dimensions
-  for(Int_t i=0; i<fNDdim;i++)
-    {
-      if(longArr[i]!=0)      
-       {
-         dimexp=dimexp+longArr[i]-1;
-       }
+
+  Int_t dimexp=0;
+  
+//   if(WasExpandCalled()) 
+//     return;
+
+  if(fNDdim==fNrow*fNumberOfChannels*fNtime)
+    return;
+
+  if(fDictionary&&fNDdim==1)
+    { 
+      dimexp = -fDictionary[0];        
+      delete [] fDictionary;
+      fDictionary=0;
+      fDictionary = new Int_t[dimexp];
+      fNDdim = dimexp;
+      // Re-initialize the array
+      memset(fDictionary,-1,sizeof(Int_t)*dimexp);
+      fFlag=kTRUE; // Not expand again
+      return;
     }
-  dimexp=dimexp+fNDdim;  
-
-  //Write in the buffer the new array
-  Int_t* bufferE;
-  bufferE = new Int_t[dimexp];
-  Int_t contaexp =0;    
-  Int_t h=0;
-  for(Int_t i=0; i<dimexp; i++)
+
+  Int_t *longArr = new Int_t[fNDdim];
+  if(longArr && fDictionary)
     {
-      if(fDictionary[contaexp]>=-1)  
-       {
-         bufferE[i]=fDictionary[contaexp];
-       }
-      if(fDictionary[contaexp]<-1)  
-       {
-         for(Int_t j=0; j<longArr[h];j++)
+      //Initialize the array
+      memset(longArr,0,sizeof(Int_t)*fNDdim);
+
+      Int_t r2=0;
+      for(Int_t i=0; i<fNDdim;i++)
+        {
+          if((fDictionary[i]<0)&&(fDictionary[i]!=-1))  
            {
-             bufferE[i+j]=-1;
+             longArr[r2]=-fDictionary[i]; 
+             r2++;
            }
-         i=i+longArr[h]-1;
-         h++;
+        }
+
+      //Calculate new dimensions
+      for(Int_t i=0; i<fNDdim;i++)
+        {
+          if(longArr[i]!=0)      
+           dimexp=dimexp+longArr[i]-1;
+         if(longArr[i]==0)
+           break;
+        }
+      dimexp=dimexp+fNDdim;  
+
+      //Write in the buffer the new array
+      Int_t contaexp =0;    
+      Int_t h=0;
+      Int_t* bufferE = new Int_t[dimexp];
+
+      if(bufferE)
+       {
+         memset(bufferE,-1,sizeof(Int_t)*dimexp);
+          for(Int_t i=0; i<dimexp; i++)
+            {
+              if(fDictionary[contaexp]>=-1)  
+               {
+                 bufferE[i]=fDictionary[contaexp];
+               }
+              if(fDictionary[contaexp]<-1)  
+               {
+                 i=i+longArr[h]-1;
+                 h++;
+               }
+              contaexp++;
+            }
+
+          //Copy the buffer
+          delete [] fDictionary;
+          fDictionary=bufferE;
+          fNDdim = dimexp;
        }
-      contaexp++;
-    }
-
-  //Copy the buffer
-  if(fDictionary)
-    {
-      delete [] fDictionary;
-      fDictionary=0;
     }
-
-  fDictionary = new Int_t[dimexp];
-  fNDdim = dimexp;
-  for(Int_t i=0; i<dimexp; i++)
+  if (longArr)
     {
-      fDictionary[i] = bufferE[i]
+      delete [] longArr
     }
-  if(bufferE) delete [] bufferE;
-  if(longArr) delete [] longArr;
+  fFlag=kTRUE; // Not expand again
 
 }
 //________________________________________________________________________________
@@ -340,3 +372,56 @@ void AliTRDarrayDictionary::Reset()
   memset(fDictionary,0,sizeof(Int_t)*fNDdim);
 
 }
+//________________________________________________________________________________
+Int_t AliTRDarrayDictionary::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 fDictionary[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime];
+
+}
+//________________________________________________________________________________
+void AliTRDarrayDictionary::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Int_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];
+
+  fDictionary[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime]=value;
+
+}
+
+//________________________________________________________________________________
+void AliTRDarrayDictionary::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;
+       }
+    }
+}