]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliTPCCompression.cxx
Quantum efficiency implemented by setting energy deposition to zero to flag inefficiency.
[u/mrichter/AliRoot.git] / RAW / AliTPCCompression.cxx
index 05ee15def643ad71693cc83725e9528a1ae5c3e4..c4080c4bdf459c761d2f2967b8ce9cb5f5bbf9ec 100644 (file)
@@ -26,6 +26,7 @@
 #include <TObjArray.h>
 #include <Riostream.h>
 #include <TMath.h>
+#include <TSystem.h>
 #include "AliTPCBuffer160.h"
 #include "AliTPCHuffman.h"
 #include "AliTPCCompression.h"
@@ -34,7 +35,7 @@ ClassImp(AliTPCCompression)
 //////////////////////////////////////////////////////////////////////////////////////////////////
 AliTPCCompression::AliTPCCompression(){
   //Defaul constructor
-  fDimBuffer=sizeof(ULong_t)*8;
+  fDimBuffer=sizeof(UInt_t)*8;
   fFreeBitsBuffer=fDimBuffer;
   fReadBits=0;
   fPos=0;
@@ -45,7 +46,8 @@ AliTPCCompression::AliTPCCompression(){
   return;
 }
 //////////////////////////////////////////////////////////////////////////////////////////////////
-AliTPCCompression::AliTPCCompression(const AliTPCCompression &source){
+AliTPCCompression::AliTPCCompression(const AliTPCCompression &source)
+  :TObject(source){
   //Constructor
   this->fDimBuffer=source.fDimBuffer;
   this->fFreeBitsBuffer=source.fFreeBitsBuffer;
@@ -124,14 +126,14 @@ void AliTPCCompression::NextTable(Int_t Val,Int_t &NextTableType,Int_t &BunchLen
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////
 
-Int_t AliTPCCompression::FillTables(const char* fSource,AliTPCHTable* table[],const Int_t NumTables){
+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);
-  ULong_t countWords=0;
-  ULong_t countTrailer=0;
+  UInt_t countWords=0;
+  UInt_t countTrailer=0;
   Int_t numWords,padNum,rowNum,secNum=0;
   Int_t value=0;
-  ULong_t stat[5]={0,0,0,0,0};
+  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 ){
@@ -204,30 +206,30 @@ Int_t AliTPCCompression::FillTables(const char* fSource,AliTPCHTable* table[],co
   fStat<<"Number of Central Samples....."<<stat[3]<<endl;
   fStat<<"Number of Border Samples......"<<stat[4]<<endl;
   fStat<<"-----------------------------------------"<<endl;
-  ULong_t fileDimension=(ULong_t)TMath::Ceil(double((countTrailer*4+countWords+fFillWords+endFill)*10/8));
+  UInt_t fileDimension=(UInt_t)TMath::Ceil(double((countTrailer*4+countWords+fFillWords+endFill)*10/8));
   fStat<<"Total file Size in bytes.."<<fileDimension<<endl;
   Double_t percentage=TMath::Ceil((fFillWords+endFill)*125)/fileDimension;
-  fStat<<"Fill Words................"<<(ULong_t)TMath::Ceil((fFillWords+endFill)*10/8)<<" bytes   "<<percentage<<"%"<<endl;  
+  fStat<<"Fill Words................"<<(UInt_t)TMath::Ceil((fFillWords+endFill)*10/8)<<" bytes   "<<percentage<<"%"<<endl;  
   percentage=(Double_t)countTrailer*500/fileDimension;
   fStat<<"Trailer..................."<<countTrailer*5<<" bytes   "<<percentage<<"%"<<endl;
 
   percentage=(Double_t)((stat[0]+stat[1]+stat[2]+stat[3]+stat[4])) *125/fileDimension;
-  fStat<<"Data......................"<<(ULong_t)TMath::Ceil((stat[0]+stat[1]+stat[2]+stat[3]+stat[4])*10/8)<<" bytes   "<<percentage<<"%"<<endl;
+  fStat<<"Data......................"<<(UInt_t)TMath::Ceil((stat[0]+stat[1]+stat[2]+stat[3]+stat[4])*10/8)<<" bytes   "<<percentage<<"%"<<endl;
 
   percentage=(Double_t)(stat[0]*125)/fileDimension;
-  fStat<<"Bunch....................."<<(ULong_t)TMath::Ceil(stat[0]*10/8)<<" bytes  "<<percentage<<"%"<<endl;  //  
+  fStat<<"Bunch....................."<<(UInt_t)TMath::Ceil(stat[0]*10/8)<<" bytes  "<<percentage<<"%"<<endl;  //  
   percentage=(Double_t)(stat[1]*125)/fileDimension;
-  fStat<<"Time......................"<<(ULong_t)TMath::Ceil(stat[1]*10/8)<<" bytes  "<<percentage<<"%"<<endl;  //  
+  fStat<<"Time......................"<<(UInt_t)TMath::Ceil(stat[1]*10/8)<<" bytes  "<<percentage<<"%"<<endl;  //  
 
 
   percentage=(Double_t)((stat[2]+stat[3]+stat[4])) *125/fileDimension;
-  fStat<<"Amplitude values.........."<<(ULong_t)TMath::Ceil((stat[2]+stat[3]+stat[4])*10/8)<<" bytes  "<<percentage<<"%"<<endl;
+  fStat<<"Amplitude values.........."<<(UInt_t)TMath::Ceil((stat[2]+stat[3]+stat[4])*10/8)<<" bytes  "<<percentage<<"%"<<endl;
   percentage=(Double_t)(stat[2]*125)/fileDimension;
-  fStat<<"     One Samples..............."<<(ULong_t)TMath::Ceil(stat[2]*10/8)<<" bytes  "<<percentage<<"%"<<endl;  //  
+  fStat<<"     One Samples..............."<<(UInt_t)TMath::Ceil(stat[2]*10/8)<<" bytes  "<<percentage<<"%"<<endl;  //  
   percentage=(Double_t)(stat[3]*125)/fileDimension;
-  fStat<<"     Central Samples..........."<<(ULong_t)TMath::Ceil(stat[3]*10/8)<<" bytes  "<<percentage<<"%"<<endl;  //  
+  fStat<<"     Central Samples..........."<<(UInt_t)TMath::Ceil(stat[3]*10/8)<<" bytes  "<<percentage<<"%"<<endl;  //  
   percentage=(Double_t)(stat[4]*125)/fileDimension;
-  fStat<<"     Border Samples............"<<(ULong_t)TMath::Ceil(stat[4]*10/8)<<" bytes  "<<percentage<<"%"<<endl;  //  
+  fStat<<"     Border Samples............"<<(UInt_t)TMath::Ceil(stat[4]*10/8)<<" bytes  "<<percentage<<"%"<<endl;  //  
   fStat.close();
   return 0;
 }
@@ -249,10 +251,10 @@ Int_t AliTPCCompression::StoreTables(AliTPCHTable* table[],const Int_t NumTable)
     //One table is written into a file
     for(Int_t i=0;i<dim;i++){
       UChar_t codeLen=table[k]->CodeLen()[i];
-      //      ULong_t code=(ULong_t)table[k]->Code()[i];
+      //      UInt_t code=(UInt_t)table[k]->Code()[i];
       Double_t code=table[k]->Code()[i];
       fTable.write((char*)(&codeLen),sizeof(UChar_t));
-      //fTable.write((char*)(&code),sizeof(ULong_t));
+      //fTable.write((char*)(&code),sizeof(UInt_t));
       fTable.write((char*)(&code),sizeof(Double_t));
     } //end for
     fTable.close();
@@ -260,10 +262,10 @@ Int_t AliTPCCompression::StoreTables(AliTPCHTable* table[],const Int_t NumTable)
   return 0;
 }
 ////////////////////////////////////////////////////////////////////////////////////////
-Int_t AliTPCCompression::CreateTableFormula(Double_t beta,ULong_t  M,Int_t dim,Int_t Type){
+Int_t AliTPCCompression::CreateTableFormula(Double_t beta,UInt_t M,Int_t dim,Int_t Type){
   // Type = 0 for Bunch length
   // Type = 1 for Time Gap
-  ULong_t freq;
+  UInt_t freq;
   Double_t sum=0;
   Double_t min=10;
   Double_t alpha=0;
@@ -324,7 +326,7 @@ Int_t AliTPCCompression::CreateTableFormula(Double_t beta,ULong_t  M,Int_t dim,I
   return 0;
 }
 ////////////////////////////////////////////////////////////////////////////////////////
-Int_t AliTPCCompression::CreateTables(const char* fSource,const Int_t NumTables){
+Int_t AliTPCCompression::CreateTables(const char* fSource,Int_t NumTables){
   //Tables manager
   /*
     Table index:
@@ -431,11 +433,11 @@ Int_t AliTPCCompression::RetrieveTables(AliTPCHTable* table[],Int_t NumTable){
   //This method retrieve the Huffman tables from a sequence of binary files
   if (fVerbose)
     cout<<"Retrieving tables from files \n";
-  //  ULong_t code;
+  //  UInt_t code;
   Double_t code;
   UChar_t codeLen;
   ifstream fTable;  
-  char filename[15];
+  char filename[256];
   //The following for loop is used to generate the Huffman trees acording to the tables
   for(Int_t k=0;k<NumTable;k++){
     Int_t dim;//this variable contains the table dimension
@@ -445,7 +447,19 @@ Int_t AliTPCCompression::RetrieveTables(AliTPCHTable* table[],Int_t NumTable){
 #else
     fTable.open(filename);
 #endif
-    if(!fTable){cout<<"File doesn't exist:"<<filename<<endl; exit(1);}
+    if(!fTable && gSystem->Getenv("ALICE_ROOT")){
+      fTable.clear();
+      sprintf(filename,"%s/RAW/Table%d.dat",gSystem->Getenv("ALICE_ROOT"),k); 
+#ifndef __DECCXX 
+      fTable.open(filename,ios::binary);
+#else
+      fTable.open(filename);
+#endif
+    }
+    if(!fTable){
+      Error("RetrieveTables", "File doesn't exist: %s", filename);
+      return 1;
+    }
     fTable.read((char*)(&dim),sizeof(Int_t));
     if (fVerbose)
       cout<<"Table dimension: "<<dim<<endl;
@@ -453,9 +467,9 @@ Int_t AliTPCCompression::RetrieveTables(AliTPCHTable* table[],Int_t NumTable){
     for(Int_t i=0;i<dim;i++){
       fTable.read((char*)(&codeLen),sizeof(UChar_t));
       table[k]->SetCodeLen(codeLen,i);
-      //      fTable.read((char*)(&code),sizeof(ULong_t));
+      //      fTable.read((char*)(&code),sizeof(UInt_t));
       fTable.read((char*)(&code),sizeof(Double_t));
-      table[k]->SetCode(Mirror((ULong_t)code,codeLen),i);
+      table[k]->SetCode(Mirror((UInt_t)code,codeLen),i);
     }//end for 
     fTable.close();
   }//end for 
@@ -479,7 +493,10 @@ Int_t AliTPCCompression::CreateTablesFromTxtFiles(Int_t NumTable){
     sprintf(filename,"Table%d.txt",k); 
     cout<<filename<<endl;
     fTable.open(filename);
-    if(!fTable){cout<<"File doesn't exist: "<<filename<<endl; exit(1);}
+    if(!fTable){
+      Error("CreateTablesFromTxtFiles", "File doesn't exist: %s", filename);
+      return 1;
+    }
     Int_t symbol=0;
     Double_t freq=0;
     table[k]=new AliTPCHTable(1024);
@@ -521,25 +538,25 @@ Int_t AliTPCCompression::CreateTablesFromTxtFiles(Int_t NumTable){
 /*                               COMPRESSION                                          */
 ////////////////////////////////////////////////////////////////////////////////////////
 
-void AliTPCCompression::StoreValue(ULong_t val,UChar_t len){
+void AliTPCCompression::StoreValue(UInt_t val,UChar_t len){
   //This method stores the value "val" of "len" bits into the internal buffer "fBuffer"
   if (len<=fFreeBitsBuffer){           // val is not splitted in two buffer
     fFreeBitsBuffer-=len;
     fBuffer=fBuffer<<len;
     fBuffer=fBuffer|val;    
     if(!fFreeBitsBuffer){              // if the buffer is full it is written into a file 
-      f.write((char*)(&fBuffer),sizeof(ULong_t));      
+      f.write((char*)(&fBuffer),sizeof(UInt_t));       
       fFreeBitsBuffer=fDimBuffer;
       fBuffer=0;
     }
   }//end if
   else{                               //val has to be splitted in two buffers
     fBuffer=fBuffer<<fFreeBitsBuffer;
-    ULong_t temp;
+    UInt_t temp;
     temp=val;
     temp=temp>>(len-fFreeBitsBuffer);
     fBuffer=fBuffer|temp;
-    f.write((char*)(&fBuffer),sizeof(ULong_t));
+    f.write((char*)(&fBuffer),sizeof(UInt_t));
     fFreeBitsBuffer=fDimBuffer-(len-fFreeBitsBuffer);
     val=val<<fFreeBitsBuffer;
     val=val>>fFreeBitsBuffer;
@@ -553,17 +570,17 @@ void AliTPCCompression::Flush(){
   //into the output file it is first necessary to fill it with an hexadecimal pattern
   if(fFreeBitsBuffer<fDimBuffer){
     fBuffer=fBuffer<<fFreeBitsBuffer;
-    f.write((char*)(&fBuffer),sizeof(ULong_t));         
+    f.write((char*)(&fBuffer),sizeof(UInt_t));  
   }//end if
   return;
 }
 //////////////////////////////////////////////////////////////////////////////////////////////////
-ULong_t AliTPCCompression::Mirror(ULong_t val,UChar_t len)const{
+UInt_t AliTPCCompression::Mirror(UInt_t val,UChar_t len)const{
   //This method inverts the digits of the number "val" and length "len"
   //indicates the number of digits of the number considered in binary notation
-  ULong_t specular=0;
-  ULong_t mask=0x1;
-  ULong_t bit;
+  UInt_t specular=0;
+  UInt_t mask=0x1;
+  UInt_t bit;
   for(Int_t i=0;i<len;i++){
     bit=val&mask;
     bit=bit>>i;
@@ -583,8 +600,14 @@ Int_t AliTPCCompression::CompressDataOptTables(Int_t NumTable,const char* fSourc
   }
   //Tables are read from the files (Each codeword has been "Mirrored")
   AliTPCHTable **table = new AliTPCHTable*[NumTable];
-  RetrieveTables(table,NumTable);
+  for(Int_t i=0;i<NumTable;i++) table[i] = NULL;
+  if (RetrieveTables(table,NumTable) != 0) {
+    for(Int_t i=0;i<NumTable;i++) delete table[i];
+    delete [] table;
+    return 1;
+  }
   //the output file is open
+  f.clear();
 #ifndef __DECCXX 
   f.open(fDest,ios::binary|ios::out);
 #else
@@ -594,13 +617,14 @@ Int_t AliTPCCompression::CompressDataOptTables(Int_t NumTable,const char* fSourc
   AliTPCBuffer160 buff(fSource,0);
   //coded words are written into a file
   Int_t numWords,padNum,rowNum,secNum=0;
-  ULong_t  storedWords=0;
+  UInt_t  storedWords=0;
   Int_t    value=0;
-  ULong_t  numPackets=0;
+  UInt_t  numPackets=0;
   Double_t stat[5]={0.,0.,0.,0.,0.};
-  ULong_t  trailerNumbers=0;
+  UInt_t  trailerNumbers=0;
   Double_t numElem[5]={0,0,0,0,0};
   Double_t fillWords=0.;
+  fStat.clear();
   fStat.open("Statistics",ios::app);
   fStat<<endl;
   fStat<<"-------------------COMPRESSION STATISTICS----------"<<endl;
@@ -657,26 +681,26 @@ Int_t AliTPCCompression::CompressDataOptTables(Int_t NumTable,const char* fSourc
       value=packet[i];
       if(nextTableType==1)timeBin=value;
       if(nextTableType>1){
-       //ULong_t val=(ULong_t)table[nextTableType]->Code()[value];     // val is the code
+       //UInt_t val=(UInt_t)table[nextTableType]->Code()[value];     // val is the code
        Double_t val=table[nextTableType]->Code()[value];     // val is the code
        UChar_t len=table[nextTableType]->CodeLen()[value];  // len is the length (number of bits)of val
        stat[nextTableType]+=len;
        numElem[nextTableType]++;
-       StoreValue((ULong_t)val,len);
+       StoreValue((UInt_t)val,len);
        storedWords++;
       }//end if
       NextTable(value,nextTableType,bunchLen,count);
       if(nextTableType==0){
-       //      ULong_t val=(ULong_t)table[1]->Code()[timeBin];     // val is the code
+       //      UInt_t val=(UInt_t)table[1]->Code()[timeBin];     // val is the code
        Double_t val=table[1]->Code()[timeBin];     // val is the code
        UChar_t len=table[1]->CodeLen()[timeBin];  // len is the length (number of bits)of val
        stat[1]+=len;
        numElem[1]++;
-       StoreValue((ULong_t)val,len);
-       //      val=(ULong_t)table[nextTableType]->Code()[(bunchLen+2)];     // val is the code
+       StoreValue((UInt_t)val,len);
+       //      val=(UInt_t)table[nextTableType]->Code()[(bunchLen+2)];     // val is the code
        val=table[nextTableType]->Code()[(bunchLen+2)];     // val is the code
        len=table[nextTableType]->CodeLen()[(bunchLen+2)];  // len is the length (number of bits)of val
-       StoreValue((ULong_t)val,len);
+       StoreValue((UInt_t)val,len);
        stat[nextTableType]+=len;
        numElem[nextTableType]++;
        storedWords+=2;
@@ -705,38 +729,38 @@ Int_t AliTPCCompression::CompressDataOptTables(Int_t NumTable,const char* fSourc
     delete table[i];
   }//end for
   delete [] table;
-  Double_t dimension=(ULong_t)TMath::Ceil((stat[0]+stat[1]+stat[2]+stat[3]+stat[4])/8)+trailerNumbers*5;
+  Double_t dimension=(UInt_t)TMath::Ceil((stat[0]+stat[1]+stat[2]+stat[3]+stat[4])/8)+trailerNumbers*5;
   fStat<<"Trailer Dimension in bytes......"<<trailerNumbers*5<<endl;
-  fStat<<"Data Dimension in bytes........."<<(ULong_t)TMath::Ceil((stat[0]+stat[1]+stat[2]+stat[3]+stat[4])/8)<<endl;
-  fStat<<"Compressed file dimension......."<<(ULong_t)dimension<<endl;
+  fStat<<"Data Dimension in bytes........."<<(UInt_t)TMath::Ceil((stat[0]+stat[1]+stat[2]+stat[3]+stat[4])/8)<<endl;
+  fStat<<"Compressed file dimension......."<<(UInt_t)dimension<<endl;
   /*
-  fStat<<(ULong_t)trailerNumbers<<endl;
-  fStat<<(ULong_t)fillWords<<endl;
-  fStat<<(ULong_t)numElem[0]<<endl;
-  fStat<<(ULong_t)numElem[1]<<endl;
-  fStat<<(ULong_t)numElem[2]<<endl;
-  fStat<<(ULong_t)numElem[3]<<endl;
-  fStat<<(ULong_t)numElem[4]<<endl;
+  fStat<<(UInt_t)trailerNumbers<<endl;
+  fStat<<(UInt_t)fillWords<<endl;
+  fStat<<(UInt_t)numElem[0]<<endl;
+  fStat<<(UInt_t)numElem[1]<<endl;
+  fStat<<(UInt_t)numElem[2]<<endl;
+  fStat<<(UInt_t)numElem[3]<<endl;
+  fStat<<(UInt_t)numElem[4]<<endl;
   */
   fillWords=(fillWords+numElem[0]+numElem[1]+numElem[2]+numElem[3]+numElem[4]+trailerNumbers*4)*10/8;
-  fStat<<"Original file dimension........."<<(ULong_t)fillWords<<endl;
+  fStat<<"Original file dimension........."<<(UInt_t)fillWords<<endl;
 
   Double_t ratio=(dimension/fillWords)*100;
   fStat<<"Compression ratio (Compressed/Uncompressed)..."<<ratio<<"%"<<endl;
   fStat<<endl;
   if (numElem[0])
-    fStat<<"Bunch length size in bytes......"<<(ULong_t)TMath::Ceil(stat[0]/8)<<" Comppression.."<<(stat[0]/numElem[0])*10<<"%"<<endl;
+    fStat<<"Bunch length size in bytes......"<<(UInt_t)TMath::Ceil(stat[0]/8)<<" Comppression.."<<(stat[0]/numElem[0])*10<<"%"<<endl;
   if (numElem[1])  
-    fStat<<"Time gap size in bytes.........."<<(ULong_t)TMath::Ceil(stat[1]/8)<<" Comppression.."<<(stat[1]/numElem[1])*10<<"%"<<endl;
+    fStat<<"Time gap size in bytes.........."<<(UInt_t)TMath::Ceil(stat[1]/8)<<" Comppression.."<<(stat[1]/numElem[1])*10<<"%"<<endl;
   if (numElem[2]+numElem[3]+numElem[4])  
-    fStat<<"Amplitude values in bytes......."<<(ULong_t)TMath::Ceil((stat[2]+stat[3]+stat[4])/8)<<" Comppression.."<<
+    fStat<<"Amplitude values in bytes......."<<(UInt_t)TMath::Ceil((stat[2]+stat[3]+stat[4])/8)<<" Comppression.."<<
       ((stat[2]+stat[3]+stat[4])/(numElem[2]+numElem[3]+numElem[4]))*10<<"%"<<endl;
   if (numElem[2])
-  fStat<<"     One Samples in bytes............"<<(ULong_t)TMath::Ceil(stat[2]/8)<<" Comppression.."<<(stat[2]/numElem[2])*10<<"%"<<endl;
+  fStat<<"     One Samples in bytes............"<<(UInt_t)TMath::Ceil(stat[2]/8)<<" Comppression.."<<(stat[2]/numElem[2])*10<<"%"<<endl;
   if (numElem[3])
-  fStat<<"     Central Samples size in bytes..."<<(ULong_t)TMath::Ceil(stat[3]/8)<<" Comppression.."<<(stat[3]/numElem[3])*10<<"%"<<endl;
+  fStat<<"     Central Samples size in bytes..."<<(UInt_t)TMath::Ceil(stat[3]/8)<<" Comppression.."<<(stat[3]/numElem[3])*10<<"%"<<endl;
   if (numElem[4])
-  fStat<<"     Border Samples size in bytes...."<<(ULong_t)TMath::Ceil(stat[4]/8)<<" Comppression.."<<(stat[4]/numElem[4])*10<<"%"<<endl;
+  fStat<<"     Border Samples size in bytes...."<<(UInt_t)TMath::Ceil(stat[4]/8)<<" Comppression.."<<(stat[4]/numElem[4])*10<<"%"<<endl;
   fStat<<endl;
   fStat<<"Average number of bits per word"<<endl;
   if (numElem[0])
@@ -759,17 +783,17 @@ Int_t AliTPCCompression::CompressDataOptTables(Int_t NumTable,const char* fSourc
 /*                               DECOMPRESSION                                        */
 ////////////////////////////////////////////////////////////////////////////////////////
 
-void AliTPCCompression::CreateTreesFromFile(AliTPCHNode *RootNode[],const Int_t NumTables){
+Int_t AliTPCCompression::CreateTreesFromFile(AliTPCHNode *RootNode[],Int_t NumTables){
   //For each table this method builds the associate Huffman tree starting from the codeword and 
   //the codelength of each symbol 
   if(fVerbose)
     cout<<"Creating the Huffman trees \n";
   AliTPCHNode *node=0;
-  // ULong_t code;
+  // UInt_t code;
   Double_t code;
   UChar_t codeLen;
   ifstream fTable;  
-  char filename[15];
+  char filename[256];
   //The following for loop is used to generate the Huffman trees acording to the tables
   //loop over the tables
   for(Int_t k=0;k<NumTables;k++){
@@ -781,20 +805,32 @@ void AliTPCCompression::CreateTreesFromFile(AliTPCHNode *RootNode[],const Int_t
 #else
     fTable.open(filename);
 #endif
-    if(!fTable){cout<<"Tables don't exist !!!"<<endl;exit(1);}
+    if(!fTable && gSystem->Getenv("ALICE_ROOT")){
+      fTable.clear();
+      sprintf(filename,"%s/RAW/Table%d.dat",gSystem->Getenv("ALICE_ROOT"),k); 
+#ifndef __DECCXX 
+      fTable.open(filename,ios::binary);
+#else
+      fTable.open(filename);
+#endif
+    }
+    if(!fTable){
+      Error("CreateTreesFromFile", "File doesn't exist: %s", filename);
+      return 1;
+    }
     fTable.read((char*)(&dim),sizeof(Int_t));
     if (fVerbose)
       cout<<"Table dimension: "<<dim<<endl;
     //loop over the words of one table
     for(Int_t i=0;i<dim;i++){
       fTable.read((char*)(&codeLen),sizeof(UChar_t));
-      //fTable.read((char*)(&code),sizeof(ULong_t));
+      //fTable.read((char*)(&code),sizeof(UInt_t));
       fTable.read((char*)(&code),sizeof(Double_t));
       node=RootNode[k];
       for(Int_t j=1;j<=codeLen;j++){
-       ULong_t bit,val=0;
-       val=(ULong_t)TMath::Power(2,codeLen-j);
-       bit=(ULong_t)code&val; 
+       UInt_t bit,val=0;
+       val=(UInt_t)TMath::Power(2,codeLen-j);
+       bit=(UInt_t)code&val; 
        AliTPCHNode *temp=node;
        if(bit){
          node=node->GetRight();
@@ -821,6 +857,7 @@ void AliTPCCompression::CreateTreesFromFile(AliTPCHNode *RootNode[],const Int_t
   if (fVerbose)
     cout<<"Trees generated \n";
   //At this point the trees are been built
+  return 0;
 }
 //////////////////////////////////////////////////////////////////////////////////////////////////
 void AliTPCCompression::DeleteHuffmanTree(AliTPCHNode* node){
@@ -843,19 +880,19 @@ void AliTPCCompression::VisitHuffmanTree(AliTPCHNode* node){
   }
 }
 //////////////////////////////////////////////////////////////////////////////////////////////////
-ULong_t AliTPCCompression::ReadWord(Int_t NumberOfBit){
+UInt_t AliTPCCompression::ReadWord(Int_t NumberOfBit){
   //This method retrieves a word of a specific number of bits from the file through the internal buffer 
-  ULong_t result=0;
-  ULong_t bit=0;
+  UInt_t result=0;
+  UInt_t bit=0;
   for (Int_t i=0;i<NumberOfBit;i++){
     if (fReadBits==32){
-      fPos-=sizeof(ULong_t);
+      fPos-=sizeof(UInt_t);
       f.seekg(fPos);
-      f.read((char*)(&fBuffer),sizeof(ULong_t));
+      f.read((char*)(&fBuffer),sizeof(UInt_t));
       fReadBits=0;
     }//end if
-    ULong_t mask=0;
-    mask=(ULong_t)TMath::Power(2,fReadBits);
+    UInt_t mask=0;
+    mask=(UInt_t)TMath::Power(2,fReadBits);
     bit=fBuffer&mask;
     bit=bit>>fReadBits;
     fReadBits++;
@@ -865,16 +902,16 @@ ULong_t AliTPCCompression::ReadWord(Int_t NumberOfBit){
   return result;
 }
 //////////////////////////////////////////////////////////////////////////////////////////////////
-ULong_t AliTPCCompression::ReadWordBuffer(Int_t NumberOfBit){
+UInt_t AliTPCCompression::ReadWordBuffer(Int_t NumberOfBit){
   //This method retrieves a word of a specific number of bits from the file through the buffer 
-  ULong_t result=0;
-  ULong_t bit=0;
+  UInt_t result=0;
+  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++){
-       ULong_t val=0;
+       UInt_t val=0;
        val=*fPointBuffer;
        val&=0xFF;
        fPointBuffer++;
@@ -883,8 +920,8 @@ ULong_t AliTPCCompression::ReadWordBuffer(Int_t NumberOfBit){
       }//end for
       fReadBits=0;
     }//end if
-    ULong_t mask=0;
-    mask=(ULong_t)TMath::Power(2,fReadBits);
+    UInt_t mask=0;
+    mask=(UInt_t)TMath::Power(2,fReadBits);
     bit=fBuffer&mask;
     bit=bit>>fReadBits;
     fReadBits++;
@@ -914,13 +951,13 @@ void AliTPCCompression::ReadTrailer(Int_t &WordsNumber,Int_t &PadNumber,Int_t &R
   return;
 }
 //////////////////////////////////////////////////////////////////////////////////////////////////
-ULong_t AliTPCCompression::GetDecodedWord(AliTPCHNode* root,Bool_t Memory){
+UInt_t AliTPCCompression::GetDecodedWord(AliTPCHNode* root,Bool_t Memory){
   //This method retrieves a decoded word.
   AliTPCHNode *node=root;
-  ULong_t symbol=0;
+  UInt_t symbol=0;
   Bool_t decoded=0;
   while(!decoded){
-    ULong_t bit=0;
+    UInt_t bit=0;
     if(Memory)
       bit=ReadWordBuffer(1);
     else
@@ -938,44 +975,55 @@ ULong_t AliTPCCompression::GetDecodedWord(AliTPCHNode* root,Bool_t Memory){
 }
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
-Int_t AliTPCCompression::DecompressDataOptTables(Int_t NumTables,const char* fname,char* fDest){
+Int_t AliTPCCompression::DecompressDataOptTables(Int_t NumTables,const char* fname, const char* fDest){
   //This method decompress a file using separate Huffman tables
   if(fVerbose){
     cout<<"   DECOMPRESSION:"<<endl;
     cout<<"Source File "<<fname<<" Destination File "<<fDest<<endl; 
   }
   AliTPCHNode ** rootNode = new AliTPCHNode*[NumTables];
+  for(Int_t i=0;i<NumTables;i++) rootNode[i] = NULL;
   //Creation of the Huffman trees
-  CreateTreesFromFile(rootNode,NumTables);
+  if (CreateTreesFromFile(rootNode,NumTables) != 0) {
+    for(Int_t i=0;i<NumTables;i++) {
+      if (rootNode[i]) DeleteHuffmanTree(rootNode[i]);
+    }
+    delete [] rootNode;
+    return 1;
+  }
+  f.clear();
 #ifndef __DECCXX
   f.open(fname,ios::binary|ios::in);
 #else
   f.open(fname,ios::in);
 #endif
-  if(!f){cout<<"File doesn't exist:"<<fname<<endl;;return -1;}
+  if(!f){
+    Error("DecompressDataOptTables", "File doesn't exist:",fname);
+    return -1;
+  }
   //to go to the end of the file
   f.seekg(0,ios::end);
   //to get the file dimension in byte
   fPos=f.tellg();
-  fPos-=sizeof(ULong_t);
+  fPos-=sizeof(UInt_t);
   f.seekg(fPos);
   fReadBits=0;
   fBuffer=0;
-  f.read((char*)(&fBuffer),sizeof(ULong_t));
+  f.read((char*)(&fBuffer),sizeof(UInt_t));
   Int_t bit=0;
-  ULong_t mask=0x1;
+  UInt_t mask=0x1;
   while(!bit){
     bit=fBuffer&mask;
     mask=mask<<1;
     fReadBits++;
   }
-  ULong_t packetNumber=ReadWord(sizeof(ULong_t)*8);
+  UInt_t packetNumber=ReadWord(sizeof(UInt_t)*8);
   if(fVerbose){
     cout<<"Number of Packect: "<<packetNumber<<endl;
   }
   AliTPCBuffer160 bufferFile(fDest,1);
-  ULong_t k=0;
-  ULong_t wordsRead=0; //number of read coded words 
+  UInt_t k=0;
+  UInt_t wordsRead=0; //number of read coded words 
   while(k<packetNumber){
     Int_t numWords,padNumber,rowNumber,secNumber=0;
     ReadTrailer(numWords,padNumber,rowNumber,secNumber,kFALSE);
@@ -987,7 +1035,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++){
-      ULong_t symbol=GetDecodedWord(rootNode[nextTableType],kFALSE);
+      UInt_t symbol=GetDecodedWord(rootNode[nextTableType],kFALSE);
       wordsRead++;
       //Time reconstruction
       if (nextTableType==1){
@@ -1021,7 +1069,7 @@ Int_t AliTPCCompression::DecompressDataOptTables(Int_t NumTables,const char* fna
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
-Int_t AliTPCCompression::Decompress(AliTPCHNode *RootNode[],const Int_t NumTables,char* PointBuffer,ULong_t BufferSize,UShort_t out[],ULong_t &dim){
+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;
@@ -1029,7 +1077,7 @@ Int_t AliTPCCompression::Decompress(AliTPCHNode *RootNode[],const Int_t NumTable
   fBuffer=0;
   
   for(Int_t i=0;i<4;i++){
-    ULong_t val=0;
+    UInt_t val=0;
     val=*fPointBuffer;
     val&=0xFF;
     fPointBuffer++;
@@ -1037,19 +1085,19 @@ Int_t AliTPCCompression::Decompress(AliTPCHNode *RootNode[],const Int_t NumTable
     fBuffer=fBuffer|val;
   }//end for
   Int_t bit=0;
-  ULong_t mask=0x1;
+  UInt_t mask=0x1;
   while(!bit){
     bit=fBuffer&mask;
     mask=mask<<1;
     fReadBits++;
   }//end while
-  ULong_t packetNumber=ReadWordBuffer(sizeof(ULong_t)*8); //32 bits
+  UInt_t packetNumber=ReadWordBuffer(sizeof(UInt_t)*8); //32 bits
   if (fVerbose){
     cout<<"First one has been found "<<endl;
     cout<<"Number of packets:"<<packetNumber<<endl;
   }//end if
-  ULong_t k=0;
-  ULong_t wordsRead=0; //number of read coded words
+  UInt_t k=0;
+  UInt_t wordsRead=0; //number of read coded words
   while(k<packetNumber){
     Int_t numWords,padNumber,rowNumber,secNumber=0;
     ReadTrailer(numWords,padNumber,rowNumber,secNumber,kTRUE);
@@ -1072,7 +1120,7 @@ Int_t AliTPCCompression::Decompress(AliTPCHNode *RootNode[],const Int_t NumTable
     Int_t count=0;
     Int_t timeDigit=0;
     for(Int_t i=0;i<numWords;i++){
-      ULong_t symbol=GetDecodedWord(RootNode[nextTableType],kTRUE);
+      UInt_t symbol=GetDecodedWord(RootNode[nextTableType],kTRUE);
       wordsRead++;
       //Time reconstruction
       if (nextTableType==1){
@@ -1108,7 +1156,7 @@ Int_t AliTPCCompression::Decompress(AliTPCHNode *RootNode[],const Int_t NumTable
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
-Int_t AliTPCCompression::DestroyTables(AliTPCHNode *RootNode[],const Int_t NumTables){
+Int_t AliTPCCompression::DestroyTables(AliTPCHNode *RootNode[],Int_t NumTables){
   //The trees are deleted
   for(Int_t j=0;j<NumTables;j++){
     DeleteHuffmanTree(RootNode[j]);