ROOT logo
// $Id$

//**************************************************************************
//* This file is property of and copyright by the ALICE HLT Project        * 
//* ALICE Experiment at CERN, All rights reserved.                         *
//*                                                                        *
//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
//*                  for The ALICE HLT Project.                            *
//*                                                                        *
//* Permission to use, copy, modify and distribute this software and its   *
//* documentation strictly for non-commercial purposes is hereby granted   *
//* without fee, provided that the above copyright notice appears in all   *
//* copies and that both the copyright notice and this permission notice   *
//* appear in the supporting documentation. The authors make no claims     *
//* about the suitability of this software for any purpose. It is          *
//* provided "as is" without express or implied warranty.                  *
//**************************************************************************

/// @file   AliHLTDataInflater.cxx
/// @author Matthias Richter, Timm Steinbeck
/// @date   2011-08-10
/// @brief  Data inflater reading the bitstream from the AliHLTDataDeflater
/// @note   Code original from AliHLTTPCCompModelInflater

#include "AliHLTDataInflater.h"
#include "AliHLTErrorGuard.h"
#include <memory>
#include <algorithm>
#include <iostream>

/** ROOT macro for the implementation of ROOT specific class methods */
ClassImp(AliHLTDataInflater)

AliHLTDataInflater::AliHLTDataInflater()
  : AliHLTLogging()
  , fBitDataCurrentWord(0)
  , fBitDataCurrentPosInWord(0)
  , fBitDataCurrentInput(NULL)
  , fBitDataCurrentInputStart(NULL)
  , fBitDataCurrentInputEnd(NULL)
{
  // see header file for class documentation
  // or
  // refer to README to build package
  // or
  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
}

AliHLTDataInflater::~AliHLTDataInflater()
{
  // destructor
  Clear();
}

int AliHLTDataInflater::InitBitDataInput(const AliHLTUInt8_t* input, UInt_t inputSize )
{
  // init inflater for reading
  fBitDataCurrentWord = 0;
  fBitDataCurrentPosInWord = 7;
  fBitDataCurrentInput = fBitDataCurrentInputStart = input;
  fBitDataCurrentInputEnd = input+inputSize;
  fBitDataCurrentWord = *fBitDataCurrentInput;
  return 0;
}

void AliHLTDataInflater::CloseBitDataInput()
{
  // close inflater for reading
  fBitDataCurrentWord=0;
  fBitDataCurrentPosInWord=0;
  fBitDataCurrentInput=NULL;
  fBitDataCurrentInputStart=NULL;
  fBitDataCurrentInputEnd=NULL;
}

bool AliHLTDataInflater::InputBit( AliHLTUInt8_t & value )
{
  // see header file for class documenation
  if ( fBitDataCurrentInput>=fBitDataCurrentInputEnd )
    return false;
  value = (fBitDataCurrentWord >> fBitDataCurrentPosInWord) & 1;
  if ( fBitDataCurrentPosInWord )
    fBitDataCurrentPosInWord--;
  else {
    fBitDataCurrentInput++;
    if ( fBitDataCurrentInput<fBitDataCurrentInputEnd ) {
      fBitDataCurrentWord = *fBitDataCurrentInput;
      fBitDataCurrentPosInWord = 7;
    }
  }
  return true;
}

bool AliHLTDataInflater::RewindBitPosition(UInt_t const & bitCount)
{
  // Reverse the current bit position by the given number of bits.
  UInt_t bitDataCurrentPosInWord=fBitDataCurrentPosInWord+bitCount;
  if ( bitDataCurrentPosInWord > 7) {
    UInt_t byteShift=bitDataCurrentPosInWord/8;
    if (fBitDataCurrentInputStart+byteShift>fBitDataCurrentInput) {
      return false;
    }
    fBitDataCurrentInput-=byteShift;
    fBitDataCurrentWord = *fBitDataCurrentInput;
    fBitDataCurrentPosInWord = bitDataCurrentPosInWord%8;
  }
  return true;
}

void AliHLTDataInflater::Pad8Bits()
{
  // see header file for class documenation
  if ( fBitDataCurrentPosInWord == 7 )
    return;
  fBitDataCurrentInput++;
  if ( fBitDataCurrentInput<fBitDataCurrentInputEnd ) {
    fBitDataCurrentWord = *fBitDataCurrentInput;
    fBitDataCurrentPosInWord = 7;
  }
}

bool AliHLTDataInflater::InputBytes( AliHLTUInt8_t* data, UInt_t const & byteCount )
{
  // see header file for class documenation
  Pad8Bits();
  if ( fBitDataCurrentInput+byteCount>fBitDataCurrentInputEnd )
    return false;
  memcpy( data, fBitDataCurrentInput, byteCount );
  fBitDataCurrentInput += byteCount;
  if ( fBitDataCurrentInput<fBitDataCurrentInputEnd ) {
    fBitDataCurrentWord = *fBitDataCurrentInput;
    fBitDataCurrentPosInWord = 7;
  }
  return true;
}

void AliHLTDataInflater::Clear(Option_t * /*option*/)
{
  // internal cleanup
}

void AliHLTDataInflater::Print(Option_t *option) const
{
  // print info
  Print(cout, option);
}

void AliHLTDataInflater::Print(ostream& out, Option_t */*option*/) const
{
  // print to stream
  out << "AliHLTDataInflater: " << endl;
}

ostream& operator<<(ostream &out, const AliHLTDataInflater& me)
{
  me.Print(out);
  return out;
}
 AliHLTDataInflater.cxx:1
 AliHLTDataInflater.cxx:2
 AliHLTDataInflater.cxx:3
 AliHLTDataInflater.cxx:4
 AliHLTDataInflater.cxx:5
 AliHLTDataInflater.cxx:6
 AliHLTDataInflater.cxx:7
 AliHLTDataInflater.cxx:8
 AliHLTDataInflater.cxx:9
 AliHLTDataInflater.cxx:10
 AliHLTDataInflater.cxx:11
 AliHLTDataInflater.cxx:12
 AliHLTDataInflater.cxx:13
 AliHLTDataInflater.cxx:14
 AliHLTDataInflater.cxx:15
 AliHLTDataInflater.cxx:16
 AliHLTDataInflater.cxx:17
 AliHLTDataInflater.cxx:18
 AliHLTDataInflater.cxx:19
 AliHLTDataInflater.cxx:20
 AliHLTDataInflater.cxx:21
 AliHLTDataInflater.cxx:22
 AliHLTDataInflater.cxx:23
 AliHLTDataInflater.cxx:24
 AliHLTDataInflater.cxx:25
 AliHLTDataInflater.cxx:26
 AliHLTDataInflater.cxx:27
 AliHLTDataInflater.cxx:28
 AliHLTDataInflater.cxx:29
 AliHLTDataInflater.cxx:30
 AliHLTDataInflater.cxx:31
 AliHLTDataInflater.cxx:32
 AliHLTDataInflater.cxx:33
 AliHLTDataInflater.cxx:34
 AliHLTDataInflater.cxx:35
 AliHLTDataInflater.cxx:36
 AliHLTDataInflater.cxx:37
 AliHLTDataInflater.cxx:38
 AliHLTDataInflater.cxx:39
 AliHLTDataInflater.cxx:40
 AliHLTDataInflater.cxx:41
 AliHLTDataInflater.cxx:42
 AliHLTDataInflater.cxx:43
 AliHLTDataInflater.cxx:44
 AliHLTDataInflater.cxx:45
 AliHLTDataInflater.cxx:46
 AliHLTDataInflater.cxx:47
 AliHLTDataInflater.cxx:48
 AliHLTDataInflater.cxx:49
 AliHLTDataInflater.cxx:50
 AliHLTDataInflater.cxx:51
 AliHLTDataInflater.cxx:52
 AliHLTDataInflater.cxx:53
 AliHLTDataInflater.cxx:54
 AliHLTDataInflater.cxx:55
 AliHLTDataInflater.cxx:56
 AliHLTDataInflater.cxx:57
 AliHLTDataInflater.cxx:58
 AliHLTDataInflater.cxx:59
 AliHLTDataInflater.cxx:60
 AliHLTDataInflater.cxx:61
 AliHLTDataInflater.cxx:62
 AliHLTDataInflater.cxx:63
 AliHLTDataInflater.cxx:64
 AliHLTDataInflater.cxx:65
 AliHLTDataInflater.cxx:66
 AliHLTDataInflater.cxx:67
 AliHLTDataInflater.cxx:68
 AliHLTDataInflater.cxx:69
 AliHLTDataInflater.cxx:70
 AliHLTDataInflater.cxx:71
 AliHLTDataInflater.cxx:72
 AliHLTDataInflater.cxx:73
 AliHLTDataInflater.cxx:74
 AliHLTDataInflater.cxx:75
 AliHLTDataInflater.cxx:76
 AliHLTDataInflater.cxx:77
 AliHLTDataInflater.cxx:78
 AliHLTDataInflater.cxx:79
 AliHLTDataInflater.cxx:80
 AliHLTDataInflater.cxx:81
 AliHLTDataInflater.cxx:82
 AliHLTDataInflater.cxx:83
 AliHLTDataInflater.cxx:84
 AliHLTDataInflater.cxx:85
 AliHLTDataInflater.cxx:86
 AliHLTDataInflater.cxx:87
 AliHLTDataInflater.cxx:88
 AliHLTDataInflater.cxx:89
 AliHLTDataInflater.cxx:90
 AliHLTDataInflater.cxx:91
 AliHLTDataInflater.cxx:92
 AliHLTDataInflater.cxx:93
 AliHLTDataInflater.cxx:94
 AliHLTDataInflater.cxx:95
 AliHLTDataInflater.cxx:96
 AliHLTDataInflater.cxx:97
 AliHLTDataInflater.cxx:98
 AliHLTDataInflater.cxx:99
 AliHLTDataInflater.cxx:100
 AliHLTDataInflater.cxx:101
 AliHLTDataInflater.cxx:102
 AliHLTDataInflater.cxx:103
 AliHLTDataInflater.cxx:104
 AliHLTDataInflater.cxx:105
 AliHLTDataInflater.cxx:106
 AliHLTDataInflater.cxx:107
 AliHLTDataInflater.cxx:108
 AliHLTDataInflater.cxx:109
 AliHLTDataInflater.cxx:110
 AliHLTDataInflater.cxx:111
 AliHLTDataInflater.cxx:112
 AliHLTDataInflater.cxx:113
 AliHLTDataInflater.cxx:114
 AliHLTDataInflater.cxx:115
 AliHLTDataInflater.cxx:116
 AliHLTDataInflater.cxx:117
 AliHLTDataInflater.cxx:118
 AliHLTDataInflater.cxx:119
 AliHLTDataInflater.cxx:120
 AliHLTDataInflater.cxx:121
 AliHLTDataInflater.cxx:122
 AliHLTDataInflater.cxx:123
 AliHLTDataInflater.cxx:124
 AliHLTDataInflater.cxx:125
 AliHLTDataInflater.cxx:126
 AliHLTDataInflater.cxx:127
 AliHLTDataInflater.cxx:128
 AliHLTDataInflater.cxx:129
 AliHLTDataInflater.cxx:130
 AliHLTDataInflater.cxx:131
 AliHLTDataInflater.cxx:132
 AliHLTDataInflater.cxx:133
 AliHLTDataInflater.cxx:134
 AliHLTDataInflater.cxx:135
 AliHLTDataInflater.cxx:136
 AliHLTDataInflater.cxx:137
 AliHLTDataInflater.cxx:138
 AliHLTDataInflater.cxx:139
 AliHLTDataInflater.cxx:140
 AliHLTDataInflater.cxx:141
 AliHLTDataInflater.cxx:142
 AliHLTDataInflater.cxx:143
 AliHLTDataInflater.cxx:144
 AliHLTDataInflater.cxx:145
 AliHLTDataInflater.cxx:146
 AliHLTDataInflater.cxx:147
 AliHLTDataInflater.cxx:148
 AliHLTDataInflater.cxx:149
 AliHLTDataInflater.cxx:150
 AliHLTDataInflater.cxx:151
 AliHLTDataInflater.cxx:152
 AliHLTDataInflater.cxx:153
 AliHLTDataInflater.cxx:154
 AliHLTDataInflater.cxx:155
 AliHLTDataInflater.cxx:156
 AliHLTDataInflater.cxx:157
 AliHLTDataInflater.cxx:158