3 #ifndef ALIHLTDATADEFLATER_H
4 #define ALIHLTDATADEFLATER_H
5 //* This file is property of and copyright by the ALICE HLT Project *
6 //* ALICE Experiment at CERN, All rights reserved. *
7 //* See cxx source for full Copyright notice *
9 /// @file AliHLTDataDeflater.h
10 /// @author Matthias Richter, Timm Steinbeck
12 /// @brief Data deflater class storing only necessary bits
13 /// @note Code original from AliHLTTPCCompModelDeflater
15 #include "AliHLTLogging.h"
16 #include "AliHLTDataTypes.h"
17 #include "AliHLTStdIncludes.h"
25 * @class AliHLTDataDeflater
26 * Data deflater class to write a bitstream into a buffer. The necessary
27 * number of bits for each value is written to a stream without gaps.
28 * The buffer can be padded to fill full bytes and continue writing at the
31 * @ingroup alihlt_base
33 class AliHLTDataDeflater : public AliHLTLogging
36 /// standard constructor
39 ~AliHLTDataDeflater();
41 /** function to initialise bit data output
42 * @param output AliHLTUInt8_t* pointer to output data
43 * @param outputSize UInt_t output size
45 int InitBitDataOutput( AliHLTUInt8_t* output, UInt_t outputSize );
47 /** function to close bit data output */
48 void CloseBitDataOutput();
50 /** function to get current byte output position
51 * @return unsigned long value for current byte output position
53 unsigned long GetCurrentByteOutputPosition() const
55 return (unsigned long)( fBitDataCurrentOutput - fBitDataCurrentOutputStart );
58 /** function to get current bit output position
59 * @return unsigned long value for current bit output position
61 unsigned GetCurrentBitOutputPosition() const
63 return fBitDataCurrentPosInWord;
66 /** function to get current output byte
67 * @param offset Int_t (set to zero if not specified explicitly)
68 * @return AliHLTUInt8_t value for current output byte
70 AliHLTUInt8_t GetCurrentOutputByte( Int_t offset=0 ) const;
72 /** function to get bit data output size bytes
73 * @return UInt_t value of bit data output size bytes
75 UInt_t GetBitDataOutputSizeBytes() const
77 return fBitDataCurrentOutput-fBitDataCurrentOutputStart;
80 /** function for output bit
81 * @param value AliHLTUInt32_t const & input
82 * @return boolean (output bit)
84 bool OutputBit( AliHLTUInt32_t const & value );
86 /** function to output bits
87 * @param value AliHLTUInt64_t const &
88 * @param bitCount UInt_t const &
89 * @return zero upon success
91 bool OutputBits( AliHLTUInt64_t const & value, UInt_t const & bitCount );
93 /** function to output bits from a bitset
94 * @param value AliHLTUInt64_t const &
95 * @param bitCount UInt_t const &
96 * @return zero upon success
98 bool OutputBits( std::bitset<64> const & value, UInt_t const & bitCount );
100 /* function pad 8 bits */
103 /** function to output bytes
104 * @param data AliHLTUInt8_t const *
105 * @param byteCount UInt_t const &
106 * @return boolean (output bytes)
108 bool OutputBytes( AliHLTUInt8_t const * data, UInt_t const & byteCount );
110 /// add a histogram for deflater statistic of the corresponding parameter
111 /// a histogram is created with default settings if h is not specified; if
112 /// provided, the ownership goes over to the base class
113 int AddHistogram(int id, const char* name, int bitWidth, TH1* h=NULL);
115 /// enable statistics accounting
116 int EnableStatistics();
118 /// check if statistics writing is enabled
119 bool DoStatistics() const {return fHistograms!=NULL;}
121 /// fill statistics for a parameter
122 /// @param id id of the parameter
123 /// @param value value
124 /// @param length bit length
125 /// @param codingWeight fraction of bit lenght used for this value
126 int FillStatistics(int id, AliHLTUInt64_t value, unsigned length, float codingWeight=0.0);
128 static float CalcEntropy(TH1* histo, const char* option="", int mode=0);
130 /// save data according to option
131 virtual void SaveAs(const char *filename="",Option_t *option="") const;
133 /// clear the object and reset pointer references
134 virtual void Clear(Option_t * /*option*/ ="");
137 virtual void Print(Option_t *option="") const;
140 virtual void Print(ostream& out, Option_t *option="") const;
143 virtual TObject *FindObject(const char */*name*/) const {return NULL;}
145 /// write bit pattern of a parameter to the current byte and position
146 virtual bool OutputParameterBits( int parameterId, AliHLTUInt64_t const & value );
148 /// write bit pattern of a parameter to the current byte and position
149 virtual bool OutputParameterBits( int parameterId, AliHLTUInt64_t const & value, int lengthOffset );
151 /// return unique version of the deflater, base class has version 0
152 virtual int GetDeflaterVersion() const {return 0;}
157 /// copy constructor prohibited
158 AliHLTDataDeflater(const AliHLTDataDeflater&);
159 /// assignment operator prohibited
160 AliHLTDataDeflater& operator=(const AliHLTDataDeflater&);
162 /// bit data current word
163 AliHLTUInt8_t fBitDataCurrentWord; //! bit data current word
164 /// bit data current position in word
165 UInt_t fBitDataCurrentPosInWord; //! data current position in word
166 /// bit data current output
167 AliHLTUInt8_t *fBitDataCurrentOutput; //! bit data current output
168 /// bit data current output start
169 AliHLTUInt8_t *fBitDataCurrentOutputStart; //! bit data current output start
170 /// bit data current output end
171 AliHLTUInt8_t *fBitDataCurrentOutputEnd; //! bit data current output end
173 TObjArray* fHistograms; //! list of histograms for parameters
174 TH2* fParameterCompression; //! compression for individual parameters
175 TH2* fParameterSize; //! accumulated size for individual parameters
177 ClassDef(AliHLTDataDeflater, 0)
180 ostream& operator<<(ostream &out, const AliHLTDataDeflater& me);