Add support for 64 bits
[u/mrichter/AliRoot.git] / RAW / AliTPCHuffman.h
CommitLineData
2e9f335b 1/* Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
2 * See cxx source for full Copyright notice */
3
4///////////////////////////////////////////////////
5// Huffman Table associated classes for set:TPC //
6///////////////////////////////////////////////////
7
8
9#ifndef AliTPCHUFFMAN_H
10#define AliTPCHUFFMAN_H
a79660fb 11
2e9f335b 12class AliTPCBuffer160;
13
14class AliTPCHNode: public TObject {
15 public:
16 AliTPCHNode(); //default constructor
17 AliTPCHNode(Int_t symbol, Double_t freq);
18 virtual ~AliTPCHNode() {}
19 AliTPCHNode(const AliTPCHNode &source); // copy constructor
20 AliTPCHNode& operator=(const AliTPCHNode &source); // ass. op.
21
22 Bool_t IsSortable() const{return kTRUE;}
23 Int_t Compare(const TObject *obj) const;
24 void SetLeft(AliTPCHNode* point){fLeft=point;}
25 void SetRight(AliTPCHNode* point){fRight=point;}
26 AliTPCHNode* GetRight()const{return fRight;}
27 AliTPCHNode* GetLeft()const{return fLeft;}
a79660fb 28 void SetSymbol(Int_t sym){fSymbol=sym;}
29 void SetFrequency(Double_t freq){fFrequency=freq;}
2e9f335b 30 Double_t GetFrequency()const{return fFrequency;}
a79660fb 31 Int_t GetSymbol()const{return fSymbol;}
2e9f335b 32
33 private:
34 Int_t fSymbol; // Symbols
a79660fb 35 Double_t fFrequency; // Frequency of the Symbol
2e9f335b 36 AliTPCHNode *fLeft; // Pointer to the left son
a79660fb 37 AliTPCHNode *fRight; // Pointer to the right son
2e9f335b 38 ClassDef(AliTPCHNode,1)
39};
40/////////////////////////////////////////////////////////////////////////////////////////////////
41class AliTPCHTable: public TObject{
42 public:
43 AliTPCHTable();
44 AliTPCHTable(Int_t size);
45 virtual ~AliTPCHTable();
46 AliTPCHTable(const AliTPCHTable &source); // copy constructor
47 AliTPCHTable& operator=(const AliTPCHTable &source); // ass. op.
48
49 Int_t Size()const {return fSize;}
50 UChar_t* CodeLen()const {return fCodeLen;}
51 Double_t* Code()const {return fCode;}
52 Short_t* Sym()const {return fSym;}
53 void SetCodeLen(UChar_t len,Int_t val);
54 void SetCode(Double_t code,Int_t val);
55 TObjArray* HNodes()const {return fHNodes;}
56 void PrintTable()const;
a79660fb 57 //This method builds the Huffman tree starting from the frequencies that are
2e9f335b 58 //strored temporary in fCode array
59 Int_t BuildHTable();
60 //This method returns the number of words stored in the fSym array
0b3c7dfc 61 UInt_t GetWordsNumber()const{return fNum;}
2e9f335b 62 //This method increase by one the frequency of each value that is present
63 //in the specified file
64 Int_t GetFrequencies(const char* fname);
65 //This method increase by one the frequency of a given value
66 Int_t SetFrequency(const Int_t Val);
a79660fb 67 //This method stores the frequency of the symbol in a text file
68 Int_t StoreFrequencies(const char *fname)const;
2e9f335b 69 void CompleteTable(Int_t k);
70 Double_t GetEntropy()const;
71 void SetVerbose(Int_t val){fVerbose=val;}
a79660fb 72 //Method to set directly a frequency
2e9f335b 73 Int_t SetValFrequency(const Int_t Val,Double_t Value);
9f992f70 74 Int_t NormalizeFrequencies();
2e9f335b 75 private:
76 //This method executes the pre-order visit of an Huffman tree and calculates the
77 //codeword for each leaf
0b3c7dfc 78 Bool_t SpanTree(AliTPCHNode*start, UInt_t code, UChar_t len);
a79660fb 79 void ResetHNodes(); //Reset the array fHNodes but not delete the removed objects
2e9f335b 80 void ClearTable(); //Reset the table
a79660fb 81 Int_t fSize; //size of the arrays fCodelen and fCode
82 UChar_t *fCodeLen; //![fSize] number of bits array
83 Double_t *fCode; //![fSize] coded symbols array
2e9f335b 84
a79660fb 85 Short_t *fSym; //![fSize] array of input symbols
86 TObjArray *fHNodes; // array of nodes
87 Int_t fNnodes; // number of nodes
0b3c7dfc 88 UInt_t fNum; // number of words
a79660fb 89 Int_t fVerbose; // if fVerbose== 0 no output messages; fVerbose!=0 output messages are printed out
90 ClassDef(AliTPCHTable,1) //Huffman Table object for set:TPC
2e9f335b 91};
92#endif