CMS 3D CMS Logo

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 160 of file XMLUtils.h.

Member Typedef Documentation

◆ Stream_t

Definition at line 162 of file XMLUtils.h.

Constructor & Destructor Documentation

◆ StorageInputStream()

lhef::StorageInputStream::StorageInputStream ( StorageWrap in)

Definition at line 168 of file XMLUtils.cc.

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

References buffer_, bufferSize_, compression_, Exception, RecoTauValidation_cfi::header, in, lstr, NULL, Storage::position(), Storage::read(), runTheMatrix::ret, and Storage::SET.

◆ ~StorageInputStream()

lhef::StorageInputStream::~StorageInputStream ( )
override

Definition at line 195 of file XMLUtils.cc.

195 { lzma_end(&(lstr)); }

References lstr.

Member Function Documentation

◆ curPos()

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

Definition at line 167 of file XMLUtils.h.

167 { return pos; }

References pos.

◆ getContentType()

const XMLCh* lhef::StorageInputStream::getContentType ( ) const
inlineoverride

Definition at line 171 of file XMLUtils.h.

171 { return nullptr; }

◆ readBytes()

XMLSize_t lhef::StorageInputStream::readBytes ( XMLByte *const  buf,
const XMLSize_t  size 
)
override

Definition at line 197 of file XMLUtils.cc.

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

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

Member Data Documentation

◆ buffer_

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

Definition at line 181 of file XMLUtils.h.

Referenced by readBytes(), and StorageInputStream().

◆ bufferSize_

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

Definition at line 182 of file XMLUtils.h.

Referenced by StorageInputStream().

◆ buffLoc_

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

Definition at line 180 of file XMLUtils.h.

Referenced by readBytes().

◆ buffTotal_

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

Definition at line 180 of file XMLUtils.h.

Referenced by readBytes().

◆ compression_

bool lhef::StorageInputStream::compression_
private

Definition at line 177 of file XMLUtils.h.

Referenced by readBytes(), and StorageInputStream().

◆ in

StorageWrap& lhef::StorageInputStream::in
private

Definition at line 174 of file XMLUtils.h.

Referenced by readBytes(), and StorageInputStream().

◆ lasttotal_

unsigned int lhef::StorageInputStream::lasttotal_
private

Definition at line 178 of file XMLUtils.h.

◆ lstr

lzma_stream lhef::StorageInputStream::lstr
private

Definition at line 176 of file XMLUtils.h.

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

◆ pos

unsigned int lhef::StorageInputStream::pos
private

Definition at line 175 of file XMLUtils.h.

Referenced by curPos().

runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
lhef::StorageInputStream::readBytes
XMLSize_t readBytes(XMLByte *const buf, const XMLSize_t size) override
Definition: XMLUtils.cc:197
min
T min(T a, T b)
Definition: MathUtil.h:58
lhef::StorageInputStream::buffTotal_
unsigned int buffTotal_
Definition: XMLUtils.h:180
Storage::SET
Definition: Storage.h:22
cms::cuda::assert
assert(be >=bs)
lhef::StorageInputStream::buffer_
std::vector< uint8_t > buffer_
Definition: XMLUtils.h:181
edm::Exception
Definition: EDMException.h:77
lhef::StorageInputStream::bufferSize_
static constexpr unsigned bufferSize_
Definition: XMLUtils.h:182
lhef::StorageInputStream::lasttotal_
unsigned int lasttotal_
Definition: XMLUtils.h:178
lhef::StorageInputStream::pos
unsigned int pos
Definition: XMLUtils.h:175
lhef::StorageInputStream::lstr
lzma_stream lstr
Definition: XMLUtils.h:176
Storage::read
virtual IOSize read(void *into, IOSize n, IOOffset pos)
Definition: Storage.cc:12
IOOffset
int64_t IOOffset
Definition: IOTypes.h:19
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
NULL
#define NULL
Definition: scimark2.h:8
lhef::StorageInputStream::in
StorageWrap & in
Definition: XMLUtils.h:174
Exception
Definition: hltDiff.cc:246
Storage::position
virtual IOOffset position(void) const
Definition: Storage.cc:72
lhef::StorageInputStream::buffLoc_
unsigned int buffLoc_
Definition: XMLUtils.h:180
Storage::CURRENT
Definition: Storage.h:22
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
edm::errors::FileReadError
Definition: EDMException.h:50
lhef::StorageInputStream::compression_
bool compression_
Definition: XMLUtils.h:177
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443