#include <Riostream.h>
#include <TMath.h>
#include <TSystem.h>
-#include "AliTPCBuffer160.h"
+#include "AliAltroBuffer.h"
#include "AliTPCHNode.h"
#include "AliTPCHTable.h"
#include "AliTPCCompression.h"
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;
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;
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;
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;
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++;
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);
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
decoded=1;
}
}//end while
+
return symbol;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
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){
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){
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
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){
//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++){