-#if !defined(__CINT__) || defined(__MAKECINT__)
-
-#include <iostream.h>
+#if !defined(__CINT__)
+#include <Riostream.h>
#include "AliITSDDLRawData.h"
#endif
#ifdef __NOCOMPILED__
}
#endif
+ Int_t eventNumber=0;
+ Int_t spdLDCs=2;
+ Int_t sddLDCs=4;
+ Int_t ssdLDCs=2;
TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(DigitsFile);
if (!file){
- file = TFile::Open(DigitsFile);
+ file = new TFile(DigitsFile);
}//end if
file->ls();
//TTree *TD = gAlice->TreeD();
-
+ cout<<"Insert the event number:";
+ cin>>eventNumber;
+ cout<<endl;
+
AliITSDDLRawData *util=new AliITSDDLRawData();
//Verbose level
// 0: Silent
//SILICON PIXEL DETECTOR
cout<<"Formatting data for SPD"<<endl;
timer.Start();
- util->RawDataSPD(ITS,TD);
- // util->RawDataSPD(ITS,TD,20);
+ util->RawDataSPD(ITS,TD,spdLDCs,eventNumber);
timer.Stop();
timer.Print();
//ONLY FOR DEBUGGING
- util->TestFormat();
-
+ // util->TestFormat(eventNumber);
+
//SILICON DRIFT DETECTOR
cout<<"Formatting data for SDD"<<endl;
timer.Start();
- //util->RawDataSDD(ITS,TD,12);
- util->RawDataSDD(ITS,TD);
+ util->RawDataSDD(ITS,TD,sddLDCs,eventNumber);
timer.Stop();
timer.Print();
//SILICON STRIP DETECTOR
cout<<"Formatting data for SSD"<<endl;
timer.Start();
- //util->RawDataSSD(ITS,TD,16);
- util->RawDataSSD(ITS,TD);
+ util->RawDataSSD(ITS,TD,ssdLDCs,eventNumber);
timer.Stop();
timer.Print();
//SSD
#include <stdlib.h>
-#include "Riostream.h"
+#include <Riostream.h>
#include <TClonesArray.h>
#include <TTree.h>
-#include "TMath.h"
-#include <AliITS.h>
-#include <AliITSgeom.h>
-#include <AliITSdigit.h>
+#include <TMath.h>
+#include "AliITS.h"
+#include "AliITSgeom.h"
+#include "AliITSdigit.h"
#include "AliITSDDLRawData.h"
ClassImp(AliITSDDLRawData)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-Int_t AliITSDDLRawData::RawDataSPD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
+Int_t AliITSDDLRawData::RawDataSPD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber,Int_t eventNumber){
//This method creates the Raw data files for SPD detectors
//Silicon Pixel Detector
const Int_t kDDLsNumber=20; // Number of DDL in SPD
Int_t detector=1; // 1==>ITS (Pixel) 2==>ITS (Drift) 3==>ITS (Strip) 0==>TPC ......
ULong_t size=0; // size of the data block that follows the mini header
Int_t magicWord=0x123456; // Magic word used to distinguish between data and garbage
- sprintf(fileName,"SPDslice%d",sliceNumber); //The name of the output file. There are as many slides as the number of LDC
+ sprintf(fileName,"Ev%dSPDslice%d",eventNumber,sliceNumber); //The name of the output file. There are as many slides as the number of LDC
#ifndef __DECCXX
outfile.open(fileName,ios::binary);
#else
if(countDDL==ddlsPerFile){
outfile.close();
sliceNumber++;
- sprintf(fileName,"SPDslice%d",sliceNumber);
+ sprintf(fileName,"Ev%dSPDslice%d",eventNumber,sliceNumber);
if(i!=(kDDLsNumber-1))
#ifndef __DECCXX
outfile.open(fileName,ios::binary);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-Int_t AliITSDDLRawData::RawDataSSD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
+Int_t AliITSDDLRawData::RawDataSSD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber,Int_t eventNumber){
//This method creates the Raw data files for SSD detectors
//Strip detector
const Int_t kDDLsNumber=16; // Number of DDL in SSD
Int_t detector=3; // 1==>ITS (Pixel) 2==>ITS (Drift) 3==>ITS (Strip) 0==>TPC ......
ULong_t size=0; // size of the data block that follows the mini header
Int_t magicWord=0x123456; // Magic word used to distinguish between data and garbage
- sprintf(fileName,"SSDslice%d",sliceNumber); //The name of the output file. There are as many slides as the number of LDC
+ sprintf(fileName,"Ev%dSSDslice%d",eventNumber,sliceNumber); //The name of the output file. There are as many slides as the number of LDC
#ifndef __DECCXX
outfile.open(fileName,ios::binary);
#else
if(countDDL==ddlsPerFile){
outfile.close();
sliceNumber++;
- sprintf(fileName,"SSDslice%d",sliceNumber);
+ sprintf(fileName,"Ev%dSSDslice%d",eventNumber,sliceNumber);
if(i!=(kDDLsNumber-1))
#ifndef __DECCXX
outfile.open(fileName,ios::binary);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-Int_t AliITSDDLRawData::RawDataSDD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber){
+Int_t AliITSDDLRawData::RawDataSDD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber,Int_t eventNumber){
//This method creates the Raw data files for SDD detectors
//Silicon Drift detector
const Int_t kDDLsNumber=12; // Number of DDL in SPD
Int_t detector=2; // 1==>ITS (Pixel) 2==>ITS (Drift) 3==>ITS (Strip) 0==>TPC ......
ULong_t size=0; // size of the data block that follows the mini header
Int_t magicWord=0x123456; // Magic word used to distinguish between data and garbage
- sprintf(fileName,"SDDslice%d",sliceNumber); //The name of the output file. There are as many slides as the number of LDC
+ sprintf(fileName,"Ev%dSDDslice%d",eventNumber,sliceNumber); //The name of the output file. There are as many slides as the number of LDC
#ifndef __DECCXX
outfile.open(fileName,ios::binary);
#else
if(countDDL==ddlsPerFile){
outfile.close();
sliceNumber++;
- sprintf(fileName,"SDDslice%d",sliceNumber);
+ sprintf(fileName,"Ev%dSDDslice%d",eventNumber,sliceNumber);
if(i!=(kDDLsNumber-1))
#ifndef __DECCXX
outfile.open(fileName,ios::binary);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-void AliITSDDLRawData::TestFormat(){
+void AliITSDDLRawData::TestFormat(Int_t eventNumber){
//This method generates a text file containing SPD information
//Used for debugging
ifstream f;
ULong_t miniHeader[3];
Int_t miniHeaderSize=sizeof(ULong_t)*3;
for(Int_t i=1;i<=ldcsNumber;i++){
- sprintf(filename,"SPDslice%d",i);
+ sprintf(filename,"Ev%dSPDslice%d",eventNumber,i);
#ifndef __DECCXX
f.open(filename,ios::binary|ios::in);
#else
virtual ~AliITSDDLRawData(){;}//destructor
AliITSDDLRawData(const AliITSDDLRawData &source); // copy constructor
AliITSDDLRawData& operator=(const AliITSDDLRawData &source); // ass. op.
- Int_t RawDataSPD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber=2);
+ Int_t RawDataSPD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber,Int_t eventNumber);
// This method generates the files with the Silicon pixel detector data
- Int_t RawDataSDD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber=4);
+ Int_t RawDataSDD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber,Int_t eventNumbe);
// This method generates the files with the Silicon drift detector data
- Int_t RawDataSSD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber=2);
+ Int_t RawDataSSD(AliITS *ITS,TTree *TD ,Int_t LDCsNumber,Int_t eventNumbe);
// This method generates the files with the Silicon pixel detector data
- void TestFormat();
+ void TestFormat(Int_t eventNumber);
// A debugging method used to test the files generated for the SPD.
void SetVerbose(Int_t Verbose){fVerbose=Verbose;}
// To set the verbose level
* about the suitability of this software for any purpose. It is *
* provided "as is" without express or implied warranty. *
**************************************************************************/
-
/* $Id$ */
// Storing digits in a binary file
#include <TObjArray.h>
#include <Riostream.h>
#include <TMath.h>
-#include "AliTPCCompression.h"
#include "AliTPCBuffer160.h"
#include "AliTPCHuffman.h"
+#include "AliTPCCompression.h"
ClassImp(AliTPCCompression)
//////////////////////////////////////////////////////////////////////////////////////////////////
fBuffer=0;
fVerbose=0;
fFillWords=0;
+ fPointBuffer=0;
return;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
this->fBuffer=source.fBuffer;
this->fVerbose=source.fVerbose;
this->fFillWords=source.fFillWords;
+ this->fPointBuffer=source.fPointBuffer;
return;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
this->fBuffer=source.fBuffer;
this->fVerbose=source.fVerbose;
this->fFillWords=source.fFillWords;
+ this->fPointBuffer=source.fPointBuffer;
return *this;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
return;
}
-/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
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;
}
return specular;
}
-//////////////////////////////////////////////////////////////////////////////////////////////////
-Int_t AliTPCCompression::CompressData(AliTPCHTable* table[],Int_t NumTable,const char* fSource,const char* fDest){
- //This method is used to compress the data stored in the Altro format file using specific tables
- //calculated considering the frequencies of the symbol of the file that has to be compressed
- cout<<" COMPRESSION "<<endl;
- cout<<"compression of the file "<<fSource<<" Output File: "<<fDest<<endl;
- //the output file is open
-#ifndef __DECCXX
- f.open(fDest,ios::binary|ios::out);
-#else
- f.open(fDest,ios::out);
-#endif
- //Tables are written into the output file
- for(Int_t k=0;k<NumTable;k++){
- Int_t dim=table[k]->Size();
- //Table dimension is written into a file
- f.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];
- ULong_t code=(ULong_t)table[k]->Code()[i];
- f.write((char*)(&codeLen),sizeof(UChar_t));
- f.write((char*)(&code),sizeof(ULong_t));
- } //end for
- }//end for
-
- // Source file is open
- AliTPCBuffer160 buff(fSource,0);
- //coded words are written into the output file
- Int_t numWords,padNum,rowNum,secNum=0;
- ULong_t storedWords=0;
- Int_t value=0;
- ULong_t numPackets=0;
- while(buff.ReadTrailerBackward(numWords,padNum,rowNum,secNum) !=-1 ){
- numPackets++;
- if (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;
- //All the words for one pad are compressed and stored in the compress file
- for(Int_t i=0;i<numWords;i++){
- value=packet[i];
- if(nextTableType==1)timeBin=value;
- if(nextTableType>1){
- // ULong_t val=(ULong_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
- StoreValue(Mirror((ULong_t)val,len),len);
- storedWords++;
- }//end if
- NextTable(value,nextTableType,bunchLen,count);
- if(nextTableType==0){
- // ULong_t val=(ULong_t)table[1]->Code()[timeBin]; // val is the code
- 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
- StoreValue(Mirror((ULong_t)val,len),len);
- //val=(ULong_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(Mirror((ULong_t)val,len),len);
- storedWords+=2;
- }
- }//end for
- //Trailer
- StoreValue(numWords,10);
- StoreValue(padNum,10);
- StoreValue(rowNum,10);
- StoreValue(secNum,9);
- StoreValue(1,1);
- storedWords+=4;
- }//end while
- StoreValue(numPackets,32);
- cout<<"Number of strored packet: "<<numPackets<<endl;
- StoreValue(1,1);
- //The last buffen cannot be completely full
- Flush();
- cout<<"Number of stored words: "<<storedWords<<endl;
- f.close();
- return 0;
-}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Int_t AliTPCCompression::CompressDataOptTables(Int_t NumTable,const char* fSource,const char* fDest){
////////////////////////////////////////////////////////////////////////////////////////
/* DECOMPRESSION */
////////////////////////////////////////////////////////////////////////////////////////
-void AliTPCCompression::CreateTrees(AliTPCHNode *RootNode[],const Int_t NumTables){
- //The first part of the compressed file cotains the tables
- //The following for loop is used to generate the Huffman trees acording to the tables
- if(fVerbose)
- cout<<"Creating the Huffman trees \n";
- AliTPCHNode *node=0;
- // ULong_t code;
- Double_t code;
- UChar_t codeLen;
- //loop over the numbero of tables
- for(Int_t k=0;k<NumTables;k++){
- RootNode[k]=new AliTPCHNode(); //RootNode is the root of the tree
- Int_t dim;//this variable contains the table dimension
- f.read((char*)(&dim),sizeof(Int_t));
- if (fVerbose)
- cout<<"Table dimension: "<<dim<<endl;
- //loop over the words of a table
- for(Int_t i=0;i<dim;i++){
- f.read((char*)(&codeLen),sizeof(UChar_t));
- //f.read((char*)(&code),sizeof(ULong_t));
- f.read((char*)(&code),sizeof(Double_t));
- node=RootNode[k];
- for(Int_t j=1;j<=codeLen;j++){
- ULong_t bit,val=0;
- val=(ULong_t)TMath::Power(2,codeLen-j);
- bit=(ULong_t)code&val;
- 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
- //cout<<node->GetSymbol()<<" "<<(Int_t)node->GetFrequency()<<endl;
- }//end for
- }//end for
- if (fVerbose)
- cout<<"Trees generated \n";
- //At this point the trees are been built
-}
-//////////////////////////////////////////////////////////////////////////////////////////////////
+
void AliTPCCompression::CreateTreesFromFile(AliTPCHNode *RootNode[],const Int_t NumTables){
//For each table this method builds the associate Huffman tree starting from the codeword and
//the codelength of each symbol
#else
fTable.open(filename);
#endif
+ if(!fTable){cout<<"Tables don't exist !!!"<<endl;exit(1);}
fTable.read((char*)(&dim),sizeof(Int_t));
if (fVerbose)
cout<<"Table dimension: "<<dim<<endl;
return result;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
-void AliTPCCompression::ReadTrailer(Int_t &WordsNumber,Int_t &PadNumber,Int_t &RowNumber,Int_t &SecNumber){
+ULong_t AliTPCCompression::ReadWordBuffer(Int_t NumberOfBit){
+ //This method retrieves a word of a specific number of bits from the file through the buffer
+ ULong_t result=0;
+ ULong_t bit=0;
+ for (Int_t i=0;i<NumberOfBit;i++){
+ if (fReadBits==32){
+ fPointBuffer-=8;
+ fBuffer=0;
+ for(Int_t i=0;i<4;i++){
+ ULong_t val=0;
+ val=*fPointBuffer;
+ val&=0xFF;
+ fPointBuffer++;
+ val<<=8*i;
+ fBuffer=fBuffer|val;
+ }//end for
+ fReadBits=0;
+ }//end if
+ ULong_t mask=0;
+ mask=(ULong_t)TMath::Power(2,fReadBits);
+ bit=fBuffer&mask;
+ bit=bit>>fReadBits;
+ fReadBits++;
+ bit=bit<<i;
+ result=result|bit;
+ }//end for
+ return result;
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+void AliTPCCompression::ReadTrailer(Int_t &WordsNumber,Int_t &PadNumber,Int_t &RowNumber,Int_t &SecNumber,Bool_t Memory){
//It retrieves a trailer
- ReadWord(1);
- SecNumber=ReadWord(9);
- RowNumber=ReadWord(10);
- PadNumber=ReadWord(10);
- WordsNumber=ReadWord(10);
+ if(Memory){
+ ReadWordBuffer(1);
+ 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;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
-ULong_t AliTPCCompression::GetDecodedWord(AliTPCHNode* root){
+ULong_t AliTPCCompression::GetDecodedWord(AliTPCHNode* root,Bool_t Memory){
//This method retrieves a decoded word.
AliTPCHNode *node=root;
ULong_t symbol=0;
Bool_t decoded=0;
while(!decoded){
- ULong_t bit=ReadWord(1);
+ ULong_t bit=0;
+ if(Memory)
+ bit=ReadWordBuffer(1);
+ else
+ bit=ReadWord(1);
if(bit)
node=node->GetRight();
else
return symbol;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
-Int_t AliTPCCompression::DecompressData(Int_t NumTables,const char* fname,char* fDest){
- //Decompression method
- cout<<" DECOMPRESSION:"<<endl;
- cout<<"Source File "<<fname<<" Destination File "<<fDest<<endl;
-#ifndef __DECCXX
+
+Int_t AliTPCCompression::DecompressDataOptTables(Int_t NumTables,const char* fname,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];
+ //Creation of the Huffman trees
+ CreateTreesFromFile(rootNode,NumTables);
+#ifndef __DECCXX
f.open(fname,ios::binary|ios::in);
#else
f.open(fname,ios::in);
#endif
if(!f){cout<<"File doesn't exist:"<<fname<<endl;;return -1;}
- AliTPCHNode ** rootNode = new AliTPCHNode*[NumTables];
- //Creation of the Huffman trees
- CreateTrees(rootNode,NumTables);
//to go to the end of the file
f.seekg(0,ios::end);
//to get the file dimension in byte
fReadBits++;
}
ULong_t packetNumber=ReadWord(sizeof(ULong_t)*8);
- cout<<"Number of Packect: "<<packetNumber<<endl;
+ if(fVerbose){
+ cout<<"Number of Packect: "<<packetNumber<<endl;
+ }
AliTPCBuffer160 bufferFile(fDest,1);
ULong_t k=0;
ULong_t wordsRead=0; //number of read coded words
while(k<packetNumber){
Int_t numWords,padNumber,rowNumber,secNumber=0;
- ReadTrailer(numWords,padNumber,rowNumber,secNumber);
+ ReadTrailer(numWords,padNumber,rowNumber,secNumber,kFALSE);
k++;
wordsRead+=4;
Int_t previousTime=-1;
Int_t bunchLen=0;
Int_t count=0;
for(Int_t i=0;i<numWords;i++){
- ULong_t symbol=GetDecodedWord(rootNode[nextTableType]);
+ ULong_t symbol=GetDecodedWord(rootNode[nextTableType],kFALSE);
wordsRead++;
//Time reconstruction
if (nextTableType==1){
}//end for
bufferFile.WriteTrailer(numWords,padNumber,rowNumber,secNumber);
}//end while
- cout<<"Number of decoded words:"<<wordsRead<<endl;
+ 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;
+ delete [] rootNode;
return 0;
}
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-Int_t AliTPCCompression::DecompressDataOptTables(Int_t NumTables,const char* fname,char* fDest){
+//////////////////////////////////////////////////////////////////////////////////////////////////
+Int_t AliTPCCompression::Decompress(AliTPCHNode *RootNode[],const Int_t NumTables,char* PointBuffer,ULong_t BufferSize,UShort_t out[],ULong_t &dim){
//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];
- //Creation of the Huffman trees
- CreateTreesFromFile(rootNode,NumTables);
-#ifndef __DECCXX
- f.open(fname,ios::binary|ios::in);
-#else
- f.open(fname,ios::in);
-#endif
- if(!f){cout<<"File doesn't exist:"<<fname<<endl;;return -1;}
- //to go to the end of the file
- f.seekg(0,ios::end);
- //to get the file dimension in byte
- fPos=f.tellg();
- fPos-=sizeof(ULong_t);
- f.seekg(fPos);
+
+ fPointBuffer=PointBuffer+BufferSize-4;
fReadBits=0;
fBuffer=0;
- f.read((char*)(&fBuffer),sizeof(ULong_t));
+
+ for(Int_t i=0;i<4;i++){
+ ULong_t val=0;
+ val=*fPointBuffer;
+ val&=0xFF;
+ fPointBuffer++;
+ val<<=8*i;
+ fBuffer=fBuffer|val;
+ }//end for
Int_t bit=0;
ULong_t mask=0x1;
while(!bit){
bit=fBuffer&mask;
mask=mask<<1;
fReadBits++;
- }
- ULong_t packetNumber=ReadWord(sizeof(ULong_t)*8);
- if(fVerbose){
- cout<<"Number of Packect: "<<packetNumber<<endl;
- }
- AliTPCBuffer160 bufferFile(fDest,1);
+ }//end while
+ ULong_t packetNumber=ReadWordBuffer(sizeof(ULong_t)*8); //32 bits
+ if (fVerbose){
+ cout<<"First one has been found "<<endl;
+ cout<<"Number of packets:"<<packetNumber<<endl;
+ }//end if
+ AliTPCBuffer160 bufferFile("DDL1.dat",1);
ULong_t k=0;
- ULong_t wordsRead=0; //number of read coded words
+ ULong_t wordsRead=0; //number of read coded words
while(k<packetNumber){
Int_t numWords,padNumber,rowNumber,secNumber=0;
- ReadTrailer(numWords,padNumber,rowNumber,secNumber);
+ 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 nextTableType=0;
Int_t bunchLen=0;
Int_t count=0;
+ Int_t timeDigit=0;
for(Int_t i=0;i<numWords;i++){
- ULong_t symbol=GetDecodedWord(rootNode[nextTableType]);
+ ULong_t symbol=GetDecodedWord(RootNode[nextTableType],kTRUE);
wordsRead++;
//Time reconstruction
if (nextTableType==1){
}
else previousTime=symbol;
time=previousTime;
+ out[dim]=bunchLen+2;
+ dim++;
+ out[dim]=time;
+ dim++;
+ timeDigit=time-bunchLen;
}
- if(nextTableType>1)
+ if(nextTableType>1){
+ //
bufferFile.FillBuffer(symbol);
+ //
+ //ftxt<<symbol<<endl;
+ out[dim]=symbol;
+ dim++;
+ timeDigit++;
+ //padDigits->SetDigits(symbol,timeDigit);
+ }
NextTable(symbol,nextTableType,bunchLen,count);
if(nextTableType==0){
+ //
bufferFile.FillBuffer(time);
bufferFile.FillBuffer(bunchLen+2);
+ //ftxt<<time<<endl;
+ // ftxt<<(bunchLen+2)<<endl;
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::DestroyTables(AliTPCHNode *RootNode[],const 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
virtual ~AliTPCCompression(){;}
AliTPCCompression(const AliTPCCompression &source); // copy constructor
AliTPCCompression& operator=(const AliTPCCompression &source); // ass. op.
- Int_t CompressData(AliTPCHTable* table[],Int_t NumTable,const char* fSource,const char* fDest);
- //This method is used to compress the data stored in the Altro format file using specific tables
- //calculated considering the frequencies of the symbol of the file that has to be compressed
- //The tables are stored at the beginning of the compressed file
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. In this case the tables are not stored in the compressed file
- Int_t DecompressData(Int_t NumTables,const char* fname,char* fDest="SourceDecompressed.dat");
- //This method is used tho decompress a file compressed using the CompressData method
+ //stored as a sequence of txt file.
Int_t DecompressDataOptTables(Int_t NumTables,const char* fname,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[],const Int_t NumTables,char* PointBuffer,ULong_t BufferSize,UShort_t out[],ULong_t &dim);
+ //This method is used to decompress data stored in a char* buffer
Int_t FillTables(const char* fSource,AliTPCHTable* table[],const Int_t NumTables);
//This method is used to compute the frequencies of the symbols in the source file
Int_t CreateTables(const char* fSource,const Int_t NumTables);
//This method is used to create and store the tables
- Int_t CreateTableFormula(Double_t beta,ULong_t M,Int_t dim,Int_t Type);
+ Int_t CreateTableFormula(Double_t beta,ULong_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
//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[],const Int_t NumTables);
+ //This methods is use to deallocate the memory used by Huffman trees
+ void CreateTreesFromFile(AliTPCHNode *RootNode[],const 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())
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
//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 CreateTrees(AliTPCHNode *RootNode[],const Int_t NumTables);
- //This method is used to create one or more Huffman tree starting from one or more tables
- //It is used in the decompression phase (DecompressData())
- void CreateTreesFromFile(AliTPCHNode *RootNode[],const 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())
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
//This method is used to complete and store the buffer in the output file when it isn't completely full
ULong_t ReadWord(Int_t NumberOfBit);
//this method is used to read a specified number of bits from the compressed file
- void ReadTrailer(Int_t &WordsNumber,Int_t &PadNumber,Int_t &RowNumber,Int_t &SecNumber);
+ ULong_t ReadWordBuffer(Int_t NumberOfBit);
+ //this method is used to read a specified number of bits from the compressed memory 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
- ULong_t GetDecodedWord(AliTPCHNode* root);
+ ULong_t GetDecodedWord(AliTPCHNode* root,Bool_t Memory);
//This method is used to get a decoded word from the compressed file
-
fstream f; // f is the logical name for the compressed and uncompressed file
ofstream fStat; // Logical name for the Statistics file
ULong_t fBuffer; // buffer
ULong_t fPos; // current file position
Int_t fVerbose; // verbose level (0 silent, !=0 output messages)
ULong_t fFillWords; // Number of hexadecimally words (2AA pattern) inside a pad data block
+ char* fPointBuffer; //pointer to the compressed raw data
ClassDef(AliTPCCompression,1)
};
#endif
AliTPCDDLRawData *util=new AliTPCDDLRawData();
AliTPCCompression *u=new AliTPCCompression();
TStopwatch timer;
-
+ Int_t eventNumber=0;
static const Int_t NumTable=5;
+
+ util->SetVerbose(1);
+ u->SetVerbose(1);
- //TABLES CREATION
//The Altro File "AltroFormatDDL.dat" is built from "AliTPCDDL.dat"
util->RawDataAltro();
- //u->SetVerbose(1);
+
+ /*
//The file "AltroFormatDDL.dat" is converted in a txt file "AltroFormatDDL.txt"
//that is used for debugging
-
- cout<<"Creating a txt file from an Altro format file"<<endl;
u->ReadAltroFormat("AltroFormatDDL.txt","AltroFormatDDL.dat");
-
+ */
+
+ /*
+ //TABLES CREATION
//Tables are created and stored in as sequence of binary files
u->CreateTables("AltroFormatDDL.dat",NumTable);
-
+ */
+
+
+ cout<<"Insert the event number:";
+ cin>>eventNumber;
+ cout<<endl;
-
//SLICE CREATION
//Slices are built here
timer.Start();
- util->RawData(LDCsNumber);
+ util->RawData(LDCsNumber,eventNumber);
timer.Stop();
timer.Print();
-
-
+
+ /*
//SLICE CHECKING
//An Altro File is created from the slides
cout<<"slice control"<<endl;
- util->RawDataAltroDecode(LDCsNumber,0);
+ util->RawDataAltroDecode(LDCsNumber,eventNumber,0);
///The Altro file AltroDDLRecomposed.dat is converted in a txt file AltroDDLRecomposed.txt
//This file must be equal to the ones created above.
- cout<<"Creating a txt file from an Altro format file"<<endl;
u->ReadAltroFormat("AltroDDLRecomposed.txt","AltroDDLRecomposed.dat");
+ */
-
-
+
//SLICE COMPRESSION
cout<<"Slice Compression"<<endl;
//Slices are compressed here using the tables created above or an optimized set of tables
//(Tables file for Huffman coding are required)
timer.Start();
- util->RawDataCompDecompress(LDCsNumber,0);
+ util->RawDataCompDecompress(LDCsNumber,eventNumber,0);
timer.Stop();
timer.Print();
-
-
+
+ /*
//SLICE DECOMPRESSION
timer.Start();
- util->RawDataCompDecompress(LDCsNumber,1);
+ util->RawDataCompDecompress(LDCsNumber,eventNumber,1);
timer.Stop();
timer.Print();
+ */
-
-
+ /*
//SLICE DECOMPRESSED CHECKING
//A new Altro file is created from the decompressed slides
- util->RawDataAltroDecode(LDCsNumber,1);
+ util->RawDataAltroDecode(LDCsNumber,eventNumber,1);
//Convertion of the Altro file AltroDDLRecomposedDec.dat in a txt file AltroDDLRecomposedDec.txt
//Useful for debugging
- cout<<"Creating a txt file from an Altro format file"<<endl;
u->ReadAltroFormat("AltroDDLRecomposedDec.txt","AltroDDLRecomposedDec.dat");
-
+ */
delete util;
delete u;
return;
////////////////////////////////////////////////////////////////////////////
-void AliTPCDDLRawData::RawData(Int_t LDCsNumber){
+void AliTPCDDLRawData::RawData(Int_t LDCsNumber,Int_t EventNumber){
//Raw data slides generation
//Number of DDL=2*36+4*36=216
//2 DDL for each inner sector
//AliTPCBuffer160 is used in write mode to generate AltroFormat.dat file
Int_t sliceNumber=1;
char filename[15];
- sprintf(filename,"TPCslice%d",sliceNumber);
+ sprintf(filename,"Ev%dTPCslice%d",EventNumber,sliceNumber);
cout<<" Creating "<<filename<<endl;
AliTPCBuffer160 *buffer=new AliTPCBuffer160(filename,1);
//cout<<"Mini header for DDL:"<<PSecNumber<<" Sub-sec:"<<PSubSector<<endl;
delete buffer;
sliceNumber++;
- sprintf(filename,"TPCslice%d",sliceNumber);
+ sprintf(filename,"Ev%dTPCslice%d",EventNumber,sliceNumber);
cout<<" Creating "<<filename<<endl;
buffer=new AliTPCBuffer160(filename,1);
buffer->WriteMiniHeader(0,data.Sec,data.SubSec,0,0);//Dummy;
////////////////////////////////////////////////////////////////////////////
-Int_t AliTPCDDLRawData::RawDataCompDecompress(Int_t LDCsNumber,Int_t Comp){
+Int_t AliTPCDDLRawData::RawDataCompDecompress(Int_t LDCsNumber,Int_t EventNumber,Int_t Comp){
//This method is used to compress and decompress the slides
static const Int_t kNumTables=5;
char filename[20];
Int_t flag=0;
for(Int_t i=1;i<=LDCsNumber;i++){
if(!Comp){
- sprintf(filename,"TPCslice%d",i);
- sprintf(dest,"TPCslice%d.comp",i);
+ sprintf(filename,"Ev%dTPCslice%d",EventNumber,i);
+ sprintf(dest,"Ev%dTPCslice%d.comp",EventNumber,i);
}
else{
- sprintf(filename,"TPCslice%d.comp",i);
- sprintf(dest,"TPCslice%d.decomp",i);
+ sprintf(filename,"Ev%dTPCslice%d.comp",EventNumber,i);
+ sprintf(dest,"Ev%dTPCslice%d.decomp",EventNumber,i);
}
#ifndef __DECCXX
f.open(filename,ios::binary|ios::in);
f.open(filename,ios::in);
#endif
if(!f){cout<<"BE CAREFUL!! There isn't enough data to generate "<<LDCsNumber<<" slices"<<endl;break;}
- cout<<filename<<" "<<dest<<endl;
+ if (fVerbose)
+ cout<<filename<<" "<<dest<<endl;
ofstream fdest;
#ifndef __DECCXX
fdest.open(dest,ios::binary);
}
/////////////////////////////////////////////////////////////////////////
-void AliTPCDDLRawData::RawDataAltroDecode(Int_t LDCsNumber,Int_t Comp){
+void AliTPCDDLRawData::RawDataAltroDecode(Int_t LDCsNumber,Int_t EventNumber,Int_t Comp){
//This method merges the slides in only one file removing at the same
//time all the mini headers. The file so obtained must be Altro format
//complaiant.
ULong_t size=0;
//Int_t MagicWord,DDLNumber,SecNumber,SubSector,Detector,flag=0;
for(Int_t i=1;i<=LDCsNumber;i++){
- if(!Comp)
- sprintf(filename,"TPCslice%d",i);
- else
- sprintf(filename,"TPCslice%d.decomp",i);
+ if(!Comp){
+ sprintf(filename,"Ev%dTPCslice%d",EventNumber,i);
+ }
+ else{
+ sprintf(filename,"Ev%dTPCslice%d.decomp",EventNumber,i);
+ }
#ifndef __DECCXX
f.open(filename,ios::binary|ios::in);
#else
virtual ~AliTPCDDLRawData(){;}//destructor
AliTPCDDLRawData(const AliTPCDDLRawData &source); // copy constructor
AliTPCDDLRawData& operator=(const AliTPCDDLRawData &source); // ass. op.
- void RawData(Int_t LDCsNumber);
+ void RawData(Int_t LDCsNumber,Int_t EventNumber);
//This method is used to create the slides (sequence of files)
- Int_t RawDataCompDecompress(Int_t LDCsNumber,Int_t Comp=0);
+ Int_t RawDataCompDecompress(Int_t LDCsNumber,Int_t EventNumber,Int_t Comp=0);
//This method is used to create the compressed slides starting from the uncompressed ones
//or it can be used to decompress a sequence of compressed slices
void RawDataAltro()const;
//This method is used to create the Altro format file from "AliTPCDDL.dat"
- void RawDataAltroDecode(Int_t LDCsNumber,Int_t Comp=0);
+ void RawDataAltroDecode(Int_t LDCsNumber,Int_t EventNumber,Int_t Comp=0);
//This method is used to construct an Altro format file starting from
//the slices compressed or uncompressed
void SetVerbose(Int_t Verbose){fVerbose=Verbose;}
TStopwatch timer;
//verbose level can be: 0=silent 1=few messages 2=pedantic output
util->SetVerbose(1);
+
Int_t choice;
do{
cout<<"**** Chose the tables set **** "<<endl;
break;
}
};
-
+
//BE CAREFUL, the following method must be used only for debugging and
//it is highly suggested to use it only for debugging files
//reasonably small, because otherwise the size of the txt files can reach
//quickly several MB wasting time and disk space.
- // util->ReadAltroFormat("File1.txt",fSource);
+ //util->ReadAltroFormat("File1.txt",fSource);
//The source file is compressed
timer.Start();
ULong_t val;
switch(k){
case 0:
- max=700;
+ max=fSize;
val=1;
break;
case 1: