]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/misc/AliL3DataHandler.cxx
New version of SPD raw-data reconstruction. The format now correponds to the actual...
[u/mrichter/AliRoot.git] / HLT / misc / AliL3DataHandler.cxx
index 2ac4e6be1d82ffc7bf85e9e71e53185078d312a9..a8eef04cef3566e0eeea2c0831678536d9107362 100644 (file)
@@ -1,18 +1,25 @@
-//$Id$
+// @(#) $Id$
 
 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
-//*-- Copyright &copy ASV
+//*-- Copyright &copy ALICE HLT Group
 
 #include "AliL3StandardIncludes.h"
 
-#include "AliL3DataHandler.h"
+#include "AliL3RootTypes.h"
+#include "AliL3Logging.h"
+#include "AliL3MemHandler.h"
 #include "AliL3Logging.h"
-#include "AliTransBit.h"
+#include "AliL3TransBit.h"
+#include "AliL3Transform.h"
+#include "AliL3DataHandler.h"
+#include "AliL3DigitData.h"
 
-#if GCCVERSION == 3
+#if __GNUC__ >= 3
 using namespace std;
 #endif
 
+/** \class AliL3DataHandler
+<pre>
 //_____________________________________________________________
 // AliL3DataHandler
 //
@@ -37,7 +44,7 @@ using namespace std;
 // --------------------
 //
 // The data is RLE encoded, using _8_bit representation of the ADC-values.
-// Conversion is done in the class AliTransBit.
+// Conversion is done in the class AliL3TransBit.
 //
 // In the beginning of every row, the row number if written and the number of pads
 // containing data on that row. For every pad with data the pad number is written,
@@ -46,16 +53,18 @@ using namespace std;
 // 255 (8 bit), another 8 bit word is written for the remaining. At the end of one 
 // pad, 2 zeros are written. Example:
 //
-// ROW PAD 0 NZEROS ADC ADC ADC ADC 0 NZEROS ADC ADC 0 0
+// ROW NPADSWITHDATA PAD 0 NZEROS ADC ADC ADC ADC 0 NZEROS ADC ADC 0 0
 //
 // Everything is written using 8 bit;
 // (ROW < 176, PAD < 200, ADC < 255, if(NZEROS > 255) write 2 words;)
+</pre>
+*/
 
 ClassImp(AliL3DataHandler)
-
   
 AliL3DataHandler::AliL3DataHandler()
 {
+  // default constructor
   fBitTransformer = 0;
   LOG(AliL3Log::kInformational,"AliL3DataHandler::AliL3DataHandler","Data format")
     <<"8 bit data handler initialized"<<ENDLOG;
@@ -63,9 +72,9 @@ AliL3DataHandler::AliL3DataHandler()
 
 AliL3DataHandler::~AliL3DataHandler()
 {
+  // destructor
   if(fBitTransformer)
     delete fBitTransformer;
-  
 }
 
 void AliL3DataHandler::Convert10to8Bit()
@@ -75,19 +84,19 @@ void AliL3DataHandler::Convert10to8Bit()
   if(!fInBinary)
     {
       LOG(AliL3Log::kError,"AliL3DataHandler::Convert10to8Bit","File")
-       <<AliL3Log::kHex<<"Pointer to input file : "<<(Int_t)fInBinary<<ENDLOG;
+       <<AliL3Log::kHex<<"Pointer to input file : "<<(void*)fInBinary<<ENDLOG;
       return;
     }
   if(!fOutBinary)
     {
       LOG(AliL3Log::kError,"AliL3DataHandler::Convert10to8Bit","File")
-       <<AliL3Log::kHex<<"Pointer to output file : "<<(Int_t)fOutBinary<<ENDLOG;
+       <<AliL3Log::kHex<<"Pointer to output file : "<<(void*)fOutBinary<<ENDLOG;
       return;
     }
   
   
   //Initialize the bit transformation class:
-  fBitTransformer = new AliTransBit_v1();
+  fBitTransformer = new AliL3TransBitV1();
   Int_t b0=10;  // original number of bits
   Int_t b1=8;   // compressed
   fBitTransformer->SetBits(b0,b1);
@@ -136,6 +145,7 @@ AliL3DigitRowData *AliL3DataHandler::CompBinary2Memory(UInt_t &nrow)
        <<"Error reading from file "<<ENDLOG;
       return 0;
     }
+
   UInt_t size = GetMemorySize(nrow,comp);
   AliL3DigitRowData *data = (AliL3DigitRowData*)Allocate(size);
   CompMemory2Memory(nrow,data,comp);
@@ -180,13 +190,13 @@ Bool_t AliL3DataHandler::Memory2CompMemory(UInt_t nrow,AliL3DigitRowData *data,B
   if(!data)
     {
       LOG(AliL3Log::kError,"AliL3DataHandler::Memory2CompMemory","Data")
-       <<AliL3Log::kHex<<" Pointer to data = "<<(Int_t)data<<ENDLOG;
+       <<AliL3Log::kHex<<" Pointer to data = "<<(void*)data<<ENDLOG;
       return 0;  
     }
   if(!comp)
     {
       LOG(AliL3Log::kError,"AliL3DataHandler::Memory2CompMemory","Data")
-       <<AliL3Log::kHex<<" Pointer to compressed data = "<<(Int_t)comp<<ENDLOG;
+       <<AliL3Log::kHex<<" Pointer to compressed data = "<<(void*)comp<<ENDLOG;
       return 0;  
     }
 
@@ -201,8 +211,8 @@ Bool_t AliL3DataHandler::Memory2CompMemory(UInt_t nrow,AliL3DigitRowData *data,B
       UShort_t value = rowPt->fRow;
       Write(comp,index,value);
       
-      UShort_t number_of_pads=0;
-      UShort_t max_pad = 0;
+      UShort_t numberOfPads=0;
+      UShort_t maxPad = 0;
       
       for(Int_t j=0; j<200; j++)
        npads[j]=0;
@@ -215,16 +225,16 @@ Bool_t AliL3DataHandler::Memory2CompMemory(UInt_t nrow,AliL3DigitRowData *data,B
        {
          if(npads[j])
            {
-             number_of_pads++;
-             max_pad = j;
+             numberOfPads++;
+             maxPad = j;
            }
        }
       
       //Write the number of pads on this row:
-      Write(comp,index,number_of_pads);
+      Write(comp,index,numberOfPads);
       UInt_t digit=0;
       
-      for(UShort_t pad=0; pad <= max_pad; pad++)
+      for(UShort_t pad=0; pad <= maxPad; pad++)
        {
          
          if(digit >= rowPt->fNDigit || rowPt->fDigitData[digit].fPad !=  pad)
@@ -242,18 +252,19 @@ Bool_t AliL3DataHandler::Memory2CompMemory(UInt_t nrow,AliL3DigitRowData *data,B
                  Write(comp,index,0);
                  
                  //Check if we have to use more than 1 byte to write the zeros:
-                 Int_t number_of_zero_intervals=0;
-                 if(rowPt->fDigitData[digit].fTime > 255)
+                 Int_t numberOfZeroIntervals=0;
+                 if(rowPt->fDigitData[digit].fTime >= 255)
                    {
-                     number_of_zero_intervals++;
+                     numberOfZeroIntervals++;
                      Write(comp,index,255);
-                     if(rowPt->fDigitData[digit].fTime > 2*255)
+                     if(rowPt->fDigitData[digit].fTime >= 2*255)
                        {
+                         cerr<<"AliL3DataHandler::Memory2CompMemory : Should not happen "<<(Int_t)rowPt->fDigitData[digit].fTime<<endl;
                          Write(comp,index,255);
-                         number_of_zero_intervals++;
+                         numberOfZeroIntervals++;
                        }
                    }
-                 Write(comp,index,(rowPt->fDigitData[digit].fTime - number_of_zero_intervals*255));
+                 Write(comp,index,(rowPt->fDigitData[digit].fTime - numberOfZeroIntervals*255));
                }
            }
          
@@ -284,18 +295,19 @@ Bool_t AliL3DataHandler::Memory2CompMemory(UInt_t nrow,AliL3DigitRowData *data,B
                      UShort_t nzero = rowPt->fDigitData[digit+1].fTime - (rowPt->fDigitData[digit].fTime + 1);
                      
                      //Check if we have to use more than one byte to write the zeros:
-                     Int_t number_of_zero_intervals=0;
-                     if(nzero > 255)
+                     Int_t numberOfZeroIntervals=0;
+                     if(nzero >= 255)
                        {
-                         number_of_zero_intervals++;
+                         numberOfZeroIntervals++;
                          Write(comp,index,255);
-                         if(nzero > 2*255)
+                         if(nzero >= 2*255)
                            {
+                             cerr<<"AliL3DataHandler::Memory2CompMemory : Should not happen "<<(Int_t)rowPt->fDigitData[digit].fTime<<endl;
                              Write(comp,index,255);
-                             number_of_zero_intervals++;
+                             numberOfZeroIntervals++;
                            }
                        }
-                     Write(comp,index,(nzero - number_of_zero_intervals*255));
+                     Write(comp,index,(nzero - numberOfZeroIntervals*255));
                    }  
                }
              digit++;
@@ -321,7 +333,7 @@ UInt_t AliL3DataHandler::GetCompMemorySize(UInt_t nrow,AliL3DigitRowData *data)
   if(!data)
     {
       LOG(AliL3Log::kError,"AliL3DataHandler::GetCompMemorySize","Data")
-       <<AliL3Log::kHex<<" Data pointer = "<<(Int_t)data<<ENDLOG;
+       <<AliL3Log::kHex<<" Data pointer = "<<(void*)data<<ENDLOG;
       return 0;
     }
   
@@ -335,8 +347,8 @@ UInt_t AliL3DataHandler::GetCompMemorySize(UInt_t nrow,AliL3DigitRowData *data)
       //Write the row number:
       index++;
       
-      UShort_t max_pad=0; 
-      UShort_t number_of_pads = 0;
+      UShort_t maxPad=0; 
+      UShort_t numberOfPads = 0;
       
       for(Int_t j=0; j<200; j++) 
        npads[j]=0;
@@ -350,8 +362,8 @@ UInt_t AliL3DataHandler::GetCompMemorySize(UInt_t nrow,AliL3DigitRowData *data)
        { 
          if(npads[j])
            {
-             number_of_pads++;
-             max_pad = j;
+             numberOfPads++;
+             maxPad = j;
            }
        }
       
@@ -359,7 +371,7 @@ UInt_t AliL3DataHandler::GetCompMemorySize(UInt_t nrow,AliL3DigitRowData *data)
       index++;
       
       UInt_t digit=0;
-      for(UShort_t pad=0; pad <= max_pad; pad++)
+      for(UShort_t pad=0; pad <= maxPad; pad++)
        {
          if(digit>=rowPt->fNDigit || rowPt->fDigitData[digit].fPad !=  pad)
            continue;
@@ -379,9 +391,9 @@ UInt_t AliL3DataHandler::GetCompMemorySize(UInt_t nrow,AliL3DigitRowData *data)
                  index++;
                  
                  //Check if we have to use more than 1 byte to write the zeros:
-                 if(rowPt->fDigitData[digit].fTime > 255)
+                 if(rowPt->fDigitData[digit].fTime >= 255)
                    index++;
-                 if(rowPt->fDigitData[digit].fTime > 2*255)
+                 if(rowPt->fDigitData[digit].fTime >= 2*255)
                    index++;
                }
            }
@@ -401,9 +413,9 @@ UInt_t AliL3DataHandler::GetCompMemorySize(UInt_t nrow,AliL3DigitRowData *data)
                      
                      //Check if we have to use more than 1 byte to write the zeros:
                      UInt_t nzeros = rowPt->fDigitData[digit+1].fTime - rowPt->fDigitData[digit].fTime + 1;
-                     if(nzeros > 255)
+                     if(nzeros >= 255)
                        index++;
-                     if(nzeros > 2*255)
+                     if(nzeros >= 2*255)
                        index++;
                    }  
                }
@@ -429,13 +441,13 @@ UInt_t AliL3DataHandler::CompMemory2Memory(UInt_t nrow,AliL3DigitRowData *data,B
   if(!data)
     {
       LOG(AliL3Log::kError,"AliL3DataHandler::CompMemory2Memory","Array")
-       <<AliL3Log::kHex<<"Pointer to data: "<<(Int_t)data<<ENDLOG;
+       <<AliL3Log::kHex<<"Pointer to data: "<<(void*)data<<ENDLOG;
       return 0;
     }
   if(!comp)
     {
       LOG(AliL3Log::kError,"AliL3DataHandler::CompMemory2Memory","Array")
-       <<AliL3Log::kHex<<"Pointer to compressed data: "<<(Int_t)data<<ENDLOG;
+       <<AliL3Log::kHex<<"Pointer to compressed data: "<<(void*)comp<<ENDLOG;
       return 0;
     }
   
@@ -467,6 +479,8 @@ UInt_t AliL3DataHandler::CompMemory2Memory(UInt_t nrow,AliL3DigitRowData *data,B
            {
              //Read the first zero
              Read(comp,index);
+             
+               
              if(Test(comp,index) == 0)//end of pad.
                {
                  time = Read(comp,index); 
@@ -476,26 +490,31 @@ UInt_t AliL3DataHandler::CompMemory2Memory(UInt_t nrow,AliL3DigitRowData *data,B
                if( (time += Read(comp,index)) == 2*255)
                  time += Read(comp,index);
            }
+
          while(1)
            {
              while( (charge = Read(comp,index)) != 0)
                {
+                 if(time >= AliL3Transform::GetNTimeBins())
+                   cerr<<"AliL3DataHandler::CompMemory2Memory : Time out of range "<<time<<endl;
                  rowPt->fDigitData[ndigit].fPad = pad;
                  rowPt->fDigitData[ndigit].fTime = time;
                  rowPt->fDigitData[ndigit].fCharge = charge;
-                 time++;
                  ndigit++;
+                 if(Test(comp,index) != 0)
+                   time++;
                }
              if(Test(comp,index) == 0)
                {
                  Read(comp,index); //end of pad
                  break;
                }
-             UShort_t time_shift;
-             if( (time_shift = Read(comp,index)) == 255)
-               if( (time_shift += Read(comp,index)) == 2*255)
-                 time_shift += Read(comp,index);
-             time += time_shift;
+             UShort_t timeShift;
+             if( (timeShift = Read(comp,index)) == 255)
+               if( (timeShift += Read(comp,index)) == 2*255)
+                 timeShift += Read(comp,index);
+             time += timeShift;
+             
            }
        }
       rowPt->fNDigit = ndigit;