1 /* Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
2 * See cxx source for full Copyright notice */
4 ///////////////////////////////////////////////////
5 // Huffman Table associated classes for set:TPC //
6 ///////////////////////////////////////////////////
9 #ifndef AliTPCHUFFMAN_H
10 #define AliTPCHUFFMAN_H
12 class AliTPCBuffer160;
14 class AliTPCHNode: public TObject {
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.
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;}
28 void SetSymbol(Int_t sym){fSymbol=sym;}
29 void SetFrequency(Double_t freq){fFrequency=freq;}
30 Double_t GetFrequency()const{return fFrequency;}
31 Int_t GetSymbol()const{return fSymbol;}
34 Int_t fSymbol; // Symbols
35 Double_t fFrequency; // Frequency of the Symbol
36 AliTPCHNode *fLeft; // Pointer to the left son
37 AliTPCHNode *fRight; // Pointer to the right son
38 ClassDef(AliTPCHNode,1)
40 /////////////////////////////////////////////////////////////////////////////////////////////////
41 class AliTPCHTable: public TObject{
44 AliTPCHTable(Int_t size);
45 virtual ~AliTPCHTable();
46 AliTPCHTable(const AliTPCHTable &source); // copy constructor
47 AliTPCHTable& operator=(const AliTPCHTable &source); // ass. op.
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;
57 //This method builds the Huffman tree starting from the frequencies that are
58 //strored temporary in fCode array
60 //This method returns the number of words stored in the fSym array
61 ULong_t GetWordsNumber()const{return fNum;}
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);
67 //This method stores the frequency of the symbol in a text file
68 Int_t StoreFrequencies(const char *fname)const;
69 void CompleteTable(Int_t k);
70 Double_t GetEntropy()const;
71 void SetVerbose(Int_t val){fVerbose=val;}
72 //Method to set directly a frequency
73 Int_t SetValFrequency(const Int_t Val,Double_t Value);
75 //This method executes the pre-order visit of an Huffman tree and calculates the
76 //codeword for each leaf
77 Bool_t SpanTree(AliTPCHNode*start, ULong_t code, UChar_t len);
78 void ResetHNodes(); //Reset the array fHNodes but not delete the removed objects
79 void ClearTable(); //Reset the table
80 Int_t fSize; //size of the arrays fCodelen and fCode
81 UChar_t *fCodeLen; //![fSize] number of bits array
82 Double_t *fCode; //![fSize] coded symbols array
84 Short_t *fSym; //![fSize] array of input symbols
85 TObjArray *fHNodes; // array of nodes
86 Int_t fNnodes; // number of nodes
87 ULong_t fNum; // number of words
88 Int_t fVerbose; // if fVerbose== 0 no output messages; fVerbose!=0 output messages are printed out
89 ClassDef(AliTPCHTable,1) //Huffman Table object for set:TPC