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
28 #include "AliHLTLogging.h"
29 #include "AliHLTCOMPHuffmanData.h"
31 class AliRawReaderMemory;
32 class AliAltroRawStreamV3;
34 /** @class AliHLTCOMPHuffmanAltro
37 @brief The Huffman Compressor with functions training (for Calibration), compress and decompress, calculate entropy
39 class AliHLTCOMPHuffmanAltro : public TObject, public AliHLTLogging
43 /** constructor for test use only */
44 AliHLTCOMPHuffmanAltro();
46 /** standard constructor
48 * @param compressionswitch decides whether to compress or decompress (TRUE for calibration/training)
49 * @param trainingmode decides whether to create a new Huffman table
50 * @param translationtable pointer to lookup Huffman table for compression and decompression
51 * @param nrcutrailerwords number of NRCU trailer words (ranging from 1 to 3)
53 AliHLTCOMPHuffmanAltro(Bool_t compressionswitch, Bool_t trainingmode, AliHLTCOMPHuffmanCodeData::AliHLTCOMPHuffmanCodeStruct* translationtable, Int_t nrcutrailerwords);
55 virtual ~AliHLTCOMPHuffmanAltro();
58 * Data buffer has to be valid all the time, no internal copy.
59 * @param memory pointer to input data
60 * @param size size of input data
61 * @param equipmentId equipment (ddl) id
63 int AddInputData(UChar_t* memory, ULong_t size, Int_t equipmentId);
66 * @param outputdata pointer to output data
67 * @param outputsize size of output data
69 int SetOutputData(AliHLTUInt8_t* outputdata, unsigned long outputsize);
72 * Reset and prepare for new event
76 /** GetOutputDataSize (which is unknown at first and has to be calculated
77 * @return output data size
79 unsigned long GetOutputDataSize();
81 /** initialise training table */
82 int InitNewTrainingTable();
84 /** write out new HuffmanData
85 * @param huffmandata pointer to Huffman data
87 int SetHuffmanData(AliHLTCOMPHuffmanData* huffmandata) const;
89 /** get training table from HuffmanData instance
90 * @param huffmandata pointer to Huffman data
92 int GetTrainingTable(const AliHLTCOMPHuffmanData* huffmandata);
94 /** initialise the translation table
95 * @param huffmandata pointer to Huffman data
97 int GetTranslationTable(const AliHLTCOMPHuffmanData* huffmandata);
99 /** function to compress or decompress data */
102 /** function to create Huffman code table by means of private functions
103 * @return zero upon success
105 Int_t CreateCodeTable();
107 /** calculate the entropy of the input data
108 * @return calculated entropy (in double precision)
110 Double_t GetEntropy();
112 /** function to read 10 bit data in and write same 10 bit data out (performance test) */
116 virtual void Print(Option_t* option = "") const;
120 /** copy constructor prohibited */
121 AliHLTCOMPHuffmanAltro(const AliHLTCOMPHuffmanAltro&);
122 /** assignment operator prohibited */
123 AliHLTCOMPHuffmanAltro& operator=(const AliHLTCOMPHuffmanAltro&);
125 /** function to calculate the entropy of the incoming data */
126 /// FIXME: the size of the array is not known, everything assumes size TIMEBINS
127 Int_t CalcEntropy(const AliHLTCOMPHuffmanOccurrenceData::AliHLTCOMPHuffmanDataStruct* occurrencetable=NULL);
129 /** function for merge sorting the array data
130 * @param unsortedarray unsorted array of data from occurrence table
131 * @param n number of entries in the unsorted array
132 * @return pointer to first element of sorted list
134 AliHLTCOMPHuffmanOccurrenceData::AliHLTCOMPHuffmanDataStruct* Mergesort(AliHLTCOMPHuffmanOccurrenceData::AliHLTCOMPHuffmanDataStruct* unsortedarray, Int_t n);
136 /** function to create the HuffmanCode and write it in a sorted array
137 * @param treeroot pointer to root of Huffman tree
138 * @param HuffmanCodearray pointer to final Huffman code table (array)
139 * @return zero upon success
141 Int_t HuffmanCode(AliHLTCOMPHuffmanData::AliHLTCOMPHuffmanTreeDataStruct* treeroot, AliHLTCOMPHuffmanCodeData::AliHLTCOMPHuffmanCodeStruct* HuffmanCodearray);
143 /** function to create the Huffmantree
144 * @param listroot pointer to first element of sorted list to build Huffman tree from
145 * @param listend pointer to last element of sorted list to build Huffman tree from
146 * @param n number of entries in the list
147 * @return pointer to root of Huffman tree
149 AliHLTCOMPHuffmanData::AliHLTCOMPHuffmanTreeDataStruct* CreateHuffmanTree(AliHLTCOMPHuffmanData::AliHLTCOMPHuffmanTreeDataStruct* listroot, AliHLTCOMPHuffmanData::AliHLTCOMPHuffmanTreeDataStruct* listend, Int_t n);
151 /** entropy encoding function: read in data, table lookup to encode, write encoded data to output array and set fOutputDataSize
152 * @return zero upon success
154 Int_t EntropyCompression();
156 /** merge sorting function for translation table
157 * @param unsortedarray Huffman code table which is not sorted for decompression yet
158 * @param n number of entries in the unsorted array
159 * @return pointer to first element of sorted list
161 AliHLTCOMPHuffmanCodeData::AliHLTCOMPHuffmanCodeStruct* TTMergesort(AliHLTCOMPHuffmanCodeData::AliHLTCOMPHuffmanCodeStruct* unsortedarray, Int_t n);
163 /** entropy decoding function
164 * @return zero upon success
166 Int_t EntropyDecompression();
168 /** training function for the translation table
169 * @return zero upon success
171 Int_t TrainingData();
173 /// raw reader instance
174 AliRawReaderMemory* fpRawReader; //! transient
175 /// raw stream decoder
176 AliAltroRawStreamV3* fpAltroRawStream; //! transient
178 /** boolean to decide whether to process data (FALSE) or create a new code table (TRUE) */
179 Bool_t fTrainingMode; // choice if new codetable is created or not
180 /** boolean to decide whether to compress (TRUE) or decompress (FALSE) incoming data (automatically TRUE for code creation) */
181 Bool_t fCompressionSwitch; // mode choice (training, compress, decompress)
182 /** pointer to input data */
183 AliHLTUInt8_t* fPointer2InData; // pointer to input data (uncompressed raw data)
184 /** pointer to output data */
185 AliHLTUInt64_t* fPointer2OutData; // pointer to output data (compressed data)
186 /** input data size */
187 unsigned long fInputDataSize; // input data size
188 /** output data size */
189 UInt_t fOutputDataSize; // output data size
190 /** number of NRCU trailer words */
191 UInt_t fNrcuTrailerwords; // number of RCU trailerwords
192 /** calculated entropy of input data */
193 Double_t fEntropy; // entropy of the file
195 int fVerbosity; //! verbosity
197 //AliHLTUInt8_t fSlice; // transient variables to specify
198 //AliHLTUInt8_t fPatch; // where output root file comes from
200 /** pointer to occurrence table */
201 AliHLTCOMPHuffmanOccurrenceData::AliHLTCOMPHuffmanDataStruct* fTrainingTable; // training table with amplitudes and resp. abundances
202 /** pointer to Huffman code table */
203 AliHLTCOMPHuffmanCodeData::AliHLTCOMPHuffmanCodeStruct* fTranslationTable; // Huffman Entropy Code Table
206 ClassDef(AliHLTCOMPHuffmanAltro, 0)