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::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 }

Member Function Documentation

◆ Close()

SRes LzmaFile::Close ( )

Definition at line 351 of file LzmaFile.cc.

351  {
354  return res;
355 }

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

Referenced by lzmaclosefile_(), and main().

◆ DecodeAll()

SRes LzmaFile::DecodeAll ( )

Definition at line 306 of file LzmaFile.cc.

306  {
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 }

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

Referenced by main().

◆ DecodeBuffer()

SRes LzmaFile::DecodeBuffer ( )

Definition at line 145 of file LzmaFile.cc.

145  {
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 }

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(), RINOK, mps_update::status, cms::cuda::stream, SZ_ERROR_DATA, and SZ_OK.

◆ FillArray()

SRes LzmaFile::FillArray ( double *  data,
const int  length 
)

Definition at line 94 of file LzmaFile.cc.

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 }

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

Referenced by lzmafillarray_().

◆ Open()

SRes LzmaFile::Open ( const std::string &  fileName)

Definition at line 44 of file LzmaFile.cc.

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 
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];
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 }

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

Referenced by lzmaopenfile_(), and main().

◆ ReadNextNumber()

SRes LzmaFile::ReadNextNumber ( double &  data)

Definition at line 80 of file LzmaFile.cc.

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 }

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

Referenced by lzmanextnumber_().

Member Data Documentation

◆ fExponent

int LzmaFile::fExponent

Definition at line 67 of file LzmaFile.h.

◆ fExponentNegative

bool LzmaFile::fExponentNegative

Definition at line 62 of file LzmaFile.h.

◆ fMantisseF

double LzmaFile::fMantisseF

Definition at line 65 of file LzmaFile.h.

◆ fMantisseFcount

int LzmaFile::fMantisseFcount

Definition at line 66 of file LzmaFile.h.

◆ fMantisseR

double LzmaFile::fMantisseR

Definition at line 64 of file LzmaFile.h.

◆ fNegative

bool LzmaFile::fNegative

Definition at line 61 of file LzmaFile.h.

◆ fReadExponent

bool LzmaFile::fReadExponent

Definition at line 59 of file LzmaFile.h.

◆ fReadExponentSign

bool LzmaFile::fReadExponentSign

Definition at line 58 of file LzmaFile.h.

◆ fReadMantisseF

bool LzmaFile::fReadMantisseF

Definition at line 57 of file LzmaFile.h.

◆ fReadMantisseR

bool LzmaFile::fReadMantisseR

Definition at line 56 of file LzmaFile.h.

◆ fReadSign

bool LzmaFile::fReadSign

Definition at line 55 of file LzmaFile.h.

◆ fStartNumber

bool LzmaFile::fStartNumber

Definition at line 53 of file LzmaFile.h.

◆ fStorage

std::queue<double> LzmaFile::fStorage

Definition at line 46 of file LzmaFile.h.

◆ inBuf

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

Definition at line 43 of file LzmaFile.h.

◆ inPos

size_t LzmaFile::inPos

Definition at line 48 of file LzmaFile.h.

◆ inSize

size_t LzmaFile::inSize

Definition at line 49 of file LzmaFile.h.

◆ inStream

CFileSeqInStream LzmaFile::inStream

Definition at line 35 of file LzmaFile.h.

◆ outBuf

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

Definition at line 44 of file LzmaFile.h.

◆ outPos

size_t LzmaFile::outPos

Definition at line 50 of file LzmaFile.h.

◆ res

int LzmaFile::res

Definition at line 36 of file LzmaFile.h.

◆ state

CLzmaDec LzmaFile::state

Definition at line 37 of file LzmaFile.h.

◆ unpackSize

UInt64 LzmaFile::unpackSize

Definition at line 41 of file LzmaFile.h.

runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:367
LzmaFile::fMantisseR
double fMantisseR
Definition: LzmaFile.h:64
CFileSeqInStream::file
CSzFile file
Definition: 7zFile.h:55
mps_fire.i
i
Definition: mps_fire.py:428
LzmaFile::fReadExponentSign
bool fReadExponentSign
Definition: LzmaFile.h:58
LzmaDec_Allocate
SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
Definition: LzmaDec.cc:887
LZMA_FINISH_ANY
Definition: LzmaDec.h:80
mps_update.status
status
Definition: mps_update.py:69
LzmaFile::fExponentNegative
bool fExponentNegative
Definition: LzmaFile.h:62
LzmaFile::state
CLzmaDec state
Definition: LzmaFile.h:37
cms::cuda::stream
cudaStream_t stream
Definition: HistoContainer.h:57
gather_cfg.cout
cout
Definition: gather_cfg.py:144
UInt64
unsigned long long int UInt64
Definition: Types.h:88
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
OUT_BUF_SIZE
#define OUT_BUF_SIZE
Definition: LzmaFile.h:22
LzmaFile::inBuf
Byte inBuf[(1<< 16)]
Definition: LzmaFile.h:43
ELzmaStatus
ELzmaStatus
Definition: LzmaDec.h:99
File_Construct
void File_Construct(CSzFile *p)
Definition: 7zFile.cc:28
LzmaFile::fReadMantisseR
bool fReadMantisseR
Definition: LzmaFile.h:56
LzmaFile::fStorage
std::queue< double > fStorage
Definition: LzmaFile.h:46
SZ_OK
#define SZ_OK
Definition: Types.h:25
LzmaDec_DecodeToBuf
SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
Definition: LzmaDec.cc:786
contentValuesFiles.number
number
Definition: contentValuesFiles.py:53
LzmaDec_Init
void LzmaDec_Init(CLzmaDec *p)
Definition: LzmaDec.cc:667
LzmaFile::fReadMantisseF
bool fReadMantisseF
Definition: LzmaFile.h:57
g_Alloc
static ISzAlloc g_Alloc
Definition: LzmaFile.cc:23
LzmaFile::outPos
size_t outPos
Definition: LzmaFile.h:50
dqmdumpme.k
k
Definition: dqmdumpme.py:60
ISeqInStream
Definition: Types.h:138
SizeT
size_t SizeT
Definition: Types.h:97
File_Close
WRes File_Close(CSzFile *p)
Definition: 7zFile.cc:77
Int64
long long int Int64
Definition: Types.h:87
IN_BUF_SIZE
#define IN_BUF_SIZE
Definition: LzmaFile.h:21
LzmaDec_Free
void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:837
LzmaFile::fNegative
bool fNegative
Definition: LzmaFile.h:61
SeqInStream_Read
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)
Definition: 7zStream.cc:20
LzmaFile::fExponent
int fExponent
Definition: LzmaFile.h:67
SRes
int SRes
Definition: Types.h:43
LZMA_FINISH_END
Definition: LzmaDec.h:81
LzmaFile::inStream
CFileSeqInStream inStream
Definition: LzmaFile.h:35
res
Definition: Electron.h:6
EgammaValidation_cff.num
num
Definition: EgammaValidation_cff.py:34
CFileSeqInStream::s
ISeqInStream s
Definition: 7zFile.h:54
LZMA_STATUS_FINISHED_WITH_MARK
Definition: LzmaDec.h:101
LzmaDec_Construct
#define LzmaDec_Construct(p)
Definition: LzmaDec.h:67
LzmaFile::fMantisseF
double fMantisseF
Definition: LzmaFile.h:65
LzmaFile::inPos
size_t inPos
Definition: LzmaFile.h:48
LzmaFile::res
int res
Definition: LzmaFile.h:36
gen::C
C
Definition: PomwigHadronizer.cc:78
LzmaFile::outBuf
Byte outBuf[(1<< 16)]
Definition: LzmaFile.h:44
LzmaFile::DecodeBuffer
SRes DecodeBuffer()
Definition: LzmaFile.cc:145
InFile_Open
WRes InFile_Open(CSzFile *p, const char *name)
Definition: 7zFile.cc:58
FileSeqInStream_CreateVTable
void FileSeqInStream_CreateVTable(CFileSeqInStream *p)
Definition: 7zFile.cc:243
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
LzmaFile::fReadExponent
bool fReadExponent
Definition: LzmaFile.h:59
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
LzmaFile::inSize
size_t inSize
Definition: LzmaFile.h:49
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
LZMA_PROPS_SIZE
#define LZMA_PROPS_SIZE
Definition: LzmaDec.h:25
LzmaFile::fReadSign
bool fReadSign
Definition: LzmaFile.h:55
LzmaFile::fStartNumber
bool fStartNumber
Definition: LzmaFile.h:53
LzmaFile::fMantisseFcount
int fMantisseFcount
Definition: LzmaFile.h:66
SZ_ERROR_DATA
#define SZ_ERROR_DATA
Definition: Types.h:27
LzmaFile::unpackSize
UInt64 unpackSize
Definition: LzmaFile.h:41
RINOK
#define RINOK(x)
Definition: Types.h:52
ELzmaFinishMode
ELzmaFinishMode
Definition: LzmaDec.h:79