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

◆ Close()

SRes LzmaFile::Close ( )

Definition at line 349 of file LzmaFile.cc.

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

Referenced by lzmaclosefile_(), and main().

349  {
352  return res;
353 }
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

◆ DecodeAll()

SRes LzmaFile::DecodeAll ( )

Definition at line 304 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, RINOK, mps_update::status, cms::cuda::stream, SZ_ERROR_DATA, and SZ_OK.

Referenced by main().

304  {
306 
307  int thereIsSize = (unpackSize != (UInt64)(Int64)-1);
308 
309  for (;;) {
310  if (inPos == inSize) {
312  RINOK(stream->Read(stream, inBuf, &inSize));
313  inPos = 0;
314  }
315 
316  SizeT inProcessed = inSize - inPos;
317  SizeT outProcessed = OUT_BUF_SIZE - outPos;
318  ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
320 
321  if (thereIsSize && outProcessed > unpackSize) {
322  outProcessed = (SizeT)unpackSize;
323  finishMode = LZMA_FINISH_END;
324  }
325 
326  SRes res = LzmaDec_DecodeToBuf(&state, outBuf, &outProcessed, inBuf + inPos, &inProcessed, finishMode, &status);
327  inPos += inProcessed;
328  unpackSize -= outProcessed;
329 
330  unsigned int k = 0;
331  for (k = 0; k < outProcessed; ++k) {
332  printf("%c", outBuf[k]);
333  }
334 
335  if (res != SZ_OK || (thereIsSize && unpackSize == 0))
336  return res;
337 
338  if (inProcessed == 0 && outProcessed == 0) {
339  if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)
340  return SZ_ERROR_DATA;
341  return res;
342  }
343 
344  } // for loop
345 
346  return 0;
347 }
#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 RINOK(x)
Definition: Types.h:52
#define OUT_BUF_SIZE
Definition: LzmaFile.h:22
size_t inSize
Definition: LzmaFile.h:49
ELzmaStatus
Definition: LzmaDec.h:99
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
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
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

◆ DecodeBuffer()

SRes LzmaFile::DecodeBuffer ( )

Definition at line 145 of file LzmaFile.cc.

References correctionTermsCaloMet_cff::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.

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  do {
174  if (countC >= int(outProcessed)) {
175  // cout << " countC=" << countC
176  // << " outProcessed=" << outProcessed
177  // << endl;
178  break;
179  }
180 
181  const char &C = strBuf[countC];
182  countC++;
183 
184  //cout << "\'" << C << "\'" << endl;
185 
186  if (C == ' ' || C == '\n') { // END OF NUMBER
187 
188  if (!fStartNumber)
189  continue;
190 
191  //istringstream strToNum(fStrNumber.str().c_str());
192  //double number = atof(fStrNumber.str().c_str());
193  //strToNum >> number;
194 
195  const double number = (fNegative ? -1 : 1) * (fMantisseR + fMantisseF / pow(10, fMantisseFcount)) *
196  pow(10, (fExponentNegative ? -1 : 1) * fExponent);
197  //cout << " number=" << number << endl;
198 
199  fStorage.push(number);
200 
201  fStartNumber = false;
202 
203  fReadSign = true;
204  fReadMantisseR = true;
205  fReadMantisseF = false;
206  fReadExponentSign = false;
207  fReadExponent = false;
208 
209  fNegative = false;
210  fExponentNegative = false;
211 
212  fMantisseR = 0;
213  fMantisseF = 0;
214  fMantisseFcount = 0;
215  fExponent = 0;
216 
217  continue;
218  }
219 
220  fStartNumber = true;
221  const int num = C - '0';
222  if (num >= 0 && num <= 9) {
223  if (fReadMantisseR) {
224  fReadSign = false;
225  fMantisseR = fMantisseR * 10 + num;
226  } else if (fReadMantisseF) {
227  fReadSign = false;
228  fMantisseF = fMantisseF * 10 + num;
229  ++fMantisseFcount;
230  } else if (fReadExponent) {
231  fReadExponentSign = false;
232  fExponent = fExponent * 10 + num;
233  }
234 
235  } else {
236  switch (C) {
237  case '-': {
238  if (fReadSign) {
239  fNegative = true;
240  fReadSign = false;
241  fReadMantisseR = true;
242  } else if (fReadExponentSign) {
243  fExponentNegative = true;
244  fReadExponentSign = false;
245  fReadExponent = true;
246  } else {
247  cout << "LzmaFile: found \'" << C << "\' at wrong position. " << endl;
248  exit(10);
249  }
250  } break;
251  case '.':
252  if (!fReadMantisseR) {
253  cout << "LzmaFile: found \'" << C << "\' at wrong position. " << endl;
254  exit(10);
255  }
256  fReadMantisseR = false;
257  fReadMantisseF = true;
258  break;
259  case 'e':
260  case 'E':
261  case 'D':
262  case 'd':
263  if (!fReadMantisseR || !fReadMantisseF) {
264  fReadMantisseR = false;
265  fReadMantisseF = false;
266  fReadExponentSign = true;
267  fReadExponent = true;
268  }
269  break;
270  default:
271  cout << "LzmaFile: found \'" << C << "\' at wrong position. " << endl;
272  exit(10);
273  break;
274  }
275  }
276 
277  } while (true);
278 
279  //strBuf.str("");
280  //strBuf.clear();
281 
282  /*
283  if (!strNumber.str().empty()) {
284  cout << "NACHZUEGLER" << endl;
285  istringstream strToNum(strNumber.str());
286  double number;
287  strToNum >> number;
288  fStorage.push(number);
289  }
290  */
291 
292  if (res != SZ_OK || (thereIsSize && unpackSize == 0))
293  return res;
294 
295  if (inProcessed == 0 && outProcessed == 0) {
296  if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)
297  return SZ_ERROR_DATA;
298  return res;
299  }
300 
301  return SZ_OK;
302 }
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 RINOK(x)
Definition: Types.h:52
#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
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
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
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:29
bool fReadExponentSign
Definition: LzmaFile.h:58
bool fReadExponent
Definition: LzmaFile.h:59
def exit(msg="")

◆ FillArray()

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

Definition at line 94 of file LzmaFile.cc.

References gather_cfg::cout, data, 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:80

◆ Open()

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

Definition at line 44 of file LzmaFile.cc.

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

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 }
#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
#define RINOK(x)
Definition: Types.h:52
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)
Definition: 7zStream.cc:20
size_t inSize
Definition: LzmaFile.h:49
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
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
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="")

◆ ReadNextNumber()

SRes LzmaFile::ReadNextNumber ( double &  data)

Definition at line 80 of file LzmaFile.cc.

References gather_cfg::cout, data, 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:80

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.