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