CMS 3D CMS Logo

Public Member Functions | Public Attributes

LzmaFile Struct Reference

#include <LzmaFile.h>

List of all members.

Public Member Functions

SRes Close ()
SRes DecodeAll ()
SRes DecodeBuffer ()
SRes FillArray (double *data, const int length)
 LzmaFile ()
SRes Open (const std::string &fileName)
SRes ReadNextNumber (double &data)

Public Attributes

int fExponent
bool fExponentNegative
double fMantisseF
int fMantisseFcount
double fMantisseR
bool fNegative
bool fReadExponent
bool fReadExponentSign
bool fReadMantisseF
bool fReadMantisseR
bool fReadSign
bool fStartNumber
std::queue< double > fStorage
Byte inBuf [IN_BUF_SIZE]
size_t inPos
size_t inSize
CFileSeqInStream inStream
Byte outBuf [OUT_BUF_SIZE]
size_t outPos
int res
CLzmaDec state
UInt64 unpackSize

Detailed Description

Definition at line 27 of file LzmaFile.h.


Constructor & Destructor Documentation

LzmaFile::LzmaFile ( )

Definition at line 25 of file LzmaFile.cc.

{
  // fStorage.reserve(10000);
  fStartNumber = false;

  fReadSign = true;
  fReadMantisseR = true;
  fReadMantisseF = false;
  fReadExponentSign = false;
  fReadExponent = false;
      
  fNegative = false;
  fExponentNegative = false;
      
  fMantisseR = 0;
  fMantisseF = 0;
  fMantisseFcount = 0;
  fExponent = 0;
}

Member Function Documentation

SRes LzmaFile::Close ( )

Definition at line 391 of file LzmaFile.cc.

References File_Close(), g_Alloc, and LzmaDec_Free().

Referenced by lzmaclosefile_(), and main().

SRes LzmaFile::DecodeAll ( )

Definition at line 339 of file LzmaFile.cc.

References IN_BUF_SIZE, gen::k, LZMA_FINISH_ANY, LZMA_FINISH_END, LZMA_STATUS_FINISHED_WITH_MARK, LzmaDec_DecodeToBuf(), OUT_BUF_SIZE, ISeqInStream::Read, RINOK, ntuplemaker::status, SZ_ERROR_DATA, and SZ_OK.

Referenced by main().

{
  ISeqInStream *stream = &inStream.s;

  int thereIsSize = (unpackSize != (UInt64)(Int64)-1);
  
  for (;;) {

    if (inPos == inSize) {
      inSize = IN_BUF_SIZE;
      RINOK(stream->Read(stream, inBuf, &inSize));
      inPos = 0;
    }
    
    SizeT inProcessed = inSize - inPos;
    SizeT outProcessed = OUT_BUF_SIZE - outPos;
    ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
    ELzmaStatus status;
    
    if (thereIsSize && outProcessed > unpackSize) {
      outProcessed = (SizeT)unpackSize;
      finishMode = LZMA_FINISH_END;
    }
    
    SRes res = LzmaDec_DecodeToBuf(&state, outBuf, &outProcessed,
                                   inBuf + inPos, &inProcessed, finishMode, &status);
    inPos += inProcessed;
    unpackSize -= outProcessed;
    
    
    unsigned int k=0;
    for (k=0; k<outProcessed; ++k) {
      printf("%c", outBuf[k]);
    }
  
    if (res != SZ_OK || (thereIsSize && unpackSize == 0))
      return res;
    
    if (inProcessed == 0 && outProcessed == 0) {
      if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)
        return SZ_ERROR_DATA;
      return res;
    }

  } // for loop
  
  return 0;
}
SRes LzmaFile::DecodeBuffer ( )

Definition at line 162 of file LzmaFile.cc.

References funct::C, gather_cfg::cout, cmsRelvalreport::exit, IN_BUF_SIZE, LZMA_FINISH_ANY, LZMA_FINISH_END, LZMA_STATUS_FINISHED_WITH_MARK, LzmaDec_DecodeToBuf(), OUT_BUF_SIZE, funct::pow(), ISeqInStream::Read, RINOK, ntuplemaker::status, SZ_ERROR_DATA, and SZ_OK.

{
  ISeqInStream *stream = &inStream.s;
  
  const int thereIsSize = (unpackSize != (UInt64)(Int64)-1);
  
    
  if (inPos == inSize) {
    inSize = IN_BUF_SIZE;
    RINOK(stream->Read(stream, inBuf, &inSize));
    inPos = 0;
  }
  
  SizeT inProcessed = inSize - inPos;
  SizeT outProcessed = OUT_BUF_SIZE - outPos;
  ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
  ELzmaStatus status;
  
  if (thereIsSize && outProcessed > unpackSize) {
    outProcessed = (SizeT)unpackSize;
    finishMode = LZMA_FINISH_END;
  }
  
  SRes res = LzmaDec_DecodeToBuf(&state, outBuf, &outProcessed,
                                 inBuf + inPos, &inProcessed, finishMode, &status);
  inPos += inProcessed;
  unpackSize -= outProcessed;
  
    
  const char* strBuf = (const char*)outBuf;

  int countC = 0;
  int countNum = 0;
  do {
    
    if (countC >= int(outProcessed)) {
      // cout << " countC=" << countC 
      //           << " outProcessed=" << outProcessed
      //           << endl;
      break;
    }
    
    const char& C = strBuf[countC]; 
    countC++;
    
    //cout << "\'" << C << "\'" << endl;
    
    if (C==' ' || C=='\n') { // END OF NUMBER

      if (!fStartNumber) 
        continue;
      
      //istringstream strToNum(fStrNumber.str().c_str());
      //double number = atof(fStrNumber.str().c_str());
      //strToNum >> number;
      
      const double number = (fNegative?-1:1) * (fMantisseR + fMantisseF/pow(10, fMantisseFcount)) * pow(10, (fExponentNegative?-1:1) * fExponent);
      //cout << " number=" << number << endl;
      
      fStorage.push(number);      
      countNum++;
      
      fStartNumber = false;

      fReadSign = true;
      fReadMantisseR = true;
      fReadMantisseF = false;
      fReadExponentSign = false;
      fReadExponent = false;
      
      fNegative = false;
      fExponentNegative = false;
      
      fMantisseR = 0;
      fMantisseF = 0;
      fMantisseFcount = 0;
      fExponent = 0;
      
      continue;
    }
    
    fStartNumber = true;
    const int num = C - '0';
    if (num >= 0 && num <= 9) {
        
      if (fReadMantisseR) {
        fReadSign = false;
        fMantisseR = fMantisseR*10 + num;
      } else if (fReadMantisseF) {
        fReadSign = false;
        fMantisseF = fMantisseF*10 + num;
        ++fMantisseFcount;
      } else if (fReadExponent) {
        fReadExponentSign = false;
        fExponent = fExponent*10 + num;
      }
      
    } else {
      
      switch(C) {
      case '-':
        {
          if (fReadSign) {
            fNegative = true;
            fReadSign = false;
            fReadMantisseR = true;
          } else if (fReadExponentSign) {       
            fExponentNegative = true;
            fReadExponentSign = false;
            fReadExponent = true;
          } else {
            cout << "LzmaFile: found \'" << C << "\' at wrong position. " << endl;
            exit(10);
          }
        }
        break;
      case '.': 
        if (!fReadMantisseR) {
          cout << "LzmaFile: found \'" << C << "\' at wrong position. " << endl;
          exit(10);
        }
        fReadMantisseR = false;
        fReadMantisseF = true;
        break;
      case 'e':
      case 'E':
      case 'D': 
      case 'd':
        if (!fReadMantisseR || !fReadMantisseF) {
          fReadMantisseR = false;
          fReadMantisseF = false;
          fReadExponentSign = true;
          fReadExponent = true;
        }
        break;
      default:
        cout << "LzmaFile: found \'" << C << "\' at wrong position. " << endl;
        exit(10);
        break;
      }
    }
        
  } while(true);
  
  //strBuf.str("");
  //strBuf.clear();
  

  /*    
  if (!strNumber.str().empty()) {
    cout << "NACHZUEGLER" << endl;
    istringstream strToNum(strNumber.str());
    double number;
    strToNum >> number;
    fStorage.push(number);
  }
  */
    
  

    
  if (res != SZ_OK || (thereIsSize && unpackSize == 0)) 
    return res;
    
  if (inProcessed == 0 && outProcessed == 0) {
    if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)
      return SZ_ERROR_DATA;
    return res;
  }

  return SZ_OK;
}
SRes LzmaFile::FillArray ( double *  data,
const int  length 
)

Definition at line 104 of file LzmaFile.cc.

References gather_cfg::cout, i, run_regression::ret, SZ_ERROR_DATA, and SZ_OK.

Referenced by lzmafillarray_().

{
  for (int i=0; i<length; ++i) {
    
    if (fStorage.empty()) {
      const int ret = DecodeBuffer();
      if (ret != SZ_OK) {
        cout << "Error in FillArray i=" << i << " ret=" << ret << endl;
        return SZ_ERROR_DATA;
      }
    }
    
    data[i] = fStorage.front();
    fStorage.pop();
    
  }
  
  return SZ_OK;
  
}
SRes LzmaFile::Open ( const std::string &  fileName)

Definition at line 47 of file LzmaFile.cc.

References gather_cfg::cout, cmsRelvalreport::exit, File_Construct(), FileSeqInStream_CreateVTable(), g_Alloc, errorMatrix2Lands::header, i, InFile_Open(), LZMA_PROPS_SIZE, LzmaDec_Allocate(), LzmaDec_Construct, LzmaDec_Init(), RINOK, SeqInStream_Read(), and SZ_OK.

Referenced by lzmaopenfile_(), and main().

{
  //fStrNumber.str("");
  //fStrNumber.clear();
  
  FileSeqInStream_CreateVTable(&inStream);
  File_Construct(&inStream.file);

  if (InFile_Open(&inStream.file, fileName.c_str()) != 0) {
    cout << "Cannot open input file: " << fileName << endl;
    cout << "First use: \n\t \'lzma --best " << fileName.substr(0, fileName.rfind(".lzma")) << "\'"
         << " to create it. "
         << endl;
    exit(1);
  }
  
  ISeqInStream *stream = &inStream.s;
  
  /* Read and parse header */
  /* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */
  unsigned char header[LZMA_PROPS_SIZE + 8];
  RINOK(SeqInStream_Read(stream, header, sizeof(header)));
  
  unpackSize = 0;
  int i = 0;
  for (i = 0; i < 8; i++)
    unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8);
  
  LzmaDec_Construct(&state);
  RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc));
  LzmaDec_Init(&state);
  
  inPos = 0;
  inSize = 0;
  outPos = 0;
  return SZ_OK;  
}
SRes LzmaFile::ReadNextNumber ( double &  data)

Definition at line 86 of file LzmaFile.cc.

References gather_cfg::cout, run_regression::ret, SZ_ERROR_DATA, and SZ_OK.

Referenced by lzmanextnumber_().

{
  if (fStorage.empty()) {
    const int ret = DecodeBuffer();
    if (ret != SZ_OK) {
      cout << "Error in ReadNextNumber  ret=" << ret << endl;
      return SZ_ERROR_DATA;
    }
  }
  
  data = fStorage.front();
  fStorage.pop();
  return SZ_OK;
}

Member Data Documentation

Definition at line 71 of file LzmaFile.h.

Definition at line 66 of file LzmaFile.h.

Definition at line 69 of file LzmaFile.h.

Definition at line 70 of file LzmaFile.h.

Definition at line 68 of file LzmaFile.h.

Definition at line 65 of file LzmaFile.h.

Definition at line 63 of file LzmaFile.h.

Definition at line 62 of file LzmaFile.h.

Definition at line 61 of file LzmaFile.h.

Definition at line 60 of file LzmaFile.h.

Definition at line 59 of file LzmaFile.h.

Definition at line 57 of file LzmaFile.h.

std::queue<double> LzmaFile::fStorage

Definition at line 50 of file LzmaFile.h.

Byte LzmaFile::inBuf[IN_BUF_SIZE]

Definition at line 47 of file LzmaFile.h.

Definition at line 52 of file LzmaFile.h.

Definition at line 53 of file LzmaFile.h.

Definition at line 39 of file LzmaFile.h.

Byte LzmaFile::outBuf[OUT_BUF_SIZE]

Definition at line 48 of file LzmaFile.h.

Definition at line 54 of file LzmaFile.h.

Definition at line 40 of file LzmaFile.h.

Definition at line 41 of file LzmaFile.h.

Definition at line 45 of file LzmaFile.h.