3 #ifndef ALIHLTCOMPHUFFMANALTRO_H
4 #define ALIHLTCOMPHUFFMANALTRO_H
6 /**************************************************************************
7 * This file is property of and copyright by the ALICE HLT Project *
8 * All rights reserved. *
10 * Primary Author: Jenny Wagner (jwagner@cern.ch) *
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 **************************************************************************/
21 /** @file AliHLTCOMPHuffmanAltro.h
24 @brief The Huffman compressor
27 #include "AliHLTLogging.h"
28 #include "AliHLTCOMPHuffmanData.h"
30 /** @class AliHLTCOMPHuffmanAltro
33 @brief The Huffman Compressor with functions training (for Calibration), compress and decompress, calculate entropy
35 class AliHLTCOMPHuffmanAltro : public AliHLTLogging
39 /** constructor for test use only */
40 AliHLTCOMPHuffmanAltro();
42 /** standard constructor
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)
49 AliHLTCOMPHuffmanAltro(Bool_t compressionswitch, Bool_t trainingmode, AliHLTCOMPHuffmanCodeData::AliHLTCOMPHuffmanCodeStruct* translationtable, Int_t nrcutrailerwords);
51 virtual ~AliHLTCOMPHuffmanAltro();
54 * @param inputdata pointer to input data
55 * @param datasize size of input data
57 void SetInputData(void* inputdata, unsigned long datasize);
60 * @param outputdata pointer to output data
61 * @param outputsize size of output data
63 void SetOutputData(AliHLTUInt8_t* outputdata, unsigned long outputsize);
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;};
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;};
71 /** GetOutputDataSize (which is unknown at first and has to be calculated
72 * @return output data size
74 unsigned long GetOutputDataSize();
76 /** initialise training table */
77 void InitNewTrainingTable();
79 /** write out new HuffmanData
80 * @param huffmandata pointer to Huffman data
82 void SetHuffmanData(AliHLTCOMPHuffmanData* huffmandata);
84 /** get training table from HuffmanData instance
85 * @param huffmandata pointer to Huffman data
87 void GetTrainingTable(AliHLTCOMPHuffmanData* huffmandata);
89 /** initialise the translation table
90 * @param huffmandata pointer to Huffman data
92 void GetTranslationTable(AliHLTCOMPHuffmanData* huffmandata);
94 /** function to compress or decompress data */
97 /** function to create Huffman code table by means of private functions
98 * @return zero upon success
100 Int_t CreateCodeTable();
102 /** calculate the entropy of the input data
103 * @return calculated entropy (in double precision)
105 Double_t GetEntropy();
107 /** function to read 10 bit data in and write same 10 bit data out (performance test) */
112 /** copy constructor prohibited */
113 AliHLTCOMPHuffmanAltro(const AliHLTCOMPHuffmanAltro&);
114 /** assignment operator prohibited */
115 AliHLTCOMPHuffmanAltro& operator=(const AliHLTCOMPHuffmanAltro&);
117 /** function to calculate the entropy of the incoming data */
120 /** function for merge sorting the array data
121 * @param unsorted array 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
125 AliHLTCOMPHuffmanOccurrenceData::AliHLTCOMPHuffmanDataStruct* Mergesort(AliHLTCOMPHuffmanOccurrenceData::AliHLTCOMPHuffmanDataStruct* unsortedarray, Int_t n);
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
132 Int_t HuffmanCode(AliHLTCOMPHuffmanData::AliHLTCOMPHuffmanTreeDataStruct* treeroot, AliHLTCOMPHuffmanCodeData::AliHLTCOMPHuffmanCodeStruct* HuffmanCodearray);
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
140 AliHLTCOMPHuffmanData::AliHLTCOMPHuffmanTreeDataStruct* CreateHuffmanTree(AliHLTCOMPHuffmanData::AliHLTCOMPHuffmanTreeDataStruct* listroot, AliHLTCOMPHuffmanData::AliHLTCOMPHuffmanTreeDataStruct* listend, Int_t n);
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
145 Int_t EntropyCompression();
147 /** merge sorting function for translation table
148 * @param unsorted array 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
152 AliHLTCOMPHuffmanCodeData::AliHLTCOMPHuffmanCodeStruct* TTMergesort(AliHLTCOMPHuffmanCodeData::AliHLTCOMPHuffmanCodeStruct* unsortedarray, Int_t n);
154 /** entropy decoding function
155 * @return zero upon success
157 Int_t EntropyDecompression();
159 /** training function for the translation table
160 * @return zero upon success
162 Int_t TrainingData();
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
181 //AliHLTUInt8_t fSlice; // transient variables to specify
182 //AliHLTUInt8_t fPatch; // where output root file comes from
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
190 ClassDef(AliHLTCOMPHuffmanAltro, 0)