Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleZip.hxx
Go to the documentation of this file.
1/// \file ROOT/RNTupleZip.hxx
2/// \ingroup NTuple ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2019-11-21
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
16#ifndef ROOT7_RNTupleZip
17#define ROOT7_RNTupleZip
18
19#include <RZip.h>
20#include <TError.h>
21
22#include <algorithm>
23#include <array>
24#include <cstring>
25#include <functional>
26#include <memory>
27#include <utility>
28
29namespace ROOT {
30namespace Internal {
31
32// clang-format off
33/**
34\class ROOT::Internal::RNTupleCompressor
35\ingroup NTuple
36\brief Helper class to compress data blocks in the ROOT compression frame format
37*/
38// clang-format on
40public:
46
47 /// Returns the size of the compressed data, written into the provided output buffer.
48 static std::size_t Zip(const void *from, std::size_t nbytes, int compression, void *to)
49 {
50 R__ASSERT(from != nullptr);
51 R__ASSERT(to != nullptr);
52 auto cxLevel = compression % 100;
53 if (cxLevel == 0) {
54 memcpy(to, from, nbytes);
55 return nbytes;
56 }
57
59 unsigned int nZipBlocks = 1 + (nbytes - 1) / kMAXZIPBUF;
60 char *source = const_cast<char *>(static_cast<const char *>(from));
61 int szTarget = nbytes;
62 char *target = reinterpret_cast<char *>(to);
63 int szOutBlock = 0;
64 int szRemaining = nbytes;
65 size_t szZipData = 0;
66 for (unsigned int i = 0; i < nZipBlocks; ++i) {
67 int szSource = std::min(static_cast<int>(kMAXZIPBUF), szRemaining);
70 if ((szOutBlock == 0) || (szOutBlock >= szSource)) {
71 // Uncompressible block, we have to store the entire input data stream uncompressed
72 memcpy(to, from, nbytes);
73 return nbytes;
74 }
75
80 }
83 return szZipData;
84 }
85};
86
87// clang-format off
88/**
89\class ROOT::Internal::RNTupleDecompressor
90\ingroup NTuple
91\brief Helper class to uncompress data blocks in the ROOT compression frame format
92*/
93// clang-format on
95public:
101
102 /**
103 * The nbytes parameter provides the size ls of the from buffer. The dataLen gives the size of the uncompressed data.
104 * The block is uncompressed iff nbytes == dataLen.
105 */
106 static void Unzip(const void *from, size_t nbytes, size_t dataLen, void *to)
107 {
108 if (dataLen == nbytes) {
109 memcpy(to, from, nbytes);
110 return;
111 }
113
114 unsigned char *source = const_cast<unsigned char *>(static_cast<const unsigned char *>(from));
115 unsigned char *target = static_cast<unsigned char *>(to);
116 int szRemaining = dataLen;
117 do {
118 int szSource;
119 int szTarget;
121 R__ASSERT(retval == 0);
122 R__ASSERT(szSource > 0);
124 R__ASSERT(static_cast<unsigned int>(szSource) <= nbytes);
125 R__ASSERT(static_cast<unsigned int>(szTarget) <= dataLen);
126
127 int unzipBytes = 0;
130
131 target += szTarget;
132 source += szSource;
134 } while (szRemaining > 0);
136 }
137};
138
139} // namespace Internal
140} // namespace ROOT
141
142#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