]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/comp/AliHLTCOMPHuffmanAltro.h
New classes for finding multiple vertices (in case of pile-up). They will be used...
[u/mrichter/AliRoot.git] / HLT / comp / AliHLTCOMPHuffmanAltro.h
1 // @(#) $Id$
2
3 #ifndef ALIHLTCOMPHUFFMANALTRO_H
4 #define ALIHLTCOMPHUFFMANALTRO_H
5
6 /**************************************************************************
7  * This file is property of and copyright by the ALICE HLT Project        * 
8  * All rights reserved.                                                   *
9  *                                                                        *
10  * Primary Author: Jenny Wagner  (jwagner@cern.ch)                        *
11  *                                                                        *
12  * Permission to use, copy, modify and distribute this software and its   *
13  * documentation strictly for non-commercial purposes is hereby granted   *
14  * without fee, provided that the above copyright notice appears in all   *
15  * copies and that both the copyright notice and this permission notice   *
16  * appear in the supporting documentation. The authors make no claims     *
17  * about the suitability of this software for any purpose. It is          * 
18  * provided "as is" without express or implied warranty.                  *
19  **************************************************************************/
20
21 /** @file   AliHLTCOMPHuffmanAltro.h
22     @author Jenny Wagner
23     @date   20-11-2007
24     @brief  The Huffman compressor
25 */
26
27 #include "AliHLTLogging.h"
28 #include "AliHLTCOMPHuffmanData.h"
29
30 /** @class   AliHLTCOMPHuffmanAltro
31     @author Jenny Wagner
32     @date   20-11-2007
33     @brief  The Huffman Compressor with functions training (for Calibration), compress and decompress, calculate entropy  
34 */
35 class AliHLTCOMPHuffmanAltro : public AliHLTLogging
36 {
37  public:
38
39   /** constructor for test use only */
40   AliHLTCOMPHuffmanAltro();
41
42   /** standard constructor
43    *
44    * @param compressionswitch   decides whether to compress or decompress (TRUE for calibration/training)
45    * @param trainingmode        decides whether to create a new Huffman table 
46    * @param translationtable    pointer to lookup Huffman table for compression and decompression
47    * @param nrcutrailerwords    number of NRCU trailer words (ranging from 1 to 3)
48    */
49   AliHLTCOMPHuffmanAltro(Bool_t compressionswitch, Bool_t trainingmode, AliHLTCOMPHuffmanCodeData::AliHLTCOMPHuffmanCodeStruct* translationtable, Int_t nrcutrailerwords);
50   /** destructor */
51   virtual ~AliHLTCOMPHuffmanAltro();
52
53   /** SetInputData 
54    *  @param inputdata  pointer to input data
55    *  @param datasize   size of input data
56    */
57   void SetInputData(void* inputdata, unsigned long datasize);
58   
59   /** SetOutputData
60    *  @param outputdata  pointer to output data
61    *  @param outputsize  size of output data
62    */
63   void SetOutputData(AliHLTUInt8_t* outputdata, unsigned long outputsize);
64
65   /** get patch from component and set it as currently processed patch of this class  (only needed for binary output)*/
66   //void SetPatch(Int_t patch) {fPatch = patch;};
67
68  /** get slice from component and set it as currently processed slice of this class (only needed for binary output) */
69   // void SetSlice(Int_t slice) {fSlice = slice;};
70   
71   /** GetOutputDataSize (which is unknown at first and has to be calculated
72    * @return output data size
73   */
74   unsigned long GetOutputDataSize();
75
76   /** initialise training table */
77   void InitNewTrainingTable();
78
79   /** write out new HuffmanData
80    * @param huffmandata   pointer to Huffman data 
81   */
82   void SetHuffmanData(AliHLTCOMPHuffmanData* huffmandata);
83
84   /** get training table from HuffmanData instance
85    * @param huffmandata  pointer to Huffman data
86   */
87   void GetTrainingTable(AliHLTCOMPHuffmanData* huffmandata);
88
89   /** initialise the translation table
90    * @param huffmandata  pointer to Huffman data
91   */
92   void GetTranslationTable(AliHLTCOMPHuffmanData* huffmandata);
93
94   /** function to compress or decompress data */
95   void ProcessData();
96
97  /** function to create Huffman code table by means of private functions
98   * @return zero upon success
99  */
100   Int_t CreateCodeTable();
101
102   /** calculate the entropy of the input data
103    * @return calculated entropy (in double precision)
104   */
105   Double_t GetEntropy();
106
107   /** function to read 10 bit data in and write same 10 bit data out (performance test) */
108   Int_t CopyData();
109
110  private:
111
112   /** copy constructor prohibited */
113   AliHLTCOMPHuffmanAltro(const AliHLTCOMPHuffmanAltro&);
114   /** assignment operator prohibited */
115   AliHLTCOMPHuffmanAltro& operator=(const AliHLTCOMPHuffmanAltro&);
116
117   /** function to calculate the entropy of the incoming data */
118   Int_t CalcEntropy();
119
120   /** function for merge sorting the array data 
121    * @param unsortedarray   unsorted array of data from occurrence table
122    * @param n               number of entries in the unsorted array
123    * @return pointer to first element of sorted list
124    */
125   AliHLTCOMPHuffmanOccurrenceData::AliHLTCOMPHuffmanDataStruct* Mergesort(AliHLTCOMPHuffmanOccurrenceData::AliHLTCOMPHuffmanDataStruct* unsortedarray, Int_t n);
126
127   /** function to create the HuffmanCode and write it in a sorted array 
128    * @param treeroot           pointer to root of Huffman tree
129    * @param HuffmanCodearray   pointer to final Huffman code table (array)
130    * @return zero upon success
131    */ 
132  Int_t HuffmanCode(AliHLTCOMPHuffmanData::AliHLTCOMPHuffmanTreeDataStruct* treeroot, AliHLTCOMPHuffmanCodeData::AliHLTCOMPHuffmanCodeStruct* HuffmanCodearray);
133   
134   /** function to create the Huffmantree
135    * @param listroot   pointer to first element of sorted list to build Huffman tree from
136    * @param listend    pointer to last element of sorted list to build Huffman tree from
137    * @param n          number of entries in the list
138    * @return pointer to root of Huffman tree
139    */
140  AliHLTCOMPHuffmanData::AliHLTCOMPHuffmanTreeDataStruct* CreateHuffmanTree(AliHLTCOMPHuffmanData::AliHLTCOMPHuffmanTreeDataStruct* listroot,  AliHLTCOMPHuffmanData::AliHLTCOMPHuffmanTreeDataStruct* listend, Int_t n);
141   
142   /** entropy encoding function: read in data, table lookup to encode, write encoded data to output array and set fOutputDataSize
143    * @return zero upon success
144    */
145  Int_t EntropyCompression();
146
147   /** merge sorting function for translation table
148    * @param unsortedarray   Huffman code table which is not sorted for decompression yet
149    * @param n               number of entries in the unsorted array
150    * @return pointer to first element of sorted list
151    */
152  AliHLTCOMPHuffmanCodeData::AliHLTCOMPHuffmanCodeStruct* TTMergesort(AliHLTCOMPHuffmanCodeData::AliHLTCOMPHuffmanCodeStruct* unsortedarray, Int_t n);
153     
154   /** entropy decoding function
155    * @return zero upon success
156    */
157   Int_t EntropyDecompression();
158   
159   /** training function for the translation table
160    * @return zero upon success
161    */
162   Int_t TrainingData(); 
163
164   /** boolean to decide whether to process data (FALSE) or create a new code table (TRUE) */
165   Bool_t fTrainingMode;                         // choice if new codetable is created or not
166   /** boolean to decide whether to compress (TRUE) or decompress (FALSE) incoming data (automatically TRUE for code creation) */
167   Bool_t fCompressionSwitch;                    // mode choice (training, compress, decompress)
168   /** pointer to input data */
169   AliHLTUInt8_t* fPointer2InData;               // pointer to input data (uncompressed raw data)
170   /** pointer to output data */
171   AliHLTUInt64_t* fPointer2OutData;             // pointer to output data (compressed data)
172   /** input data size */
173   unsigned long fInputDataSize;                 // input data size
174   /** output data size */
175   UInt_t fOutputDataSize;                        // output data size
176   /** number of NRCU trailer words */
177   UInt_t fNrcuTrailerwords;                      // number of RCU trailerwords
178   /** calculated entropy of input data */
179   Double_t fEntropy;                            // entropy of the file
180
181   //AliHLTUInt8_t fSlice;                         // transient variables to specify
182   //AliHLTUInt8_t fPatch;                         // where output root file comes from
183  
184   /** pointer to occurrence table */
185   AliHLTCOMPHuffmanOccurrenceData::AliHLTCOMPHuffmanDataStruct* fTrainingTable;       // training table with amplitudes and resp. abundances
186   /** pointer to Huffman code table */
187   AliHLTCOMPHuffmanCodeData::AliHLTCOMPHuffmanCodeStruct* fTranslationTable;    // Huffman Entropy Code Table
188
189
190   ClassDef(AliHLTCOMPHuffmanAltro, 0)
191         };
192 #endif