Line data Source code
1 : //**************************************************************************
2 : //* This file is property of and copyright by the ALICE HLT Project *
3 : //* ALICE Experiment at CERN, All rights reserved. *
4 : //* *
5 : //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
6 : //* for The ALICE HLT Project. *
7 : //* *
8 : //* Permission to use, copy, modify and distribute this software and its *
9 : //* documentation strictly for non-commercial purposes is hereby granted *
10 : //* without fee, provided that the above copyright notice appears in all *
11 : //* copies and that both the copyright notice and this permission notice *
12 : //* appear in the supporting documentation. The authors make no claims *
13 : //* about the suitability of this software for any purpose. It is *
14 : //* provided "as is" without express or implied warranty. *
15 : //**************************************************************************
16 :
17 : /// @file AliHLTDataInflater.cxx
18 : /// @author Matthias Richter, Timm Steinbeck
19 : /// @date 2011-08-10
20 : /// @brief Data inflater reading the bitstream from the AliHLTDataDeflater
21 : /// @note Code original from AliHLTTPCCompModelInflater
22 :
23 : #include "AliHLTDataInflater.h"
24 : #include "AliHLTErrorGuard.h"
25 : #include <memory>
26 : #include <algorithm>
27 : #include <iostream>
28 :
29 : /** ROOT macro for the implementation of ROOT specific class methods */
30 126 : ClassImp(AliHLTDataInflater)
31 :
32 : AliHLTDataInflater::AliHLTDataInflater()
33 0 : : AliHLTLogging()
34 0 : , fBitDataCurrentWord(0)
35 0 : , fBitDataCurrentPosInWord(0)
36 0 : , fBitDataCurrentInput(NULL)
37 0 : , fBitDataCurrentInputStart(NULL)
38 0 : , fBitDataCurrentInputEnd(NULL)
39 0 : {
40 : // constructor, see header file for class documentation
41 0 : }
42 :
43 : AliHLTDataInflater::~AliHLTDataInflater()
44 0 : {
45 : // destructor
46 0 : Clear();
47 0 : }
48 :
49 : int AliHLTDataInflater::InitBitDataInput(const AliHLTUInt8_t* input, UInt_t inputSize )
50 : {
51 : // init inflater for reading
52 0 : fBitDataCurrentWord = 0;
53 0 : fBitDataCurrentPosInWord = 7;
54 0 : fBitDataCurrentInput = fBitDataCurrentInputStart = input;
55 0 : fBitDataCurrentInputEnd = input+inputSize;
56 0 : fBitDataCurrentWord = *fBitDataCurrentInput;
57 0 : return 0;
58 : }
59 :
60 : void AliHLTDataInflater::CloseBitDataInput()
61 : {
62 : // close inflater for reading
63 0 : fBitDataCurrentWord=0;
64 0 : fBitDataCurrentPosInWord=0;
65 0 : fBitDataCurrentInput=NULL;
66 0 : fBitDataCurrentInputStart=NULL;
67 0 : fBitDataCurrentInputEnd=NULL;
68 0 : }
69 :
70 : bool AliHLTDataInflater::InputBit( AliHLTUInt8_t & value )
71 : {
72 : // see header file for class documenation
73 0 : if ( fBitDataCurrentInput>=fBitDataCurrentInputEnd )
74 0 : return false;
75 0 : value = (fBitDataCurrentWord >> fBitDataCurrentPosInWord) & 1;
76 0 : if ( fBitDataCurrentPosInWord )
77 0 : fBitDataCurrentPosInWord--;
78 : else {
79 0 : fBitDataCurrentInput++;
80 0 : if ( fBitDataCurrentInput<fBitDataCurrentInputEnd ) {
81 0 : fBitDataCurrentWord = *fBitDataCurrentInput;
82 0 : fBitDataCurrentPosInWord = 7;
83 0 : }
84 : }
85 : HLTDebug(" code 0x%08x length 1", value);
86 0 : return true;
87 0 : }
88 :
89 : bool AliHLTDataInflater::RewindBitPosition(UInt_t const & bitCount)
90 : {
91 : // Reverse the current bit position by the given number of bits.
92 0 : UInt_t bitDataCurrentPosInWord=fBitDataCurrentPosInWord+bitCount;
93 0 : if ( bitDataCurrentPosInWord > 7) {
94 0 : UInt_t byteShift=bitDataCurrentPosInWord/8;
95 0 : if (fBitDataCurrentInputStart+byteShift>fBitDataCurrentInput) {
96 0 : return false;
97 : }
98 0 : fBitDataCurrentInput-=byteShift;
99 0 : fBitDataCurrentWord = *fBitDataCurrentInput;
100 0 : }
101 0 : fBitDataCurrentPosInWord = bitDataCurrentPosInWord%8;
102 0 : return true;
103 0 : }
104 :
105 : void AliHLTDataInflater::Pad8Bits()
106 : {
107 : // see header file for class documenation
108 0 : if ( fBitDataCurrentPosInWord == 7 )
109 : return;
110 0 : fBitDataCurrentInput++;
111 0 : if ( fBitDataCurrentInput<fBitDataCurrentInputEnd ) {
112 0 : fBitDataCurrentWord = *fBitDataCurrentInput;
113 0 : fBitDataCurrentPosInWord = 7;
114 0 : }
115 0 : }
116 :
117 : bool AliHLTDataInflater::InputBytes( AliHLTUInt8_t* data, UInt_t const & byteCount )
118 : {
119 : // see header file for class documenation
120 0 : Pad8Bits();
121 0 : if ( fBitDataCurrentInput+byteCount>fBitDataCurrentInputEnd )
122 0 : return false;
123 0 : memcpy( data, fBitDataCurrentInput, byteCount );
124 0 : fBitDataCurrentInput += byteCount;
125 0 : if ( fBitDataCurrentInput<fBitDataCurrentInputEnd ) {
126 0 : fBitDataCurrentWord = *fBitDataCurrentInput;
127 0 : fBitDataCurrentPosInWord = 7;
128 0 : }
129 0 : return true;
130 0 : }
131 :
132 : void AliHLTDataInflater::Clear(Option_t * /*option*/)
133 : {
134 : // internal cleanup
135 0 : }
136 :
137 : void AliHLTDataInflater::Print(Option_t *option) const
138 : {
139 : // print info
140 0 : Print(cout, option);
141 0 : }
142 :
143 : void AliHLTDataInflater::Print(ostream& out, Option_t */*option*/) const
144 : {
145 : // print to stream
146 0 : out << "AliHLTDataInflater: " << endl;
147 0 : }
148 :
149 : ostream& operator<<(ostream &out, const AliHLTDataInflater& me)
150 : {
151 0 : me.Print(out);
152 0 : return out;
153 : }
|