test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 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::LHEXMLStringProduct ( )

Definition at line 13 of file LHEXMLStringProduct.cc.

14 {
15 }
LHEXMLStringProduct::LHEXMLStringProduct ( const std::string &  content)
LHEXMLStringProduct::~LHEXMLStringProduct ( )
virtual

Definition at line 24 of file LHEXMLStringProduct.cc.

25 {
26 }

Member Function Documentation

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

Definition at line 28 of file LHEXMLStringProduct.cc.

References mps_fire::action, compressedContent_, constexpr, Exception, convertSQLitetoXML_cfg::output, and runTheMatrix::ret.

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

Definition at line 25 of file LHEXMLStringProduct.h.

References compressedContent_.

Referenced by mergeProduct().

25  {
26  return compressedContent_;
27  }
std::vector< std::vector< uint8_t > > compressedContent_
const std::vector<std::string>& LHEXMLStringProduct::getStrings ( ) const
inline

Definition at line 21 of file LHEXMLStringProduct.h.

References content_.

Referenced by mergeProduct().

21  {
22  return content_;
23  }
std::vector< std::string > content_
bool LHEXMLStringProduct::mergeProduct ( LHEXMLStringProduct const &  other)

Definition at line 142 of file LHEXMLStringProduct.cc.

References compressedContent_, content_, getCompressed(), and getStrings().

143 {
144  content_.insert(content_.end(), other.getStrings().begin(), other.getStrings().end());
145  compressedContent_.insert(compressedContent_.end(), other.getCompressed().begin(), other.getCompressed().end());
146  return true;
147 }
std::vector< std::vector< uint8_t > > compressedContent_
std::vector< std::string > content_
void LHEXMLStringProduct::writeCompressedContent ( std::ostream &  output,
unsigned int  i 
) const

Definition at line 98 of file LHEXMLStringProduct.cc.

References mps_fire::action, compressedContent_, constexpr, Exception, i, input, and runTheMatrix::ret.

98  {
99 
100  //initialize lzma
101  lzma_stream strm = LZMA_STREAM_INIT;
102  lzma_ret ret = lzma_stream_decoder(&strm, UINT64_MAX, LZMA_CONCATENATED);
103  //all output available from the start, so start "close out" immediately
104  lzma_action action = LZMA_FINISH;
105 
106  //write buffer
107  constexpr unsigned int bufsize = 4096;
108  char outbuf[bufsize];
109 
110  const std::vector<uint8_t> &input = compressedContent_[i];
111 
112  strm.next_in = input.data();
113  strm.avail_in = input.size();
114  strm.next_out = reinterpret_cast<uint8_t*>(&outbuf[0]);
115  strm.avail_out = bufsize;
116 
117  while (ret==LZMA_OK) {
118 
119  ret = lzma_code(&strm, action);
120 
121  //write to stream
122  output.write(outbuf,bufsize-strm.avail_out);
123 
124  //output buffer full, recycle
125  if (strm.avail_out==0 && ret==LZMA_OK) {
126  strm.next_out = reinterpret_cast<uint8_t*>(&outbuf[0]);
127  strm.avail_out = bufsize;
128  }
129  }
130 
131  lzma_end(&strm);
132 
133  if (ret!=LZMA_STREAM_END) {
134  throw cms::Exception("DecompressionError")
135  << "There was a failure in LZMA decompression in LHEXMLStringProduct.";
136  }
137 
138 }
int i
Definition: DBlmapReader.cc:9
tuple ret
prodAgent to be discontinued
#define constexpr
static std::string const input
Definition: EdmProvDump.cc:44
std::vector< std::vector< uint8_t > > compressedContent_
string action
Definition: mps_fire.py:28

Member Data Documentation

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

Definition at line 37 of file LHEXMLStringProduct.h.

Referenced by getStrings(), and mergeProduct().