ECCE @ EIC Software
Reference for
ECCE @ EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
DeflateOutputStreamBuffer.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file DeflateOutputStreamBuffer.cc
1
// Copyright FreeHEP, 2005.
2
3
#include "
cheprep/DeflateOutputStreamBuffer.h
"
4
8
namespace
cheprep {
9
10
using namespace
std;
11
12
unsigned
long
DeflateOutputStreamBuffer::crctable
[] = {
13
0x00000000
L
, 0x77073096
L
, 0xEE0E612C
L
, 0x990951BA
L
,
14
0x076DC419
L
, 0x706AF48F
L
, 0xE963A535
L
, 0x9E6495A3
L
,
15
0x0EDB8832
L
, 0x79DCB8A4
L
, 0xE0D5E91E
L
, 0x97D2D988
L
,
16
0x09B64C2B
L
, 0x7EB17CBD
L
, 0xE7B82D07
L
, 0x90BF1D91
L
,
17
0x1DB71064
L
, 0x6AB020F2
L
, 0xF3B97148
L
, 0x84BE41DE
L
,
18
0x1ADAD47D
L
, 0x6DDDE4EB
L
, 0xF4D4B551
L
, 0x83D385C7
L
,
19
0x136C9856
L
, 0x646BA8C0
L
, 0xFD62F97A
L
, 0x8A65C9EC
L
,
20
0x14015C4F
L
, 0x63066CD9
L
, 0xFA0F3D63
L
, 0x8D080DF5
L
,
21
0x3B6E20C8
L
, 0x4C69105E
L
, 0xD56041E4
L
, 0xA2677172
L
,
22
0x3C03E4D1
L
, 0x4B04D447
L
, 0xD20D85FD
L
, 0xA50AB56B
L
,
23
0x35B5A8FA
L
, 0x42B2986C
L
, 0xDBBBC9D6
L
, 0xACBCF940
L
,
24
0x32D86CE3
L
, 0x45DF5C75
L
, 0xDCD60DCF
L
, 0xABD13D59
L
,
25
0x26D930AC
L
, 0x51DE003A
L
, 0xC8D75180
L
, 0xBFD06116
L
,
26
0x21B4F4B5
L
, 0x56B3C423
L
, 0xCFBA9599
L
, 0xB8BDA50F
L
,
27
0x2802B89E
L
, 0x5F058808
L
, 0xC60CD9B2
L
, 0xB10BE924
L
,
28
0x2F6F7C87
L
, 0x58684C11
L
, 0xC1611DAB
L
, 0xB6662D3D
L
,
29
0x76DC4190
L
, 0x01DB7106
L
, 0x98D220BC
L
, 0xEFD5102A
L
,
30
0x71B18589
L
, 0x06B6B51F
L
, 0x9FBFE4A5
L
, 0xE8B8D433
L
,
31
0x7807C9A2
L
, 0x0F00F934
L
, 0x9609A88E
L
, 0xE10E9818
L
,
32
0x7F6A0DBB
L
, 0x086D3D2D
L
, 0x91646C97
L
, 0xE6635C01
L
,
33
0x6B6B51F4
L
, 0x1C6C6162
L
, 0x856530D8
L
, 0xF262004E
L
,
34
0x6C0695ED
L
, 0x1B01A57B
L
, 0x8208F4C1
L
, 0xF50FC457
L
,
35
0x65B0D9C6
L
, 0x12B7E950
L
, 0x8BBEB8EA
L
, 0xFCB9887C
L
,
36
0x62DD1DDF
L
, 0x15DA2D49
L
, 0x8CD37CF3
L
, 0xFBD44C65
L
,
37
0x4DB26158
L
, 0x3AB551CE
L
, 0xA3BC0074
L
, 0xD4BB30E2
L
,
38
0x4ADFA541
L
, 0x3DD895D7
L
, 0xA4D1C46D
L
, 0xD3D6F4FB
L
,
39
0x4369E96A
L
, 0x346ED9FC
L
, 0xAD678846
L
, 0xDA60B8D0
L
,
40
0x44042D73
L
, 0x33031DE5
L
, 0xAA0A4C5F
L
, 0xDD0D7CC9
L
,
41
0x5005713C
L
, 0x270241AA
L
, 0xBE0B1010
L
, 0xC90C2086
L
,
42
0x5768B525
L
, 0x206F85B3
L
, 0xB966D409
L
, 0xCE61E49F
L
,
43
0x5EDEF90E
L
, 0x29D9C998
L
, 0xB0D09822
L
, 0xC7D7A8B4
L
,
44
0x59B33D17
L
, 0x2EB40D81
L
, 0xB7BD5C3B
L
, 0xC0BA6CAD
L
,
45
0xEDB88320
L
, 0x9ABFB3B6
L
, 0x03B6E20C
L
, 0x74B1D29A
L
,
46
0xEAD54739
L
, 0x9DD277AF
L
, 0x04DB2615
L
, 0x73DC1683
L
,
47
0xE3630B12
L
, 0x94643B84
L
, 0x0D6D6A3E
L
, 0x7A6A5AA8
L
,
48
0xE40ECF0B
L
, 0x9309FF9D
L
, 0x0A00AE27
L
, 0x7D079EB1
L
,
49
0xF00F9344
L
, 0x8708A3D2
L
, 0x1E01F268
L
, 0x6906C2FE
L
,
50
0xF762575D
L
, 0x806567CB
L
, 0x196C3671
L
, 0x6E6B06E7
L
,
51
0xFED41B76
L
, 0x89D32BE0
L
, 0x10DA7A5A
L
, 0x67DD4ACC
L
,
52
0xF9B9DF6F
L
, 0x8EBEEFF9
L
, 0x17B7BE43
L
, 0x60B08ED5
L
,
53
0xD6D6A3E8
L
, 0xA1D1937E
L
, 0x38D8C2C4
L
, 0x4FDFF252
L
,
54
0xD1BB67F1
L
, 0xA6BC5767
L
, 0x3FB506DD
L
, 0x48B2364B
L
,
55
0xD80D2BDA
L
, 0xAF0A1B4C
L
, 0x36034AF6
L
, 0x41047A60
L
,
56
0xDF60EFC3
L
, 0xA867DF55
L
, 0x316E8EEF
L
, 0x4669BE79
L
,
57
0xCB61B38C
L
, 0xBC66831A
L
, 0x256FD2A0
L
, 0x5268E236
L
,
58
0xCC0C7795
L
, 0xBB0B4703
L
, 0x220216B9
L
, 0x5505262F
L
,
59
0xC5BA3BBE
L
, 0xB2BD0B28
L
, 0x2BB45A92
L
, 0x5CB36A04
L
,
60
0xC2D7FFA7
L
, 0xB5D0CF31
L
, 0x2CD99E8B
L
, 0x5BDEAE1D
L
,
61
0x9B64C2B0
L
, 0xEC63F226
L
, 0x756AA39C
L
, 0x026D930A
L
,
62
0x9C0906A9
L
, 0xEB0E363F
L
, 0x72076785
L
, 0x05005713
L
,
63
0x95BF4A82
L
, 0xE2B87A14
L
, 0x7BB12BAE
L
, 0x0CB61B38
L
,
64
0x92D28E9B
L
, 0xE5D5BE0D
L
, 0x7CDCEFB7
L
, 0x0BDBDF21
L
,
65
0x86D3D2D4
L
, 0xF1D4E242
L
, 0x68DDB3F8
L
, 0x1FDA836E
L
,
66
0x81BE16CD
L
, 0xF6B9265B
L
, 0x6FB077E1
L
, 0x18B74777
L
,
67
0x88085AE6
L
, 0xFF0F6A70
L
, 0x66063BCA
L
, 0x11010B5C
L
,
68
0x8F659EFF
L
, 0xF862AE69
L
, 0x616BFFD3
L
, 0x166CCF45
L
,
69
0xA00AE278
L
, 0xD70DD2EE
L
, 0x4E048354
L
, 0x3903B3C2
L
,
70
0xA7672661
L
, 0xD06016F7
L
, 0x4969474D
L
, 0x3E6E77DB
L
,
71
0xAED16A4A
L
, 0xD9D65ADC
L
, 0x40DF0B66
L
, 0x37D83BF0
L
,
72
0xA9BCAE53
L
, 0xDEBB9EC5
L
, 0x47B2CF7F
L
, 0x30B5FFE9
L
,
73
0xBDBDF21C
L
, 0xCABAC28A
L
, 0x53B39330
L
, 0x24B4A3A6
L
,
74
0xBAD03605
L
, 0xCDD70693
L
, 0x54DE5729
L
, 0x23D967BF
L
,
75
0xB3667A2E
L
, 0xC4614AB8
L
, 0x5D681B02
L
, 0x2A6F2B94
L
,
76
0xB40BBE37
L
, 0xC30C8EA1
L
, 0x5A05DF1B
L
, 0x2D02EF8DL
77
};
78
79
DeflateOutputStreamBuffer::DeflateOutputStreamBuffer
(streambuf *aBuffer)
80
:
buffer
(aBuffer)
81
, crc(0)
82
, size(0)
83
#ifndef CHEPREP_NO_ZLIB
84
, zStreamOpen(
false
)
85
,
in
(inSize)
86
, out(outSize)
87
#endif
// CHEPREP_NO_ZLIB
88
{
89
90
#ifndef CHEPREP_NO_ZLIB
91
zStream
.
zalloc
=
Z_NULL
;
92
zStream
.
zfree
=
Z_NULL
;
93
zStream
.
opaque
=
Z_NULL
;
94
zStream
.
msg
= 0;
95
zStream
.
next_in
= 0;
96
zStream
.
next_out
= 0;
97
zStream
.
state
= 0;
98
#endif // CHEPREP_NO_ZLIB
99
}
100
101
#ifndef CHEPREP_NO_ZLIB
102
void
DeflateOutputStreamBuffer::init
(
bool
compress
) {
103
104
if
(compress) {
105
if
(
zStreamOpen
)
return
;
106
107
zStream
.
next_in
=
reinterpret_cast<
unsigned
char
*
>
(&(
in
[0]));
108
zStream
.
avail_in
= 0 ;
109
110
zStream
.
next_out
=
reinterpret_cast<
unsigned
char
*
>
(&(
out
[0]));
111
zStream
.
avail_out
=
out
.size();
112
113
if
(
deflateInit2
(&
zStream
, 6,
Z_DEFLATED
, -MAX_WBITS, 8,
Z_DEFAULT_STRATEGY
) !=
Z_OK
) {
114
cerr <<
"ERROR: deflateInit2 failed"
<< endl;
115
}
else
{
116
zStreamOpen
=
true
;
117
setp(&(
in
[0]), &(
in
[0])+
inSize
);
118
}
119
}
120
#else
121
void
DeflateOutputStreamBuffer::init
(
bool
/*compress*/
) {
122
#endif // CHEPREP_NO_ZLIB
123
124
crc
= 0;
125
size
= 0;
126
}
127
128
void
DeflateOutputStreamBuffer::finish
() {
129
130
#ifndef CHEPREP_NO_ZLIB
131
if
(
zStreamOpen
) {
132
133
overflow
() ;
134
135
zStream
.
next_out
=
reinterpret_cast<
unsigned
char
*
>
(&(
out
[0]));
136
zStream
.
avail_out
=
outSize
;
137
138
int
err
=
Z_OK
;
139
while
( err ==
Z_OK
) {
140
if
(
zStream
.
avail_out
== 0) {
141
flushOut
();
142
}
143
err =
deflate
(&
zStream
,
Z_FINISH
);
144
}
145
146
flushOut
() ;
147
148
if
(err !=
Z_STREAM_END
) {
149
cerr <<
"ERROR: deflation failed"
<< endl;
150
}
151
152
if
(
deflateEnd
(&
zStream
) !=
Z_OK
) {
153
cerr <<
"ERROR: deflateEnd failed"
<< endl;
154
}
155
156
zStreamOpen
=
false
;
157
}
158
#endif // CHEPREP_NO_ZLIB
159
}
160
161
DeflateOutputStreamBuffer::~DeflateOutputStreamBuffer
() {
162
}
163
164
165
#ifndef CHEPREP_NO_ZLIB
166
#define DO1 crc = crctable[(crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
167
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
168
#endif // CHEPREP_NO_ZLIB
169
170
171
int
DeflateOutputStreamBuffer::overflow
(
int
c
) {
172
173
#ifndef CHEPREP_NO_ZLIB
174
if
(
zStreamOpen
) {
175
zStream
.
avail_in
= pptr() - pbase() ;
176
zStream
.
next_in
=
reinterpret_cast<
unsigned
char
*
>
(&(
in
[0]));
177
178
int
len
=
zStream
.
avail_in
;
179
unsigned
char
* buf =
zStream
.
next_in
;
180
181
crc
=
crc
^ 0xffffffffUL;
182
while
(len >= 8) {
183
DO8
;
184
len -= 8;
185
}
186
if
(len)
do
{
187
DO1
;
188
}
while
(--len);
189
crc
=
crc
^ 0xffffffffUL;
190
191
size
+=
zStream
.
avail_in
;
192
193
zStream
.
next_out
=
reinterpret_cast<
unsigned
char
*
>
(&(
out
[0]));
194
zStream
.
avail_out
=
outSize
;
195
196
int
err
=
Z_OK
;
197
while
((
zStream
.
avail_in
> 0 ||
zStream
.
avail_out
== 0) && err ==
Z_OK
) {
198
if
(
zStream
.
avail_out
== 0 ) {
199
flushOut
();
200
}
201
err =
deflate
(&
zStream
,
Z_NO_FLUSH
);
202
}
203
204
flushOut
();
205
206
setp(&(
in
[0]), &(
in
[0]) +
inSize
);
207
208
if
((err !=
Z_OK
) && (err !=
Z_STREAM_END
)) {
209
cerr <<
"ERROR: deflation failed"
<< endl;
210
return
EOF ;
211
}
212
213
if
( c != EOF ) {
214
*pptr() =
c
;
215
pbump(1);
216
}
217
218
return
0 ;
219
}
else
{
220
#endif // CHEPREP_NO_ZLIB
221
crc
=
crc
^ 0xffffffffUL;
222
crc
=
crctable
[(
crc
^
c
) & 0xff] ^ (
crc
>> 8);
223
crc
=
crc
^ 0xffffffffUL;
224
size
++;
225
return
buffer
->sputc((
char
)c);
226
#ifndef CHEPREP_NO_ZLIB
227
}
228
#endif // CHEPREP_NO_ZLIB
229
}
230
231
232
#ifndef CHEPREP_NO_ZLIB
233
bool
DeflateOutputStreamBuffer::flushOut
() {
234
int
deflatedCount =
outSize
-
zStream
.
avail_out
;
235
int
byteCount =
buffer
->sputn(&(
out
[0]), deflatedCount);
236
237
zStream
.
next_out
=
reinterpret_cast<
unsigned
char
*
>
(&(
out
[0]));
238
zStream
.
avail_out
=
outSize
;
239
240
return
deflatedCount == byteCount ;
241
}
242
#endif // CHEPREP_NO_ZLIB
243
244
}
// cheprep
geant4
tree
geant4-10.6-release
source
visualization
HepRep
src
DeflateOutputStreamBuffer.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:25:55
using
1.8.2 with
ECCE GitHub integration