CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes
LzmaFile Struct Reference

#include <LzmaFile.h>

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 26 of file LzmaFile.h.

Constructor & Destructor Documentation

LzmaFile::LzmaFile ( )

Definition at line 25 of file LzmaFile.cc.

26 {
27  // fStorage.reserve(10000);
28  fStartNumber = false;
29 
30  fReadSign = true;
31  fReadMantisseR = true;
32  fReadMantisseF = false;
33  fReadExponentSign = false;
34  fReadExponent = false;
35 
36  fNegative = false;
37  fExponentNegative = false;
38 
39  fMantisseR = 0;
40  fMantisseF = 0;
41  fMantisseFcount = 0;
42  fExponent = 0;
43 }
bool fExponentNegative
Definition: LzmaFile.h:65
bool fNegative
Definition: LzmaFile.h:64
bool fReadMantisseR
Definition: LzmaFile.h:59
bool fReadSign
Definition: LzmaFile.h:58
bool fReadMantisseF
Definition: LzmaFile.h:60
bool fStartNumber
Definition: LzmaFile.h:56
int fExponent
Definition: LzmaFile.h:70
int fMantisseFcount
Definition: LzmaFile.h:69
double fMantisseF
Definition: LzmaFile.h:68
double fMantisseR
Definition: LzmaFile.h:67
bool fReadExponentSign
Definition: LzmaFile.h:61
bool fReadExponent
Definition: LzmaFile.h:62

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().

392 {
395  return res;
396 }
void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:892
CSzFile file
Definition: 7zFile.h:58
int res
Definition: LzmaFile.h:39
CFileSeqInStream inStream
Definition: LzmaFile.h:38
CLzmaDec state
Definition: LzmaFile.h:40
WRes File_Close(CSzFile *p)
Definition: 7zFile.cc:76
static ISzAlloc g_Alloc
Definition: LzmaFile.cc:23
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, edmStreamStallGrapher::stream, SZ_ERROR_DATA, and SZ_OK.

Referenced by main().

340 {
342 
343  int thereIsSize = (unpackSize != (UInt64)(Int64)-1);
344 
345  for (;;) {
346 
347  if (inPos == inSize) {
349  RINOK(stream->Read(stream, inBuf, &inSize));
350  inPos = 0;
351  }
352 
353  SizeT inProcessed = inSize - inPos;
354  SizeT outProcessed = OUT_BUF_SIZE - outPos;
355  ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
357 
358  if (thereIsSize && outProcessed > unpackSize) {
359  outProcessed = (SizeT)unpackSize;
360  finishMode = LZMA_FINISH_END;
361  }
362 
363  SRes res = LzmaDec_DecodeToBuf(&state, outBuf, &outProcessed,
364  inBuf + inPos, &inProcessed, finishMode, &status);
365  inPos += inProcessed;
366  unpackSize -= outProcessed;
367 
368 
369  unsigned int k=0;
370  for (k=0; k<outProcessed; ++k) {
371  printf("%c", outBuf[k]);
372  }
373 
374  if (res != SZ_OK || (thereIsSize && unpackSize == 0))
375  return res;
376 
377  if (inProcessed == 0 && outProcessed == 0) {
378  if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)
379  return SZ_ERROR_DATA;
380  return res;
381  }
382 
383  } // for loop
384 
385  return 0;
386 }
#define SZ_ERROR_DATA
Definition: Types.h:27
unsigned long long int UInt64
Definition: Types.h:83
size_t outPos
Definition: LzmaFile.h:53
ELzmaFinishMode
Definition: LzmaDec.h:79
#define RINOK(x)
Definition: Types.h:52
#define OUT_BUF_SIZE
Definition: LzmaFile.h:24
Byte outBuf[OUT_BUF_SIZE]
Definition: LzmaFile.h:47
size_t inSize
Definition: LzmaFile.h:52
ELzmaStatus
Definition: LzmaDec.h:100
Byte inBuf[IN_BUF_SIZE]
Definition: LzmaFile.h:46
UInt64 unpackSize
Definition: LzmaFile.h:44
int res
Definition: LzmaFile.h:39
size_t SizeT
Definition: Types.h:92
int SRes
Definition: Types.h:43
#define IN_BUF_SIZE
Definition: LzmaFile.h:23
#define SZ_OK
Definition: Types.h:25
CFileSeqInStream inStream
Definition: LzmaFile.h:38
CLzmaDec state
Definition: LzmaFile.h:40
long long int Int64
Definition: Types.h:82
int k[5][pyjets_maxn]
size_t inPos
Definition: LzmaFile.h:51
ISeqInStream s
Definition: 7zFile.h:57
SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
Definition: LzmaDec.cc:840
tuple status
Definition: ntuplemaker.py:245
SRes(* Read)(void *p, void *buf, size_t *size)
Definition: Types.h:139
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(), pileupDistInMC::num, OUT_BUF_SIZE, funct::pow(), ISeqInStream::Read, RINOK, ntuplemaker::status, edmStreamStallGrapher::stream, SZ_ERROR_DATA, and SZ_OK.

163 {
165 
166  const int thereIsSize = (unpackSize != (UInt64)(Int64)-1);
167 
168 
169  if (inPos == inSize) {
171  RINOK(stream->Read(stream, inBuf, &inSize));
172  inPos = 0;
173  }
174 
175  SizeT inProcessed = inSize - inPos;
176  SizeT outProcessed = OUT_BUF_SIZE - outPos;
177  ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
179 
180  if (thereIsSize && outProcessed > unpackSize) {
181  outProcessed = (SizeT)unpackSize;
182  finishMode = LZMA_FINISH_END;
183  }
184 
185  SRes res = LzmaDec_DecodeToBuf(&state, outBuf, &outProcessed,
186  inBuf + inPos, &inProcessed, finishMode, &status);
187  inPos += inProcessed;
188  unpackSize -= outProcessed;
189 
190 
191  const char* strBuf = (const char*)outBuf;
192 
193  int countC = 0;
194  int countNum = 0;
195  do {
196 
197  if (countC >= int(outProcessed)) {
198  // cout << " countC=" << countC
199  // << " outProcessed=" << outProcessed
200  // << endl;
201  break;
202  }
203 
204  const char& C = strBuf[countC];
205  countC++;
206 
207  //cout << "\'" << C << "\'" << endl;
208 
209  if (C==' ' || C=='\n') { // END OF NUMBER
210 
211  if (!fStartNumber)
212  continue;
213 
214  //istringstream strToNum(fStrNumber.str().c_str());
215  //double number = atof(fStrNumber.str().c_str());
216  //strToNum >> number;
217 
218  const double number = (fNegative?-1:1) * (fMantisseR + fMantisseF/pow(10, fMantisseFcount)) * pow(10, (fExponentNegative?-1:1) * fExponent);
219  //cout << " number=" << number << endl;
220 
221  fStorage.push(number);
222  countNum++;
223 
224  fStartNumber = false;
225 
226  fReadSign = true;
227  fReadMantisseR = true;
228  fReadMantisseF = false;
229  fReadExponentSign = false;
230  fReadExponent = false;
231 
232  fNegative = false;
233  fExponentNegative = false;
234 
235  fMantisseR = 0;
236  fMantisseF = 0;
237  fMantisseFcount = 0;
238  fExponent = 0;
239 
240  continue;
241  }
242 
243  fStartNumber = true;
244  const int num = C - '0';
245  if (num >= 0 && num <= 9) {
246 
247  if (fReadMantisseR) {
248  fReadSign = false;
249  fMantisseR = fMantisseR*10 + num;
250  } else if (fReadMantisseF) {
251  fReadSign = false;
252  fMantisseF = fMantisseF*10 + num;
253  ++fMantisseFcount;
254  } else if (fReadExponent) {
255  fReadExponentSign = false;
256  fExponent = fExponent*10 + num;
257  }
258 
259  } else {
260 
261  switch(C) {
262  case '-':
263  {
264  if (fReadSign) {
265  fNegative = true;
266  fReadSign = false;
267  fReadMantisseR = true;
268  } else if (fReadExponentSign) {
269  fExponentNegative = true;
270  fReadExponentSign = false;
271  fReadExponent = true;
272  } else {
273  cout << "LzmaFile: found \'" << C << "\' at wrong position. " << endl;
274  exit(10);
275  }
276  }
277  break;
278  case '.':
279  if (!fReadMantisseR) {
280  cout << "LzmaFile: found \'" << C << "\' at wrong position. " << endl;
281  exit(10);
282  }
283  fReadMantisseR = false;
284  fReadMantisseF = true;
285  break;
286  case 'e':
287  case 'E':
288  case 'D':
289  case 'd':
290  if (!fReadMantisseR || !fReadMantisseF) {
291  fReadMantisseR = false;
292  fReadMantisseF = false;
293  fReadExponentSign = true;
294  fReadExponent = true;
295  }
296  break;
297  default:
298  cout << "LzmaFile: found \'" << C << "\' at wrong position. " << endl;
299  exit(10);
300  break;
301  }
302  }
303 
304  } while(true);
305 
306  //strBuf.str("");
307  //strBuf.clear();
308 
309 
310  /*
311  if (!strNumber.str().empty()) {
312  cout << "NACHZUEGLER" << endl;
313  istringstream strToNum(strNumber.str());
314  double number;
315  strToNum >> number;
316  fStorage.push(number);
317  }
318  */
319 
320 
321 
322 
323  if (res != SZ_OK || (thereIsSize && unpackSize == 0))
324  return res;
325 
326  if (inProcessed == 0 && outProcessed == 0) {
327  if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)
328  return SZ_ERROR_DATA;
329  return res;
330  }
331 
332  return SZ_OK;
333 }
bool fExponentNegative
Definition: LzmaFile.h:65
bool fNegative
Definition: LzmaFile.h:64
#define SZ_ERROR_DATA
Definition: Types.h:27
unsigned long long int UInt64
Definition: Types.h:83
size_t outPos
Definition: LzmaFile.h:53
ELzmaFinishMode
Definition: LzmaDec.h:79
#define RINOK(x)
Definition: Types.h:52
#define OUT_BUF_SIZE
Definition: LzmaFile.h:24
Byte outBuf[OUT_BUF_SIZE]
Definition: LzmaFile.h:47
bool fReadMantisseR
Definition: LzmaFile.h:59
size_t inSize
Definition: LzmaFile.h:52
ELzmaStatus
Definition: LzmaDec.h:100
Byte inBuf[IN_BUF_SIZE]
Definition: LzmaFile.h:46
bool fReadSign
Definition: LzmaFile.h:58
std::queue< double > fStorage
Definition: LzmaFile.h:49
UInt64 unpackSize
Definition: LzmaFile.h:44
bool fReadMantisseF
Definition: LzmaFile.h:60
int res
Definition: LzmaFile.h:39
bool fStartNumber
Definition: LzmaFile.h:56
size_t SizeT
Definition: Types.h:92
int SRes
Definition: Types.h:43
#define IN_BUF_SIZE
Definition: LzmaFile.h:23
int fExponent
Definition: LzmaFile.h:70
#define SZ_OK
Definition: Types.h:25
CFileSeqInStream inStream
Definition: LzmaFile.h:38
CLzmaDec state
Definition: LzmaFile.h:40
long long int Int64
Definition: Types.h:82
int fMantisseFcount
Definition: LzmaFile.h:69
size_t inPos
Definition: LzmaFile.h:51
double fMantisseF
Definition: LzmaFile.h:68
ISeqInStream s
Definition: 7zFile.h:57
tuple cout
Definition: gather_cfg.py:121
double fMantisseR
Definition: LzmaFile.h:67
SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
Definition: LzmaDec.cc:840
tuple status
Definition: ntuplemaker.py:245
SRes(* Read)(void *p, void *buf, size_t *size)
Definition: Types.h:139
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
bool fReadExponentSign
Definition: LzmaFile.h:61
bool fReadExponent
Definition: LzmaFile.h:62
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_().

105 {
106  for (int i=0; i<length; ++i) {
107 
108  if (fStorage.empty()) {
109  const int ret = DecodeBuffer();
110  if (ret != SZ_OK) {
111  cout << "Error in FillArray i=" << i << " ret=" << ret << endl;
112  return SZ_ERROR_DATA;
113  }
114  }
115 
116  data[i] = fStorage.front();
117  fStorage.pop();
118 
119  }
120 
121  return SZ_OK;
122 
123 }
int i
Definition: DBlmapReader.cc:9
#define SZ_ERROR_DATA
Definition: Types.h:27
std::queue< double > fStorage
Definition: LzmaFile.h:49
SRes DecodeBuffer()
Definition: LzmaFile.cc:162
#define SZ_OK
Definition: Types.h:25
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
tuple cout
Definition: gather_cfg.py:121
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, i, InFile_Open(), LZMA_PROPS_SIZE, LzmaDec_Allocate(), LzmaDec_Construct, LzmaDec_Init(), RINOK, SeqInStream_Read(), edmStreamStallGrapher::stream, and SZ_OK.

Referenced by lzmaopenfile_(), and main().

48 {
49  //fStrNumber.str("");
50  //fStrNumber.clear();
51 
54 
55  if (InFile_Open(&inStream.file, fileName.c_str()) != 0) {
56  cout << "Cannot open input file: " << fileName << endl;
57  cout << "First use: \n\t \'lzma --best " << fileName.substr(0, fileName.rfind(".lzma")) << "\'"
58  << " to create it. "
59  << endl;
60  exit(1);
61  }
62 
64 
65  /* Read and parse header */
66  /* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */
67  unsigned char header[LZMA_PROPS_SIZE + 8];
68  RINOK(SeqInStream_Read(stream, header, sizeof(header)));
69 
70  unpackSize = 0;
71  int i = 0;
72  for (i = 0; i < 8; i++)
73  unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8);
74 
78 
79  inPos = 0;
80  inSize = 0;
81  outPos = 0;
82  return SZ_OK;
83 }
int i
Definition: DBlmapReader.cc:9
#define LZMA_PROPS_SIZE
Definition: LzmaDec.h:26
unsigned long long int UInt64
Definition: Types.h:83
size_t outPos
Definition: LzmaFile.h:53
CSzFile file
Definition: 7zFile.h:58
#define RINOK(x)
Definition: Types.h:52
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)
Definition: 7zStream.cc:22
size_t inSize
Definition: LzmaFile.h:52
UInt64 unpackSize
Definition: LzmaFile.h:44
void File_Construct(CSzFile *p)
Definition: 7zFile.cc:28
#define SZ_OK
Definition: Types.h:25
CFileSeqInStream inStream
Definition: LzmaFile.h:38
CLzmaDec state
Definition: LzmaFile.h:40
#define LzmaDec_Construct(p)
Definition: LzmaDec.h:71
size_t inPos
Definition: LzmaFile.h:51
static ISzAlloc g_Alloc
Definition: LzmaFile.cc:23
ISeqInStream s
Definition: 7zFile.h:57
void FileSeqInStream_CreateVTable(CFileSeqInStream *p)
Definition: 7zFile.cc:245
tuple cout
Definition: gather_cfg.py:121
void LzmaDec_Init(CLzmaDec *p)
Definition: LzmaDec.cc:701
SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
Definition: LzmaDec.cc:947
WRes InFile_Open(CSzFile *p, const char *name)
Definition: 7zFile.cc:58
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_().

87 {
88  if (fStorage.empty()) {
89  const int ret = DecodeBuffer();
90  if (ret != SZ_OK) {
91  cout << "Error in ReadNextNumber ret=" << ret << endl;
92  return SZ_ERROR_DATA;
93  }
94  }
95 
96  data = fStorage.front();
97  fStorage.pop();
98  return SZ_OK;
99 }
#define SZ_ERROR_DATA
Definition: Types.h:27
std::queue< double > fStorage
Definition: LzmaFile.h:49
SRes DecodeBuffer()
Definition: LzmaFile.cc:162
#define SZ_OK
Definition: Types.h:25
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
tuple cout
Definition: gather_cfg.py:121

Member Data Documentation

int LzmaFile::fExponent

Definition at line 70 of file LzmaFile.h.

bool LzmaFile::fExponentNegative

Definition at line 65 of file LzmaFile.h.

double LzmaFile::fMantisseF

Definition at line 68 of file LzmaFile.h.

int LzmaFile::fMantisseFcount

Definition at line 69 of file LzmaFile.h.

double LzmaFile::fMantisseR

Definition at line 67 of file LzmaFile.h.

bool LzmaFile::fNegative

Definition at line 64 of file LzmaFile.h.

bool LzmaFile::fReadExponent

Definition at line 62 of file LzmaFile.h.

bool LzmaFile::fReadExponentSign

Definition at line 61 of file LzmaFile.h.

bool LzmaFile::fReadMantisseF

Definition at line 60 of file LzmaFile.h.

bool LzmaFile::fReadMantisseR

Definition at line 59 of file LzmaFile.h.

bool LzmaFile::fReadSign

Definition at line 58 of file LzmaFile.h.

bool LzmaFile::fStartNumber

Definition at line 56 of file LzmaFile.h.

std::queue<double> LzmaFile::fStorage

Definition at line 49 of file LzmaFile.h.

Byte LzmaFile::inBuf[IN_BUF_SIZE]

Definition at line 46 of file LzmaFile.h.

size_t LzmaFile::inPos

Definition at line 51 of file LzmaFile.h.

size_t LzmaFile::inSize

Definition at line 52 of file LzmaFile.h.

CFileSeqInStream LzmaFile::inStream

Definition at line 38 of file LzmaFile.h.

Byte LzmaFile::outBuf[OUT_BUF_SIZE]

Definition at line 47 of file LzmaFile.h.

size_t LzmaFile::outPos

Definition at line 53 of file LzmaFile.h.

int LzmaFile::res

Definition at line 39 of file LzmaFile.h.

CLzmaDec LzmaFile::state

Definition at line 40 of file LzmaFile.h.

UInt64 LzmaFile::unpackSize

Definition at line 44 of file LzmaFile.h.