]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCHuffman.h
Adding some QCD diffractive states to the PDG list
[u/mrichter/AliRoot.git] / TPC / AliTPCHuffman.h
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
11
12 class AliTPCBuffer160;
13
14 class 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;}
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;}
32
33  private:
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)     
39 };
40 /////////////////////////////////////////////////////////////////////////////////////////////////
41 class 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;
57   //This method builds the Huffman tree starting from the frequencies that are 
58   //strored temporary in fCode array
59   Int_t      BuildHTable();
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);
74  private:
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
83   
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
90 };
91 #endif