6 #include "Alignment/Geners/interface/BZ2Handle.hh" 7 #include "Alignment/Geners/interface/CStringStream.hh" 8 #include "Alignment/Geners/interface/IOException.hh" 11 const bool defl, z_stream_s& strm,
12 char*
buffer,
const unsigned long long bufLen,
19 strm.next_in =
reinterpret_cast<Bytef*
>(
const_cast<char*
>(
data));
23 strm.next_out =
reinterpret_cast<Bytef*
>(
buffer);
24 strm.avail_out = bufLen;
25 status = defl ? deflate(&strm, Z_FINISH) :
26 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);
30 if (sink.fail())
throw gs::IOWriteFailure(
31 "In gs::doZlibCompression: sink stream failure");
32 }
while (strm.avail_out == 0);
36 assert(strm.avail_in == 0);
37 assert(status == Z_STREAM_END);
38 assert(deflateReset(&strm) == Z_OK);
41 assert(inflateReset(&strm) == Z_OK);
46 const bool defl, bz_stream& strm,
47 char*
buffer,
const unsigned long long bufLen,
54 strm.next_in =
const_cast<char*
>(
data);
59 strm.avail_out = bufLen;
60 status = defl ? BZ2_bzCompress(&strm, BZ_FINISH) :
61 BZ2_bzDecompress(&strm);
62 assert(status == BZ_OK || status == BZ_STREAM_END);
63 const unsigned have = bufLen - strm.avail_out;
64 sink.write(buffer, have);
65 if (sink.fail())
throw gs::IOWriteFailure(
66 "In gs::doBZ2Compression: sink stream failure");
67 }
while (status != BZ_STREAM_END);
72 CStringStream::CStringStream(
const CompressionMode
m,
73 const int compressionLevel,
74 const unsigned minSizeToCompress,
77 compressionLevel_(compressionLevel),
78 minSizeToCompress_(minSizeToCompress),
82 comprBuf_(bufSize > 1024
U ? bufSize : 1024
U),
88 void CStringStream::setCompressionMode(
const CompressionMode newmode)
101 void CStringStream::readCompressed(std::istream&
in,
102 const unsigned compressionCode,
103 const unsigned long long len)
110 if (len > readBuf_.size())
111 readBuf_.resize(len);
112 in.read(&readBuf_[0], len);
114 switch (static_cast<CompressionMode>(compressionCode))
117 this->
write(&readBuf_[0], len);
122 if (!inflator_.get())
123 inflator_ = CPP11_auto_ptr<ZlibInflateHandle>(
124 new ZlibInflateHandle());
126 &comprBuf_[0], comprBuf_.size(), *
this);
135 BZ2InflateHandle
h(strm);
137 &comprBuf_[0], comprBuf_.size(), *
this);
142 assert(!
"Unhandled switch case in " 143 "CStringStream::readCompressed. " 144 "This is a bug. Please report.");
148 CStringStream::CompressionMode CStringStream::writeCompressed()
153 unsigned long long len = 0;
154 const char*
data = buf_.getPutBuffer(&len);
156 return NOT_COMPRESSED;
158 if (mode_ == NOT_COMPRESSED || len < minSizeToCompress_)
160 sink_->write(data, len);
161 return NOT_COMPRESSED;
168 if (!deflator_.get())
169 deflator_ = CPP11_auto_ptr<ZlibDeflateHandle>(
170 new ZlibDeflateHandle(compressionLevel_));
172 &comprBuf_[0], comprBuf_.size(), *sink_);
181 BZ2DeflateHandle
h(strm);
183 &comprBuf_[0], comprBuf_.size(), *sink_);
188 assert(!
"Unhandled switch case in " 189 "CStringStream::writeCompressed. " 190 "This is a bug. Please report.");
197 bool CStringStream::getCompressionModeByName(
const char*
name,
200 static const char*
names[] = {
207 for (
unsigned i=0;
i<
sizeof(
names)/
sizeof(names[0]); ++
i)
208 if (strcasecmp(name, names[
i]) == 0)
210 *m =
static_cast<CompressionMode
>(
i);
216 std::string CStringStream::compressionModeName(
const CompressionMode m,
217 const bool useShortName)
223 mode = useShortName ?
"n" :
"not compressed";
226 mode = useShortName ?
"z" :
"zlib";
229 mode = useShortName ?
"b" :
"bzip2";
232 assert(!
"Unhandled switch case in " 233 "CStringStream::compressionModeName. " 234 "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)
static const HistoName names[]
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
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])