CMS 3D CMS Logo

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 [(1<< 16)]
 
size_t inPos
 
size_t inSize
 
CFileSeqInStream inStream
 
Byte outBuf [(1<< 16)]
 
size_t outPos
 
int res
 
CLzmaDec state
 
UInt64 unpackSize
 

Detailed Description

Definition at line 24 of file LzmaFile.h.

Constructor & Destructor Documentation

LzmaFile::LzmaFile ( )

Definition at line 25 of file LzmaFile.cc.

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

Member Function Documentation

SRes LzmaFile::Close ( )

Definition at line 351 of file LzmaFile.cc.

References File_Close(), and LzmaDec_Free().

Referenced by lzmaclosefile_(), and main().

351  {
354  return res;
355 }
void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:837
CSzFile file
Definition: 7zFile.h:55
Definition: Electron.h:6
int res
Definition: LzmaFile.h:36
CFileSeqInStream inStream
Definition: LzmaFile.h:35
CLzmaDec state
Definition: LzmaFile.h:37
WRes File_Close(CSzFile *p)
Definition: 7zFile.cc:77
static ISzAlloc g_Alloc
Definition: LzmaFile.cc:23
SRes LzmaFile::DecodeAll ( )

Definition at line 306 of file LzmaFile.cc.

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

Referenced by main().

306  {
307  ISeqInStream *stream = &inStream.s;
308 
309  int thereIsSize = (unpackSize != (UInt64)(Int64)-1);
310 
311  for (;;) {
312  if (inPos == inSize) {
314  RINOK(stream->Read(stream, inBuf, &inSize));
315  inPos = 0;
316  }
317 
318  SizeT inProcessed = inSize - inPos;
319  SizeT outProcessed = OUT_BUF_SIZE - outPos;
320  ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
322 
323  if (thereIsSize && outProcessed > unpackSize) {
324  outProcessed = (SizeT)unpackSize;
325  finishMode = LZMA_FINISH_END;
326  }
327 
328  SRes res = LzmaDec_DecodeToBuf(&state, outBuf, &outProcessed, inBuf + inPos, &inProcessed, finishMode, &status);
329  inPos += inProcessed;
330  unpackSize -= outProcessed;
331 
332  unsigned int k = 0;
333  for (k = 0; k < outProcessed; ++k) {
334  printf("%c", outBuf[k]);
335  }
336 
337  if (res != SZ_OK || (thereIsSize && unpackSize == 0))
338  return res;
339 
340  if (inProcessed == 0 && outProcessed == 0) {
341  if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)
342  return SZ_ERROR_DATA;
343  return res;
344  }
345 
346  } // for loop
347 
348  return 0;
349 }
#define SZ_ERROR_DATA
Definition: Types.h:27
unsigned long long int UInt64
Definition: Types.h:88
size_t outPos
Definition: LzmaFile.h:50
ELzmaFinishMode
Definition: LzmaDec.h:79
Byte inBuf[(1<< 16)]
Definition: LzmaFile.h:43
#define OUT_BUF_SIZE
Definition: LzmaFile.h:22
size_t inSize
Definition: LzmaFile.h:49
ELzmaStatus
Definition: LzmaDec.h:99
UInt64 unpackSize
Definition: LzmaFile.h:41
Definition: Electron.h:6
int res
Definition: LzmaFile.h:36
size_t SizeT
Definition: Types.h:97
int SRes
Definition: Types.h:43
#define IN_BUF_SIZE
Definition: LzmaFile.h:21
#define SZ_OK
Definition: Types.h:25
CFileSeqInStream inStream
Definition: LzmaFile.h:35
CLzmaDec state
Definition: LzmaFile.h:37
long long int Int64
Definition: Types.h:87
#define RINOK(x)
Definition: Types.h:52
size_t inPos
Definition: LzmaFile.h:48
Byte outBuf[(1<< 16)]
Definition: LzmaFile.h:44
ISeqInStream s
Definition: 7zFile.h:54
SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
Definition: LzmaDec.cc:786
SRes(* Read)(void *p, void *buf, size_t *size)
Definition: Types.h:139
SRes LzmaFile::DecodeBuffer ( )

Definition at line 145 of file LzmaFile.cc.

References gen::C, gather_cfg::cout, beamvalidation::exit(), IN_BUF_SIZE, LZMA_FINISH_ANY, LZMA_FINISH_END, LZMA_STATUS_FINISHED_WITH_MARK, LzmaDec_DecodeToBuf(), EgammaValidation_cff::num, contentValuesFiles::number, OUT_BUF_SIZE, funct::pow(), ISeqInStream::Read, RINOK, mps_update::status, SZ_ERROR_DATA, and SZ_OK.

145  {
146  ISeqInStream *stream = &inStream.s;
147 
148  const int thereIsSize = (unpackSize != (UInt64)(Int64)-1);
149 
150  if (inPos == inSize) {
152  RINOK(stream->Read(stream, inBuf, &inSize));
153  inPos = 0;
154  }
155 
156  SizeT inProcessed = inSize - inPos;
157  SizeT outProcessed = OUT_BUF_SIZE - outPos;
158  ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
160 
161  if (thereIsSize && outProcessed > unpackSize) {
162  outProcessed = (SizeT)unpackSize;
163  finishMode = LZMA_FINISH_END;
164  }
165 
166  SRes res = LzmaDec_DecodeToBuf(&state, outBuf, &outProcessed, inBuf + inPos, &inProcessed, finishMode, &status);
167  inPos += inProcessed;
168  unpackSize -= outProcessed;
169 
170  const char *strBuf = (const char *)outBuf;
171 
172  int countC = 0;
173  int countNum = 0;
174  do {
175  if (countC >= int(outProcessed)) {
176  // cout << " countC=" << countC
177  // << " outProcessed=" << outProcessed
178  // << endl;
179  break;
180  }
181 
182  const char &C = strBuf[countC];
183  countC++;
184 
185  //cout << "\'" << C << "\'" << endl;
186 
187  if (C == ' ' || C == '\n') { // END OF NUMBER
188 
189  if (!fStartNumber)
190  continue;
191 
192  //istringstream strToNum(fStrNumber.str().c_str());
193  //double number = atof(fStrNumber.str().c_str());
194  //strToNum >> number;
195 
196  const double number = (fNegative ? -1 : 1) * (fMantisseR + fMantisseF / pow(10, fMantisseFcount)) *
197  pow(10, (fExponentNegative ? -1 : 1) * fExponent);
198  //cout << " number=" << number << endl;
199 
200  fStorage.push(number);
201  countNum++;
202 
203  fStartNumber = false;
204 
205  fReadSign = true;
206  fReadMantisseR = true;
207  fReadMantisseF = false;
208  fReadExponentSign = false;
209  fReadExponent = false;
210 
211  fNegative = false;
212  fExponentNegative = false;
213 
214  fMantisseR = 0;
215  fMantisseF = 0;
216  fMantisseFcount = 0;
217  fExponent = 0;
218 
219  continue;
220  }
221 
222  fStartNumber = true;
223  const int num = C - '0';
224  if (num >= 0 && num <= 9) {
225  if (fReadMantisseR) {
226  fReadSign = false;
227  fMantisseR = fMantisseR * 10 + num;
228  } else if (fReadMantisseF) {
229  fReadSign = false;
230  fMantisseF = fMantisseF * 10 + num;
231  ++fMantisseFcount;
232  } else if (fReadExponent) {
233  fReadExponentSign = false;
234  fExponent = fExponent * 10 + num;
235  }
236 
237  } else {
238  switch (C) {
239  case '-': {
240  if (fReadSign) {
241  fNegative = true;
242  fReadSign = false;
243  fReadMantisseR = true;
244  } else if (fReadExponentSign) {
245  fExponentNegative = true;
246  fReadExponentSign = false;
247  fReadExponent = true;
248  } else {
249  cout << "LzmaFile: found \'" << C << "\' at wrong position. " << endl;
250  exit(10);
251  }
252  } break;
253  case '.':
254  if (!fReadMantisseR) {
255  cout << "LzmaFile: found \'" << C << "\' at wrong position. " << endl;
256  exit(10);
257  }
258  fReadMantisseR = false;
259  fReadMantisseF = true;
260  break;
261  case 'e':
262  case 'E':
263  case 'D':
264  case 'd':
265  if (!fReadMantisseR || !fReadMantisseF) {
266  fReadMantisseR = false;
267  fReadMantisseF = false;
268  fReadExponentSign = true;
269  fReadExponent = true;
270  }
271  break;
272  default:
273  cout << "LzmaFile: found \'" << C << "\' at wrong position. " << endl;
274  exit(10);
275  break;
276  }
277  }
278 
279  } while (true);
280 
281  //strBuf.str("");
282  //strBuf.clear();
283 
284  /*
285  if (!strNumber.str().empty()) {
286  cout << "NACHZUEGLER" << endl;
287  istringstream strToNum(strNumber.str());
288  double number;
289  strToNum >> number;
290  fStorage.push(number);
291  }
292  */
293 
294  if (res != SZ_OK || (thereIsSize && unpackSize == 0))
295  return res;
296 
297  if (inProcessed == 0 && outProcessed == 0) {
298  if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)
299  return SZ_ERROR_DATA;
300  return res;
301  }
302 
303  return SZ_OK;
304 }
bool fExponentNegative
Definition: LzmaFile.h:62
bool fNegative
Definition: LzmaFile.h:61
#define SZ_ERROR_DATA
Definition: Types.h:27
unsigned long long int UInt64
Definition: Types.h:88
size_t outPos
Definition: LzmaFile.h:50
ELzmaFinishMode
Definition: LzmaDec.h:79
Byte inBuf[(1<< 16)]
Definition: LzmaFile.h:43
#define OUT_BUF_SIZE
Definition: LzmaFile.h:22
bool fReadMantisseR
Definition: LzmaFile.h:56
size_t inSize
Definition: LzmaFile.h:49
ELzmaStatus
Definition: LzmaDec.h:99
bool fReadSign
Definition: LzmaFile.h:55
std::queue< double > fStorage
Definition: LzmaFile.h:46
UInt64 unpackSize
Definition: LzmaFile.h:41
bool fReadMantisseF
Definition: LzmaFile.h:57
Definition: Electron.h:6
int res
Definition: LzmaFile.h:36
bool fStartNumber
Definition: LzmaFile.h:53
size_t SizeT
Definition: Types.h:97
int SRes
Definition: Types.h:43
#define IN_BUF_SIZE
Definition: LzmaFile.h:21
int fExponent
Definition: LzmaFile.h:67
#define SZ_OK
Definition: Types.h:25
CFileSeqInStream inStream
Definition: LzmaFile.h:35
CLzmaDec state
Definition: LzmaFile.h:37
long long int Int64
Definition: Types.h:87
#define RINOK(x)
Definition: Types.h:52
int fMantisseFcount
Definition: LzmaFile.h:66
size_t inPos
Definition: LzmaFile.h:48
double fMantisseF
Definition: LzmaFile.h:65
Byte outBuf[(1<< 16)]
Definition: LzmaFile.h:44
ISeqInStream s
Definition: 7zFile.h:54
double fMantisseR
Definition: LzmaFile.h:64
SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
Definition: LzmaDec.cc:786
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
bool fReadExponentSign
Definition: LzmaFile.h:58
bool fReadExponent
Definition: LzmaFile.h:59
SRes(* Read)(void *p, void *buf, size_t *size)
Definition: Types.h:139
def exit(msg="")
SRes LzmaFile::FillArray ( double *  data,
const int  length 
)

Definition at line 94 of file LzmaFile.cc.

References gather_cfg::cout, mps_fire::i, runTheMatrix::ret, SZ_ERROR_DATA, and SZ_OK.

Referenced by lzmafillarray_().

94  {
95  for (int i = 0; i < length; ++i) {
96  if (fStorage.empty()) {
97  const int ret = DecodeBuffer();
98  if (ret != SZ_OK) {
99  cout << "Error in FillArray i=" << i << " ret=" << ret << endl;
100  return SZ_ERROR_DATA;
101  }
102  }
103 
104  data[i] = fStorage.front();
105  fStorage.pop();
106  }
107 
108  return SZ_OK;
109 }
#define SZ_ERROR_DATA
Definition: Types.h:27
ret
prodAgent to be discontinued
std::queue< double > fStorage
Definition: LzmaFile.h:46
SRes DecodeBuffer()
Definition: LzmaFile.cc:145
#define SZ_OK
Definition: Types.h:25
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
SRes LzmaFile::Open ( const std::string &  fileName)

Definition at line 44 of file LzmaFile.cc.

References gather_cfg::cout, beamvalidation::exit(), File_Construct(), FileSeqInStream_CreateVTable(), RecoTauValidation_cfi::header, mps_fire::i, InFile_Open(), LZMA_PROPS_SIZE, LzmaDec_Allocate(), LzmaDec_Construct, LzmaDec_Init(), RINOK, SeqInStream_Read(), and SZ_OK.

Referenced by lzmaopenfile_(), and main().

44  {
45  //fStrNumber.str("");
46  //fStrNumber.clear();
47 
50 
51  if (InFile_Open(&inStream.file, fileName.c_str()) != 0) {
52  cout << "Cannot open input file: " << fileName << endl;
53  cout << "First use: \n\t \'lzma --best " << fileName.substr(0, fileName.rfind(".lzma")) << "\'"
54  << " to create it. " << endl;
55  exit(1);
56  }
57 
58  ISeqInStream *stream = &inStream.s;
59 
60  /* Read and parse header */
61  /* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */
62  unsigned char header[LZMA_PROPS_SIZE + 8];
63  RINOK(SeqInStream_Read(stream, header, sizeof(header)));
64 
65  unpackSize = 0;
66  int i = 0;
67  for (i = 0; i < 8; i++)
68  unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8);
69 
73 
74  inPos = 0;
75  inSize = 0;
76  outPos = 0;
77  return SZ_OK;
78 }
#define LZMA_PROPS_SIZE
Definition: LzmaDec.h:25
unsigned long long int UInt64
Definition: Types.h:88
size_t outPos
Definition: LzmaFile.h:50
CSzFile file
Definition: 7zFile.h:55
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)
Definition: 7zStream.cc:20
size_t inSize
Definition: LzmaFile.h:49
UInt64 unpackSize
Definition: LzmaFile.h:41
void File_Construct(CSzFile *p)
Definition: 7zFile.cc:28
#define SZ_OK
Definition: Types.h:25
CFileSeqInStream inStream
Definition: LzmaFile.h:35
CLzmaDec state
Definition: LzmaFile.h:37
#define LzmaDec_Construct(p)
Definition: LzmaDec.h:67
#define RINOK(x)
Definition: Types.h:52
size_t inPos
Definition: LzmaFile.h:48
static ISzAlloc g_Alloc
Definition: LzmaFile.cc:23
ISeqInStream s
Definition: 7zFile.h:54
void FileSeqInStream_CreateVTable(CFileSeqInStream *p)
Definition: 7zFile.cc:243
void LzmaDec_Init(CLzmaDec *p)
Definition: LzmaDec.cc:667
SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
Definition: LzmaDec.cc:887
WRes InFile_Open(CSzFile *p, const char *name)
Definition: 7zFile.cc:58
def exit(msg="")
SRes LzmaFile::ReadNextNumber ( double &  data)

Definition at line 80 of file LzmaFile.cc.

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

Referenced by lzmanextnumber_().

80  {
81  if (fStorage.empty()) {
82  const int ret = DecodeBuffer();
83  if (ret != SZ_OK) {
84  cout << "Error in ReadNextNumber ret=" << ret << endl;
85  return SZ_ERROR_DATA;
86  }
87  }
88 
89  data = fStorage.front();
90  fStorage.pop();
91  return SZ_OK;
92 }
#define SZ_ERROR_DATA
Definition: Types.h:27
ret
prodAgent to be discontinued
std::queue< double > fStorage
Definition: LzmaFile.h:46
SRes DecodeBuffer()
Definition: LzmaFile.cc:145
#define SZ_OK
Definition: Types.h:25
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79

Member Data Documentation

int LzmaFile::fExponent

Definition at line 67 of file LzmaFile.h.

bool LzmaFile::fExponentNegative

Definition at line 62 of file LzmaFile.h.

double LzmaFile::fMantisseF

Definition at line 65 of file LzmaFile.h.

int LzmaFile::fMantisseFcount

Definition at line 66 of file LzmaFile.h.

double LzmaFile::fMantisseR

Definition at line 64 of file LzmaFile.h.

bool LzmaFile::fNegative

Definition at line 61 of file LzmaFile.h.

bool LzmaFile::fReadExponent

Definition at line 59 of file LzmaFile.h.

bool LzmaFile::fReadExponentSign

Definition at line 58 of file LzmaFile.h.

bool LzmaFile::fReadMantisseF

Definition at line 57 of file LzmaFile.h.

bool LzmaFile::fReadMantisseR

Definition at line 56 of file LzmaFile.h.

bool LzmaFile::fReadSign

Definition at line 55 of file LzmaFile.h.

bool LzmaFile::fStartNumber

Definition at line 53 of file LzmaFile.h.

std::queue<double> LzmaFile::fStorage

Definition at line 46 of file LzmaFile.h.

Byte LzmaFile::inBuf[(1<< 16)]

Definition at line 43 of file LzmaFile.h.

size_t LzmaFile::inPos

Definition at line 48 of file LzmaFile.h.

size_t LzmaFile::inSize

Definition at line 49 of file LzmaFile.h.

CFileSeqInStream LzmaFile::inStream

Definition at line 35 of file LzmaFile.h.

Byte LzmaFile::outBuf[(1<< 16)]

Definition at line 44 of file LzmaFile.h.

size_t LzmaFile::outPos

Definition at line 50 of file LzmaFile.h.

int LzmaFile::res

Definition at line 36 of file LzmaFile.h.

CLzmaDec LzmaFile::state

Definition at line 37 of file LzmaFile.h.

UInt64 LzmaFile::unpackSize

Definition at line 41 of file LzmaFile.h.