Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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#include <memory>
24
25namespace ROOT {
26namespace Experimental {
27namespace Internal {
28
29class RPageAllocator;
30class RPageRef;
31
32// clang-format off
33/**
34\class ROOT::Experimental::Internal::RPage
35\ingroup NTuple
36\brief A page is a slice of a column that is mapped into memory
37
38The page provides an opaque memory buffer for uncompressed, unpacked data. It does not interpret
39the contents but it does now about the size (and thus the number) of the elements inside as well as the element
40number range within the backing column/cluster.
41For reading, pages are allocated and filled by the page source and then registered with the page pool.
42For writing, the page sink allocates uninitialized pages of a given size.
43The page has a pointer to its memory allocator so that it can release itself.
44*/
45// clang-format on
46class RPage {
47 friend class RPageRef;
48
49public:
50 static constexpr size_t kPageZeroSize = 64 * 1024;
51
52 /**
53 * Stores information about the cluster in which this page resides.
54 */
56 private:
57 /// The cluster number
59 /// The first element index of the column in this cluster
61 public:
62 RClusterInfo() = default;
63 RClusterInfo(NTupleSize_t id, NTupleSize_t indexOffset) : fId(id), fIndexOffset(indexOffset) {}
64 NTupleSize_t GetId() const { return fId; }
66 };
67
68private:
70 void *fBuffer = nullptr;
71 /// The allocator used to allocate fBuffer. Can be null if the buffer doesn't need to be freed.
73 std::uint32_t fElementSize = 0;
74 std::uint32_t fNElements = 0;
75 /// The capacity of the page in number of elements
76 std::uint32_t fMaxElements = 0;
79
80public:
81 RPage() = default;
82 RPage(ColumnId_t columnId, void *buffer, RPageAllocator *pageAllocator, ClusterSize_t::ValueType elementSize,
83 ClusterSize_t::ValueType maxElements)
84 : fColumnId(columnId),
85 fBuffer(buffer),
86 fPageAllocator(pageAllocator),
87 fElementSize(elementSize),
88 fMaxElements(maxElements)
89 {}
90 RPage(const RPage &) = delete;
91 RPage &operator=(const RPage &) = delete;
92 RPage(RPage &&other)
93 {
94 fColumnId = other.fColumnId;
95 fBuffer = other.fBuffer;
96 fPageAllocator = other.fPageAllocator;
97 fElementSize = other.fElementSize;
98 fNElements = other.fNElements;
99 fMaxElements = other.fMaxElements;
100 fRangeFirst = other.fRangeFirst;
101 fClusterInfo = other.fClusterInfo;
102 other.fPageAllocator = nullptr;
103 }
105 {
106 if (this != &other) {
107 std::swap(fColumnId, other.fColumnId);
108 std::swap(fBuffer, other.fBuffer);
109 std::swap(fPageAllocator, other.fPageAllocator);
110 std::swap(fElementSize, other.fElementSize);
111 std::swap(fNElements, other.fNElements);
112 std::swap(fMaxElements, other.fMaxElements);
113 std::swap(fRangeFirst, other.fRangeFirst);
114 std::swap(fClusterInfo, other.fClusterInfo);
115 }
116 return *this;
117 }
118 ~RPage();
119
120 ColumnId_t GetColumnId() const { return fColumnId; }
121 /// The space taken by column elements in the buffer
122 std::size_t GetNBytes() const
123 {
124 return static_cast<std::size_t>(fElementSize) * static_cast<std::size_t>(fNElements);
125 }
126 std::size_t GetCapacity() const
127 {
128 return static_cast<std::size_t>(fElementSize) * static_cast<std::size_t>(fMaxElements);
129 }
130 std::uint32_t GetElementSize() const { return fElementSize; }
131 std::uint32_t GetNElements() const { return fNElements; }
132 std::uint32_t GetMaxElements() const { return fMaxElements; }
138 }
139 const RClusterInfo& GetClusterInfo() const { return fClusterInfo; }
140
141 bool Contains(NTupleSize_t globalIndex) const {
142 return (globalIndex >= fRangeFirst) && (globalIndex < fRangeFirst + NTupleSize_t(fNElements));
143 }
144
145 bool Contains(RClusterIndex clusterIndex) const
146 {
147 if (fClusterInfo.GetId() != clusterIndex.GetClusterId())
148 return false;
149 auto clusterRangeFirst = ClusterSize_t(fRangeFirst - fClusterInfo.GetIndexOffset());
150 return (clusterIndex.GetIndex() >= clusterRangeFirst) &&
151 (clusterIndex.GetIndex() < clusterRangeFirst + fNElements);
152 }
153
154 void* GetBuffer() const { return fBuffer; }
155 /// Called during writing: returns a pointer after the last element and increases the element counter
156 /// in anticipation of the caller filling nElements in the page. It is the responsibility of the caller
157 /// to prevent page overflows, i.e. that fNElements + nElements <= fMaxElements
159 auto offset = GetNBytes();
160 fNElements += nElements;
161 return static_cast<unsigned char *>(fBuffer) + offset;
162 }
163 /// Seek the page to a certain position of the column
164 void SetWindow(const NTupleSize_t rangeFirst, const RClusterInfo &clusterInfo) {
165 fClusterInfo = clusterInfo;
166 fRangeFirst = rangeFirst;
167 }
168 /// Forget all currently stored elements (size == 0) and set a new starting index.
169 void Reset(NTupleSize_t rangeFirst) { fNElements = 0; fRangeFirst = rangeFirst; }
170 void ResetCluster(const RClusterInfo &clusterInfo) { fNElements = 0; fClusterInfo = clusterInfo; }
171
172 /// Make a 'zero' page for column `columnId` (that is comprised of 0x00 bytes only). The caller is responsible for
173 /// invoking `GrowUnchecked()` and `SetWindow()` as appropriate.
175 {
176 return RPage{columnId, const_cast<void *>(GetPageZeroBuffer()), nullptr, elementSize,
177 /*maxElements=*/(kPageZeroSize / elementSize)};
178 }
179 /// Return a pointer to the page zero buffer used if there is no on-disk data for a particular deferred column
180 static const void *GetPageZeroBuffer();
181
182 bool IsValid() const { return fColumnId != kInvalidColumnId; }
183 bool IsNull() const { return fBuffer == nullptr; }
184 bool IsEmpty() const { return fNElements == 0; }
185 bool operator ==(const RPage &other) const { return fBuffer == other.fBuffer; }
186 bool operator !=(const RPage &other) const { return !(*this == other); }
187}; // class RPage
188
189} // namespace Internal
190} // namespace Experimental
191} // namespace ROOT
192
193#endif
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 offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Abstract interface to allocate and release pages.
Reference to a page stored in the page pool.
Definition RPagePool.hxx:85
Stores information about the cluster in which this page resides.
Definition RPage.hxx:55
NTupleSize_t fIndexOffset
The first element index of the column in this cluster.
Definition RPage.hxx:60
RClusterInfo(NTupleSize_t id, NTupleSize_t indexOffset)
Definition RPage.hxx:63
DescriptorId_t fId
The cluster number.
Definition RPage.hxx:58
A page is a slice of a column that is mapped into memory.
Definition RPage.hxx:46
void ResetCluster(const RClusterInfo &clusterInfo)
Definition RPage.hxx:170
bool operator!=(const RPage &other) const
Definition RPage.hxx:186
void Reset(NTupleSize_t rangeFirst)
Forget all currently stored elements (size == 0) and set a new starting index.
Definition RPage.hxx:169
void * GrowUnchecked(ClusterSize_t::ValueType nElements)
Called during writing: returns a pointer after the last element and increases the element counter in ...
Definition RPage.hxx:158
bool operator==(const RPage &other) const
Definition RPage.hxx:185
std::size_t GetCapacity() const
Definition RPage.hxx:126
ClusterSize_t::ValueType GetClusterRangeFirst() const
Definition RPage.hxx:135
RPage & operator=(const RPage &)=delete
RPage & operator=(RPage &&other)
Definition RPage.hxx:104
std::size_t GetNBytes() const
The space taken by column elements in the buffer.
Definition RPage.hxx:122
static constexpr size_t kPageZeroSize
Definition RPage.hxx:50
NTupleSize_t GetGlobalRangeFirst() const
Definition RPage.hxx:133
const RClusterInfo & GetClusterInfo() const
Definition RPage.hxx:139
bool Contains(RClusterIndex clusterIndex) const
Definition RPage.hxx:145
ColumnId_t GetColumnId() const
Definition RPage.hxx:120
static RPage MakePageZero(ColumnId_t columnId, ClusterSize_t::ValueType elementSize)
Make a 'zero' page for column columnId (that is comprised of 0x00 bytes only).
Definition RPage.hxx:174
std::uint32_t GetElementSize() const
Definition RPage.hxx:130
std::uint32_t fMaxElements
The capacity of the page in number of elements.
Definition RPage.hxx:76
std::uint32_t GetNElements() const
Definition RPage.hxx:131
RPageAllocator * fPageAllocator
The allocator used to allocate fBuffer. Can be null if the buffer doesn't need to be freed.
Definition RPage.hxx:72
bool Contains(NTupleSize_t globalIndex) const
Definition RPage.hxx:141
void SetWindow(const NTupleSize_t rangeFirst, const RClusterInfo &clusterInfo)
Seek the page to a certain position of the column.
Definition RPage.hxx:164
ClusterSize_t::ValueType GetClusterRangeLast() const
Definition RPage.hxx:136
NTupleSize_t GetGlobalRangeLast() const
Definition RPage.hxx:134
RPage(ColumnId_t columnId, void *buffer, RPageAllocator *pageAllocator, ClusterSize_t::ValueType elementSize, ClusterSize_t::ValueType maxElements)
Definition RPage.hxx:82
static const void * GetPageZeroBuffer()
Return a pointer to the page zero buffer used if there is no on-disk data for a particular deferred c...
Definition RPage.cxx:25
std::uint32_t GetMaxElements() const
Definition RPage.hxx:132
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
DescriptorId_t GetClusterId() const
ClusterSize_t::ValueType GetIndex() const
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
RClusterSize ClusterSize_t
constexpr ColumnId_t kInvalidColumnId
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
std::int64_t ColumnId_t
Uniquely identifies a physical column within the scope of the current process, used to tag pages.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...