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 <cassert>
22#include <cstddef>
23#include <cstdint>
24#include <memory>
25
26namespace ROOT {
27namespace Experimental {
28namespace Internal {
29
30class RPageAllocator;
31class RPageRef;
32
33// clang-format off
34/**
35\class ROOT::Experimental::Internal::RPage
36\ingroup NTuple
37\brief A page is a slice of a column that is mapped into memory
38
39The page provides an opaque memory buffer for uncompressed, unpacked data. It does not interpret
40the contents but it does now about the size (and thus the number) of the elements inside as well as the element
41number range within the backing column/cluster.
42For reading, pages are allocated and filled by the page source and then registered with the page pool.
43For writing, the page sink allocates uninitialized pages of a given size.
44The page has a pointer to its memory allocator so that it can release itself.
45*/
46// clang-format on
47class RPage {
48 friend class RPageRef;
49
50public:
51 static constexpr size_t kPageZeroSize = 64 * 1024;
52
53 /**
54 * Stores information about the cluster in which this page resides.
55 */
57 private:
58 /// The cluster number
60 /// The first element index of the column in this cluster
62 public:
63 RClusterInfo() = default;
64 RClusterInfo(NTupleSize_t id, NTupleSize_t indexOffset) : fId(id), fIndexOffset(indexOffset) {}
65 NTupleSize_t GetId() const { return fId; }
67 };
68
69private:
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(void *buffer, RPageAllocator *pageAllocator, ClusterSize_t::ValueType elementSize,
83 ClusterSize_t::ValueType maxElements)
84 : fBuffer(buffer), fPageAllocator(pageAllocator), fElementSize(elementSize), fMaxElements(maxElements)
85 {}
86 RPage(const RPage &) = delete;
87 RPage &operator=(const RPage &) = delete;
88 RPage(RPage &&other)
89 {
90 fBuffer = other.fBuffer;
91 fPageAllocator = other.fPageAllocator;
92 fElementSize = other.fElementSize;
93 fNElements = other.fNElements;
94 fMaxElements = other.fMaxElements;
95 fRangeFirst = other.fRangeFirst;
96 fClusterInfo = other.fClusterInfo;
97 other.fPageAllocator = nullptr;
98 }
100 {
101 if (this != &other) {
102 std::swap(fBuffer, other.fBuffer);
103 std::swap(fPageAllocator, other.fPageAllocator);
104 std::swap(fElementSize, other.fElementSize);
105 std::swap(fNElements, other.fNElements);
106 std::swap(fMaxElements, other.fMaxElements);
107 std::swap(fRangeFirst, other.fRangeFirst);
108 std::swap(fClusterInfo, other.fClusterInfo);
109 }
110 return *this;
111 }
112 ~RPage();
113
114 /// The space taken by column elements in the buffer
115 std::size_t GetNBytes() const
116 {
117 return static_cast<std::size_t>(fElementSize) * static_cast<std::size_t>(fNElements);
118 }
119 std::size_t GetCapacity() const
120 {
121 return static_cast<std::size_t>(fElementSize) * static_cast<std::size_t>(fMaxElements);
122 }
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 /// Increases the number elements in the page. The caller is responsible to respect the page capacity,
149 /// i.e. to ensure that fNElements + nElements <= fMaxElements.
150 /// Returns a pointer after the last element, which is used during writing in anticipation of the caller filling
151 /// nElements in the page.
152 /// When reading a page from disk, GrowUnchecked is used to set the actual number of elements. In this case, the
153 /// return value is ignored.
155 {
156 assert(fNElements + nElements <= fMaxElements);
157 auto offset = GetNBytes();
158 fNElements += nElements;
159 return static_cast<unsigned char *>(fBuffer) + offset;
160 }
161 /// Seek the page to a certain position of the column
162 void SetWindow(const NTupleSize_t rangeFirst, const RClusterInfo &clusterInfo) {
163 fClusterInfo = clusterInfo;
164 fRangeFirst = rangeFirst;
165 }
166 /// Forget all currently stored elements (size == 0) and set a new starting index.
167 void Reset(NTupleSize_t rangeFirst) { fNElements = 0; fRangeFirst = rangeFirst; }
168 void ResetCluster(const RClusterInfo &clusterInfo) { fNElements = 0; fClusterInfo = clusterInfo; }
169
170 /// Return a pointer to the page zero buffer used if there is no on-disk data for a particular deferred column
171 static const void *GetPageZeroBuffer();
172
173 bool IsNull() const { return fBuffer == nullptr; }
174 bool IsEmpty() const { return fNElements == 0; }
175 bool operator ==(const RPage &other) const { return fBuffer == other.fBuffer; }
176 bool operator !=(const RPage &other) const { return !(*this == other); }
177}; // class RPage
178
179} // namespace Internal
180} // namespace Experimental
181} // namespace ROOT
182
183#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.
Stores information about the cluster in which this page resides.
Definition RPage.hxx:56
NTupleSize_t fIndexOffset
The first element index of the column in this cluster.
Definition RPage.hxx:61
RClusterInfo(NTupleSize_t id, NTupleSize_t indexOffset)
Definition RPage.hxx:64
DescriptorId_t fId
The cluster number.
Definition RPage.hxx:59
A page is a slice of a column that is mapped into memory.
Definition RPage.hxx:47
void ResetCluster(const RClusterInfo &clusterInfo)
Definition RPage.hxx:168
bool operator!=(const RPage &other) const
Definition RPage.hxx:176
void Reset(NTupleSize_t rangeFirst)
Forget all currently stored elements (size == 0) and set a new starting index.
Definition RPage.hxx:167
void * GrowUnchecked(ClusterSize_t::ValueType nElements)
Increases the number elements in the page.
Definition RPage.hxx:154
bool operator==(const RPage &other) const
Definition RPage.hxx:175
std::size_t GetCapacity() const
Definition RPage.hxx:119
ClusterSize_t::ValueType GetClusterRangeFirst() const
Definition RPage.hxx:128
RPage & operator=(const RPage &)=delete
RPage & operator=(RPage &&other)
Definition RPage.hxx:99
std::size_t GetNBytes() const
The space taken by column elements in the buffer.
Definition RPage.hxx:115
static constexpr size_t kPageZeroSize
Definition RPage.hxx:51
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
RPage(void *buffer, RPageAllocator *pageAllocator, ClusterSize_t::ValueType elementSize, ClusterSize_t::ValueType maxElements)
Definition RPage.hxx:82
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:162
ClusterSize_t::ValueType GetClusterRangeLast() const
Definition RPage.hxx:129
NTupleSize_t GetGlobalRangeLast() const
Definition RPage.hxx:127
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
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...