6 #include "Alignment/Geners/interface/BZ2Handle.hh" 7 #include "Alignment/Geners/interface/CStringStream.hh" 8 #include "Alignment/Geners/interface/IOException.hh" 11 const unsigned long long len,
15 const unsigned long long bufLen,
21 strm.next_in =
reinterpret_cast<Bytef *
>(
const_cast<char *
>(
data));
24 strm.next_out =
reinterpret_cast<Bytef *
>(
buffer);
25 strm.avail_out = bufLen;
26 status = defl ? deflate(&strm, Z_FINISH) : inflate(&strm, Z_NO_FLUSH);
27 assert(status == Z_OK || status == Z_STREAM_END);
28 const unsigned have = bufLen - strm.avail_out;
29 sink.write(buffer, have);
31 throw gs::IOWriteFailure(
"In gs::doZlibCompression: sink stream failure");
32 }
while (strm.avail_out == 0);
35 assert(strm.avail_in == 0);
36 assert(status == Z_STREAM_END);
37 assert(deflateReset(&strm) == Z_OK);
39 assert(inflateReset(&strm) == Z_OK);
43 const unsigned long long len,
47 const unsigned long long bufLen,
53 strm.next_in =
const_cast<char *
>(
data);
57 strm.avail_out = bufLen;
58 status = defl ? BZ2_bzCompress(&strm, BZ_FINISH) : BZ2_bzDecompress(&strm);
59 assert(status == BZ_OK || status == BZ_STREAM_END);
60 const unsigned have = bufLen - strm.avail_out;
61 sink.write(buffer, have);
63 throw gs::IOWriteFailure(
"In gs::doBZ2Compression: sink stream failure");
64 }
while (status != BZ_STREAM_END);
68 CStringStream::CStringStream(
const CompressionMode
m,
70 const unsigned minSizeToCompress,
73 compressionLevel_(compressionLevel),
74 minSizeToCompress_(minSizeToCompress),
78 comprBuf_(bufSize > 1024
U ? bufSize : 1024
U),
83 void CStringStream::setCompressionMode(
const CompressionMode newmode) {
94 void CStringStream::readCompressed(std::istream &
in,
const unsigned compressionCode,
const unsigned long long len) {
100 if (len > readBuf_.size())
101 readBuf_.resize(len);
102 in.read(&readBuf_[0], len);
104 switch (static_cast<CompressionMode>(compressionCode)) {
106 this->
write(&readBuf_[0], len);
110 if (!inflator_.get())
111 inflator_ = CPP11_auto_ptr<ZlibInflateHandle>(
new ZlibInflateHandle());
112 doZlibCompression(&readBuf_[0], len,
false, inflator_->strm(), &comprBuf_[0], comprBuf_.size(), *
this);
119 BZ2InflateHandle
h(strm);
120 doBZ2Compression(&readBuf_[0], len,
false, strm, &comprBuf_[0], comprBuf_.size(), *
this);
124 assert(!
"Unhandled switch case in " 125 "CStringStream::readCompressed. " 126 "This is a bug. Please report.");
130 CStringStream::CompressionMode CStringStream::writeCompressed() {
134 unsigned long long len = 0;
135 const char *
data = buf_.getPutBuffer(&len);
137 return NOT_COMPRESSED;
139 if (mode_ == NOT_COMPRESSED || len < minSizeToCompress_) {
140 sink_->write(data, len);
141 return NOT_COMPRESSED;
146 if (!deflator_.get())
147 deflator_ = CPP11_auto_ptr<ZlibDeflateHandle>(
new ZlibDeflateHandle(compressionLevel_));
148 doZlibCompression(data, len,
true, deflator_->strm(), &comprBuf_[0], comprBuf_.size(), *sink_);
155 BZ2DeflateHandle
h(strm);
156 doBZ2Compression(data, len,
true, strm, &comprBuf_[0], comprBuf_.size(), *sink_);
160 assert(!
"Unhandled switch case in " 161 "CStringStream::writeCompressed. " 162 "This is a bug. Please report.");
169 bool CStringStream::getCompressionModeByName(
const char *
name, CompressionMode *m) {
170 static const char *
names[] = {
"n",
"z",
"b"};
173 for (
unsigned i = 0;
i <
sizeof(
names) /
sizeof(names[0]); ++
i)
174 if (strcasecmp(name, names[
i]) == 0) {
175 *m =
static_cast<CompressionMode
>(
i);
181 std::string CStringStream::compressionModeName(
const CompressionMode m,
const bool useShortName) {
185 mode = useShortName ?
"n" :
"not compressed";
188 mode = useShortName ?
"z" :
"zlib";
191 mode = useShortName ?
"b" :
"bzip2";
194 assert(!
"Unhandled switch case in " 195 "CStringStream::compressionModeName. " 196 "This is a bug. Please report.");
static void doBZ2Compression(const char *data, const unsigned long long len, const bool defl, bz_stream &strm, char *buffer, const unsigned long long bufLen, std::ostream &sink)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
const std::string names[nVars_]
static void doZlibCompression(const char *data, const unsigned long long len, const bool defl, z_stream_s &strm, char *buffer, const unsigned long long bufLen, std::ostream &sink)
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
char data[epos_bytes_allocation]
void reset(double vett[256])