3 #ifndef ALIHLTDATAINFLATER_H
4 #define ALIHLTDATAINFLATER_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 AliHLTDataInflater.h
10 /// @author Matthias Richter, Timm Steinbeck
12 /// @brief Data inflater reading the bitstream from the AliHLTDataDeflater
13 /// @note Code original from AliHLTTPCCompModelInflater
15 #include "AliHLTLogging.h"
16 #include "AliHLTDataTypes.h"
17 #include "AliHLTStdIncludes.h"
20 * @class AliHLTDataInflater
21 * Data inflating interface to a bitstream encoded by AliHLTDataInflater
26 * @ingroup alihlt_base
28 class AliHLTDataInflater : public AliHLTLogging
31 /// standard constructor
34 ~AliHLTDataInflater();
36 /** init inflater for reading
37 * @param input AliHLTUInt8_t* pointer to input data
38 * @param inputSize UInt_t input data size
40 int InitBitDataInput(const AliHLTUInt8_t* input, UInt_t inputSize );
42 /** close inflater for reading */
43 void CloseBitDataInput();
45 /** function to get current byte input position
46 * @return unsigned long value of current byte input position
48 unsigned long GetCurrentByteInputPosition() const
50 return (unsigned long)( fBitDataCurrentInput - fBitDataCurrentInputStart );
53 /** function to get current bit input position
54 * @return unsigned value of current bit input position
56 unsigned GetCurrentBitInputPosition() const
58 return fBitDataCurrentPosInWord;
61 /** function to get current input byte
62 * @return AliHLTUInt8_t value of current input byte
64 AliHLTUInt8_t GetCurrentInputByte() const
66 return fBitDataCurrentWord;
69 /** function to determine end of bit input
70 * @return boolean if end is reached or not
72 bool EndOfBitInput() const
74 return (fBitDataCurrentInput>=fBitDataCurrentInputEnd);
77 /** function to get bit data input size bytes
78 * @return UInt_t value of bit data input size bytes
80 UInt_t GetBitDataInputSizeBytes() const
82 return fBitDataCurrentInput-fBitDataCurrentInputStart;
85 /** function to determine input bit
86 * @return boolean (if bit is 1 or 0)
88 bool InputBit( AliHLTUInt8_t & value );
90 /** function to read bits from bitstream
96 bool InputBits( T & value, UInt_t const & bitCount );
98 /** function pad 8 bits */
101 /** function to determine input bytes
102 * @param data AliHLTUInt8_t* pointer to input data
103 * @param byteCount UInt_t const &
106 bool InputBytes( AliHLTUInt8_t* data, UInt_t const & byteCount );
108 /// clear the object and reset pointer references
109 virtual void Clear(Option_t * /*option*/ ="");
112 virtual void Print(Option_t *option="") const;
115 virtual void Print(ostream& out, Option_t *option="") const;
119 /** copy constructor prohibited */
120 AliHLTDataInflater(const AliHLTDataInflater&);
121 /** assignment operator prohibited */
122 AliHLTDataInflater& operator=(const AliHLTDataInflater&);
124 /** member variable for bit data current word */
125 AliHLTUInt8_t fBitDataCurrentWord; // member variable for bit data current word
126 /** member variable for bit data current position in word */
127 UInt_t fBitDataCurrentPosInWord;// member variable for bit data current position in word
128 /** member variable for bit data current input */
129 const AliHLTUInt8_t *fBitDataCurrentInput; // member variable for bit data current input
130 /** member variable for bit data current input start */
131 const AliHLTUInt8_t *fBitDataCurrentInputStart; // member variable for bit data current input star
132 /** member variable for bit data current input end */
133 const AliHLTUInt8_t *fBitDataCurrentInputEnd; // member variable for bit data current input end
135 ClassDef(AliHLTDataInflater, 0)
139 bool AliHLTDataInflater::InputBits( T & value, UInt_t const & bitCount )
141 // read bits from the input stream into variable
142 if (bitCount>sizeof(T)*8) {
143 HLTFatal( "variable of type size %u too small to read %u bits", sizeof(T)*8, (unsigned)bitCount);
146 UInt_t bitsToRead=bitCount;
149 while ( bitsToRead>0 ) {
150 if ( fBitDataCurrentInput>=fBitDataCurrentInputEnd )
152 if ( bitsToRead >= fBitDataCurrentPosInWord+1 )
153 curBitCount = fBitDataCurrentPosInWord+1;
155 curBitCount = bitsToRead;
156 value = (value << curBitCount) | ( (fBitDataCurrentWord >> (fBitDataCurrentPosInWord-curBitCount+1)) & ((1 << curBitCount)-1) );
157 if ( fBitDataCurrentPosInWord < curBitCount ) {
158 fBitDataCurrentInput++;
159 if ( fBitDataCurrentInput<fBitDataCurrentInputEnd ) {
160 fBitDataCurrentWord = *fBitDataCurrentInput;
161 fBitDataCurrentPosInWord = 7;
165 fBitDataCurrentPosInWord -= curBitCount;
166 bitsToRead -= curBitCount;
171 ostream& operator<<(ostream &out, const AliHLTDataInflater& me);