]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliTPCCompression.h
Presenting to the outside world a (x,y) reference located at the center of the slat...
[u/mrichter/AliRoot.git] / RAW / AliTPCCompression.h
1 /* Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
2  * See cxx source for full Copyright notice                               */
3
4 //////////////////////////////////////////////////////
5 // Class for Compression and Decompression          //
6 //////////////////////////////////////////////////////
7
8  
9 #ifndef AliTPCCOMPRESSION_H
10 #define AliTPCCOMPRESSION_H
11
12 #ifdef __CINT__
13 class fstream;
14 #else
15 #include "Riostream.h"
16 #endif
17
18 class AliTPCHNode;
19 class AliTPCHTable;
20
21 class AliTPCCompression:public TObject{
22  public:
23   AliTPCCompression();
24   virtual ~AliTPCCompression(){;}
25   AliTPCCompression(const AliTPCCompression &source); // copy constructor
26   AliTPCCompression& operator=(const AliTPCCompression &source); // ass. op.
27   Int_t  CompressDataOptTables(Int_t NumTable,const char* fSource,const char* fDest);
28   //This method is used to compress an Altro file using a set of general table previously calculated  and
29   //stored as a sequence of txt file. 
30   Int_t  DecompressDataOptTables(Int_t NumTables,const char* fname,const char* fDest="SourceDecompressed.dat");
31   //This method is used to decompress a file compressed using the CompressDataOptTable method
32   //It expects a set of table used for compressing the file in the same directory of the compressed file
33   Int_t  Decompress(AliTPCHNode *RootNode[],Int_t NumTables,char* PointBuffer,UInt_t BufferSize,UShort_t out[],UInt_t &dim);
34   //This method is used to decompress data stored in a char* buffer
35   Int_t  DecompressWithLUTs(AliTPCHNode *RootNode[],UInt_t *LUTDimension[],AliTPCHNode **LUTNode[],Int_t /*NumTables*/,char* PointBuffer,UInt_t BufferSize,UShort_t out[],UInt_t &dim);
36   Int_t  FillTables(const char* fSource,AliTPCHTable* table[],Int_t NumTables);
37   //This method is used to compute the frequencies of the symbols in the source file
38   Int_t  CreateTables(const char* fSource,Int_t NumTables);
39   //This method is used to create and store the tables 
40   Int_t  CreateTableFormula(Double_t beta,UInt_t  M,Int_t dim,Int_t Type);
41   //This method is used to create and store the Bunch length or Time Gap Table using a formula
42   void   SetVerbose(Int_t val){fVerbose=val;}
43   //This method is used to set up the verbose level
44   //   0 ==> No output messages are displayed
45   //   1 ==> Some output messages are displayed during the running
46   //   2 ==> A complete output is displayed
47   void   ReadAltroFormat(char* fileOut,char* fileIn)const;
48   //This method is used to read an Altro file and generate a text file containing the same information
49   //It's is useful for debugging
50   Int_t  CreateTablesFromTxtFiles(Int_t NumTable);
51   //This method creates a set of binary tables starting from a set of txt tables
52   Int_t  DestroyTables(AliTPCHNode *RootNode[],Int_t NumTables);
53   //This methods is use to deallocate the memory used by Huffman trees
54   Int_t  CreateTreesFromFile(AliTPCHNode *RootNode[],Int_t NumTables);
55   //This method is like the previous one but the tables are stored in binary files
56   //It is used in the decompression phase (DecompressDataOptTables())
57   Int_t  CreateLUTsFromTrees(AliTPCHNode *RootNode[],Int_t NumTables,UInt_t *LUTDimension[],AliTPCHNode **LUTNode[]);
58  private:
59   Int_t   StoreTables(AliTPCHTable* table[],const Int_t NumTable);
60   //This method is used to store an array of tables in a sequence of binary files
61   //Each file contains the Size of the table (number of words) and for each word contains the correspondent 
62   //codeword and codelength
63   Int_t   RetrieveTables(AliTPCHTable* table[],Int_t NumTable);
64   //This method is used to retrieve an array of tables from a sequence of binary files created using 
65   //the previous method 
66   void    DeleteHuffmanTree(AliTPCHNode* node);
67   //This method is used to delete an Huffman tree
68   void    VisitHuffmanTree(AliTPCHNode* node);
69   //This method realizes an in order visit of a binary tree
70   void    NextTable(Int_t Val,Int_t &NextTableType,Int_t &BunchLen,Int_t &Count)const;
71   //This method is used to deduce which is the next table that as to be used to interpret the next value
72   //reading the Altro format
73   void    StoreValue(UInt_t val,UChar_t len);
74   //This method is used to store a value in the compressed file 
75   UInt_t  Mirror(UInt_t val,UChar_t len)const;
76   //This method is used to get the specular value of a given value
77   //for instance the specular value of 12345 is 54321
78   void    Flush();
79   //This method is used to complete and store the buffer in the output file when it isn't completely full 
80   UInt_t  ReadWord(UInt_t NumberOfBit);
81   //this method is used to read a specified number of bits from the compressed file
82   UInt_t  ReadWordBuffer(UInt_t NumberOfBit);
83   //this method is used to read a specified number of bits from the compressed memory buffer
84   inline void   AdjustWordBuffer(UInt_t NumberOfBit);
85   inline UInt_t ReadWordBufferWithLUTs();
86   inline UInt_t ReadBitFromWordBuffer();
87   inline UInt_t ReadBitFromLUTBuffer(UInt_t *buffer);
88   void    ReadTrailer(Int_t &WordsNumber,Int_t &PadNumber,Int_t &RowNumber,Int_t &SecNumberr,Bool_t Memory);
89   //This method is used to read the trailer 
90   inline UInt_t GetDecodedWordBuffer(AliTPCHNode* root);
91   //This method is used to get a decoded word from the compressed file
92   inline UInt_t GetDecodedWord(AliTPCHNode* root);
93   //This method is used to get a decoded word from the compressed file
94   inline UInt_t GetDecodedWordBufferWithLUTs(UInt_t* LUTDimension,AliTPCHNode** LUTNode);
95   inline UInt_t GetDecodedLUTBuffer(AliTPCHNode** node,UInt_t *buffer);
96
97   fstream f;                  // f is the logical name for the compressed and uncompressed file
98   ofstream fStat;             // Logical name for the Statistics file
99   UInt_t  fBuffer;            // buffer 
100   Int_t   fDimBuffer;         // buffer dimension (32 bit)
101   Int_t   fFreeBitsBuffer;    // number of free bits inside the buffer
102   UInt_t  fBitsToRead;        // number of bits to be read
103   UInt_t  fPos;               // current file position
104   Int_t   fVerbose;           // verbose level (0 silent, !=0 output messages)
105   UInt_t  fFillWords;         // Number of hexadecimally words (2AA pattern) inside a pad data block 
106   UInt_t* fPointBuffer;       //pointer to the compressed raw data
107   static const UInt_t   fgkTableDimension = 7; // size of LUTs for fast decompression
108
109   ClassDef(AliTPCCompression,1)
110 };
111 #endif