]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTDataInflater.cxx
restoring ostream properties after printout
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTDataInflater.cxx
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
94 void AliHLTDataInflater::Pad8Bits()
95 {
96   // see header file for class documenation
97   if ( fBitDataCurrentPosInWord == 7 )
98     return;
99   fBitDataCurrentInput++;
100   if ( fBitDataCurrentInput<fBitDataCurrentInputEnd ) {
101     fBitDataCurrentWord = *fBitDataCurrentInput;
102     fBitDataCurrentPosInWord = 7;
103   }
104 }
105
106 bool AliHLTDataInflater::InputBytes( AliHLTUInt8_t* data, UInt_t const & byteCount )
107 {
108   // see header file for class documenation
109   Pad8Bits();
110   if ( fBitDataCurrentInput+byteCount>fBitDataCurrentInputEnd )
111     return false;
112   memcpy( data, fBitDataCurrentInput, byteCount );
113   fBitDataCurrentInput += byteCount;
114   if ( fBitDataCurrentInput<fBitDataCurrentInputEnd ) {
115     fBitDataCurrentWord = *fBitDataCurrentInput;
116     fBitDataCurrentPosInWord = 7;
117   }
118   return true;
119 }
120
121 void AliHLTDataInflater::Clear(Option_t * /*option*/)
122 {
123   // internal cleanup
124 }
125
126 void AliHLTDataInflater::Print(Option_t *option) const
127 {
128   // print info
129   Print(cout, option);
130 }
131
132 void AliHLTDataInflater::Print(ostream& out, Option_t */*option*/) const
133 {
134   // print to stream
135   out << "AliHLTDataInflater: " << endl;
136 }
137
138 ostream& operator<<(ostream &out, const AliHLTDataInflater& me)
139 {
140   me.Print(out);
141   return out;
142 }