#include "AliAltroRawStream.h"
#include "AliRawReader.h"
+#include "AliLog.h"
ClassImp(AliAltroRawStream)
fPrevRow(-1),
fPad(-1),
fPrevPad(-1),
+ fHWAddress(-1),
+ fPrevHWAddress(-1),
fTime(-1),
fSignal(-1),
fRawReader(rawReader),
fData(NULL),
+ fNoAltroMapping(kTRUE),
fPosition(0),
fCount(0),
fBunchLength(0)
fPrevRow(-1),
fPad(-1),
fPrevPad(-1),
+ fHWAddress(-1),
+ fPrevHWAddress(-1),
fTime(-1),
fSignal(-1),
fRawReader(NULL),
fData(NULL),
+ fNoAltroMapping(kTRUE),
fPosition(0),
fCount(0),
fBunchLength(0)
}
+//_____________________________________________________________________________
+void AliAltroRawStream::Reset()
+{
+// reset altro raw stream params
+
+ fPosition = fCount = fBunchLength = 0;
+
+ fSector = fPrevSector = fRow = fPrevRow = fPad = fPrevPad = fHWAddress = fPrevHWAddress = fTime = fSignal = -1;
+
+ if (fRawReader) fRawReader->Reset();
+}
//_____________________________________________________________________________
Bool_t AliAltroRawStream::Next()
fPrevSector = fSector;
fPrevRow = fRow;
fPrevPad = fPad;
+ fPrevHWAddress = fHWAddress;
while (fCount == 0) { // next trailer
if (fPosition <= 0) { // next payload
if (!fRawReader->ReadNextData(fData)) return kFALSE;
} while (fRawReader->GetDataSize() == 0);
- fPosition = (fRawReader->GetDataSize() * 8) / 10;
- while (Get10BitWord(fData, fPosition-1) == 0x2AA) fPosition--;
- }
-
- if (fPosition > 0) {
- // read the trailer
- if (fPosition <= 4) {
- Error("Next", "could not read trailer");
- return kFALSE;
- }
- fSector = Get10BitWord(fData, --fPosition);
- fRow = Get10BitWord(fData, --fPosition);
- fPad = Get10BitWord(fData, --fPosition);
- fCount = Get10BitWord(fData, --fPosition);
-
- fPosition -= (4 - (fCount % 4)) % 4; // skip fill words
- fBunchLength = 0;
+ fPosition = GetPosition();
}
- }
- if (fBunchLength == 0) {
- if (fPosition <= 0) {
- Error("Next", "could not read bunch length");
- return kFALSE;
- }
- fBunchLength = Get10BitWord(fData, --fPosition) - 2;
- fTimeBunch = fBunchLength;
- fCount--;
+ if (!ReadTrailer())
+ AliFatal("Incorrect trailer information !");
- if (fPosition <= 0) {
- Error("Next", "could not read time bin");
- return kFALSE;
- }
- fTime = Get10BitWord(fData, --fPosition);
- fCount--;
- } else {
- fTime--;
+ fBunchLength = 0;
}
- if (fPosition <= 0) {
- Error("Next", "could not read sample amplitude");
- return kFALSE;
- }
- fSignal = Get10BitWord(fData, --fPosition);
- fCount--;
- fBunchLength--;
+ if (fBunchLength == 0) ReadBunch();
+ else fTime--;
+
+ ReadAmplitude();
return kTRUE;
}
-
//_____________________________________________________________________________
-UShort_t AliAltroRawStream::Get10BitWord(UChar_t* buffer, Int_t position) const
+UShort_t AliAltroRawStream::GetNextWord()
{
-// return a word in a 10 bit array as an UShort_t
+ // Read the next 10 bit word in backward direction
+ // The input stream access is given by fData and fPosition
- Int_t iBit = position * 10;
+ fPosition--;
+
+ Int_t iBit = fPosition * 10;
Int_t iByte = iBit / 8;
Int_t shift = iBit % 8;
-// return ((buffer[iByte+1] * 256 + buffer[iByte]) >> shift) & 0x03FF;
// recalculate the byte numbers and the shift because
// the raw data is written as integers where the high bits are filled first
iByte++;
Int_t iByteLow = 4 * (iByte / 4) + 3 - (iByte % 4);
shift = 6 - shift;
- return ((buffer[iByteHigh] * 256 + buffer[iByteLow]) >> shift) & 0x03FF;
+ return ((fData[iByteHigh] * 256 + fData[iByteLow]) >> shift) & 0x03FF;
+}
+
+//_____________________________________________________________________________
+Bool_t AliAltroRawStream::ReadTrailer()
+{
+ //Read a trailer of 40 bits in the backward reading mode
+ //In case of no mapping is provided, read a dummy trailer
+ if (fNoAltroMapping) {
+ AliError("No ALTRO mapping information is loaded! Reading a dummy trailer!");
+ return ReadDummyTrailer();
+ }
+
+ //First reading filling words
+ UShort_t temp;
+ Int_t nFillWords = 0;
+ while ((temp = GetNextWord()) == 0x2AA) nFillWords++;
+ if (nFillWords == 0)
+ AliFatal("Incorrect trailer found ! Expected 0x2AA not found !");
+
+ //Then read the trailer
+ if (fPosition <= 4)
+ AliFatal(Form("Incorrect raw data size ! Expected at lest 4 words but found %d !",fPosition));
+
+ fCount = (temp << 4) & 0x3FF;
+ if ((temp >> 6) != 0xA)
+ AliFatal(Form("Incorrect trailer found ! Expecting 0xA but found %x !",temp >> 6));
+
+ temp = GetNextWord();
+ fHWAddress = (temp & 0x3) << 10;
+ if (((temp >> 2) & 0xF) != 0xA)
+ AliFatal(Form("Incorrect trailer found ! Expecting second 0xA but found %x !",(temp >> 2) & 0xF));
+ fCount |= ((temp & 0x3FF) >> 6);
+ if (fCount == 0) return kFALSE;
+
+ temp = GetNextWord();
+ fHWAddress |= temp;
+
+ fPosition -= (4 - (fCount % 4)) % 4; // skip fill words
+
+ ApplyAltroMapping();
+
+ return kTRUE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliAltroRawStream::ReadDummyTrailer()
+{
+ //Read a trailer of 40 bits in the backward reading mode
+ //In case of no mapping is provided, read a dummy trailer
+ UShort_t temp;
+ while ((temp = GetNextWord()) == 0x2AA);
+
+ fSector = temp;
+ fRow = GetNextWord();
+ fPad = GetNextWord();
+ fCount = GetNextWord();
+ if (fCount == 0) return kFALSE;
+ fHWAddress = -1;
+
+ return kTRUE;
+}
+
+//_____________________________________________________________________________
+void AliAltroRawStream::ReadBunch()
+{
+ // Read altro payload in
+ // backward direction
+ if (fPosition <= 0)
+ AliFatal("Could not read bunch length !");
+
+ fBunchLength = GetNextWord() - 2;
+ fTimeBunch = fBunchLength;
+ fCount--;
+
+ if (fPosition <= 0)
+ AliFatal("Could not read time bin !");
+
+ fTime = GetNextWord();
+ fCount--;
+
+ return;
+}
+
+//_____________________________________________________________________________
+void AliAltroRawStream::ReadAmplitude()
+{
+ // Read next time bin amplitude
+ if (fPosition <= 0)
+ AliFatal("Could not read sample amplitude !");
+
+ fSignal = GetNextWord();
+ fCount--;
+ fBunchLength--;
+
+ return;
+}
+
+//_____________________________________________________________________________
+Int_t AliAltroRawStream::GetPosition()
+{
+ // Sets the position in the
+ // input stream
+ Int_t position = (fRawReader->GetDataSize() * 8) / 10;
+ if (position <= 4)
+ AliFatal(Form("Incorrect raw data size ! Expected at lest 4 words but found %d !",position));
+
+ return position;
}
class AliRawReader;
-
class AliAltroRawStream: public TObject {
public :
AliAltroRawStream(AliRawReader* rawReader);
virtual ~AliAltroRawStream();
- virtual Bool_t Next();
+ virtual void Reset();
+ virtual Bool_t Next();
- Int_t GetSector() const { return fSector; } // Provide index of current sector
- Int_t GetPrevSector() const { return fPrevSector; } // Provide index of previous sector
- Int_t GetRow() const { return fRow; } // Provide index of current row
- Int_t GetPrevRow() const { return fPrevRow; } // Provide index of previous row
- Int_t GetPad() const { return fPad; } // Provide index of current pad
- Int_t GetPrevPad() const { return fPrevPad; } // Provide index of previous pad
- Int_t GetTimeBin() const { return fTime; } // Provide index of current time bin
- Int_t GetADC() const { return fSignal; } // Provide signal in ADC counts
- Int_t GetTimeLength() const { return fTimeBunch; } // Provide total length of current time bunch
+ inline Int_t GetSector() const { return fSector; } // Provide index of current sector
+ inline Int_t GetPrevSector() const { return fPrevSector; } // Provide index of previous sector
+ inline Bool_t IsNewSector() const {return fSector != fPrevSector;};
+ inline Int_t GetRow() const { return fRow; } // Provide index of current row
+ inline Int_t GetPrevRow() const { return fPrevRow; } // Provide index of previous row
+ inline Bool_t IsNewRow() const {return (fRow != fPrevRow) || IsNewSector();};
+ inline Int_t GetPad() const { return fPad; } // Provide index of current pad
+ inline Int_t GetPrevPad() const { return fPrevPad; } // Provide index of previous pad
+ inline Bool_t IsNewPad() const {return (fPad != fPrevPad) || IsNewRow();};
+ inline Int_t GetHWAddress() const { return fHWAddress; } // Provide current hardware address
+ inline Int_t GetPrevHWAddress() const { return fPrevHWAddress; } // Provide previous hardware address
+ inline Int_t GetTime() const { return fTime; } // Provide index of current time bin
+ inline Int_t GetSignal() const { return fSignal; } // Provide signal in ADC counts
+ inline Int_t GetTimeLength() const { return fTimeBunch; } // Provide total length of current time bunch
protected:
+ AliAltroRawStream(const AliAltroRawStream& stream);
+ AliAltroRawStream& operator = (const AliAltroRawStream& stream);
+
+ virtual void ApplyAltroMapping() { fSector = fRow = fPad = -1; }
+
Int_t fSector; // index of current sector
Int_t fPrevSector; // index of previous sector
Int_t fRow; // index of current row
Int_t fPrevRow; // index of previous row
Int_t fPad; // index of current pad
Int_t fPrevPad; // index of previous pad
+ Short_t fHWAddress; // current hardware address
+ Short_t fPrevHWAddress;// previous hardware address
Int_t fTime; // index of current time bin
Int_t fSignal; // signal in ADC counts
Int_t fTimeBunch; // total length of the current time bunch
AliRawReader* fRawReader; // object for reading the raw data
+ UChar_t* fData; // raw data
+
+ Bool_t fNoAltroMapping; // temporary flag in case of no altro mapping is provided
+
private :
- AliAltroRawStream(const AliAltroRawStream& stream);
- AliAltroRawStream& operator = (const AliAltroRawStream& stream);
- UShort_t Get10BitWord(UChar_t* buffer, Int_t position) const;
+ UShort_t GetNextWord();
+ Bool_t ReadTrailer();
+ Bool_t ReadDummyTrailer();
+ void ReadBunch();
+ void ReadAmplitude();
+ Int_t GetPosition();
- UChar_t* fData; // raw data
Int_t fPosition; // current (10 bit) position in fData
Int_t fCount; // counter of words to be read for current trailer
Int_t fBunchLength; // remaining number of signal bins in the current bunch
+++ /dev/null
-/**************************************************************************
- * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
- * *
- * Author: The ALICE Off-line Project. *
- * Contributors are mentioned in the code where appropriate. *
- * *
- * Permission to use, copy, modify and distribute this software and its *
- * documentation strictly for non-commercial purposes is hereby granted *
- * without fee, provided that the above copyright notice appears in all *
- * copies and that both the copyright notice and this permission notice *
- * appear in the supporting documentation. The authors make no claims *
- * about the suitability of this software for any purpose. It is *
- * provided "as is" without express or implied warranty. *
- **************************************************************************/
-
-/* $Id$ */
-
-
-// This class contains the implementation of the
-// compression and decompression algorithms
-// Compression is performed reading the Altro data block (called packet) backward.
-// Similarly decompression is also done backward so that the final file is restored
-// after the compression and decompression phase.
-
-#include <stdlib.h>
-#include <TObjArray.h>
-#include <Riostream.h>
-#include <TMath.h>
-#include <TSystem.h>
-#include "AliAltroBuffer.h"
-#include "AliTPCHNode.h"
-#include "AliTPCHTable.h"
-#include "AliTPCCompression.h"
-
-ClassImp(AliTPCCompression)
-
-//////////////////////////////////////////////////////////////////////////////////////////////////
-AliTPCCompression::AliTPCCompression(){
- //Defaul constructor
- fDimBuffer=sizeof(UInt_t)*8;
- fFreeBitsBuffer=fDimBuffer;
- fBitsToRead=32;
- fPos=0;
- fBuffer=0;
- fVerbose=0;
- fFillWords=0;
- fPointBuffer=0;
- return;
-}
-//////////////////////////////////////////////////////////////////////////////////////////////////
-AliTPCCompression::AliTPCCompression(const AliTPCCompression &source)
- :TObject(source){
- //Constructor
- this->fDimBuffer=source.fDimBuffer;
- this->fFreeBitsBuffer=source.fFreeBitsBuffer;
- this->fBitsToRead=source.fBitsToRead;
- this->fPos=source.fPos;
- this->fBuffer=source.fBuffer;
- this->fVerbose=source.fVerbose;
- this->fFillWords=source.fFillWords;
- this->fPointBuffer=source.fPointBuffer;
- return;
-}
-//////////////////////////////////////////////////////////////////////////////////////////////////
-AliTPCCompression& AliTPCCompression::operator=(const AliTPCCompression &source){
- //Redefinition of the assignment operator
- this->fDimBuffer=source.fDimBuffer;
- this->fFreeBitsBuffer=source.fFreeBitsBuffer;
- this->fBitsToRead=source.fBitsToRead;
- this->fPos=source.fPos;
- this->fBuffer=source.fBuffer;
- this->fVerbose=source.fVerbose;
- this->fFillWords=source.fFillWords;
- this->fPointBuffer=source.fPointBuffer;
- return *this;
-}
-//////////////////////////////////////////////////////////////////////////////////////////////////
-void AliTPCCompression::NextTable(Int_t Val,Int_t &NextTableType,Int_t &BunchLen,Int_t &Count)const{
- //Depending on the data type (5 types of data) a specific table is called
- /*
- Table index:
- 0==> Bunch length value
- 1==> Time Bin value
- 2==> 1-samples bunch
- 3==> Central samples
- 4==> Border samples
- */
- switch (NextTableType){
- case 0:{
- BunchLen=Val-2;
- NextTableType=1;
- break;
- }//end case 0
- case 1:{
- if (BunchLen==1)NextTableType=2;
- else{
- NextTableType=4;
- Count=1;
- }
- break;
- }//end case 1
- case 2:{
- NextTableType=0;
- break;
- }//end case 2
- case 3:{
- Count++;
- if (Count==(BunchLen-1)){
- NextTableType=4;
- }
- break;
- }//end case 3
- case 4:{
- if (Count==1){
- if (BunchLen>2)
- NextTableType=3;
- else
- Count++;
- }
- else
- NextTableType=0;
- break;
- }//end case 4
- }//end switch
- return;
-}
-
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////
-
-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
- AliAltroBuffer buff(fSource,0);
- UInt_t countWords=0;
- UInt_t countTrailer=0;
- Int_t numWords,padNum,rowNum,secNum=0;
- Int_t value=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)){
- if(end){
- endFill=buff.GetFillWordsNum();
- end=0;
- }//endif
- countTrailer++;
- if (numWords%4){
- fFillWords+=4-numWords%4;
- for(Int_t j=0;j<(4-numWords%4);j++){
- value=buff.GetNextBackWord();
- }//end for
- }//end if
-
- Int_t packet[1024];
- Int_t timePos[345];
- Int_t tp=0;
- for(Int_t i=0;i<345;i++)timePos[i]=0;
- for(Int_t i=0;i<1024;i++)packet[i]=0;
-
- Int_t nextTableType=0;
- Int_t bunchLen=0;
- Int_t count=0;
- for(Int_t i=0;i<numWords;i++){
- value=buff.GetNextBackWord();
- packet[i]=value;
- if(nextTableType==1){
- timePos[tp]=i;
- tp++;
- }
- NextTable(value,nextTableType,bunchLen,count);
- }//end for
- //computing the Time gap between two bunches
- Int_t temp=0;
- tp--;
- Int_t previousTime=packet[timePos[tp]];
- for(Int_t i=tp-1;i>=0;i--){
- Int_t timPos=timePos[i];
- Int_t bunchLen=packet[timPos-1]-2;
- temp=packet[timPos];
- packet[timPos]=packet[timPos]-previousTime-bunchLen;
- previousTime=temp;
- }
- nextTableType=0;
- count=0;
- bunchLen=0;
- for(Int_t i=0;i<numWords;i++){
- value=packet[i];
- table[nextTableType]->SetFrequency(value);
- stat[nextTableType]++;
- NextTable(value,nextTableType,bunchLen,count);
- countWords++;
- }//end for
- }//end while
- cout<<"Number of words: "<<countWords<<endl;
- cout<<"Number of trailers: "<<countTrailer<<endl;
- cout<<"Number of fill words "<<fFillWords+endFill<<endl;
- cout<<"Total number of words: "<<countWords+countTrailer*4+fFillWords<<endl;
- //STATISTICS
- fStat.open("Statistics");
- fStat<<"Number of words:..........................................."<<countWords<<endl;
- fStat<<"Number of trailers (4 10 bits words in each one)..........."<<countTrailer<<endl;
- fStat<<"Number of fill words:......................................"<<fFillWords+endFill<<endl;
- fStat<<"Total number of words:....................................."<<countWords+countTrailer*4+fFillWords+endFill<<endl;
- fStat<<"-----------------------------------------"<<endl;
- fStat<<"Number of Bunches............."<<stat[0]<<endl;
- fStat<<"Number of Time bin............"<<stat[1]<<endl;
- fStat<<"Number of One Samples Bunch..."<<stat[2]<<endl;
- fStat<<"Number of Central Samples....."<<stat[3]<<endl;
- fStat<<"Number of Border Samples......"<<stat[4]<<endl;
- fStat<<"-----------------------------------------"<<endl;
- 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................"<<(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......................"<<(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....................."<<(UInt_t)TMath::Ceil(stat[0]*10/8)<<" bytes "<<percentage<<"%"<<endl; //
- percentage=(Double_t)(stat[1]*125)/fileDimension;
- 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.........."<<(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..............."<<(UInt_t)TMath::Ceil(stat[2]*10/8)<<" bytes "<<percentage<<"%"<<endl; //
- percentage=(Double_t)(stat[3]*125)/fileDimension;
- fStat<<" Central Samples..........."<<(UInt_t)TMath::Ceil(stat[3]*10/8)<<" bytes "<<percentage<<"%"<<endl; //
- percentage=(Double_t)(stat[4]*125)/fileDimension;
- fStat<<" Border Samples............"<<(UInt_t)TMath::Ceil(stat[4]*10/8)<<" bytes "<<percentage<<"%"<<endl; //
- fStat.close();
- return 0;
-}
-////////////////////////////////////////////////////////////////////////////////////////
-Int_t AliTPCCompression::StoreTables(AliTPCHTable* table[],const Int_t NumTable){
- //This method stores the tables in a sequence of binary file
- char filename[15];
- ofstream fTable;
- for(Int_t k=0;k<NumTable;k++){
- sprintf(filename,"Table%d.dat",k);
-#ifndef __DECCXX
- fTable.open(filename,ios::binary);
-#else
- fTable.open(filename);
-#endif
- Int_t dim=table[k]->Size();
- //Table dimension is written into a file
- fTable.write((char*)(&dim),sizeof(Int_t));
- //One table is written into a file
- for(Int_t i=0;i<dim;i++){
- UChar_t codeLen=table[k]->CodeLen()[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(UInt_t));
- fTable.write((char*)(&code),sizeof(Double_t));
- } //end for
- fTable.close();
- }//end for
- return 0;
-}
-////////////////////////////////////////////////////////////////////////////////////////
-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);
-
- freq=1;
- Double_t freqArray[1024];
- for(Int_t i=0;i<1024;i++){
- 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));
- else
- 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;
- if (fVerbose)
- 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);
- else
- table->SetValFrequency(x,0);
- else //Time table
- table->SetValFrequency(x,a*freqArray[x]);
- }
- table->BuildHTable();
- ofstream fTable;
- char filename[15];
- sprintf(filename,"Table%d.dat",Type);
-#ifndef __DECCXX
- fTable.open(filename,ios::binary);
-#else
- fTable.open(filename);
-#endif
- 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));
- } //end for
- fTable.close();
- delete table;
- return 0;
-}
-////////////////////////////////////////////////////////////////////////////////////////
-Int_t AliTPCCompression::CreateTables(const char* fSource,Int_t NumTables){
- //Tables manager
- /*
- Table index:
- 0==> Bunch length values
- 1==> Time Bin values
- 2==> 1-samples bunch
- 3==> Central samples
- 4==> Border samples
- */
- Int_t n=10;// 10 bits per symbol
- AliTPCHTable ** table = new AliTPCHTable*[NumTables];
- //The table is inizialized with the rigth number of rows
- for(Int_t i=0;i<NumTables;i++){
- table[i]=new AliTPCHTable((Int_t)(TMath::Power(2,n)));
- table[i]->SetVerbose(fVerbose);
- }
- //The frequencies are calculated and the tables are filled
- if (fVerbose)
- cout<<"Filling tables...\n";
- //The get the frequencies
- FillTables(fSource,table,NumTables);
-
- //This part will be used in the table optimization phase
-
- for(Int_t i=0;i<NumTables;i++){
- table[i]->CompleteTable(i);
- }
-
- if(fVerbose){
- cout<<"Entropy of Bunch length table........."<<table[0]->GetEntropy()<<endl;
- cout<<"Entropy of Time bin table............."<<table[1]->GetEntropy()<<endl;
- cout<<"Entropy of one Sample bunch table....."<<table[2]->GetEntropy()<<endl;
- cout<<"Entropy of Central Sample table......."<<table[3]->GetEntropy()<<endl;
- cout<<"Entropy Border Samples table.........."<<table[4]->GetEntropy()<<endl;
- }
- fStat.open("Statistics",ios::app);
- fStat<<endl;
- fStat<<"----------------- ENTROPY for castomized tables --------------------------"<<endl;
- fStat<<"Entropy of Bunch length table......."<<table[0]->GetEntropy()<<endl;
- fStat<<"Entropy of Time bin table..........."<<table[1]->GetEntropy()<<endl;
- fStat<<"Entropy of one Sample bunch table..."<<table[2]->GetEntropy()<<endl;
- fStat<<"Entropy of Central Sample table....."<<table[3]->GetEntropy()<<endl;
- fStat<<"Entropy Border Samples table........"<<table[4]->GetEntropy()<<endl;
- fStat.close();
-
- if (fVerbose)
- cout<<"Tables filled \n";
-
- //Frequencies normalization
- table[0]->NormalizeFrequencies();
- table[1]->NormalizeFrequencies();
- table[2]->NormalizeFrequencies();
- table[3]->NormalizeFrequencies();
- table[4]->NormalizeFrequencies();
-
- //Tables are saved in a sequence of text file and using the macro Histo.C is it possible to get
- //a series of histograms rappresenting the frequency distribution
- table[0]->StoreFrequencies("BunchLenFreq.txt");
- table[1]->StoreFrequencies("TimeFreq.txt");
- table[2]->StoreFrequencies("Sample1Freq.txt");
- table[3]->StoreFrequencies("SCentralFreq.txt");
- table[4]->StoreFrequencies("SBorderFreq.txt");
- if (fVerbose)
- cout<<"Creating Tables..\n";
- //One Huffman tree is created for each table starting from the frequencies of the symbols
- for(Int_t i=0;i<NumTables;i++){
- table[i]->BuildHTable();
- if (fVerbose==2){
- cout<<"Number of elements inside the table:"<<table[i]->GetWordsNumber();
- switch(i){
- case 0:{
- cout<<" (Bunch Length)"<<endl;
- break;
- }
- case 1:{
- cout<<" (Time Bin)"<<endl;
- break;
- }
- case 2:{
- cout<<" (1 Samples Bunch)"<<endl;
- break;
- }
- case 3:{
- cout<<" (Central Samples)"<<endl;
- break;
- }
- case 4:{
- cout<<" (Border Samples)"<<endl;
- break;
- }
- }//end switch
- table[i]->PrintTable();
- }
- }
- //The tables are saved ad binary files
- StoreTables(table,NumTables);
- //The tables stored in memory are deleted;
- for(Int_t i=0;i<NumTables;i++)delete table[i];
- delete [] table;
- return 0;
-}
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-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";
- // UInt_t code;
- Double_t code;
- UChar_t codeLen;
- ifstream fTable;
- 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
- sprintf(filename,"Table%d.dat",k);
-#ifndef __DECCXX
- fTable.open(filename,ios::binary);
-#else
- fTable.open(filename);
-#endif
- 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;
- table[k]=new AliTPCHTable(dim);
- 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(UInt_t));
- fTable.read((char*)(&code),sizeof(Double_t));
- table[k]->SetCode(Mirror((UInt_t)code,codeLen),i);
- }//end for
- fTable.close();
- }//end for
- if (fVerbose)
- cout<<"Trees generated \n";
- //At this point the trees are been built
- return 0;
-}
-
-Int_t AliTPCCompression::CreateTablesFromTxtFiles(Int_t NumTable){
- //This method creates a set of binary tables, needed by the Huffman
- //algorith, starting from a set of frequencies tables stored in form of
- //txt files
- if (fVerbose)
- cout<<"Retrieving frequencies from txt files \n";
- ifstream fTable;
- char filename[15];
- //Tables are read from the files (Each codeword has been "Mirrored")
- AliTPCHTable **table = new AliTPCHTable*[NumTable];
- for(Int_t k=0;k<NumTable;k++){
- sprintf(filename,"Table%d.txt",k);
- cout<<filename<<endl;
- fTable.open(filename);
- 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);
- while(!fTable.eof()){
- fTable>>freq;
- if (fTable.good()){
- if (freq<0){
- cout<<"Frequency cannot be negative !!!\n";
- exit(1);
- }
- table[k]->SetValFrequency(symbol,freq);
- }
- symbol++;
- }//end while
- fTable.clear();
- fTable.close();
- }//end for
- fStat.open("Statistics",ios::app);
- fStat<<endl;
- fStat<<"----------------- ENTROPY for external txt tables --------------------------"<<endl;
- fStat<<"Entropy of Bunch length table......."<<table[0]->GetEntropy()<<endl;
- fStat<<"Entropy of Time bin table..........."<<table[1]->GetEntropy()<<endl;
- fStat<<"Entropy of one Sample bunch table..."<<table[2]->GetEntropy()<<endl;
- fStat<<"Entropy of Central Sample table....."<<table[3]->GetEntropy()<<endl;
- fStat<<"Entropy Border Samples table........"<<table[4]->GetEntropy()<<endl;
- fStat.close();
- for(Int_t k=0;k<NumTable;k++){
- table[k]->BuildHTable();
- }//end for
- //The tables are saved ad binary files
- StoreTables(table,NumTable);
- //The tables stored in memory are deleted;
- for(Int_t i=0;i<NumTable;i++)delete table[i];
- delete [] table;
- return 0;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////
-/* COMPRESSION */
-////////////////////////////////////////////////////////////////////////////////////////
-
-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(UInt_t));
- fFreeBitsBuffer=fDimBuffer;
- fBuffer=0;
- }
- }//end if
- else{ //val has to be splitted in two buffers
- fBuffer=fBuffer<<fFreeBitsBuffer;
- UInt_t temp;
- temp=val;
- temp=temp>>(len-fFreeBitsBuffer);
- fBuffer=fBuffer|temp;
- f.write((char*)(&fBuffer),sizeof(UInt_t));
- fFreeBitsBuffer=fDimBuffer-(len-fFreeBitsBuffer);
- val=val<<fFreeBitsBuffer;
- val=val>>fFreeBitsBuffer;
- fBuffer=val;
- }//end else
- return;
-}
-//////////////////////////////////////////////////////////////////////////////////////////////////
-void AliTPCCompression::Flush(){
- //The last buffer cannot be completely full so to save it
- //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(UInt_t));
- }//end if
- return;
-}
-//////////////////////////////////////////////////////////////////////////////////////////////////
-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
- 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;
- specular=specular<<1;
- specular=specular|bit;
- mask=mask<<1;
- }
- return specular;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-Int_t AliTPCCompression::CompressDataOptTables(Int_t NumTable,const char* fSource,const char* fDest){
- //This method compress an Altro format file using a general set of tables stored as binary files to be provided
- if (fVerbose){
- cout<<" BackWord COMPRESSION "<<endl;
- cout<<"compression of the file "<<fSource<<" Output File: "<<fDest<<endl;
- }
- //Tables are read from the files (Each codeword has been "Mirrored")
- AliTPCHTable **table = new AliTPCHTable*[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
- f.open(fDest,ios::out);
-#endif
- // Source file is open
- AliAltroBuffer buff(fSource,0);
- //coded words are written into a file
- Int_t numWords,padNum,rowNum,secNum=0;
- UInt_t storedWords=0;
- Int_t value=0;
- UInt_t numPackets=0;
- Double_t stat[5]={0.,0.,0.,0.,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;
- Int_t end=1;
- while(buff.ReadTrailerBackward(numWords,padNum,rowNum,secNum)){
- if(end){
- fillWords=buff.GetFillWordsNum();
- end=0;
- }//endif
-
- numPackets++;
- if (numWords%4){
- fillWords+=4-numWords%4;
- for(Int_t j=0;j<(4-numWords%4);j++){
- value=buff.GetNextBackWord();
- }//end for
- }//end if
-
- Int_t packet[1024];
- Int_t timePos[345];
- Int_t tp=0;
- for(Int_t i=0;i<345;i++)timePos[i]=0;
- for(Int_t i=0;i<1024;i++)packet[i]=0;
-
- Int_t nextTableType=0;
- Int_t bunchLen=0;
- Int_t count=0;
- for(Int_t i=0;i<numWords;i++){
- value=buff.GetNextBackWord();
- packet[i]=value;
- if(nextTableType==1){
- timePos[tp]=i;
- tp++;
- }
- NextTable(value,nextTableType,bunchLen,count);
- }//end for
- //computing the Time gap between two bunches
- Int_t temp=0;
- tp--;
- Int_t previousTime=packet[timePos[tp]];
- for(Int_t i=tp-1;i>=0;i--){
- Int_t timPos=timePos[i];
- Int_t bunchLen=packet[timPos-1]-2;
- temp=packet[timPos];
- packet[timPos]=packet[timPos]-previousTime-bunchLen;
- previousTime=temp;
- }//end for
-
- nextTableType=0;
- count=0;
- bunchLen=0;
- Int_t timeBin=0;
- for(Int_t i=0;i<numWords;i++){
- value=packet[i];
- if(nextTableType==1)timeBin=value;
- if(nextTableType>1){
- //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((UInt_t)val,len);
- storedWords++;
- }//end if
- NextTable(value,nextTableType,bunchLen,count);
- if(nextTableType==0){
- // 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((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((UInt_t)val,len);
- stat[nextTableType]+=len;
- numElem[nextTableType]++;
- storedWords+=2;
- }
- }//end for
- //Trailer
- StoreValue(numWords,10);
- StoreValue(padNum,10);
- StoreValue(rowNum,10);
- StoreValue(secNum,9);
- StoreValue(1,1);
- storedWords+=4;
- trailerNumbers++;
- }//end while
- StoreValue(numPackets,32);
- if(fVerbose)
- cout<<"Number of strored packets: "<<numPackets<<endl;
- StoreValue(1,1);
- //The last buffen cannot be completely full
- Flush();
- if(fVerbose)
- cout<<"Number of stored words: "<<storedWords<<endl;
- f.close();
- //Tables are deleted
- for(Int_t i=0;i<NumTable;i++){
- delete table[i];
- }//end for
- delete [] table;
- 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........."<<(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<<(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........."<<(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......"<<(UInt_t)TMath::Ceil(stat[0]/8)<<" Comppression.."<<(stat[0]/numElem[0])*10<<"%"<<endl;
- if (numElem[1])
- 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......."<<(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............"<<(UInt_t)TMath::Ceil(stat[2]/8)<<" Comppression.."<<(stat[2]/numElem[2])*10<<"%"<<endl;
- if (numElem[3])
- 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...."<<(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])
- fStat<<"Bunch length ......"<<stat[0]/numElem[0]<<endl;
- if (numElem[1])
- fStat<<"Time gap .........."<<stat[1]/numElem[1]<<endl;
- if (numElem[2])
- fStat<<"One Samples........"<<stat[2]/numElem[2]<<endl;
- if (numElem[3])
- fStat<<"Central Samples ..."<<stat[3]/numElem[3]<<endl;
- if (numElem[4])
- fStat<<"Border Samples....."<<stat[4]/numElem[4]<<endl;
- fStat.close();
- return 0;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////////////////////////////////
-/* DECOMPRESSION */
-////////////////////////////////////////////////////////////////////////////////////////
-
-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;
- // UInt_t code;
- Double_t code;
- UChar_t codeLen;
- ifstream fTable;
- 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++){
- RootNode[k]=new AliTPCHNode(); //RootNode is the root of the tree
- Int_t dim=0;//this variable contains the table dimension
- sprintf(filename,"Table%d.dat",k);
-#ifndef __DECCXX
- fTable.open(filename,ios::binary);
-#else
- fTable.open(filename);
-#endif
- 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(UInt_t));
- fTable.read((char*)(&code),sizeof(Double_t));
- node=RootNode[k];
- for(Int_t j=1;j<=codeLen;j++){
- UInt_t bit,val=0;
- // val=(UInt_t)TMath::Power(2,codeLen-j);
- val=(UInt_t)(1<<(codeLen-j));
- bit=(UInt_t)code&val;
- AliTPCHNode *temp=node;
- if(bit){
- node=node->GetRight();
- if(!node){
- node=new AliTPCHNode();
- temp->SetRight(node);
- }//end if
- }//end if
- else{
- node=node->GetLeft();
- if(!node){
- node=new AliTPCHNode();
- temp->SetLeft(node);
- }//end if
- }//end else
- }//end for
- if(codeLen){
- node->SetSymbol(i);
- node->SetFrequency(codeLen);
- }//end if
- }//end for
- fTable.close();
- }//end for
- if (fVerbose)
- cout<<"Trees generated \n";
- //At this point the trees are been built
- return 0;
-}
-
-Int_t AliTPCCompression::CreateLUTsFromTrees(AliTPCHNode *RootNode[],Int_t NumTables,UInt_t *LUTDimension[],AliTPCHNode **LUTNode[]){
- //For each Huffman tree this method builds the associate look-up-table for fast
- //decoding of compressed data.
- //Should be called after CreateTreesFromFile.
- if(fVerbose)
- cout<<"Creating the LUTs \n";
- AliTPCHNode *node=0;
-
- //loop over the tables
- for(Int_t k=0;k<NumTables;k++){
- UInt_t dim = 1<<fgkTableDimension;
- LUTDimension[k] = new UInt_t[dim];
- LUTNode[k] = new AliTPCHNode*[dim];
- //loop over the words of one LUT
- for(UInt_t i=0;i<dim;i++){
- UInt_t buffer = i;
- node=RootNode[k];
- LUTDimension[k][i] = GetDecodedLUTBuffer(&node,&buffer);
- LUTNode[k][i] = node;
- // cout<<"LUT "<<k<<" "<<i<<" "<<LUTDimension[k][i]<<" "<<LUTNode[k][i]<<" "<<LUTNode[k][i]->GetSymbol()<<endl;
- }
- }
- if (fVerbose)
- cout<<"LUTs generated \n";
- //At this point the LUTs are built
- return 0;
-}
-//////////////////////////////////////////////////////////////////////////////////////////////////
-void AliTPCCompression::DeleteHuffmanTree(AliTPCHNode* node){
- //This function deletes all the nodes of an Huffman tree
- //In an Huffman tree any internal node has always two children
- if (node){
- DeleteHuffmanTree(node->GetLeft());
- DeleteHuffmanTree(node->GetRight());
- // cout<<node->GetSymbol()<<" "<<(Int_t)node->GetFrequency()<<endl;
- delete node;
- }
-}
-//////////////////////////////////////////////////////////////////////////////////////////////////
-void AliTPCCompression::VisitHuffmanTree(AliTPCHNode* node){
- //This function realizes an in order visit of a binary tree
- if (node){
- cout<<node->GetSymbol()<<" "<<node->GetFrequency()<<endl;
- VisitHuffmanTree(node->GetLeft());
- VisitHuffmanTree(node->GetRight());
- }
-}
-//////////////////////////////////////////////////////////////////////////////////////////////////
-UInt_t AliTPCCompression::ReadWord(UInt_t NumberOfBit){
- //This method retrieves a word of a specific number of bits from the file through the internal buffer
- UInt_t result=0;
- UInt_t bit=0;
- for (UInt_t i=0;i<NumberOfBit;i++){
- if (fBitsToRead==0){
- fPos-=sizeof(UInt_t);
- f.seekg(fPos);
- f.read((char*)(&fBuffer),sizeof(UInt_t));
- fBitsToRead=32;
- }//end if
- UInt_t mask=(UInt_t)(1<<(32-fBitsToRead));
- bit=fBuffer&mask;
- bit=bit>>(32-fBitsToRead);
- fBitsToRead--;
- bit=bit<<i;
- result=result|bit;
- }//end for
- return result;
-}
-//////////////////////////////////////////////////////////////////////////////////////////////////
-UInt_t AliTPCCompression::ReadWordBuffer(UInt_t NumberOfBit){
- //This method retrieves a word of a specific number of bits from the file through the buffer
- UInt_t result=0;
-
- if(NumberOfBit<=fBitsToRead) {
- result = fBuffer&((1<<NumberOfBit)-1);
- fBuffer=fBuffer>>NumberOfBit;
- fBitsToRead-=NumberOfBit;
- }
- else {
- fPointBuffer--;
- UInt_t tempbuffer = *fPointBuffer;
- if((NumberOfBit-fBitsToRead) != 32)
- tempbuffer=tempbuffer&((1<<(NumberOfBit-fBitsToRead))-1);
- tempbuffer=tempbuffer<<fBitsToRead;
- result = fBuffer|tempbuffer;
- fBuffer=*fPointBuffer;
- fBitsToRead=(32+fBitsToRead)-NumberOfBit;
- fBuffer=fBuffer>>(32-fBitsToRead);
- }
-
- return result;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////
-inline void AliTPCCompression::AdjustWordBuffer(UInt_t NumberOfBit){
- //This method retrieves a word of a specific number of bits from the file through the buffer
- //The method is used together with LUTs for fast decoding
- if(NumberOfBit<=fBitsToRead) {
- fBuffer=fBuffer>>NumberOfBit;
- fBitsToRead-=NumberOfBit;
- }
- else {
- fPointBuffer--;
- fBuffer=*fPointBuffer;
- fBitsToRead=(32+fBitsToRead)-NumberOfBit;
- fBuffer=fBuffer>>(32-fBitsToRead);
- }
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////
-inline UInt_t AliTPCCompression::ReadWordBufferWithLUTs(){
- //This method retrieves a word of a specific number of bits from the file through the buffer
- //The method is used together with LUTs for fast decoding
- if(fgkTableDimension<=fBitsToRead)
- return fBuffer&((1<<fgkTableDimension)-1);
- else {
- UInt_t tempbuffer = *(fPointBuffer-1);
- tempbuffer=tempbuffer&((1<<(fgkTableDimension-fBitsToRead))-1);
- tempbuffer=tempbuffer<<fBitsToRead;
- return fBuffer|tempbuffer;
- }
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////
-inline UInt_t AliTPCCompression::ReadBitFromWordBuffer(){
- //This method retrieves a bit from the file through the buffer
- UInt_t result=0;
-
- if (fBitsToRead==0){
- fPointBuffer--;
- fBuffer=*fPointBuffer;
- fBitsToRead=32;
- }//end if
- result=fBuffer&0x1;
- fBitsToRead--;
- fBuffer=fBuffer>>1;
- return result;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////
-inline UInt_t AliTPCCompression::ReadBitFromLUTBuffer(UInt_t *buffer){
- //This method retrieves a word of a bit out of the LUT buffer
- UInt_t result=0;
-
- result=*buffer&0x1;
- *buffer=*buffer>>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){
- ReadBitFromWordBuffer();
- SecNumber=ReadWordBuffer(9);
- RowNumber=ReadWordBuffer(10);
- PadNumber=ReadWordBuffer(10);
- WordsNumber=ReadWordBuffer(10);
- }
- else{
- ReadWord(1);
- SecNumber=ReadWord(9);
- RowNumber=ReadWord(10);
- PadNumber=ReadWord(10);
- WordsNumber=ReadWord(10);
- }
- return;
-}
-//////////////////////////////////////////////////////////////////////////////////////////////////
-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=ReadBitFromWordBuffer();
- if(bit)
- node=node->GetRight();
- else
- node=node->GetLeft();
- if (!(node->GetLeft())){
- symbol=node->GetSymbol();
- decoded=1;
- }
- }//end while
- return symbol;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////
-inline UInt_t AliTPCCompression::GetDecodedWordBufferWithLUTs(UInt_t* LUTDimension,AliTPCHNode** LUTNode){
- //This method retrieves a decoded word.
- UInt_t symbol=0;
- UInt_t buffer=0;
- Bool_t decoded=0;
-
- buffer = ReadWordBufferWithLUTs();
- AliTPCHNode *node=LUTNode[buffer];
- if (!(node->GetLeft())){
- symbol=node->GetSymbol();
- decoded=1;
- }
- AdjustWordBuffer(LUTDimension[buffer]);
- while(!decoded){
- UInt_t bit=ReadBitFromWordBuffer();
- if(bit)
- node=node->GetRight();
- else
- node=node->GetLeft();
- if (!(node->GetLeft())){
- symbol=node->GetSymbol();
- decoded=1;
- }
- }//end while
- return symbol;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////
-inline UInt_t AliTPCCompression::GetDecodedLUTBuffer(AliTPCHNode** node,UInt_t *buffer){
- //This method retrieves a decoded word for the LUTs.
- Bool_t decoded=0;
- UInt_t counter=0;
-
- while(!decoded && counter<fgkTableDimension){
- UInt_t bit=ReadBitFromLUTBuffer(buffer);
- counter++;
- if(bit)
- *node=(*node)->GetRight();
- else
- *node=(*node)->GetLeft();
- if (!((*node)->GetLeft())){
- decoded=1;
- }
- }//end while
- return counter;
-}
-
-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
- node=node->GetLeft();
- if (!(node->GetLeft())){
- symbol=node->GetSymbol();
- decoded=1;
- }
- }//end while
-
- return symbol;
-}
-//////////////////////////////////////////////////////////////////////////////////////////////////
-
-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
- 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){
- 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(UInt_t);
- f.seekg(fPos);
- fBitsToRead=32;
- fBuffer=0;
- f.read((char*)(&fBuffer),sizeof(UInt_t));
- Int_t bit=0;
- UInt_t mask=0x1;
- while(!bit){
- bit=fBuffer&mask;
- mask=mask<<1;
- fBitsToRead--;
- }
- UInt_t packetNumber=ReadWord(sizeof(UInt_t)*8);
- if(fVerbose){
- cout<<"Number of Packect: "<<packetNumber<<endl;
- }
- AliAltroBuffer bufferFile(fDest,1);
- 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);
- k++;
- wordsRead+=4;
- Int_t previousTime=-1;
- Int_t time=0;
- Int_t nextTableType=0;
- Int_t bunchLen=0;
- Int_t count=0;
- for(Int_t i=0;i<numWords;i++){
- UInt_t symbol=GetDecodedWord(rootNode[nextTableType]);
- wordsRead++;
- //Time reconstruction
- if (nextTableType==1){
- if (previousTime!=-1){
- previousTime=symbol+previousTime+bunchLen;
- }
- else previousTime=symbol;
- time=previousTime;
- }
- if(nextTableType>1)
- bufferFile.FillBuffer(symbol);
- NextTable(symbol,nextTableType,bunchLen,count);
- if(nextTableType==0){
- bufferFile.FillBuffer(time);
- bufferFile.FillBuffer(bunchLen+2);
- bunchLen=0;
- }
- }//end for
- bufferFile.WriteTrailer(numWords,padNumber,rowNumber,secNumber);
- }//end while
- if(fVerbose){
- cout<<"Number of decoded words:"<<wordsRead<<endl;
- }
- f.close();
- //The trees are deleted
- for(Int_t j=0;j<NumTables;j++){
- DeleteHuffmanTree(rootNode[j]);
- }//end for
- delete [] rootNode;
- return 0;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////
-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=((UInt_t *)PointBuffer)+(UInt_t)(BufferSize/4)-1;
- fPointBuffer=(UInt_t *)(PointBuffer+BufferSize-4);
- fBitsToRead=32;
- fBuffer=0;
-
- fBuffer=*fPointBuffer;
- Int_t bit=0;
- while(!bit){
- bit=fBuffer&0x1;
- fBuffer=fBuffer>>1;
- fBitsToRead--;
- }//end while
- 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
- 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);
- out[dim]=numWords;
- dim++;
- out[dim]=padNumber;
- dim++;
- out[dim]=rowNumber;
- dim++;
- out[dim]=secNumber;
- dim++;
- //ftxt<<"S:"<<secNumber<<" R:"<<rowNumber<<" P:"<<padNumber<<" W:"<<numWords<<endl;
- // padDigits->SetPadID(padNumber,rowNumber,secNumber,DDL);
- k++;
- wordsRead+=4;
- Int_t previousTime=-1;
- Int_t time=0;
- Int_t nextTableType=0;
- Int_t bunchLen=0;
- Int_t count=0;
- Int_t timeDigit=0;
- for(Int_t i=0;i<numWords;i++){
- UInt_t symbol=GetDecodedWordBuffer(RootNode[nextTableType]);
- wordsRead++;
- //Time reconstruction
- if (nextTableType==1){
- if (previousTime!=-1){
- previousTime=symbol+previousTime+bunchLen;
- }
- else previousTime=symbol;
- time=previousTime;
- out[dim]=bunchLen+2;
- dim++;
- out[dim]=time;
- dim++;
- timeDigit=time-bunchLen;
- }
- if(nextTableType>1){
- //
- //ftxt<<symbol<<endl;
- out[dim]=symbol;
- dim++;
- timeDigit++;
- //padDigits->SetDigits(symbol,timeDigit);
- }
- NextTable(symbol,nextTableType,bunchLen,count);
- if(nextTableType==0){
- //
- //ftxt<<time<<endl;
- // ftxt<<(bunchLen+2)<<endl;
- bunchLen=0;
- }
- }//end for
- }//end while
- return 0;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////
-Int_t AliTPCCompression::DecompressWithLUTs(AliTPCHNode *RootNode[],UInt_t *LUTDimension[],AliTPCHNode **LUTNode[],Int_t /*NumTables*/,char* PointBuffer,UInt_t BufferSize,UShort_t out[],UInt_t &dim){
- //This method decompress a file using separate Huffman tables and already prepared LUTs for fast decoding
-
- // fPointBuffer=((UInt_t *)PointBuffer)+(UInt_t)(BufferSize/4)-1;
- fPointBuffer=(UInt_t *)(PointBuffer+BufferSize-4);
- fBitsToRead=32;
- fBuffer=0;
-
- fBuffer=*fPointBuffer;
- Int_t bit=0;
- while(!bit){
- bit=fBuffer&0x1;
- fBuffer=fBuffer>>1;
- fBitsToRead--;
- }//end while
- 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
- 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);
- out[dim]=numWords;
- dim++;
- out[dim]=padNumber;
- dim++;
- out[dim]=rowNumber;
- dim++;
- out[dim]=secNumber;
- dim++;
- //ftxt<<"S:"<<secNumber<<" R:"<<rowNumber<<" P:"<<padNumber<<" W:"<<numWords<<endl;
- // padDigits->SetPadID(padNumber,rowNumber,secNumber,DDL);
- k++;
- wordsRead+=4;
- Int_t previousTime=-1;
- Int_t time=0;
- Int_t nextTableType=0;
- Int_t bunchLen=0;
- Int_t count=0;
- Int_t timeDigit=0;
- for(Int_t i=0;i<numWords;i++){
- UInt_t symbol;
- if(i == (numWords-1))
- symbol = GetDecodedWordBuffer(RootNode[nextTableType]);
- else
- symbol=GetDecodedWordBufferWithLUTs(LUTDimension[nextTableType],LUTNode[nextTableType]);
- wordsRead++;
- //Time reconstruction
- if (nextTableType==1){
- if (previousTime!=-1){
- previousTime=symbol+previousTime+bunchLen;
- }
- else previousTime=symbol;
- time=previousTime;
- out[dim]=bunchLen+2;
- dim++;
- out[dim]=time;
- dim++;
- timeDigit=time-bunchLen;
- }
- if(nextTableType>1){
- //
- //ftxt<<symbol<<endl;
- out[dim]=symbol;
- dim++;
- timeDigit++;
- //padDigits->SetDigits(symbol,timeDigit);
- }
- NextTable(symbol,nextTableType,bunchLen,count);
- if(nextTableType==0){
- //
- //ftxt<<time<<endl;
- // ftxt<<(bunchLen+2)<<endl;
- bunchLen=0;
- }
- }//end for
- }//end while
- return 0;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////
-Int_t AliTPCCompression::DestroyTables(AliTPCHNode *RootNode[],Int_t NumTables){
- //The trees are deleted
- for(Int_t j=0;j<NumTables;j++){
- DeleteHuffmanTree(RootNode[j]);
- }//end for
- if(fVerbose)
- cout<<"Huffman trees destroyed"<<endl;
- return 0;
-}
-//////////////////////////////////////////////////////////////////////////////////////////////////
-
-void AliTPCCompression::ReadAltroFormat(char* fileOut,char* fileIn)const{
- //This method creates a text file containing the same information stored in
- //an Altro file. The information in the text file is organized pad by pad and
- //and for each pad it consists in a sequence of bunches (Bunch length +2,
- //Time bin of the last amplitude sample in the bunch, amplitude values)
- //It is used mainly for debugging
- ofstream ftxt(fileOut);
- 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)){
- ftxt<<"S:"<<secNum<<" R:"<<rowNum<<" P:"<<padNum<<" W:"<<numWords<<endl;
- if (numWords%4){
- for(Int_t j=0;j<(4-numWords%4);j++){
- value=buff.GetNextBackWord();
- }//end for
- }//end if
- for(Int_t i=0;i<numWords;i++){
- value=buff.GetNextBackWord();
- ftxt<<value<<endl;
- }//end for
- }//end while
- ftxt.close();
- return;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////
+++ /dev/null
-/* Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
- * See cxx source for full Copyright notice */
-
-//////////////////////////////////////////////////////
-// Class for Compression and Decompression //
-//////////////////////////////////////////////////////
-
-
-#ifndef AliTPCCOMPRESSION_H
-#define AliTPCCOMPRESSION_H
-
-#ifdef __CINT__
-class fstream;
-#else
-#include "Riostream.h"
-#endif
-
-class AliTPCHNode;
-class AliTPCHTable;
-
-class AliTPCCompression:public TObject{
- public:
- AliTPCCompression();
- virtual ~AliTPCCompression(){;}
- AliTPCCompression(const AliTPCCompression &source); // copy constructor
- AliTPCCompression& operator=(const AliTPCCompression &source); // ass. op.
- Int_t CompressDataOptTables(Int_t NumTable,const char* fSource,const char* fDest);
- //This method is used to compress an Altro file using a set of general table previously calculated and
- //stored as a sequence of txt file.
- Int_t DecompressDataOptTables(Int_t NumTables,const char* fname,const char* fDest="SourceDecompressed.dat");
- //This method is used to decompress a file compressed using the CompressDataOptTable method
- //It expects a set of table used for compressing the file in the same directory of the compressed file
- Int_t Decompress(AliTPCHNode *RootNode[],Int_t NumTables,char* PointBuffer,UInt_t BufferSize,UShort_t out[],UInt_t &dim);
- //This method is used to decompress data stored in a char* buffer
- Int_t DecompressWithLUTs(AliTPCHNode *RootNode[],UInt_t *LUTDimension[],AliTPCHNode **LUTNode[],Int_t /*NumTables*/,char* PointBuffer,UInt_t BufferSize,UShort_t out[],UInt_t &dim);
- Int_t FillTables(const char* fSource,AliTPCHTable* table[],Int_t NumTables);
- //This method is used to compute the frequencies of the symbols in the source file
- Int_t CreateTables(const char* fSource,Int_t NumTables);
- //This method is used to create and store the tables
- Int_t CreateTableFormula(Double_t beta,UInt_t M,Int_t dim,Int_t Type);
- //This method is used to create and store the Bunch length or Time Gap Table using a formula
- void SetVerbose(Int_t val){fVerbose=val;}
- //This method is used to set up the verbose level
- // 0 ==> No output messages are displayed
- // 1 ==> Some output messages are displayed during the running
- // 2 ==> A complete output is displayed
- void ReadAltroFormat(char* fileOut,char* fileIn)const;
- //This method is used to read an Altro file and generate a text file containing the same information
- //It's is useful for debugging
- Int_t CreateTablesFromTxtFiles(Int_t NumTable);
- //This method creates a set of binary tables starting from a set of txt tables
- Int_t DestroyTables(AliTPCHNode *RootNode[],Int_t NumTables);
- //This methods is use to deallocate the memory used by Huffman trees
- Int_t CreateTreesFromFile(AliTPCHNode *RootNode[],Int_t NumTables);
- //This method is like the previous one but the tables are stored in binary files
- //It is used in the decompression phase (DecompressDataOptTables())
- Int_t CreateLUTsFromTrees(AliTPCHNode *RootNode[],Int_t NumTables,UInt_t *LUTDimension[],AliTPCHNode **LUTNode[]);
- private:
- Int_t StoreTables(AliTPCHTable* table[],const Int_t NumTable);
- //This method is used to store an array of tables in a sequence of binary files
- //Each file contains the Size of the table (number of words) and for each word contains the correspondent
- //codeword and codelength
- Int_t RetrieveTables(AliTPCHTable* table[],Int_t NumTable);
- //This method is used to retrieve an array of tables from a sequence of binary files created using
- //the previous method
- void DeleteHuffmanTree(AliTPCHNode* node);
- //This method is used to delete an Huffman tree
- void VisitHuffmanTree(AliTPCHNode* node);
- //This method realizes an in order visit of a binary tree
- void NextTable(Int_t Val,Int_t &NextTableType,Int_t &BunchLen,Int_t &Count)const;
- //This method is used to deduce which is the next table that as to be used to interpret the next value
- //reading the Altro format
- void StoreValue(UInt_t val,UChar_t len);
- //This method is used to store a value in the compressed file
- UInt_t Mirror(UInt_t val,UChar_t len)const;
- //This method is used to get the specular value of a given value
- //for instance the specular value of 12345 is 54321
- void Flush();
- //This method is used to complete and store the buffer in the output file when it isn't completely full
- UInt_t ReadWord(UInt_t NumberOfBit);
- //this method is used to read a specified number of bits from the compressed file
- UInt_t ReadWordBuffer(UInt_t NumberOfBit);
- //this method is used to read a specified number of bits from the compressed memory buffer
- inline void AdjustWordBuffer(UInt_t NumberOfBit);
- inline UInt_t ReadWordBufferWithLUTs();
- inline UInt_t ReadBitFromWordBuffer();
- inline UInt_t ReadBitFromLUTBuffer(UInt_t *buffer);
- void ReadTrailer(Int_t &WordsNumber,Int_t &PadNumber,Int_t &RowNumber,Int_t &SecNumberr,Bool_t Memory);
- //This method is used to read the trailer
- inline UInt_t GetDecodedWordBuffer(AliTPCHNode* root);
- //This method is used to get a decoded word from the compressed file
- inline UInt_t GetDecodedWord(AliTPCHNode* root);
- //This method is used to get a decoded word from the compressed file
- inline UInt_t GetDecodedWordBufferWithLUTs(UInt_t* LUTDimension,AliTPCHNode** LUTNode);
- inline UInt_t GetDecodedLUTBuffer(AliTPCHNode** node,UInt_t *buffer);
-
- fstream f; // f is the logical name for the compressed and uncompressed file
- ofstream fStat; // Logical name for the Statistics file
- UInt_t fBuffer; // buffer
- Int_t fDimBuffer; // buffer dimension (32 bit)
- Int_t fFreeBitsBuffer; // number of free bits inside the buffer
- UInt_t fBitsToRead; // number of bits to be read
- UInt_t fPos; // current file position
- Int_t fVerbose; // verbose level (0 silent, !=0 output messages)
- UInt_t fFillWords; // Number of hexadecimally words (2AA pattern) inside a pad data block
- UInt_t* fPointBuffer; //pointer to the compressed raw data
- static const UInt_t fgkTableDimension = 7; // size of LUTs for fast decompression
-
- ClassDef(AliTPCCompression,1)
-};
-#endif
+++ /dev/null
-/**************************************************************************
- * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
- * *
- * Author: The ALICE Off-line Project. *
- * Contributors are mentioned in the code where appropriate. *
- * *
- * Permission to use, copy, modify and distribute this software and its *
- * documentation strictly for non-commercial purposes is hereby granted *
- * without fee, provided that the above copyright notice appears in all *
- * copies and that both the copyright notice and this permission notice *
- * appear in the supporting documentation. The authors make no claims *
- * about the suitability of this software for any purpose. It is *
- * provided "as is" without express or implied warranty. *
- **************************************************************************/
-/* $Id:*/
-////////////////////////////////////////////////
-// Huffman classes for set:TPC //
-////////////////////////////////////////////////
-//This file contains two classes and it implements
-//the Huffman algorithm for creating tables
-//used in the compression phase.
-//The class AliTPCHNode represents a node of the Huffman tree, while
-//the class AliTPCHTable represents a compression table
-
-#include "AliTPCHNode.h"
-
-ClassImp(AliTPCHNode)
-
-AliTPCHNode::AliTPCHNode(){
- //Constructor
- fLeft=0;
- fRight=0;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-AliTPCHNode::AliTPCHNode(Int_t sym, Double_t freq){
- //Standard constructor
- fSymbol=sym;
- fFrequency=freq;
- fLeft=0;
- fRight=0;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-AliTPCHNode::AliTPCHNode(const AliTPCHNode &source)
- :TObject(source){
- //Copy Constructor
- if(&source == this) return;
- this->fSymbol = source.fSymbol;
- this->fFrequency = source.fFrequency;
- this->fLeft = source.fLeft;
- this->fRight = source.fRight;
- return;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-AliTPCHNode& AliTPCHNode::operator=(const AliTPCHNode &source){
- //Assignment operator
- if(&source == this) return *this;
- this->fSymbol = source.fSymbol;
- this->fFrequency = source.fFrequency;
- this->fLeft = source.fLeft;
- this->fRight = source.fRight;
- return *this;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-Int_t AliTPCHNode::Compare(const TObject *obj)const{
- //Function called by Sort method of TObjArray
- AliTPCHNode *node=(AliTPCHNode *)obj;
- Double_t f=fFrequency;
- Double_t fo=node->fFrequency;
- if (f<fo) return 1;
- else if (f>fo) return -1;
- else return 0;
-}
-
-//////////////////////////////////////////////////////////////////////////////
+++ /dev/null
-/* Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
- * See cxx source for full Copyright notice */
-
-///////////////////////////////////////////////////
-// Huffman Table associated classes for set:TPC //
-///////////////////////////////////////////////////
-
-
-#ifndef AliTPCHNODE_H
-#define AliTPCHNODE_H
-
-#include <TObject.h>
-
-class AliTPCHNode: public TObject {
- public:
- AliTPCHNode(); //default constructor
- AliTPCHNode(Int_t symbol, Double_t freq);
- virtual ~AliTPCHNode() {}
- AliTPCHNode(const AliTPCHNode &source); // copy constructor
- AliTPCHNode& operator=(const AliTPCHNode &source); // ass. op.
-
- Bool_t IsSortable() const{return kTRUE;}
- Int_t Compare(const TObject *obj) const;
- void SetLeft(AliTPCHNode* point){fLeft=point;}
- void SetRight(AliTPCHNode* point){fRight=point;}
- inline AliTPCHNode* GetRight()const{return fRight;}
- inline AliTPCHNode* GetLeft()const{return fLeft;}
- void SetSymbol(Int_t sym){fSymbol=sym;}
- void SetFrequency(Double_t freq){fFrequency=freq;}
- Double_t GetFrequency()const{return fFrequency;}
- inline Int_t GetSymbol()const{return fSymbol;}
-
- private:
- Int_t fSymbol; // Symbols
- Double_t fFrequency; // Frequency of the Symbol
- AliTPCHNode *fLeft; // Pointer to the left son
- AliTPCHNode *fRight; // Pointer to the right son
- ClassDef(AliTPCHNode,1)
-};
-
-#endif
+++ /dev/null
-/**************************************************************************
- * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
- * *
- * Author: The ALICE Off-line Project. *
- * Contributors are mentioned in the code where appropriate. *
- * *
- * Permission to use, copy, modify and distribute this software and its *
- * documentation strictly for non-commercial purposes is hereby granted *
- * without fee, provided that the above copyright notice appears in all *
- * copies and that both the copyright notice and this permission notice *
- * appear in the supporting documentation. The authors make no claims *
- * about the suitability of this software for any purpose. It is *
- * provided "as is" without express or implied warranty. *
- **************************************************************************/
-/* $Id:*/
-////////////////////////////////////////////////
-// Huffman classes for set:TPC //
-////////////////////////////////////////////////
-//This file contains two classes and it implements
-//the Huffman algorithm for creating tables
-//used in the compression phase.
-//The class AliTPCHNode represents a node of the Huffman tree, while
-//the class AliTPCHTable represents a compression table
-
-#include <TObjArray.h>
-#include <TMath.h>
-#include "AliAltroBuffer.h"
-#include "AliTPCHNode.h"
-#include "AliTPCHTable.h"
-
-ClassImp(AliTPCHTable)
-
-AliTPCHTable::AliTPCHTable(){
- //Constructor
- fCodeLen=0;
- fCode=0;
- fHNodes=0;
- fNnodes=0;
- fNum=0;
- fVerbose=0;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-AliTPCHTable::AliTPCHTable(Int_t size){
- //Initialization
- fSize=size;
- fCodeLen = new UChar_t[fSize];
- fCode = new Double_t[fSize];
- fHNodes = new TObjArray;
- fNnodes=0;
- fNum=0;
- fVerbose=0;
- fSym= new Short_t[fSize];
- for (Short_t i=0;i<fSize;i++) {
- fSym[i]=i;
- }//end for
- ClearTable();
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-AliTPCHTable::AliTPCHTable(const AliTPCHTable &source)
- :TObject(source){
- //Copy Constructor
- if(&source == this) return;
- this->fSize = source.fSize;
- this->fCodeLen = source.fCodeLen;
- this->fCode = source.fCode;
- this->fSym = source.fSym;
- this->fHNodes = source.fHNodes;
- this->fNnodes = source.fNnodes;
- this->fNum=source.fNum;
- this->fVerbose=source.fVerbose;
- return;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-AliTPCHTable& AliTPCHTable::operator=(const AliTPCHTable &source) {
- //Assignment operator
- if(&source == this) return *this;
- this->fSize = source.fSize;
- this->fCodeLen = source.fCodeLen;
- this->fCode = source.fCode;
- this->fSym = source.fSym;
- this->fHNodes = source.fHNodes;
- this->fNnodes = source.fNnodes;
- this->fNum=source.fNum;
- this->fVerbose=source.fVerbose;
- return *this;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-AliTPCHTable::~AliTPCHTable(){
- //HTable destructor
- if(fVerbose)
- cout<<"HTable destructor !\n";
- if (fCodeLen) delete[] fCodeLen;
- if (fCode) delete [] fCode;
- if (fHNodes) {
- fHNodes->Delete(); //Clear out the collection and deletes the removed objects
- delete fHNodes;
- }//end if
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-void AliTPCHTable::SetCodeLen(UChar_t len,Int_t val){
- //Sets codelength of "val" to the variable "len"
- fCodeLen[val]=len;
- return;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-void AliTPCHTable::SetCode(Double_t code,Int_t val){
- //Sets the binary code of the variable "val"
- fCode[val]=code;
- return;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-void AliTPCHTable::PrintTable()const{
- //This method prints a table
- cout<<"Table for Huffman coding\n";
- cout<<" Symbol| Code | Length \n";
- for (Int_t i=0;i<fSize;i++){
- if (fCodeLen[i]){
- cout.width(6);cout<<fSym[i];
- cout.width(3);cout<<"|";
- cout.width(6);cout<<hex<<(UInt_t)fCode[i]<<dec;
- cout.width(5);cout<<"|";
- cout.width(6);cout<<(UInt_t)fCodeLen[i]<<endl;
- }//end if
- }//end for
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-Bool_t AliTPCHTable::SpanTree(AliTPCHNode *start, UInt_t code, UChar_t len){
- //Hoffman codes are generated spanning the Huffman tree
- //In an Huffman tree any internal node has always two children
- AliTPCHNode * visited;
- visited = start;
- Int_t idx=visited->GetSymbol();
- if (!visited->GetLeft()) {
- fCode[idx] = code;
- fCodeLen[idx] = len;
- return kTRUE;
- }//end if
- SpanTree(visited->GetLeft(), code << 1, len + 1);
- SpanTree(visited->GetRight(), code << 1 | 0x0001, len + 1);
- return kTRUE;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-void AliTPCHTable::ResetHNodes(){
- //Reset number of HNodes and the HNodes array
- if (fHNodes) fHNodes->Clear();
- if (fNnodes) fNnodes=0;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-void AliTPCHTable::ClearTable(){
- //Clear the table
- memset(fCodeLen,0,sizeof(UChar_t)*fSize);
- memset(fCode,0,sizeof(Double_t)*fSize);
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-Int_t AliTPCHTable::GetFrequencies(const char *fname){
- //It fills the "fCode" array with the frequencies of the symbols read from the file
- AliAltroBuffer buff(fname,0);
- UInt_t numberOfWords=0;
- Int_t val;
- while((val=buff.GetNext())!=-1){
- fCode[val]++;
- fNum++;
- numberOfWords++;
- }
- cout<<"Total number of words: "<<numberOfWords<<endl;
- //Print out the frequencies
- /*
- for (Int_t i=0;i<fSize;i++){
- if (fCode[i])cout<<"Symbol: "<<i<<" Freq: "<<fCode[i]<<endl;
- }
- cout<<endl;
- */
- return 0;
-}
-
-Int_t AliTPCHTable::SetValFrequency(Int_t Val,Double_t Value){
- //This method sets to "Value" the frequency of the symbol "Val"
- fCode[Val]=Value;
- fNum=1;
- return 0;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-Int_t AliTPCHTable::SetFrequency(Int_t Val){
- //It increments by one the frequency of the symbol "Val" whose frequency is
- //stored in the fCode array
- fCode[Val]++;
- fNum++;
- return 0;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-Int_t AliTPCHTable::NormalizeFrequencies(){
- //This method normalized the frequencies
- //Frequencies normalization
- Double_t sum=0.;
- for (Int_t i=0; i< fSize; i++) {
- sum+=fCode[i];
- }//end for
- if (fVerbose){
- cout<<"Frequency sum: "<<sum<<endl;
- }//end if
- if(sum!=0.){
- for (Int_t i=0; i< fSize; i++) {
- fCode[i]/=sum;
- if ((fCode[i]!=0.) && (fCode[i]<10e-20))cout<<"Frequency value very small !!! "<<fCode[i]<<endl;
- }//end for
- }
- return 0;
-}
-//////////////////////////////////////////////////////////////////////////////
-Int_t AliTPCHTable::StoreFrequencies(const char *fname)const{
- //It stores the frequencies in a text file
- ofstream ftxt(fname);
- for (Int_t i=0;i<fSize;i++){
- ftxt<<fCode[i]<<endl;
- }
- ftxt.close();
- return 0;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-void AliTPCHTable::CompleteTable(Int_t k){
- //According to the kind of table (0..4) it associates a dummy frequency (1) to
- //every symbols whose real frequency is zero, in a given range 0..max
- Int_t max;
- UInt_t val;
- switch(k){
- case 0:
- max=fSize;
- val=1;
- break;
- case 1:
- max=445;
- val=1;
- break;
- default:
- max=fSize;
- val=1;
- break;
- }//end switch
-
- for(Int_t i=0;i<max;i++){
- if(fCode[i]==0.0)fCode[i]=val;
- }
- return;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-Double_t AliTPCHTable::GetEntropy()const{
- //This method calculates the value of the entropy
- Double_t entropy=0;
- Double_t prob=0;
- for (Int_t i=0;i<fSize;i++){
- if (fCode[i]){
- prob=fCode[i]/(Double_t)fNum;
- entropy+=prob*(TMath::Log2(prob));
- }
- }
- return -entropy;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-Int_t AliTPCHTable::BuildHTable(){
- //It builds a Huffman tree
- if(GetWordsNumber()){
- for (Int_t i=0; i< fSize; i++) {
- if (fCode[i] > 0.){
- fNnodes++;
- //cout<< "Symbol:"<<i<<" Freq:"<<fCode[i]<<endl;
- fHNodes->Add(new AliTPCHNode(i,fCode[i]));
- }//end if
- }//end for
- Int_t nentries=fHNodes->GetEntriesFast();
- //cout<<"Number of symbols: "<<nentries<<endl;
- Int_t nindex=nentries-1;
- while (nindex > 0){
- fHNodes->Sort(nindex+1);
- AliTPCHNode *aux = new AliTPCHNode(0,0);
- AliTPCHNode *node= (AliTPCHNode*)fHNodes->UncheckedAt(nindex-1);
- AliTPCHNode *node1= (AliTPCHNode*)fHNodes->UncheckedAt(nindex);
-
- aux->SetLeft(node);
- aux->SetRight(node1);
- aux->SetFrequency(node->GetFrequency() + node1->GetFrequency());
- fHNodes->RemoveAt(nindex-1);
- fHNodes->AddAt(aux,nindex-1);
- nindex--;
- }//end while
- ClearTable();
- AliTPCHNode *start= (AliTPCHNode*)fHNodes->UncheckedAt(0);
- SpanTree(start,0,0);
- }//end if
- else{
- cout<<"Table contains 0 elements\n";
- }//end else
- return 0;
-}
-//////////////////////////////////////////////////////////////////////////////
+++ /dev/null
-/* Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
- * See cxx source for full Copyright notice */
-
-///////////////////////////////////////////////////
-// Huffman Table associated classes for set:TPC //
-///////////////////////////////////////////////////
-
-
-#ifndef AliTPCHTABLE_H
-#define AliTPCHTABLE_H
-
-#include <TObject.h>
-
-class TObjArray;
-class AliTPCHNode;
-
-class AliTPCHTable: public TObject{
- public:
- AliTPCHTable();
- AliTPCHTable(Int_t size);
- virtual ~AliTPCHTable();
- AliTPCHTable(const AliTPCHTable &source); // copy constructor
- AliTPCHTable& operator=(const AliTPCHTable &source); // ass. op.
-
- Int_t Size()const {return fSize;}
- UChar_t* CodeLen()const {return fCodeLen;}
- Double_t* Code()const {return fCode;}
- Short_t* Sym()const {return fSym;}
- void SetCodeLen(UChar_t len,Int_t val);
- void SetCode(Double_t code,Int_t val);
- TObjArray* HNodes()const {return fHNodes;}
- void PrintTable()const;
- //This method builds the Huffman tree starting from the frequencies that are
- //strored temporary in fCode array
- Int_t BuildHTable();
- //This method returns the number of words stored in the fSym array
- UInt_t GetWordsNumber()const{return fNum;}
- //This method increase by one the frequency of each value that is present
- //in the specified file
- Int_t GetFrequencies(const char* fname);
- //This method increase by one the frequency of a given value
- Int_t SetFrequency(Int_t Val);
- //This method stores the frequency of the symbol in a text file
- Int_t StoreFrequencies(const char *fname)const;
- void CompleteTable(Int_t k);
- Double_t GetEntropy()const;
- void SetVerbose(Int_t val){fVerbose=val;}
- //Method to set directly a frequency
- Int_t SetValFrequency(Int_t Val,Double_t Value);
- Int_t NormalizeFrequencies();
- private:
- //This method executes the pre-order visit of an Huffman tree and calculates the
- //codeword for each leaf
- Bool_t SpanTree(AliTPCHNode*start, UInt_t code, UChar_t len);
- void ResetHNodes(); //Reset the array fHNodes but not delete the removed objects
- void ClearTable(); //Reset the table
- Int_t fSize; //size of the arrays fCodelen and fCode
- UChar_t *fCodeLen; //![fSize] number of bits array
- Double_t *fCode; //![fSize] coded symbols array
-
- Short_t *fSym; //![fSize] array of input symbols
- TObjArray *fHNodes; // array of nodes
- Int_t fNnodes; // number of nodes
- UInt_t fNum; // number of words
- Int_t fVerbose; // if fVerbose== 0 no output messages; fVerbose!=0 output messages are printed out
- ClassDef(AliTPCHTable,1) //Huffman Table object for set:TPC
-};
-
-#endif
+++ /dev/null
-/**************************************************************************
- * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- * *
- * Author: The ALICE Off-line Project. *
- * Contributors are mentioned in the code where appropriate. *
- * *
- * Permission to use, copy, modify and distribute this software and its *
- * documentation strictly for non-commercial purposes is hereby granted *
- * without fee, provided that the above copyright notice appears in all *
- * copies and that both the copyright notice and this permission notice *
- * appear in the supporting documentation. The authors make no claims *
- * about the suitability of this software for any purpose. It is *
- * provided "as is" without express or implied warranty. *
- **************************************************************************/
-
-/* $Id$ */
-
-///////////////////////////////////////////////////////////////////////////////
-///
-/// This class provides access to TPC digits in raw data.
-///
-/// It loops over all TPC digits in the raw data given by the AliRawReader.
-/// The Next method goes to the next digit. If there are no digits left
-/// it returns kFALSE.
-/// Several getters provide information about the current digit.
-///
-///////////////////////////////////////////////////////////////////////////////
-
-#include <TSystem.h>
-
-#include "AliTPCRawStream.h"
-#include "AliTPCHNode.h"
-#include "AliRawReader.h"
-#include "AliLog.h"
-#include "AliTPCAltroMapping.h"
-
-ClassImp(AliTPCRawStream)
-
-
-AliTPCHNode** AliTPCRawStream::fgRootNode = NULL;
-UInt_t** AliTPCRawStream::fgLUTDimension = NULL;
-AliTPCHNode***AliTPCRawStream::fgLUTNode = NULL;
-
-
-AliTPCRawStream::AliTPCRawStream(AliRawReader* rawReader)
-{
-// create an object to read TPC raw digits
-
- fRawReader = rawReader;
- fRawReader->Select(0);
- fData = new UShort_t[fgkDataMax];
- fDataSize = fPosition = 0;
- fCount = fBunchLength = 0;
-
- if (!fgRootNode) {
- fgRootNode = new AliTPCHNode*[fgkNumTables];
- fgLUTDimension = new UInt_t*[fgkNumTables];
- fgLUTNode = new AliTPCHNode**[fgkNumTables];
- fCompression.CreateTreesFromFile(fgRootNode, fgkNumTables);
- fCompression.CreateLUTsFromTrees(fgRootNode, fgkNumTables, fgLUTDimension, fgLUTNode);
- }
-
- fSector = fPrevSector = fRow = fPrevRow = fPad = fPrevPad = fTime = fSignal = -1;
-
- TString path = gSystem->Getenv("ALICE_ROOT");
- path += "/TPC/mapping/Patch";
- TString path2;
- for(Int_t i = 0; i < 6; i++) {
- path2 = path;
- path2 += i;
- path2 += ".data";
- fMapping[i] = new AliTPCAltroMapping(path2.Data());
- }
-}
-
-AliTPCRawStream::AliTPCRawStream(const AliTPCRawStream& stream) :
- TObject(stream)
-{
- Fatal("AliTPCRawStream", "copy constructor not implemented");
-}
-
-AliTPCRawStream& AliTPCRawStream::operator = (const AliTPCRawStream&
- /* stream */)
-{
- Fatal("operator =", "assignment operator not implemented");
- return *this;
-}
-
-AliTPCRawStream::~AliTPCRawStream()
-{
-// clean up
-
- delete[] fData;
-
- for(Int_t i = 0; i < 6; i++) delete fMapping[i];
-}
-
-void AliTPCRawStream::Reset()
-{
-// reset tpc raw stream params
-
- fDataSize = fPosition = 0;
- fCount = fBunchLength = 0;
-
- fSector = fPrevSector = fRow = fPrevRow = fPad = fPrevPad = fTime = fSignal = -1;
-}
-
-Bool_t AliTPCRawStream::Next()
-{
-// read the next raw digit
-// returns kFALSE if there is no digit left
-
- fPrevSector = fSector;
- fPrevRow = fRow;
- fPrevPad = fPad;
-
- while (fCount == 0) { // next trailer
- if (fPosition >= fDataSize) { // next payload
- UChar_t* data;
- do {
- if (!fRawReader->ReadNextData(data)) return kFALSE;
- } while (fRawReader->GetDataSize() == 0);
-
- if (fRawReader->IsCompressed()) { // compressed data
- UInt_t size = 0;
- // fCompression.Decompress(fgRootNode, fgkNumTables,
- // (char*) data, fRawReader->GetDataSize(),
- // fData, size);
- fCompression.DecompressWithLUTs(fgRootNode, fgLUTDimension, fgLUTNode, fgkNumTables,
- (char*) data, fRawReader->GetDataSize(),
- fData, size);
- fDataSize = size;
-
- } else { // uncompressed data
- fDataSize = 0;
- Int_t pos = (fRawReader->GetDataSize() * 8) / 10;
- while (Get10BitWord(data, pos-1) == 0x2AA) pos--;
- pos++;
- while (pos > 0) {
- for (Int_t i = 0; i < 4; i++) { // copy trailer
- fData[fDataSize++] = Get10BitWord(data, pos-4+i);
- }
- pos -= 4;
-
- Int_t count = (fData[fDataSize-2] << 4) & 0x3FF;
- count |= ((fData[fDataSize-3] & 0x3FF) >> 6);
- // Int_t count = fData[fDataSize-4];
- pos -= (4 - (count % 4)) % 4; // skip fill words
-
- while (count > 0) {
- UShort_t bunchLength = Get10BitWord(data, pos-1);
- fData[fDataSize++] = bunchLength;
- fData[fDataSize++] = Get10BitWord(data, pos-2); // time bin
-
- // copy signal amplitudes in increasing order on time
- for (Int_t i = 0; i < bunchLength-2; i++) {
- fData[fDataSize++] = Get10BitWord(data, pos - bunchLength + i);
- }
- pos -= bunchLength;
- count -= bunchLength;
- }
- }
- }
-
- fPosition = 0;
- }
- if (fPosition + 4 >= fDataSize) {
- Error("Next", "could not read trailer");
- return kFALSE;
- }
-
- Short_t temp = fData[fPosition++];
- Short_t hwAdress = temp & 0x3FF;
-
- temp = fData[fPosition++];
- hwAdress |= (temp & 0x3) << 10;
- if (((temp >> 2) & 0xF) != 0xA)
- AliFatal(Form("Incorrect trailer found ! Expecting second 0xA but found %x !",(temp >> 2) & 0xF));
- fCount = ((temp & 0x3FF) >> 6);
-
- temp = fData[fPosition++];
- fCount |= (temp << 4) & 0x3FF;
- if ((temp >> 6) != 0xA)
- AliFatal(Form("Incorrect trailer found ! Expecting 0xA but found %x !",temp >> 6));
-
- temp = fData[fPosition++];
- if (temp != 0x2AA)
- AliFatal(Form("Incorrect trailer found ! Expecting 0x2AA but found %x !",temp));
-
- Int_t ddlNumber = fRawReader->GetDDLID();
- Int_t patchIndex;
- if (ddlNumber < 72) {
- fSector = ddlNumber / 2;
- patchIndex = ddlNumber % 2;
- }
- else {
- fSector = (ddlNumber - 72) / 4 + 36;
- patchIndex = (ddlNumber - 72) % 4 + 2;
- }
- fPad = fMapping[patchIndex]->GetPad(hwAdress);
- fRow = fMapping[patchIndex]->GetPadRow(hwAdress);
-
- fBunchLength = 0;
- }
-
- if (fBunchLength == 0) {
- if (fPosition >= fDataSize) {
- Error("Next", "could not read bunch length");
- return kFALSE;
- }
- fBunchLength = fData[fPosition++] - 2;
- fCount--;
-
- if (fPosition >= fDataSize) {
- Error("Next", "could not read time bin");
- return kFALSE;
- }
- fTime = fData[fPosition++] - fBunchLength;
- fCount--;
- }
-
- fTime++;
- if (fPosition >= fDataSize) {
- Error("Next", "could not read sample amplitude");
- return kFALSE;
- }
- fSignal = fData[fPosition++] + fgkOffset;
- fCount--;
- fBunchLength--;
-
- return kTRUE;
-}
-
-
-UShort_t AliTPCRawStream::Get10BitWord(UChar_t* buffer, Int_t position) const
-{
-// return a word in a 10 bit array as an UShort_t
-
- Int_t iBit = position * 10;
- Int_t iByte = iBit / 8;
- Int_t shift = iBit % 8;
-// return ((buffer[iByte+1] * 256 + buffer[iByte]) >> shift) & 0x03FF;
-
- // recalculate the byte numbers and the shift because
- // the raw data is written as integers where the high bits are filled first
- // -> little endian is assumed here !
- Int_t iByteHigh = 4 * (iByte / 4) + 3 - (iByte % 4);
- iByte++;
- Int_t iByteLow = 4 * (iByte / 4) + 3 - (iByte % 4);
- shift = 6 - shift;
- return ((buffer[iByteHigh] * 256 + buffer[iByteLow]) >> shift) & 0x03FF;
-}
+++ /dev/null
-#ifndef ALITPCRAWSTREAM_H
-#define ALITPCRAWSTREAM_H
-/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- * See cxx source for full Copyright notice */
-
-/* $Id$ */
-
-///////////////////////////////////////////////////////////////////////////////
-///
-/// This class provides access to TPC digits in raw data.
-///
-///////////////////////////////////////////////////////////////////////////////
-
-#include <TObject.h>
-#include "AliTPCCompression.h"
-
-class AliRawReader;
-class AliAltroMapping;
-
-
-class AliTPCRawStream: public TObject {
- public :
- AliTPCRawStream(AliRawReader* rawReader);
- AliTPCRawStream(const AliTPCRawStream& stream);
- AliTPCRawStream& operator = (const AliTPCRawStream& stream);
- virtual ~AliTPCRawStream();
- void Reset();
-
- virtual Bool_t Next();
-
- inline Int_t GetSector() const {return fSector;};
- inline Int_t GetPrevSector() const {return fPrevSector;};
- inline Bool_t IsNewSector() const {return fSector != fPrevSector;};
- inline Int_t GetRow() const {return fRow;};
- inline Int_t GetPrevRow() const {return fPrevRow;};
- inline Bool_t IsNewRow() const {return (fRow != fPrevRow) || IsNewSector();};
- inline Int_t GetPad() const {return fPad;};
- inline Int_t GetPrevPad() const {return fPrevPad;};
- inline Bool_t IsNewPad() const {return (fPad != fPrevPad) || IsNewRow();};
- inline Int_t GetTime() const {return fTime;};
- inline Int_t GetSignal() const {return fSignal;};
-
- protected :
- UShort_t Get10BitWord(UChar_t* buffer, Int_t position) const;
-
- AliRawReader* fRawReader; // object for reading the raw data
-
- AliTPCCompression fCompression; // object for decompression
- static const Int_t fgkNumTables = 5; // number of (de)compression tables
- static AliTPCHNode** fgRootNode; // (de)compression tables
- static UInt_t** fgLUTDimension; // LUT for fast decompression
- static AliTPCHNode***fgLUTNode; // LUT for fast decompression
-
- static const Int_t fgkDataMax = 10000000; // size of array for uncompressed raw data
- UShort_t* fData; // uncompressed raw data
- Int_t fDataSize; // actual size of the uncompressed raw data
- Int_t fPosition; // current position in fData
- Int_t fCount; // counter of words to be read for current trailer
- Int_t fBunchLength; // remaining number of signal bins in the current bunch
- static const Int_t fgkOffset = 1; // offset of signal
-
- Int_t fSector; // index of current sector
- Int_t fPrevSector; // index of previous sector
- Int_t fRow; // index of current row
- Int_t fPrevRow; // index of previous row
- Int_t fPad; // index of current pad
- Int_t fPrevPad; // index of previous pad
- Int_t fTime; // index of current time bin
- Int_t fSignal; // signal in ADC counts
-
- AliAltroMapping *fMapping[6]; // Pointers to ALTRO mapping
-
- ClassDef(AliTPCRawStream, 0) // base class for reading TPC raw digits
-};
-
-#endif
#pragma link C++ class AliBitPacking+;
#pragma link C++ class AliAltroBuffer+;
#pragma link C++ class AliAltroMapping+;
-#pragma link C++ class AliTPCCompression+;
-#pragma link C++ class AliTPCHNode+;
-#pragma link C++ class AliTPCHTable+;
#pragma link C++ class AliAltroRawStream+;
-#pragma link C++ class AliTPCRawStream+;
#pragma link C++ class AliVMERawStream+;
#endif
AliRawReaderDate.cxx AliRawReaderDateV3.cxx \
AliRawReaderMemory.cxx \
AliBitPacking.cxx AliAltroBuffer.cxx AliAltroMapping.cxx \
- AliTPCCompression.cxx AliTPCHNode.cxx AliTPCHTable.cxx \
- AliAltroRawStream.cxx AliTPCRawStream.cxx \
+ AliAltroRawStream.cxx \
AliVMERawStream.cxx
HDRS:= $(SRCS:.cxx=.h)