Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleUtil.cxx
Go to the documentation of this file.
1/// \file RNTupleUtil.cxx
2/// \ingroup NTuple ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch> & Max Orok <maxwellorok@gmail.com>
4/// \date 2020-07-14
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-2020, 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#include "ROOT/RNTupleUtil.hxx"
17
18#include "ROOT/RLogger.hxx"
19#include "ROOT/RMiniFile.hxx"
20
21#include <cstring>
22#include <iostream>
23
25 static RLogChannel sLog("ROOT.NTuple");
26 return sLog;
27}
28
29
30namespace ROOT {
31namespace Experimental {
32namespace Internal {
33
34/// \brief Machine-independent serialization functions for fundamental types.
35namespace RNTupleSerialization {
36
37std::uint32_t SerializeInt64(std::int64_t val, void *buffer)
38{
39 if (buffer != nullptr) {
40 auto bytes = reinterpret_cast<unsigned char *>(buffer);
41 bytes[0] = (val & 0x00000000000000FF);
42 bytes[1] = (val & 0x000000000000FF00) >> 8;
43 bytes[2] = (val & 0x0000000000FF0000) >> 16;
44 bytes[3] = (val & 0x00000000FF000000) >> 24;
45 bytes[4] = (val & 0x000000FF00000000) >> 32;
46 bytes[5] = (val & 0x0000FF0000000000) >> 40;
47 bytes[6] = (val & 0x00FF000000000000) >> 48;
48 bytes[7] = (val & 0xFF00000000000000) >> 56;
49 }
50 return 8;
51}
52
53std::uint32_t SerializeUInt64(std::uint64_t val, void *buffer)
54{
55 return SerializeInt64(val, buffer);
56}
57
58std::uint32_t DeserializeInt64(const void *buffer, std::int64_t *val)
59{
60 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
61 *val = std::int64_t(bytes[0]) + (std::int64_t(bytes[1]) << 8) +
62 (std::int64_t(bytes[2]) << 16) + (std::int64_t(bytes[3]) << 24) +
63 (std::int64_t(bytes[4]) << 32) + (std::int64_t(bytes[5]) << 40) +
64 (std::int64_t(bytes[6]) << 48) + (std::int64_t(bytes[7]) << 56);
65 return 8;
66}
67
68std::uint32_t DeserializeUInt64(const void *buffer, std::uint64_t *val)
69{
70 return DeserializeInt64(buffer, reinterpret_cast<std::int64_t *>(val));
71}
72
73std::uint32_t SerializeInt32(std::int32_t val, void *buffer)
74{
75 if (buffer != nullptr) {
76 auto bytes = reinterpret_cast<unsigned char *>(buffer);
77 bytes[0] = (val & 0x000000FF);
78 bytes[1] = (val & 0x0000FF00) >> 8;
79 bytes[2] = (val & 0x00FF0000) >> 16;
80 bytes[3] = (val & 0xFF000000) >> 24;
81 }
82 return 4;
83}
84
85std::uint32_t SerializeUInt32(std::uint32_t val, void *buffer)
86{
87 return SerializeInt32(val, buffer);
88}
89
90std::uint32_t DeserializeInt32(const void *buffer, std::int32_t *val)
91{
92 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
93 *val = std::int32_t(bytes[0]) + (std::int32_t(bytes[1]) << 8) +
94 (std::int32_t(bytes[2]) << 16) + (std::int32_t(bytes[3]) << 24);
95 return 4;
96}
97
98std::uint32_t DeserializeUInt32(const void *buffer, std::uint32_t *val)
99{
100 return DeserializeInt32(buffer, reinterpret_cast<std::int32_t *>(val));
101}
102
103std::uint32_t SerializeInt16(std::int16_t val, void *buffer)
104{
105 if (buffer != nullptr) {
106 auto bytes = reinterpret_cast<unsigned char *>(buffer);
107 bytes[0] = (val & 0x00FF);
108 bytes[1] = (val & 0xFF00) >> 8;
109 }
110 return 2;
111}
112
113std::uint32_t SerializeUInt16(std::uint16_t val, void *buffer)
114{
115 return SerializeInt16(val, buffer);
116}
117
118std::uint32_t DeserializeInt16(const void *buffer, std::int16_t *val)
119{
120 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
121 *val = std::int16_t(bytes[0]) + (std::int16_t(bytes[1]) << 8);
122 return 2;
123}
124
125std::uint32_t DeserializeUInt16(const void *buffer, std::uint16_t *val)
126{
127 return DeserializeInt16(buffer, reinterpret_cast<std::int16_t *>(val));
128}
129
130std::uint32_t SerializeString(const std::string &val, void *buffer)
131{
132 if (buffer != nullptr) {
133 auto pos = reinterpret_cast<unsigned char *>(buffer);
134 pos += SerializeUInt32(val.length(), pos);
135 memcpy(pos, val.data(), val.length());
136 }
137 return SerializeUInt32(val.length(), nullptr) + val.length();
138}
139
140std::uint32_t DeserializeString(const void *buffer, std::string *val)
141{
142 auto base = reinterpret_cast<const unsigned char *>(buffer);
143 auto bytes = base;
144 std::uint32_t length;
145 bytes += DeserializeUInt32(buffer, &length);
146 val->resize(length);
147 memcpy(&(*val)[0], bytes, length);
148 return bytes + length - base;
149}
150
151} // namespace RNTupleSerialization
152
153void PrintRNTuple(const RNTuple& ntuple, std::ostream& output) {
154 output << "RNTuple {\n";
155 output << " fVersion: " << ntuple.fVersion << ",\n";
156 output << " fSize: " << ntuple.fSize << ",\n";
157 output << " fSeekHeader: " << ntuple.fSeekHeader << ",\n";
158 output << " fNBytesHeader: " << ntuple.fNBytesHeader << ",\n";
159 output << " fLenHeader: " << ntuple.fLenHeader << ",\n";
160 output << " fSeekFooter: " << ntuple.fSeekFooter << ",\n";
161 output << " fNBytesFooter: " << ntuple.fNBytesFooter << ",\n";
162 output << " fLenFooter: " << ntuple.fLenFooter << ",\n";
163 output << " fReserved: " << ntuple.fReserved << ",\n";
164 output << "}";
165}
166
167} // namespace Internal
168} // namespace Experimental
169} // namespace ROOT
A log configuration for a channel, e.g.
Definition RLogger.hxx:101
std::uint32_t DeserializeInt64(const void *buffer, std::int64_t *val)
std::uint32_t DeserializeUInt16(const void *buffer, std::uint16_t *val)
std::uint32_t SerializeInt64(std::int64_t val, void *buffer)
std::uint32_t SerializeUInt32(std::uint32_t val, void *buffer)
std::uint32_t SerializeInt32(std::int32_t val, void *buffer)
std::uint32_t SerializeUInt16(std::uint16_t val, void *buffer)
std::uint32_t SerializeInt16(std::int16_t val, void *buffer)
std::uint32_t DeserializeUInt64(const void *buffer, std::uint64_t *val)
std::uint32_t SerializeUInt64(std::uint64_t val, void *buffer)
std::uint32_t DeserializeString(const void *buffer, std::string *val)
std::uint32_t DeserializeInt16(const void *buffer, std::int16_t *val)
std::uint32_t DeserializeInt32(const void *buffer, std::int32_t *val)
std::uint32_t DeserializeUInt32(const void *buffer, std::uint32_t *val)
std::uint32_t SerializeString(const std::string &val, void *buffer)
void PrintRNTuple(const RNTuple &ntuple, std::ostream &output)
RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Entry point for an RNTuple in a ROOT file.
Definition RMiniFile.hxx:55
std::uint64_t fSeekFooter
The file offset of the footer excluding the TKey part.
Definition RMiniFile.hxx:67
std::uint32_t fLenHeader
The size of the uncompressed ntuple header.
Definition RMiniFile.hxx:65
std::uint64_t fReserved
Currently unused, reserved for later use.
Definition RMiniFile.hxx:73
std::uint32_t fVersion
Allows for evolving the struct in future versions.
Definition RMiniFile.hxx:57
std::uint32_t fNBytesHeader
The size of the compressed ntuple header.
Definition RMiniFile.hxx:63
std::uint32_t fSize
Allows for skipping the struct.
Definition RMiniFile.hxx:59
std::uint32_t fNBytesFooter
The size of the compressed ntuple footer.
Definition RMiniFile.hxx:69
std::uint32_t fLenFooter
The size of the uncompressed ntuple footer.
Definition RMiniFile.hxx:71
std::uint64_t fSeekHeader
The file offset of the header excluding the TKey part.
Definition RMiniFile.hxx:61
static void output(int code)
Definition gifencode.c:226