Logo ROOT   6.18/05
Reference Guide
RPage.hxx
Go to the documentation of this file.
1/// \file ROOT/RPage.hxx
2/// \ingroup NTuple ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2018-10-09
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_RPage
17#define ROOT7_RPage
18
19#include <ROOT/RNTupleUtil.hxx>
20
21#include <cstddef>
22#include <cstdint>
23
24namespace ROOT {
25namespace Experimental {
26
27namespace Detail {
28
29// clang-format off
30/**
31\class ROOT::Experimental::Detail::RPage
32\ingroup NTuple
33\brief A page is a fixed size slice of a column that is mapped into memory
34
35The page provides a fixed-size opaque memory buffer for uncompressed data. It does not know how to interpret
36the contents but it does now about the size (and thus the number) of the elements inside as well as the element
37number range within the backing column. The memory buffer is not managed by the page but normally by the page pool.
38*/
39// clang-format on
40class RPage {
41public:
42 /**
43 * Stores information about the cluster in which this page resides.
44 */
46 private:
47 /// The cluster number
49 /// The first element index of the column in this cluster
51 /// For offset columns, also store the cluster offset of the column being referenced
53 public:
55 RClusterInfo(NTupleSize_t id, NTupleSize_t selfOffset, NTupleSize_t pointeeOffset)
56 : fId(id), fSelfOffset(selfOffset), fPointeeOffset(pointeeOffset) {}
57 NTupleSize_t GetId() const { return fId; }
60 };
61
62private:
64 void* fBuffer;
65 std::size_t fCapacity;
66 std::size_t fSize;
67 std::size_t fElementSize;
71
72public:
76 {}
77 RPage(ColumnId_t columnId, void* buffer, std::size_t capacity, std::size_t elementSize)
78 : fColumnId(columnId), fBuffer(buffer), fCapacity(capacity), fSize(0), fElementSize(elementSize),
80 {}
81 ~RPage() = default;
82
83 std::int64_t GetColumnId() { return fColumnId; }
84 /// The total space available in the page
85 std::size_t GetCapacity() const { return fCapacity; }
86 /// The space taken by column elements in the buffer
87 std::size_t GetSize() const { return fSize; }
91 const RClusterInfo& GetClusterInfo() const { return fClusterInfo; }
92 bool Contains(NTupleSize_t index) const {
93 return (index >= fRangeFirst) && (index < fRangeFirst + fNElements);
94 }
95 void* GetBuffer() const { return fBuffer; }
96 /// Return a pointer after the last element that has space for nElements new elements. If there is not enough capacity,
97 /// return nullptr
98 void* TryGrow(std::size_t nElements) {
99 size_t offset = fSize;
100 size_t nbyte = nElements * fElementSize;
101 if (offset + nbyte > fCapacity) {
102 return nullptr;
103 }
104 fSize += nbyte;
105 fNElements = nElements;
106 return static_cast<unsigned char *>(fBuffer) + offset;
107 }
108 /// Seek the page to a certain position of the column
109 void SetWindow(const NTupleSize_t rangeFirst, const RClusterInfo &clusterInfo) {
110 fClusterInfo = clusterInfo;
111 fRangeFirst = rangeFirst;
112 }
113 /// Forget all currently stored elements (size == 0) and set a new starting index.
114 void Reset(NTupleSize_t rangeFirst) { fSize = 0; fRangeFirst = rangeFirst; }
115 void ResetCluster(const RClusterInfo &clusterInfo) { fSize = 0; fClusterInfo = clusterInfo; }
116
117 bool IsNull() const { return fBuffer == nullptr; }
118 bool operator ==(const RPage &other) const { return fBuffer == other.fBuffer; }
119};
120
121} // namespace Detail
122
123} // namespace Experimental
124} // namespace ROOT
125
126#endif
XFontStruct * id
Definition: TGX11.cxx:108
Stores information about the cluster in which this page resides.
Definition: RPage.hxx:45
RClusterInfo(NTupleSize_t id, NTupleSize_t selfOffset, NTupleSize_t pointeeOffset)
Definition: RPage.hxx:55
NTupleSize_t fSelfOffset
The first element index of the column in this cluster.
Definition: RPage.hxx:50
NTupleSize_t fPointeeOffset
For offset columns, also store the cluster offset of the column being referenced.
Definition: RPage.hxx:52
NTupleSize_t fId
The cluster number.
Definition: RPage.hxx:48
A page is a fixed size slice of a column that is mapped into memory.
Definition: RPage.hxx:40
RPage(ColumnId_t columnId, void *buffer, std::size_t capacity, std::size_t elementSize)
Definition: RPage.hxx:77
bool Contains(NTupleSize_t index) const
Definition: RPage.hxx:92
std::size_t GetSize() const
The space taken by column elements in the buffer.
Definition: RPage.hxx:87
NTupleSize_t GetNElements() const
Definition: RPage.hxx:88
std::size_t GetCapacity() const
The total space available in the page.
Definition: RPage.hxx:85
const RClusterInfo & GetClusterInfo() const
Definition: RPage.hxx:91
bool operator==(const RPage &other) const
Definition: RPage.hxx:118
void SetWindow(const NTupleSize_t rangeFirst, const RClusterInfo &clusterInfo)
Seek the page to a certain position of the column.
Definition: RPage.hxx:109
void ResetCluster(const RClusterInfo &clusterInfo)
Definition: RPage.hxx:115
NTupleSize_t GetRangeFirst() const
Definition: RPage.hxx:89
void Reset(NTupleSize_t rangeFirst)
Forget all currently stored elements (size == 0) and set a new starting index.
Definition: RPage.hxx:114
NTupleSize_t GetRangeLast() const
Definition: RPage.hxx:90
void * TryGrow(std::size_t nElements)
Return a pointer after the last element that has space for nElements new elements.
Definition: RPage.hxx:98
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
Definition: RNTupleUtil.hxx:44
constexpr ColumnId_t kInvalidColumnId
Definition: RNTupleUtil.hxx:62
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