Logo ROOT   6.18/05
Reference Guide
RPageStorage.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_RPageStorage
17#define ROOT7_RPageStorage
18
20#include <ROOT/RNTupleUtil.hxx>
21#include <ROOT/RPage.hxx>
22#include <ROOT/RStringView.hxx>
23
24#include <atomic>
25#include <memory>
26
27namespace ROOT {
28namespace Experimental {
29
30class RNTupleModel;
31// TODO(jblomer): factory methods to create tree sinks and sources outside Detail namespace
32
33namespace Detail {
34
35class RColumn;
36class RPagePool;
37class RFieldBase;
38
39enum class EPageStorageType {
40 kSink,
41 kSource,
42};
43
44// clang-format off
45/**
46\class ROOT::Experimental::Detail::RPageStorage
47\ingroup NTuple
48\brief Manages tree meta-data, which is common for sinks and sources.
49
50The tree meta-data contains of a list of fields, a unique identifier, and provenance information.
51*/
52// clang-format on
54protected:
55 /// All data is shipped to and from physical storage in pages, and moderated through a page pool
56 std::unique_ptr<RPagePool> fPagePool;
57
58public:
60 RPageStorage(const RPageStorage &other) = delete;
61 RPageStorage& operator =(const RPageStorage &other) = delete;
62 virtual ~RPageStorage();
63
65 RColumnHandle() : fId(-1), fColumn(nullptr) {}
66 RColumnHandle(int id, RColumn* column) : fId(id), fColumn(column) {}
67 int fId;
69 };
70 /// The column handle identfies a column with the current open page storage
72
73 /// Register a new column. When reading, the column must exist in the tree on disk corresponding to the meta-data.
74 /// When writing, every column can only be attached once.
75 virtual ColumnHandle_t AddColumn(RColumn *column) = 0;
77 RPagePool* GetPagePool() const { return fPagePool.get(); }
78};
79
80// clang-format off
81/**
82\class ROOT::Experimental::Detail::RPageSink
83\ingroup NTuple
84\brief Abstract interface to write data into a tree
85
86The page sink takes the list of columns and afterwards a series of page commits and cluster commits.
87The user is responsible to commit clusters at consistent point, i.e. when all pages corresponding to data
88up to the given entry number are committed.
89*/
90// clang-format on
91class RPageSink : public RPageStorage {
92public:
94 virtual ~RPageSink();
96
97 /// Physically creates the storage container to hold the tree (e.g., a directory in a TFile or a S3 bucket)
98 virtual void Create(RNTupleModel* model) = 0;
99 /// Write a page to the storage. The column must have been added before.
100 virtual void CommitPage(ColumnHandle_t columnHandle, const RPage &page) = 0;
101 /// Finalize the current cluster and create a new one for the following data.
102 virtual void CommitCluster(NTupleSize_t nEntries) = 0;
103 /// Finalize the current cluster and the entrire data set.
104 virtual void CommitDataset() = 0;
105};
106
107// clang-format off
108/**
109\class ROOT::Experimental::Detail::RPageSource
110\ingroup NTuple
111\brief Abstract interface to read data from a tree
112
113The page source is initialized with the columns of interest. Pages from those columns can then be
114mapped into pages. The page source also gives access to its meta-data.
115*/
116// clang-format on
117class RPageSource : public RPageStorage {
118public:
120 virtual ~RPageSource();
122 /// TODO: copy/assignment for creating clones in multiple threads.
123
124 /// Open the physical storage container for the tree
125 virtual void Attach() = 0;
126
127 // TODO(jblomer): virtual std::unique_ptr<RFieldBase> ListFields() {/* Make me abstract */ return nullptr;}
128 // TODO(jblomer): ListClusters()
129 virtual std::unique_ptr<ROOT::Experimental::RNTupleModel> GenerateModel() = 0;
130
131 /// Fills a page starting with index rangeStart; the corresponding column is taken from the page object
132 virtual void PopulatePage(ColumnHandle_t columnHandle, NTupleSize_t index, RPage* page) = 0;
134 virtual NTupleSize_t GetNElements(ColumnHandle_t columnHandle) = 0;
135 virtual ColumnId_t GetColumnId(ColumnHandle_t columnHandle) = 0;
136 virtual const RNTupleDescriptor& GetDescriptor() const = 0;
137};
138
139} // namespace Detail
140
141} // namespace Experimental
142} // namespace ROOT
143
144#endif
XFontStruct * id
Definition: TGX11.cxx:108
A thread-safe cache of column pages.
Definition: RPagePool.hxx:46
Abstract interface to write data into a tree.
virtual void Create(RNTupleModel *model)=0
Physically creates the storage container to hold the tree (e.g., a directory in a TFile or a S3 bucke...
virtual void CommitPage(ColumnHandle_t columnHandle, const RPage &page)=0
Write a page to the storage. The column must have been added before.
RPageSink(std::string_view treeName)
virtual void CommitCluster(NTupleSize_t nEntries)=0
Finalize the current cluster and create a new one for the following data.
virtual void CommitDataset()=0
Finalize the current cluster and the entrire data set.
EPageStorageType GetType() final
Abstract interface to read data from a tree.
virtual const RNTupleDescriptor & GetDescriptor() const =0
virtual NTupleSize_t GetNEntries()=0
virtual void PopulatePage(ColumnHandle_t columnHandle, NTupleSize_t index, RPage *page)=0
Fills a page starting with index rangeStart; the corresponding column is taken from the page object.
virtual void Attach()=0
TODO: copy/assignment for creating clones in multiple threads.
virtual NTupleSize_t GetNElements(ColumnHandle_t columnHandle)=0
virtual std::unique_ptr< ROOT::Experimental::RNTupleModel > GenerateModel()=0
RPageSource(std::string_view treeName)
virtual ColumnId_t GetColumnId(ColumnHandle_t columnHandle)=0
Manages tree meta-data, which is common for sinks and sources.
RPageStorage(const RPageStorage &other)=delete
std::unique_ptr< RPagePool > fPagePool
All data is shipped to and from physical storage in pages, and moderated through a page pool.
virtual EPageStorageType GetType()=0
virtual ColumnHandle_t AddColumn(RColumn *column)=0
Register a new column.
RPageStorage & operator=(const RPageStorage &other)=delete
A page is a fixed size slice of a column that is mapped into memory.
Definition: RPage.hxx:40
A column is a storage-backed array of a simple, fixed-size type, from which pages can be mapped into ...
A field translates read and write calls from/to underlying columns to/from tree values.
Definition: RField.hxx:53
Represents the on-disk (on storage) information about an ntuple.
The RNTupleModel encapulates the schema of an ntuple.
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