]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliTPCCompression.cxx
Automatic calculation of the paramters of the hough space. Optimization of the hough...
[u/mrichter/AliRoot.git] / RAW / AliTPCCompression.cxx
index ca2250b2e3bf2e5ec8ab9a833881a6fcfc0293bb..d127128391194b18c4a2e9a96358083d2963bd71 100644 (file)
@@ -27,7 +27,7 @@
 #include <Riostream.h>
 #include <TMath.h>
 #include <TSystem.h>
-#include "AliTPCBuffer160.h"
+#include "AliAltroBuffer.h"
 #include "AliTPCHNode.h"
 #include "AliTPCHTable.h"
 #include "AliTPCCompression.h"
@@ -129,7 +129,7 @@ void AliTPCCompression::NextTable(Int_t Val,Int_t &NextTableType,Int_t &BunchLen
 
 Int_t AliTPCCompression::FillTables(const char* fSource,AliTPCHTable* table[],Int_t /*NumTables*/){
   //This method is used to compute the frequencies of the symbols in the source file
-  AliTPCBuffer160 buff(fSource,0);
+  AliAltroBuffer buff(fSource,0);
   UInt_t countWords=0;
   UInt_t countTrailer=0;
   Int_t numWords,padNum,rowNum,secNum=0;
@@ -137,7 +137,7 @@ Int_t AliTPCCompression::FillTables(const char* fSource,AliTPCHTable* table[],In
   UInt_t stat[5]={0,0,0,0,0};
   Int_t endFill=0;
   Int_t end=1;
-  while(buff.ReadTrailerBackward(numWords,padNum,rowNum,secNum) !=-1 ){
+  while(buff.ReadTrailerBackward(numWords,padNum,rowNum,secNum)){
     if(end){
       endFill=buff.GetFillWordsNum();
       end=0;
@@ -615,7 +615,7 @@ Int_t AliTPCCompression::CompressDataOptTables(Int_t NumTable,const char* fSourc
   f.open(fDest,ios::out);
 #endif
   // Source file is open
-  AliTPCBuffer160 buff(fSource,0);
+  AliAltroBuffer buff(fSource,0);
   //coded words are written into a file
   Int_t numWords,padNum,rowNum,secNum=0;
   UInt_t  storedWords=0;
@@ -630,7 +630,7 @@ Int_t AliTPCCompression::CompressDataOptTables(Int_t NumTable,const char* fSourc
   fStat<<endl;
   fStat<<"-------------------COMPRESSION STATISTICS----------"<<endl;
   Int_t end=1;
-  while(buff.ReadTrailerBackward(numWords,padNum,rowNum,secNum) !=-1 ){
+  while(buff.ReadTrailerBackward(numWords,padNum,rowNum,secNum)){
     if(end){
       fillWords=buff.GetFillWordsNum();
       end=0;
@@ -892,8 +892,9 @@ UInt_t AliTPCCompression::ReadWord(Int_t NumberOfBit){
       f.read((char*)(&fBuffer),sizeof(UInt_t));
       fReadBits=0;
     }//end if
-    UInt_t mask=0;
-    mask=(UInt_t)TMath::Power(2,fReadBits);
+    //    UInt_t mask=0;
+    //    mask=(UInt_t)TMath::Power(2,fReadBits);
+    UInt_t mask=(UInt_t)(1<<fReadBits);
     bit=fBuffer&mask;
     bit=bit>>fReadBits;
     fReadBits++;
@@ -909,34 +910,40 @@ UInt_t AliTPCCompression::ReadWordBuffer(Int_t NumberOfBit){
   UInt_t bit=0;
   for (Int_t i=0;i<NumberOfBit;i++){
     if (fReadBits==32){
-      fPointBuffer-=8;
-      fBuffer=0;
-      for(Int_t i=0;i<4;i++){
-       UInt_t val=0;
-       val=*fPointBuffer;
-       val&=0xFF;
-       fPointBuffer++;
-       val<<=8*i;
-       fBuffer=fBuffer|val;
-      }//end for
+      fPointBuffer--;
+      fBuffer=*fPointBuffer;
       fReadBits=0;
     }//end if
-    UInt_t mask=0;
-    mask=(UInt_t)TMath::Power(2,fReadBits);
-    bit=fBuffer&mask;
-    bit=bit>>fReadBits;
-    fReadBits++;
+    bit=fBuffer&0x1;
     bit=bit<<i;
     result=result|bit;
+    fReadBits++;
+    fBuffer=fBuffer>>1;
   }//end for
   return result;
 }
 
+//////////////////////////////////////////////////////////////////////////////////////////////////
+inline UInt_t AliTPCCompression::ReadBitFromWordBuffer(){
+  //This method retrieves a word of a specific number of bits from the file through the buffer 
+  UInt_t result=0;
+
+  if (fReadBits==32){
+    fPointBuffer--;
+    fBuffer=*fPointBuffer;
+    fReadBits=0;
+  }//end if
+  result=fBuffer&0x1;
+  fReadBits++;
+  fBuffer=fBuffer>>1;
+  return result;
+}
+
 //////////////////////////////////////////////////////////////////////////////////////////////////
 void AliTPCCompression::ReadTrailer(Int_t &WordsNumber,Int_t &PadNumber,Int_t &RowNumber,Int_t &SecNumber,Bool_t Memory){
   //It retrieves a trailer 
   if(Memory){
-    ReadWordBuffer(1);
+    ReadBitFromWordBuffer();
     SecNumber=ReadWordBuffer(9);
     RowNumber=ReadWordBuffer(10);
     PadNumber=ReadWordBuffer(10);
@@ -952,17 +959,34 @@ void AliTPCCompression::ReadTrailer(Int_t &WordsNumber,Int_t &PadNumber,Int_t &R
   return;
 }
 //////////////////////////////////////////////////////////////////////////////////////////////////
-UInt_t AliTPCCompression::GetDecodedWord(AliTPCHNode* root,Bool_t Memory){
+inline UInt_t AliTPCCompression::GetDecodedWordBuffer(AliTPCHNode* root){
   //This method retrieves a decoded word.
   AliTPCHNode *node=root;
   UInt_t symbol=0;
   Bool_t decoded=0;
+
   while(!decoded){
-    UInt_t bit=0;
-    if(Memory)
-      bit=ReadWordBuffer(1);
+    UInt_t bit=ReadBitFromWordBuffer();
+    if(bit)
+      node=node->GetRight();
     else
-      bit=ReadWord(1);
+      node=node->GetLeft();
+    if (!(node->GetLeft())){
+      symbol=node->GetSymbol();
+      decoded=1;
+    }
+  }//end while
+  return symbol;
+}
+
+inline UInt_t AliTPCCompression::GetDecodedWord(AliTPCHNode* root){
+  //This method retrieves a decoded word.
+  AliTPCHNode *node=root;
+  UInt_t symbol=0;
+  Bool_t decoded=0;
+
+  while(!decoded){
+    UInt_t bit=ReadWord(1);
     if(bit)
       node=node->GetRight();
     else
@@ -972,6 +996,7 @@ UInt_t AliTPCCompression::GetDecodedWord(AliTPCHNode* root,Bool_t Memory){
       decoded=1;
     }
   }//end while
+
   return symbol;
 }
 //////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1022,7 +1047,7 @@ Int_t AliTPCCompression::DecompressDataOptTables(Int_t NumTables,const char* fna
   if(fVerbose){
     cout<<"Number of Packect: "<<packetNumber<<endl;
   }
-  AliTPCBuffer160 bufferFile(fDest,1);
+  AliAltroBuffer bufferFile(fDest,1);
   UInt_t k=0;
   UInt_t wordsRead=0; //number of read coded words 
   while(k<packetNumber){
@@ -1036,7 +1061,7 @@ Int_t AliTPCCompression::DecompressDataOptTables(Int_t NumTables,const char* fna
     Int_t bunchLen=0;
     Int_t count=0;
     for(Int_t i=0;i<numWords;i++){
-      UInt_t symbol=GetDecodedWord(rootNode[nextTableType],kFALSE);
+      UInt_t symbol=GetDecodedWord(rootNode[nextTableType]);
       wordsRead++;
       //Time reconstruction
       if (nextTableType==1){
@@ -1073,23 +1098,16 @@ Int_t AliTPCCompression::DecompressDataOptTables(Int_t NumTables,const char* fna
 Int_t AliTPCCompression::Decompress(AliTPCHNode *RootNode[],Int_t /*NumTables*/,char* PointBuffer,UInt_t BufferSize,UShort_t out[],UInt_t &dim){
   //This method decompress a file using separate Huffman tables
 
-  fPointBuffer=PointBuffer+BufferSize-4;
+  //  fPointBuffer=((UInt_t *)PointBuffer)+(UInt_t)(BufferSize/4)-1;
+  fPointBuffer=(UInt_t *)(PointBuffer+BufferSize-4);
   fReadBits=0;
   fBuffer=0;
   
-  for(Int_t i=0;i<4;i++){
-    UInt_t val=0;
-    val=*fPointBuffer;
-    val&=0xFF;
-    fPointBuffer++;
-    val<<=8*i;
-    fBuffer=fBuffer|val;
-  }//end for
+  fBuffer=*fPointBuffer;
   Int_t bit=0;
-  UInt_t mask=0x1;
   while(!bit){
-    bit=fBuffer&mask;
-    mask=mask<<1;
+    bit=fBuffer&0x1;
+    fBuffer=fBuffer>>1;
     fReadBits++;
   }//end while
   UInt_t packetNumber=ReadWordBuffer(sizeof(UInt_t)*8); //32 bits
@@ -1121,7 +1139,7 @@ Int_t AliTPCCompression::Decompress(AliTPCHNode *RootNode[],Int_t /*NumTables*/,
     Int_t count=0;
     Int_t timeDigit=0;
     for(Int_t i=0;i<numWords;i++){
-      UInt_t symbol=GetDecodedWord(RootNode[nextTableType],kTRUE);
+      UInt_t symbol=GetDecodedWordBuffer(RootNode[nextTableType]);
       wordsRead++;
       //Time reconstruction
       if (nextTableType==1){
@@ -1175,11 +1193,11 @@ void AliTPCCompression::ReadAltroFormat(char* fileOut,char* fileIn)const{
   //Time bin of the last amplitude sample in the bunch, amplitude values)
   //It is used mainly for debugging
   ofstream ftxt(fileOut);
-  AliTPCBuffer160 buff(fileIn,0);
+  AliAltroBuffer buff(fileIn,0);
   Int_t numWords,padNum,rowNum,secNum=0;
   Int_t value=0;
   if (fVerbose) cout<<"Creating a txt file from an Altro Format file"<<endl;
-  while(buff.ReadTrailerBackward(numWords,padNum,rowNum,secNum) !=-1 ){
+  while(buff.ReadTrailerBackward(numWords,padNum,rowNum,secNum)){
     ftxt<<"S:"<<secNum<<" R:"<<rowNum<<" P:"<<padNum<<" W:"<<numWords<<endl;
     if (numWords%4){
       for(Int_t j=0;j<(4-numWords%4);j++){