Logo ROOT   6.18/05
Reference Guide
RPageStorageRoot.hxx
Go to the documentation of this file.
1/// \file ROOT/RPageStorage.hxx
2/// \ingroup NTuple ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2018-07-19
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_RPageStorageRoot
17#define ROOT7_RPageStorageRoot
18
19#include <ROOT/RPageStorage.hxx>
20#include <ROOT/RColumnModel.hxx>
22#include <ROOT/RNTupleUtil.hxx>
23
24#include <TDirectory.h>
25#include <TFile.h>
26
27#include <memory>
28#include <string>
29#include <unordered_map>
30
31namespace ROOT {
32namespace Experimental {
33
34namespace Internal {
35
37 std::int32_t fVersion = 0;
38 std::string fName;
39 std::string fType;
40 std::string fParentName;
41};
42
44 std::int32_t fVersion = 0;
45 std::string fName;
48 std::string fOffsetColumn;
49};
50
52 std::int32_t fVersion = 0;
53 std::string fModelUuid;
54 std::int32_t fPageSize = 0;
55 std::vector<RFieldHeader> fFields;
56 std::vector<RColumnHeader> fColumns;
57};
58
60 std::int32_t fVersion = 0;
61 std::int32_t fNClusters = 0;
63 std::vector<NTupleSize_t> fNElementsPerColumn;
64};
65
66struct RPageInfo {
67 std::vector<NTupleSize_t> fRangeStarts;
68};
69
71 std::int32_t fVersion = 0;
74 std::vector<RPageInfo> fPagesPerColumn;
75};
76
78 std::int32_t fVersion = 0;
79 int fSize = 0;
80 unsigned char* fContent = nullptr; //[fSize]
81};
82
83} // namespace Internal
84
85
86namespace Detail {
87
88class RPagePool;
89
90/**
91 * Maps the ntuple meta-data to and from TFile
92 */
93class RMapper {
94public:
95 static constexpr const char* kKeySeparator = "_";
96 static constexpr const char* kKeyNTupleHeader = "RFH";
97 static constexpr const char* kKeyNTupleFooter = "RFF";
98 static constexpr const char* kKeyClusterFooter = "RFCF";
99 static constexpr const char* kKeyPagePayload = "RFP";
100
103 std::vector<NTupleSize_t> fRangeStarts;
104 std::vector<NTupleSize_t> fClusterId;
105 std::vector<NTupleSize_t> fPageInCluster;
106 std::vector<NTupleSize_t> fSelfClusterOffset;
107 std::vector<NTupleSize_t> fPointeeClusterOffset;
108 };
109
111 RFieldDescriptor(const std::string &f, const std::string &t) : fFieldName(f), fTypeName(t) {}
112 std::string fFieldName;
113 std::string fTypeName;
114 };
115
117 std::unordered_map<std::int32_t, std::unique_ptr<RColumnModel>> fId2ColumnModel;
118 std::unordered_map<std::string, std::int32_t> fColumnName2Id;
119 std::unordered_map<std::int32_t, std::int32_t> fColumn2Pointee;
120 std::vector<RColumnIndex> fColumnIndex;
121 std::vector<RFieldDescriptor> fRootFields;
122};
123
124
125// clang-format off
126/**
127\class ROOT::Experimental::Detail::RPageSinkRoot
128\ingroup NTuple
129\brief Storage provider that write ntuple pages into a ROOT TFile
130*/
131// clang-format on
132class RPageSinkRoot : public RPageSink {
133public:
134 struct RSettings {
135 TFile *fFile = nullptr;
136 bool fTakeOwnership = false;
137 };
138
139private:
140 static constexpr std::size_t kPageSize = 32000;
141
142 std::string fNTupleName;
143 /// Currently, an ntuple is stored as a directory in a TFile
146 /// Updated on CommitPage and written and reset on CommitCluster
150
153
154public:
155 RPageSinkRoot(std::string_view ntupleName, RSettings settings);
157 virtual ~RPageSinkRoot();
158
159 ColumnHandle_t AddColumn(RColumn* column) final;
160 void Create(RNTupleModel* model) final;
161 void CommitPage(ColumnHandle_t columnHandle, const RPage &page) final;
162 void CommitCluster(NTupleSize_t nEntries) final;
163 void CommitDataset() final;
164};
165
166
167// clang-format off
168/**
169\class ROOT::Experimental::Detail::RPageSourceRoot
170\ingroup NTuple
171\brief Storage provider that reads ntuple pages from a ROOT TFile
172*/
173// clang-format on
175public:
176 struct RSettings {
177 TFile *fFile = nullptr;
178 bool fTakeOwnership = false;
179 };
180
181private:
182 std::string fNTupleName;
183 /// Currently, an ntuple is stored as a directory in a TFile
186
189
190public:
191 RPageSourceRoot(std::string_view ntupleName, RSettings settings);
193 virtual ~RPageSourceRoot();
194
195 ColumnHandle_t AddColumn(RColumn* column) final;
196 void Attach() final;
197 std::unique_ptr<ROOT::Experimental::RNTupleModel> GenerateModel() final;
198 void PopulatePage(ColumnHandle_t columnHandle, NTupleSize_t index, RPage* page) final;
199 NTupleSize_t GetNEntries() final;
200 NTupleSize_t GetNElements(ColumnHandle_t columnHandle) final;
201 ColumnId_t GetColumnId(ColumnHandle_t columnHandle) final;
202 const RNTupleDescriptor& GetDescriptor() const final { return fDescriptor; }
203};
204
205} // namespace Detail
206
207} // namespace Experimental
208} // namespace ROOT
209
210#endif
#define f(i)
Definition: RSha256.hxx:104
Maps the ntuple meta-data to and from TFile.
static constexpr const char * kKeyClusterFooter
static constexpr const char * kKeyPagePayload
static constexpr const char * kKeySeparator
std::vector< RFieldDescriptor > fRootFields
std::unordered_map< std::int32_t, std::unique_ptr< RColumnModel > > fId2ColumnModel
std::unordered_map< std::int32_t, std::int32_t > fColumn2Pointee
static constexpr const char * kKeyNTupleFooter
std::unordered_map< std::string, std::int32_t > fColumnName2Id
static constexpr const char * kKeyNTupleHeader
std::vector< RColumnIndex > fColumnIndex
Storage provider that write ntuple pages into a ROOT TFile.
void CommitDataset() final
Finalize the current cluster and the entrire data set.
ROOT::Experimental::Internal::RClusterFooter fCurrentCluster
Updated on CommitPage and written and reset on CommitCluster.
void CommitPage(ColumnHandle_t columnHandle, const RPage &page) final
Write a page to the storage. The column must have been added before.
RPageSinkRoot(std::string_view ntupleName, RSettings settings)
ROOT::Experimental::Internal::RNTupleFooter fNTupleFooter
void CommitCluster(NTupleSize_t nEntries) final
Finalize the current cluster and create a new one for the following data.
void Create(RNTupleModel *model) final
Physically creates the storage container to hold the tree (e.g., a directory in a TFile or a S3 bucke...
ROOT::Experimental::Internal::RNTupleHeader fNTupleHeader
TDirectory * fDirectory
Currently, an ntuple is stored as a directory in a TFile.
ColumnHandle_t AddColumn(RColumn *column) final
Register a new column.
Abstract interface to write data into a tree.
Storage provider that reads ntuple pages from a ROOT TFile.
TDirectory * fDirectory
Currently, an ntuple is stored as a directory in a TFile.
Abstract interface to read data from a tree.
A page is a fixed size slice of a column that is mapped into memory.
Definition: RPage.hxx:40
Represents the on-disk (on storage) information about an ntuple.
The RNTupleModel encapulates the schema of an ntuple.
Describe directory structure in memory.
Definition: TDirectory.h:34
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:48
basic_string_view< char > string_view
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
Definition: RNTupleUtil.hxx:44
std::int64_t ColumnId_t
Uniquely identifies a physical column within the scope of the current process, used to tag pages.
Definition: RNTupleUtil.hxx:61
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
RFieldDescriptor(const std::string &f, const std::string &t)
std::vector< NTupleSize_t > fNElementsPerColumn
std::vector< NTupleSize_t > fRangeStarts