#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)
/////////////////////////////////////////////////////////////////////////////////////////////////////
-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);
UInt_t countWords=0;
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////
-Int_t AliTPCCompression::CreateTableFormula(Double_t beta,UInt_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
UInt_t freq;
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);
#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;
}
////////////////////////////////////////////////////////////////////////////////////////
-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:
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
#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;
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);
}
//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
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;
/* 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)
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++){
#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;
if (fVerbose)
cout<<"Trees generated \n";
//At this point the trees are been built
+ return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
void AliTPCCompression::DeleteHuffmanTree(AliTPCHNode* node){
}
//////////////////////////////////////////////////////////////////////////////////////////////////
-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
}
//////////////////////////////////////////////////////////////////////////////////////////////////
-Int_t AliTPCCompression::Decompress(AliTPCHNode *RootNode[],const Int_t /*NumTables*/,char* PointBuffer,UInt_t BufferSize,UShort_t out[],UInt_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;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
-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]);