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::uint32_t GetNBytes() const { return fElementSize * fNElements; }
123 std::uint32_t GetElementSize() const { return fElementSize; }
124 std::uint32_t GetNElements() const { return fNElements; }
125 std::uint32_t GetMaxElements() const { return fMaxElements; }
131 }
132 const RClusterInfo& GetClusterInfo() const { return fClusterInfo; }
133
134 bool Contains(NTupleSize_t globalIndex) const {
135 return (globalIndex >= fRangeFirst) && (globalIndex < fRangeFirst + NTupleSize_t(fNElements));
136 }
137
138 bool Contains(RClusterIndex clusterIndex) const
139 {
140 if (fClusterInfo.GetId() != clusterIndex.GetClusterId())
141 return false;
142 auto clusterRangeFirst = ClusterSize_t(fRangeFirst - fClusterInfo.GetIndexOffset());
143 return (clusterIndex.GetIndex() >= clusterRangeFirst) &&
144 (clusterIndex.GetIndex() < clusterRangeFirst + fNElements);
145 }
146
147 void* GetBuffer() const { return fBuffer; }
148 /// Called during writing: returns a pointer after the last element and increases the element counter
149 /// in anticipation of the caller filling nElements in the page. It is the responsibility of the caller
150 /// to prevent page overflows, i.e. that fNElements + nElements <= fMaxElements
152 auto offset = GetNBytes();
153 fNElements += nElements;
154 return static_cast<unsigned char *>(fBuffer) + offset;
155 }
156 /// Seek the page to a certain position of the column
157 void SetWindow(const NTupleSize_t rangeFirst, const RClusterInfo &clusterInfo) {
158 fClusterInfo = clusterInfo;
159 fRangeFirst = rangeFirst;
160 }
161 /// Forget all currently stored elements (size == 0) and set a new starting index.
162 void Reset(NTupleSize_t rangeFirst) { fNElements = 0; fRangeFirst = rangeFirst; }
163 void ResetCluster(const RClusterInfo &clusterInfo) { fNElements = 0; fClusterInfo = clusterInfo; }
164
165 /// Make a 'zero' page for column `columnId` (that is comprised of 0x00 bytes only). The caller is responsible for
166 /// invoking `GrowUnchecked()` and `SetWindow()` as appropriate.
168 {
169 return RPage{columnId, const_cast<void *>(GetPageZeroBuffer()), nullptr, elementSize,
170 /*maxElements=*/(kPageZeroSize / elementSize)};
171 }
172 /// Return a pointer to the page zero buffer used if there is no on-disk data for a particular deferred column
173 static const void *GetPageZeroBuffer();
174
175 bool IsValid() const { return fColumnId != kInvalidColumnId; }
176 bool IsNull() const { return fBuffer == nullptr; }
177 bool IsEmpty() const { return fNElements == 0; }
178 bool operator ==(const RPage &other) const { return fBuffer == other.fBuffer; }
179 bool operator !=(const RPage &other) const { return !(*this == other); }
180}; // class RPage
181
182} // namespace Internal
183} // namespace Experimental
184} // namespace ROOT
185
186#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:163
bool operator!=(const RPage &other) const
Definition RPage.hxx:179
void Reset(NTupleSize_t rangeFirst)
Forget all currently stored elements (size == 0) and set a new starting index.
Definition RPage.hxx:162
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:151
bool operator==(const RPage &other) const
Definition RPage.hxx:178
ClusterSize_t::ValueType GetClusterRangeFirst() const
Definition RPage.hxx:128
RPage & operator=(const RPage &)=delete
RPage & operator=(RPage &&other)
Definition RPage.hxx:104
static constexpr size_t kPageZeroSize
Definition RPage.hxx:50
NTupleSize_t GetGlobalRangeFirst() const
Definition RPage.hxx:126
const RClusterInfo & GetClusterInfo() const
Definition RPage.hxx:132
bool Contains(RClusterIndex clusterIndex) const
Definition RPage.hxx:138
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:167
std::uint32_t GetNBytes() const
The space taken by column elements in the buffer.
Definition RPage.hxx:122
std::uint32_t GetElementSize() const
Definition RPage.hxx:123
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:124
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:134
void SetWindow(const NTupleSize_t rangeFirst, const RClusterInfo &clusterInfo)
Seek the page to a certain position of the column.
Definition RPage.hxx:157
ClusterSize_t::ValueType GetClusterRangeLast() const
Definition RPage.hxx:129
NTupleSize_t GetGlobalRangeLast() const
Definition RPage.hxx:127
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:125
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...