CMS 3D CMS Logo

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

#include <XMLUtils.h>

Inheritance diagram for lhef::StorageInputStream:

Public Types

typedef StorageWrap Stream_t
 

Public Member Functions

virtual unsigned int curPos () const
 
virtual unsigned int readBytes (XMLByte *const buf, const unsigned int size)
 
 StorageInputStream (StorageWrap &in)
 
virtual ~StorageInputStream ()
 

Private Attributes

bool compression_
 
StorageWrapin
 
unsigned int lasttotal_
 
lzma_stream lstr
 
unsigned int pos
 

Detailed Description

Definition at line 167 of file XMLUtils.h.

Member Typedef Documentation

Definition at line 170 of file XMLUtils.h.

Constructor & Destructor Documentation

lhef::StorageInputStream::StorageInputStream ( StorageWrap in)

Definition at line 206 of file XMLUtils.cc.

References compression_, edm::hlt::Exception, lstr, NULL, Storage::position(), Storage::read(), run_regression::ret, and Storage::SET.

206  :
207  in(in),
208  lstr(LZMA_STREAM_INIT),
209  compression_(false),
210  lasttotal_(0)
211 {
212  // Check the kind of file.
213  char header[6];
214  /*unsigned int s = */ in->read(header, 6);
215  in->position(0, Storage::SET);
216  // Let's use lzma to start with.
217  if (header[1] == '7'
218  && header[2] == 'z'
219  && header[3] == 'X'
220  && header[4] == 'Z')
221  {
222  compression_ = true;
223  lstr = LZMA_STREAM_INIT;
224  // We store the beginning of the outBuffer to make sure
225  // we can always update previous results.
226 
227 #if LZMA_VERSION <= UINT32_C(49990030)
228  int ret = lzma_auto_decoder(&lstr, NULL, NULL);
229 #else
230  int ret = lzma_auto_decoder(&lstr, -1, 0);
231 #endif
232 
233  if (ret != LZMA_OK)
234  {
235  lzma_end(&lstr);
236  throw cms::Exception("IO") << "Error while reading compressed LHE file";
237  }
238  }
239 }
virtual IOSize read(void *into, IOSize n, IOOffset pos)
Definition: Storage.cc:17
#define NULL
Definition: scimark2.h:8
unsigned int lasttotal_
Definition: XMLUtils.h:185
virtual IOOffset position(void) const
Definition: Storage.cc:95
StorageWrap & in
Definition: XMLUtils.h:181
lhef::StorageInputStream::~StorageInputStream ( )
virtual

Definition at line 241 of file XMLUtils.cc.

References lstr.

242 {
243  lzma_end(&(lstr));
244 }

Member Function Documentation

virtual unsigned int lhef::StorageInputStream::curPos ( ) const
inlinevirtual

Definition at line 175 of file XMLUtils.h.

References pos.

175 { return pos; }
unsigned int lhef::StorageInputStream::readBytes ( XMLByte *const  buf,
const unsigned int  size 
)
virtual

Definition at line 246 of file XMLUtils.cc.

References BUF_SIZE, compression_, gather_cfg::cout, Storage::CURRENT, edm::hlt::Exception, in, lasttotal_, lstr, pos, Storage::position(), SiPixelLorentzAngle_cfi::read, Storage::read(), and run_regression::ret.

248 {
249  // Simple read-in write-out in case
250  if (!compression_)
251  {
252  void *rawBuf = reinterpret_cast<void*>(buf);
253  unsigned int bytes = size * sizeof(XMLByte);
254  unsigned int readBytes = in->read(rawBuf, bytes);
255 
256  unsigned int read = (unsigned int)(readBytes / sizeof(XMLByte));
257  unsigned int rest = (unsigned int)(readBytes % sizeof(XMLByte));
258  if (rest)
260 
261  /*for (unsigned int i = 0; i < read; ++i){
262  std::cout << buf[i] ;
263  }*/
264 
265  pos += read;
266  return read;
267  }
268  // Compressed case.
269  // We simply read as many bytes as we can and we
270  // uncompress them in the output buffer.
271  // We never decompress more bytes we were asked by
272  // xerces.
273  // In case we read from file more bytes than needed
274  // we simply rollback by the (hopefully) correct amount.
275  // If we don't read enough bytes, we simply return
276  // the amount of bytes read and we wait for being called
277  // again by xerces.
278  unsigned int bytes = size * sizeof(XMLByte);
279 // std::cout << "bites " << bytes << std::endl;
280  uint8_t inBuf[BUF_SIZE];
281  unsigned int rd = in->read((void*)inBuf, BUF_SIZE);
282  lstr.next_in = inBuf;
283  lstr.avail_in = rd;
284  lstr.next_out = buf;
285  lstr.avail_out = bytes;
286 /* for (unsigned int i = 0; i < size; ++i){
287  std::cout << buf[i] ;
288  }
289  std::cout << std::endl;*/
290 
291  int ret = lzma_code(&lstr, LZMA_RUN);
292  if(ret != LZMA_OK && ret != LZMA_STREAM_END) { /* decompression error */
293  lzma_end(&lstr);
294  throw cms::Exception("IO") << "Error while reading compressed LHE file";
295  }
296  // If we did not consume everything we put it back.
297 // std::cout << "lstr.avail_in " << lstr.avail_in << " lstr.total_in " << lstr.total_in << std::endl;
298 // std::cout << "lstr.avail_out " << lstr.avail_out << " lstr.total_out " << lstr.total_out << std::endl;
299  if (lstr.avail_in){
300  std::cout << "rolling back" << std::endl;
301  in->position(-(IOOffset)(lstr.avail_in), Storage::CURRENT);
302  }
303  pos = lstr.total_out;
304  unsigned int read = lstr.total_out - lasttotal_;
305  lasttotal_ = lstr.total_out;
306  return read;
307 }
virtual IOSize read(void *into, IOSize n, IOOffset pos)
Definition: Storage.cc:17
unsigned int lasttotal_
Definition: XMLUtils.h:185
virtual unsigned int readBytes(XMLByte *const buf, const unsigned int size)
Definition: XMLUtils.cc:246
virtual IOOffset position(void) const
Definition: Storage.cc:95
StorageWrap & in
Definition: XMLUtils.h:181
int64_t IOOffset
Definition: IOTypes.h:19
#define BUF_SIZE
Definition: XMLUtils.cc:20
tuple cout
Definition: gather_cfg.py:121
tuple size
Write out results.

Member Data Documentation

bool lhef::StorageInputStream::compression_
private

Definition at line 184 of file XMLUtils.h.

Referenced by readBytes(), and StorageInputStream().

StorageWrap& lhef::StorageInputStream::in
private

Definition at line 181 of file XMLUtils.h.

Referenced by readBytes().

unsigned int lhef::StorageInputStream::lasttotal_
private

Definition at line 185 of file XMLUtils.h.

Referenced by readBytes().

lzma_stream lhef::StorageInputStream::lstr
private

Definition at line 183 of file XMLUtils.h.

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

unsigned int lhef::StorageInputStream::pos
private