CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions | Private Attributes | Static Private Attributes
lhef::StorageInputStream Class Reference

#include <XMLUtils.h>

Inheritance diagram for lhef::StorageInputStream:

Public Types

typedef StorageWrap Stream_t
 

Public Member Functions

XMLFilePos curPos () const override
 
const XMLCh * getContentType () const override
 
XMLSize_t readBytes (XMLByte *const buf, const XMLSize_t size) override
 
 StorageInputStream (StorageWrap &in)
 
 ~StorageInputStream () override
 

Private Attributes

std::vector< uint8_t > buffer_
 
unsigned int buffLoc_ = 0
 
unsigned int buffTotal_ = 0
 
bool compression_
 
StorageWrapin
 
unsigned int lasttotal_
 
lzma_stream lstr
 
unsigned int pos
 

Static Private Attributes

static constexpr unsigned bufferSize_ = 16 * 1024 * 1024
 

Detailed Description

Definition at line 163 of file XMLUtils.h.

Member Typedef Documentation

Definition at line 165 of file XMLUtils.h.

Constructor & Destructor Documentation

lhef::StorageInputStream::StorageInputStream ( StorageWrap in)

Definition at line 169 of file XMLUtils.cc.

References buffer_, bufferSize_, compression_, Exception, lstr, NULL, edm::storage::Storage::position(), edm::storage::Storage::read(), and runTheMatrix::ret.

170  : in(in), lstr(LZMA_STREAM_INIT), compression_(false), lasttotal_(0) {
171  buffer_.reserve(bufferSize_);
172  // Check the kind of file.
173  char header[6];
174  /*unsigned int s = */ in->read(header, 6);
175  in->position(0, Storage::SET);
176  // Let's use lzma to start with.
177  if (header[1] == '7' && header[2] == 'z' && header[3] == 'X' && header[4] == 'Z') {
178  compression_ = true;
179  lstr = LZMA_STREAM_INIT;
180  // We store the beginning of the outBuffer to make sure
181  // we can always update previous results.
182 
183 #if LZMA_VERSION <= UINT32_C(49990030)
184  int ret = lzma_auto_decoder(&lstr, NULL, NULL);
185 #else
186  int ret = lzma_auto_decoder(&lstr, -1, 0);
187 #endif
188 
189  if (ret != LZMA_OK) {
190  lzma_end(&lstr);
191  throw cms::Exception("IO") << "Error while reading compressed LHE file";
192  }
193  }
194  }
tuple ret
prodAgent to be discontinued
#define NULL
Definition: scimark2.h:8
unsigned int lasttotal_
Definition: XMLUtils.h:181
static constexpr unsigned bufferSize_
Definition: XMLUtils.h:185
virtual IOOffset position() const
Definition: Storage.cc:504
StorageWrap & in
Definition: XMLUtils.h:177
std::vector< uint8_t > buffer_
Definition: XMLUtils.h:184
lhef::StorageInputStream::~StorageInputStream ( )
override

Definition at line 196 of file XMLUtils.cc.

References lstr.

196 { lzma_end(&(lstr)); }

Member Function Documentation

XMLFilePos lhef::StorageInputStream::curPos ( ) const
inlineoverride

Definition at line 170 of file XMLUtils.h.

References pos.

170 { return pos; }
const XMLCh* lhef::StorageInputStream::getContentType ( ) const
inlineoverride

Definition at line 174 of file XMLUtils.h.

174 { return nullptr; }
XMLSize_t lhef::StorageInputStream::readBytes ( XMLByte *const  buf,
const XMLSize_t  size 
)
override

Definition at line 198 of file XMLUtils.cc.

References cms::cuda::assert(), visDQMUpload::buf, buffer_, buffLoc_, buffTotal_, compression_, Exception, edm::errors::FileReadError, in, lstr, SiStripPI::min, edm::storage::Storage::position(), edm::storage::Storage::read(), runTheMatrix::ret, and findQualityFiles::size.

198  {
199  // Compression code is not able to handle sizeof(XMLByte) > 1.
200  assert(sizeof(XMLByte) == sizeof(unsigned char));
201 
202  if (!(buffLoc_ < buffTotal_)) {
203  int rd = in->read((void *)&buffer_[0], buffer_.capacity());
204  // Storage layer is supposed to throw exceptions instead of returning errors; just-in-case
205  if (rd < 0) {
207  ex << "Error while reading buffered LHE file";
208  throw ex;
209  }
210  buffLoc_ = 0;
211  buffTotal_ = rd;
212  if (buffTotal_ == 0) {
213  return 0;
214  }
215  }
216  unsigned int dataRead;
217  if (!compression_) {
218  dataRead = std::min(buffTotal_ - buffLoc_, static_cast<unsigned int>(size));
219  memcpy(buf, &buffer_[buffLoc_], dataRead);
220  buffLoc_ += dataRead;
221  } else {
222  dataRead = buffTotal_ - buffLoc_;
223  lstr.next_in = &buffer_[buffLoc_];
224  lstr.avail_in = dataRead;
225  lstr.next_out = buf;
226  lstr.avail_out = size;
227  int ret = lzma_code(&lstr, LZMA_RUN);
228  if (ret != LZMA_OK && ret != LZMA_STREAM_END) { /* decompression error */
229  lzma_end(&lstr);
230  throw cms::Exception("IO") << "Error while reading compressed LHE file (error code " << ret << ")";
231  }
232  dataRead -= lstr.avail_in;
233  buffLoc_ += dataRead;
234  // Decoder was unable to make progress; reset stream and try again.
235  // If this becomes problematic, we can make the buffer circular.
236  if (!dataRead) {
237  // NOTE: lstr.avail_in == buffTotal-buffLoc_
238  in->position(-(IOOffset)(lstr.avail_in), Storage::CURRENT);
239  buffLoc_ = 0;
240  buffTotal_ = 0;
241  return readBytes(buf, size);
242  }
243  dataRead = (size - lstr.avail_out);
244  }
245  return dataRead;
246  }
int64_t IOOffset
Definition: IOTypes.h:20
tuple ret
prodAgent to be discontinued
assert(be >=bs)
virtual IOOffset position() const
Definition: Storage.cc:504
XMLSize_t readBytes(XMLByte *const buf, const XMLSize_t size) override
Definition: XMLUtils.cc:198
StorageWrap & in
Definition: XMLUtils.h:177
unsigned int buffLoc_
Definition: XMLUtils.h:183
unsigned int buffTotal_
Definition: XMLUtils.h:183
std::vector< uint8_t > buffer_
Definition: XMLUtils.h:184
tuple size
Write out results.

Member Data Documentation

std::vector<uint8_t> lhef::StorageInputStream::buffer_
private

Definition at line 184 of file XMLUtils.h.

Referenced by readBytes(), and StorageInputStream().

constexpr unsigned lhef::StorageInputStream::bufferSize_ = 16 * 1024 * 1024
staticprivate

Definition at line 185 of file XMLUtils.h.

Referenced by StorageInputStream().

unsigned int lhef::StorageInputStream::buffLoc_ = 0
private

Definition at line 183 of file XMLUtils.h.

Referenced by readBytes().

unsigned int lhef::StorageInputStream::buffTotal_ = 0
private

Definition at line 183 of file XMLUtils.h.

Referenced by readBytes().

bool lhef::StorageInputStream::compression_
private

Definition at line 180 of file XMLUtils.h.

Referenced by readBytes(), and StorageInputStream().

StorageWrap& lhef::StorageInputStream::in
private

Definition at line 177 of file XMLUtils.h.

Referenced by readBytes().

unsigned int lhef::StorageInputStream::lasttotal_
private

Definition at line 181 of file XMLUtils.h.

lzma_stream lhef::StorageInputStream::lstr
private

Definition at line 179 of file XMLUtils.h.

Referenced by readBytes(), StorageInputStream(), and ~StorageInputStream().

unsigned int lhef::StorageInputStream::pos
private

Definition at line 178 of file XMLUtils.h.

Referenced by curPos().