CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
LHEXMLStringProduct Class Reference

#include <LHEXMLStringProduct.h>

Public Member Functions

void fillCompressedContent (std::istream &input, unsigned int initialSize=4 *1024 *1024)
 
const std::vector< std::vector< uint8_t > > & getCompressed () const
 
const std::vector< std::string > & getStrings () const
 
 LHEXMLStringProduct ()
 
 LHEXMLStringProduct (const std::string &content)
 
bool mergeProduct (LHEXMLStringProduct const &other)
 
void swap (LHEXMLStringProduct &other)
 
void writeCompressedContent (std::ostream &output, unsigned int i) const
 
virtual ~LHEXMLStringProduct ()
 

Private Attributes

std::vector< std::vector< uint8_t > > compressedContent_
 
std::vector< std::string > content_
 

Detailed Description

Definition at line 12 of file LHEXMLStringProduct.h.

Constructor & Destructor Documentation

◆ LHEXMLStringProduct() [1/2]

LHEXMLStringProduct::LHEXMLStringProduct ( )

Definition at line 12 of file LHEXMLStringProduct.cc.

12 {}

◆ LHEXMLStringProduct() [2/2]

LHEXMLStringProduct::LHEXMLStringProduct ( const std::string &  content)

◆ ~LHEXMLStringProduct()

LHEXMLStringProduct::~LHEXMLStringProduct ( )
virtual

Definition at line 16 of file LHEXMLStringProduct.cc.

16 {}

Member Function Documentation

◆ fillCompressedContent()

void LHEXMLStringProduct::fillCompressedContent ( std::istream &  input,
unsigned int  initialSize = 4 * 1024 * 1024 
)

Definition at line 18 of file LHEXMLStringProduct.cc.

18  {
19  //create blob with desired size
20  compressedContent_.emplace_back(initialSize);
21  std::vector<uint8_t> &output = compressedContent_.back();
22 
23  //read buffer
24  constexpr unsigned int bufsize = 4096;
25  char inbuf[bufsize];
26 
27  const unsigned int threshsize = 32 * 1024 * 1024;
28 
29  //initialize lzma
30  uint32_t preset = 9;
31  lzma_stream strm = LZMA_STREAM_INIT;
32  lzma_ret ret = lzma_easy_encoder(&strm, preset, LZMA_CHECK_CRC64);
33 
34  lzma_action action = LZMA_RUN;
35 
36  strm.next_in = reinterpret_cast<uint8_t *>(&inbuf[0]);
37  strm.avail_in = 0;
38  strm.next_out = output.data();
39  strm.avail_out = output.size();
40 
41  unsigned int compressedSize = 0;
42 
43  while (ret == LZMA_OK) {
44  //read input to buffer if necessary
45  if (strm.avail_in == 0 && !input.eof()) {
46  input.read(inbuf, bufsize);
47  strm.next_in = reinterpret_cast<uint8_t *>(&inbuf[0]);
48  strm.avail_in = input.gcount();
49  if (input.eof()) {
50  //signal to lzma that there is no more input
51  action = LZMA_FINISH;
52  }
53  }
54 
55  //actual compression
56  ret = lzma_code(&strm, action);
57 
58  //update compressed size
59  compressedSize = output.size() - strm.avail_out;
60 
61  //if output blob is full and compression is still going, allocate more memory
62  if (strm.avail_out == 0 && ret == LZMA_OK) {
63  unsigned int oldsize = output.size();
64  if (oldsize < threshsize) {
65  output.resize(2 * oldsize);
66  } else {
67  output.resize(oldsize + threshsize);
68  }
69  strm.next_out = &output[oldsize];
70  strm.avail_out = output.size() - oldsize;
71  }
72  }
73 
74  lzma_end(&strm);
75 
76  if (ret != LZMA_STREAM_END) {
77  throw cms::Exception("CompressionError") << "There was a failure in LZMA compression in LHEXMLStringProduct.";
78  }
79 
80  //trim output blob
81  output.resize(compressedSize);
82 }

References writedatasetfile::action, compressedContent_, Exception, input, convertSQLitetoXML_cfg::output, and runTheMatrix::ret.

◆ getCompressed()

const std::vector<std::vector<uint8_t> >& LHEXMLStringProduct::getCompressed ( ) const
inline

Definition at line 22 of file LHEXMLStringProduct.h.

22 { return compressedContent_; }

References compressedContent_.

Referenced by ExternalLHEAsciiDumper::endRun().

◆ getStrings()

const std::vector<std::string>& LHEXMLStringProduct::getStrings ( ) const
inline

Definition at line 20 of file LHEXMLStringProduct.h.

20 { return content_; }

References content_.

Referenced by ExternalLHEAsciiDumper::endRun().

◆ mergeProduct()

bool LHEXMLStringProduct::mergeProduct ( LHEXMLStringProduct const &  other)

Definition at line 122 of file LHEXMLStringProduct.cc.

122  {
123  content_.insert(content_.end(), other.getStrings().begin(), other.getStrings().end());
124  compressedContent_.insert(compressedContent_.end(), other.getCompressed().begin(), other.getCompressed().end());
125  return true;
126 }

References compressedContent_, content_, and trackingPlots::other.

◆ swap()

void LHEXMLStringProduct::swap ( LHEXMLStringProduct other)

Definition at line 128 of file LHEXMLStringProduct.cc.

128  {
129  content_.swap(other.content_);
130  compressedContent_.swap(other.compressedContent_);
131 }

References compressedContent_, content_, and trackingPlots::other.

◆ writeCompressedContent()

void LHEXMLStringProduct::writeCompressedContent ( std::ostream &  output,
unsigned int  i 
) const

Definition at line 84 of file LHEXMLStringProduct.cc.

84  {
85  //initialize lzma
86  lzma_stream strm = LZMA_STREAM_INIT;
87  lzma_ret ret = lzma_stream_decoder(&strm, UINT64_MAX, LZMA_CONCATENATED);
88  //all output available from the start, so start "close out" immediately
89  lzma_action action = LZMA_FINISH;
90 
91  //write buffer
92  constexpr unsigned int bufsize = 4096;
93  char outbuf[bufsize];
94 
95  const std::vector<uint8_t> &input = compressedContent_[i];
96 
97  strm.next_in = input.data();
98  strm.avail_in = input.size();
99  strm.next_out = reinterpret_cast<uint8_t *>(&outbuf[0]);
100  strm.avail_out = bufsize;
101 
102  while (ret == LZMA_OK) {
103  ret = lzma_code(&strm, action);
104 
105  //write to stream
106  output.write(outbuf, bufsize - strm.avail_out);
107 
108  //output buffer full, recycle
109  if (strm.avail_out == 0 && ret == LZMA_OK) {
110  strm.next_out = reinterpret_cast<uint8_t *>(&outbuf[0]);
111  strm.avail_out = bufsize;
112  }
113  }
114 
115  lzma_end(&strm);
116 
117  if (ret != LZMA_STREAM_END) {
118  throw cms::Exception("DecompressionError") << "There was a failure in LZMA decompression in LHEXMLStringProduct.";
119  }
120 }

References writedatasetfile::action, compressedContent_, Exception, mps_fire::i, input, convertSQLitetoXML_cfg::output, and runTheMatrix::ret.

Referenced by ExternalLHEAsciiDumper::endRun().

Member Data Documentation

◆ compressedContent_

std::vector<std::vector<uint8_t> > LHEXMLStringProduct::compressedContent_
private

◆ content_

std::vector<std::string> LHEXMLStringProduct::content_
private

Definition at line 32 of file LHEXMLStringProduct.h.

Referenced by getStrings(), mergeProduct(), and swap().

runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:373
mps_fire.i
i
Definition: mps_fire.py:428
input
static const std::string input
Definition: EdmProvDump.cc:48
LHEXMLStringProduct::compressedContent_
std::vector< std::vector< uint8_t > > compressedContent_
Definition: LHEXMLStringProduct.h:33
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
LHEXMLStringProduct::content_
std::vector< std::string > content_
Definition: LHEXMLStringProduct.h:32
trackingPlots.other
other
Definition: trackingPlots.py:1467
writedatasetfile.action
action
Definition: writedatasetfile.py:8
Exception
Definition: hltDiff.cc:246