16#ifndef ROOT7_RNTupleZip
17#define ROOT7_RNTupleZip
30namespace Experimental {
42 using Buffer_t = std::array<unsigned char, kMAXZIPBUF>;
48 using Writer_t = std::function<
void(
const void *buffer,
size_t nbytes,
size_t offset)>;
51 return [=](
const void *
b,
size_t n,
size_t o) { memcpy(
dest + o,
b,
n); };
63 size_t Zip(
const void *from,
size_t nbytes,
int compression,
Writer_t fnWriter) {
66 auto cxLevel = compression % 100;
68 fnWriter(from, nbytes, 0);
73 unsigned int nZipBlocks = 1 + (nbytes - 1) / kMAXZIPBUF;
74 char *source =
const_cast<char *
>(
static_cast<const char *
>(from));
75 int szTarget = kMAXZIPBUF;
76 char *target =
reinterpret_cast<char *
>(
fZipBuffer->data());
78 int szRemaining = nbytes;
80 for (
unsigned int i = 0; i < nZipBlocks; ++i) {
81 int szSource = std::min(
static_cast<int>(kMAXZIPBUF), szRemaining);
82 R__zipMultipleAlgorithm(cxLevel, &szSource, source, &szTarget, target, &szOutBlock, cxAlgorithm);
84 if ((szOutBlock == 0) || (szOutBlock >= szSource)) {
86 fnWriter(from, nbytes, 0);
90 fnWriter(target, szOutBlock, szZipData);
91 szZipData += szOutBlock;
93 szRemaining -= szSource;
102 size_t Zip(
const void *from,
size_t nbytes,
int compression) {
106 auto cxLevel = compression % 100;
113 int szSource = nbytes;
114 char *source =
const_cast<char *
>(
static_cast<const char *
>(from));
115 int szTarget = nbytes;
116 char *target =
reinterpret_cast<char *
>(
fZipBuffer->data());
118 R__zipMultipleAlgorithm(cxLevel, &szSource, source, &szTarget, target, &szOut, cxAlgorithm);
120 if ((szOut > 0) && (
static_cast<unsigned int>(szOut) < nbytes))
128 static std::size_t
Zip(
const void *from, std::size_t nbytes,
int compression,
void *to) {
131 auto cxLevel = compression % 100;
133 memcpy(to, from, nbytes);
138 unsigned int nZipBlocks = 1 + (nbytes - 1) / kMAXZIPBUF;
139 char *source =
const_cast<char *
>(
static_cast<const char *
>(from));
140 int szTarget = nbytes;
141 char *target =
reinterpret_cast<char *
>(to);
143 int szRemaining = nbytes;
144 size_t szZipData = 0;
145 for (
unsigned int i = 0; i < nZipBlocks; ++i) {
146 int szSource = std::min(
static_cast<int>(kMAXZIPBUF), szRemaining);
147 R__zipMultipleAlgorithm(cxLevel, &szSource, source, &szTarget, target, &szOutBlock, cxAlgorithm);
149 if ((szOutBlock == 0) || (szOutBlock >= szSource)) {
151 memcpy(to, from, nbytes);
155 szZipData += szOutBlock;
157 szRemaining -= szSource;
177 using Buffer_t = std::array<unsigned char, kMAXZIPBUF>;
191 void Unzip(
const void *from,
size_t nbytes,
size_t dataLen,
void *to) {
192 if (dataLen == nbytes) {
193 memcpy(to, from, nbytes);
198 unsigned char *source =
const_cast<unsigned char *
>(
static_cast<const unsigned char *
>(from));
199 unsigned char *target =
static_cast<unsigned char *
>(to);
200 int szRemaining = dataLen;
208 R__ASSERT(
static_cast<unsigned int>(szSource) <= nbytes);
209 R__ASSERT(
static_cast<unsigned int>(szTarget) <= dataLen);
212 R__unzip(&szSource, source, &szTarget, target, &unzipBytes);
217 szRemaining -= unzipBytes;
218 }
while (szRemaining > 0);
225 void Unzip(
void *fromto,
size_t nbytes,
size_t dataLen) {
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
void R__unzip(Int_t *nin, UChar_t *bufin, Int_t *lout, char *bufout, Int_t *nout)
int R__unzip_header(Int_t *nin, UChar_t *bufin, Int_t *lout)
Helper class to compress data blocks in the ROOT compression frame format.
static constexpr size_t kMaxSingleBlock
std::array< unsigned char, kMAXZIPBUF > Buffer_t
std::unique_ptr< Buffer_t > fZipBuffer
RNTupleCompressor(RNTupleCompressor &&other)=default
static Writer_t MakeMemCopyWriter(unsigned char *dest)
std::function< void(const void *buffer, size_t nbytes, size_t offset)> Writer_t
Data might be overwritten, if a zipped block in the middle of a large input data stream turns out to ...
size_t Zip(const void *from, size_t nbytes, int compression)
Returns the size of the compressed data block.
static std::size_t Zip(const void *from, std::size_t nbytes, int compression, void *to)
Returns the size of the compressed data, written into the provided output buffer.
size_t Zip(const void *from, size_t nbytes, int compression, Writer_t fnWriter)
Returns the size of the compressed data.
RNTupleCompressor(const RNTupleCompressor &other)=delete
RNTupleCompressor & operator=(const RNTupleCompressor &other)=delete
Helper class to uncompress data blocks in the ROOT compression frame format.
RNTupleDecompressor & operator=(const RNTupleDecompressor &other)=delete
std::array< unsigned char, kMAXZIPBUF > Buffer_t
void Unzip(const void *from, size_t nbytes, size_t dataLen, void *to)
The nbytes parameter provides the size ls of the from buffer.
void Unzip(void *fromto, size_t nbytes, size_t dataLen)
In-place decompression via unzip buffer.
std::unique_ptr< Buffer_t > fUnzipBuffer
RNTupleDecompressor(RNTupleDecompressor &&other)=default
RNTupleDecompressor(const RNTupleDecompressor &other)=delete
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
EValues
Note: this is only temporarily a struct and will become a enum class hence the name.
#define dest(otri, vertexptr)