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 UInt_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(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(Int_t Val,Double_t Value);
74 Int_t NormalizeFrequencies();
76 //This method executes the pre-order visit of an Huffman tree and calculates the
77 //codeword for each leaf
78 Bool_t SpanTree(AliTPCHNode*start, UInt_t code, UChar_t len);
79 void ResetHNodes(); //Reset the array fHNodes but not delete the removed objects
80 void ClearTable(); //Reset the table
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
85 Short_t *fSym; //![fSize] array of input symbols
86 TObjArray *fHNodes; // array of nodes
87 Int_t fNnodes; // number of nodes
88 UInt_t fNum; // number of words
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