]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliTPCCompression.cxx
Track points are moved according to vertex position so vertex is in (0,0,0)
[u/mrichter/AliRoot.git] / RAW / AliTPCCompression.cxx
index 5a8fe56250c34ffded9bed339bcc3d5bca8c9d6b..ca2250b2e3bf2e5ec8ab9a833881a6fcfc0293bb 100644 (file)
 #include <TObjArray.h>
 #include <Riostream.h>
 #include <TMath.h>
+#include <TSystem.h>
 #include "AliTPCBuffer160.h"
-#include "AliTPCHuffman.h"
+#include "AliTPCHNode.h"
+#include "AliTPCHTable.h"
 #include "AliTPCCompression.h"
 
 ClassImp(AliTPCCompression)
@@ -268,40 +270,40 @@ Int_t AliTPCCompression::CreateTableFormula(Double_t beta,UInt_t M,Int_t dim,Int
   Double_t sum=0;
   Double_t min=10;
   Double_t alpha=0;
-  Double_t A=0;
-  AliTPCHTable *Table=new AliTPCHTable(dim);
+  Double_t a=0;
+  AliTPCHTable *table=new AliTPCHTable(dim);
   
   freq=1;
-  Double_t FreqArray[1024];
+  Double_t freqArray[1024];
   for(Int_t i=0;i<1024;i++){
-    FreqArray[i]=0;
+    freqArray[i]=0;
   }
   alpha=M*0.000000602+0.0104;
   if (fVerbose)
     cout<<"alpha "<<alpha<<endl;
   for(Int_t x=0;x<dim;x++){
     if (Type==1)
-      FreqArray[x]=TMath::Power((x+1),-beta)*TMath::Exp(-alpha*(x+1));
+      freqArray[x]=TMath::Power((x+1),-beta)*TMath::Exp(-alpha*(x+1));
     else
-      FreqArray[x]=TMath::Power((x+1),-beta);
-    sum+=FreqArray[x];
-    if (FreqArray[x]<min)min=FreqArray[x];
+      freqArray[x]=TMath::Power((x+1),-beta);
+    sum+=freqArray[x];
+    if (freqArray[x]<min)min=freqArray[x];
   }//end for
   if (fVerbose)
     cout<<"Minimun Value "<<min<<endl;
-  A=1/sum;
+  a=1/sum;
   if (fVerbose)
-    cout<<"A Value: "<<A<<endl;
+    cout<<"a Value: "<<a<<endl;
   for(Int_t x=0;x<dim;x++){
     if (Type==0)//Bunch length
       if (x>=3)//minimum bunch length
-       Table->SetValFrequency(x,A*FreqArray[x]*1000);
+       table->SetValFrequency(x,a*freqArray[x]*1000);
       else
-       Table->SetValFrequency(x,0);
+       table->SetValFrequency(x,0);
     else //Time table
-      Table->SetValFrequency(x,A*FreqArray[x]);
+      table->SetValFrequency(x,a*freqArray[x]);
   }
-  Table->BuildHTable();
+  table->BuildHTable();
   ofstream fTable;
   char filename[15];
   sprintf(filename,"Table%d.dat",Type); 
@@ -310,18 +312,18 @@ Int_t AliTPCCompression::CreateTableFormula(Double_t beta,UInt_t M,Int_t dim,Int
 #else
   fTable.open(filename);
 #endif
-  Int_t dimTable=Table->Size();
+  Int_t dimTable=table->Size();
   //Table dimension is written into a file
   fTable.write((char*)(&dimTable),sizeof(Int_t));
   //One table is written into a file
   for(Int_t i=0;i<dimTable;i++){
-    UChar_t CodeLen=Table->CodeLen()[i];
-    Double_t Code=Table->Code()[i];
-    fTable.write((char*)(&CodeLen),sizeof(UChar_t));
-    fTable.write((char*)(&Code),sizeof(Double_t));
+    UChar_t codeLen=table->CodeLen()[i];
+    Double_t code=table->Code()[i];
+    fTable.write((char*)(&codeLen),sizeof(UChar_t));
+    fTable.write((char*)(&code),sizeof(Double_t));
   } //end for
   fTable.close();
-  delete Table;
+  delete table;
   return 0;
 }
 ////////////////////////////////////////////////////////////////////////////////////////
@@ -436,7 +438,7 @@ Int_t AliTPCCompression::RetrieveTables(AliTPCHTable* table[],Int_t NumTable){
   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
@@ -446,7 +448,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;
@@ -480,7 +494,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);
@@ -584,8 +601,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
@@ -602,6 +625,7 @@ Int_t AliTPCCompression::CompressDataOptTables(Int_t NumTable,const char* fSourc
   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;
@@ -760,7 +784,7 @@ Int_t AliTPCCompression::CompressDataOptTables(Int_t NumTable,const char* fSourc
 /*                               DECOMPRESSION                                        */
 ////////////////////////////////////////////////////////////////////////////////////////
 
-void AliTPCCompression::CreateTreesFromFile(AliTPCHNode *RootNode[],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)
@@ -770,7 +794,7 @@ void AliTPCCompression::CreateTreesFromFile(AliTPCHNode *RootNode[],Int_t NumTab
   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++){
@@ -782,7 +806,19 @@ void AliTPCCompression::CreateTreesFromFile(AliTPCHNode *RootNode[],Int_t NumTab
 #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;
@@ -822,6 +858,7 @@ void AliTPCCompression::CreateTreesFromFile(AliTPCHNode *RootNode[],Int_t NumTab
   if (fVerbose)
     cout<<"Trees generated \n";
   //At this point the trees are been built
+  return 0;
 }
 //////////////////////////////////////////////////////////////////////////////////////////////////
 void AliTPCCompression::DeleteHuffmanTree(AliTPCHNode* node){
@@ -939,21 +976,32 @@ UInt_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