Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
RNTupleZip.hxx
Go to the documentation of this file.
1/// \file ROOT/RNTupleZip.hxx
2/// \ingroup NTuple
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2019-11-21
5
6/*************************************************************************
7 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
8 * All rights reserved. *
9 * *
10 * For the licensing terms see $ROOTSYS/LICENSE. *
11 * For the list of contributors see $ROOTSYS/README/CREDITS. *
12 *************************************************************************/
13
14#ifndef ROOT_RNTupleZip
15#define ROOT_RNTupleZip
16
17#include <RZip.h>
18#include <TError.h>
19
20#include <algorithm>
21#include <array>
22#include <cstring>
23#include <functional>
24#include <memory>
25#include <utility>
26
27namespace ROOT {
28namespace Internal {
29
30// clang-format off
31/**
32\class ROOT::Internal::RNTupleCompressor
33\ingroup NTuple
34\brief Helper class to compress data blocks in the ROOT compression frame format
35*/
36// clang-format on
38public:
44
45 /// Returns the size of the compressed data, written into the provided output buffer.
46 static std::size_t Zip(const void *from, std::size_t nbytes, int compression, void *to)
47 {
48 R__ASSERT(from != nullptr);
49 R__ASSERT(to != nullptr);
50 auto cxLevel = compression % 100;
51 if (cxLevel == 0) {
52 memcpy(to, from, nbytes);
53 return nbytes;
54 }
55
57 unsigned int nZipBlocks = 1 + (nbytes - 1) / kMAXZIPBUF;
58 char *source = const_cast<char *>(static_cast<const char *>(from));
59 int szTarget = nbytes;
60 char *target = reinterpret_cast<char *>(to);
61 int szOutBlock = 0;
62 int szRemaining = nbytes;
63 size_t szZipData = 0;
64 for (unsigned int i = 0; i < nZipBlocks; ++i) {
65 int szSource = std::min(static_cast<int>(kMAXZIPBUF), szRemaining);
68 if ((szOutBlock == 0) || (szOutBlock >= szSource)) {
69 // Uncompressible block, we have to store the entire input data stream uncompressed
70 memcpy(to, from, nbytes);
71 return nbytes;
72 }
73
78 }
81 return szZipData;
82 }
83};
84
85// clang-format off
86/**
87\class ROOT::Internal::RNTupleDecompressor
88\ingroup NTuple
89\brief Helper class to uncompress data blocks in the ROOT compression frame format
90*/
91// clang-format on
93public:
99
100 /**
101 * The nbytes parameter provides the size ls of the from buffer. The dataLen gives the size of the uncompressed data.
102 * The block is uncompressed iff nbytes == dataLen.
103 */
104 static void Unzip(const void *from, size_t nbytes, size_t dataLen, void *to)
105 {
106 if (dataLen == nbytes) {
107 memcpy(to, from, nbytes);
108 return;
109 }
111
112 unsigned char *source = const_cast<unsigned char *>(static_cast<const unsigned char *>(from));
113 unsigned char *target = static_cast<unsigned char *>(to);
114 int szRemaining = dataLen;
115 do {
116 int szSource;
117 int szTarget;
119 R__ASSERT(retval == 0);
120 R__ASSERT(szSource > 0);
122 R__ASSERT(static_cast<unsigned int>(szSource) <= nbytes);
123 R__ASSERT(static_cast<unsigned int>(szTarget) <= dataLen);
124
125 int unzipBytes = 0;
128
129 target += szTarget;
130 source += szSource;
132 } while (szRemaining > 0);
134 }
135};
136
137} // namespace Internal
138} // namespace ROOT
139
140#endif
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
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.
RNTupleCompressor & operator=(const RNTupleCompressor &other)=delete
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.
RNTupleCompressor(RNTupleCompressor &&other)=delete
RNTupleCompressor(const RNTupleCompressor &other)=delete
RNTupleCompressor & operator=(RNTupleCompressor &&other)=delete
Helper class to uncompress data blocks in the ROOT compression frame format.
RNTupleDecompressor(RNTupleDecompressor &&other)=delete
static void Unzip(const void *from, size_t nbytes, size_t dataLen, void *to)
The nbytes parameter provides the size ls of the from buffer.
RNTupleDecompressor(const RNTupleDecompressor &other)=delete
RNTupleDecompressor & operator=(const RNTupleDecompressor &other)=delete
RNTupleDecompressor & operator=(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 convention used.
Definition Compression.h:88