Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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, std::uint32_t elementSize, std::uint32_t maxElements)
83 : fBuffer(buffer), fPageAllocator(pageAllocator), fElementSize(elementSize), fMaxElements(maxElements)
84 {}
85 RPage(const RPage &) = delete;
86 RPage &operator=(const RPage &) = delete;
87 RPage(RPage &&other)
88 {
89 fBuffer = other.fBuffer;
90 fPageAllocator = other.fPageAllocator;
91 fElementSize = other.fElementSize;
92 fNElements = other.fNElements;
93 fMaxElements = other.fMaxElements;
94 fRangeFirst = other.fRangeFirst;
95 fClusterInfo = other.fClusterInfo;
96 other.fPageAllocator = nullptr;
97 }
99 {
100 if (this != &other) {
101 std::swap(fBuffer, other.fBuffer);
102 std::swap(fPageAllocator, other.fPageAllocator);
103 std::swap(fElementSize, other.fElementSize);
104 std::swap(fNElements, other.fNElements);
105 std::swap(fMaxElements, other.fMaxElements);
106 std::swap(fRangeFirst, other.fRangeFirst);
107 std::swap(fClusterInfo, other.fClusterInfo);
108 }
109 return *this;
110 }
111 ~RPage();
112
113 /// The space taken by column elements in the buffer
114 std::size_t GetNBytes() const
115 {
116 return static_cast<std::size_t>(fElementSize) * static_cast<std::size_t>(fNElements);
117 }
118 std::size_t GetCapacity() const
119 {
120 return static_cast<std::size_t>(fElementSize) * static_cast<std::size_t>(fMaxElements);
121 }
122 std::uint32_t GetElementSize() const { return fElementSize; }
123 std::uint32_t GetNElements() const { return fNElements; }
124 std::uint32_t GetMaxElements() const { return fMaxElements; }
129 const RClusterInfo& GetClusterInfo() const { return fClusterInfo; }
130
131 bool Contains(NTupleSize_t globalIndex) const {
132 return (globalIndex >= fRangeFirst) && (globalIndex < fRangeFirst + NTupleSize_t(fNElements));
133 }
134
135 bool Contains(RClusterIndex clusterIndex) const
136 {
137 if (fClusterInfo.GetId() != clusterIndex.GetClusterId())
138 return false;
139 auto clusterRangeFirst = fRangeFirst - fClusterInfo.GetIndexOffset();
140 return (clusterIndex.GetIndex() >= clusterRangeFirst) &&
141 (clusterIndex.GetIndex() < clusterRangeFirst + fNElements);
142 }
143
144 void* GetBuffer() const { return fBuffer; }
145 /// Increases the number elements in the page. The caller is responsible to respect the page capacity,
146 /// i.e. to ensure that fNElements + nElements <= fMaxElements.
147 /// Returns a pointer after the last element, which is used during writing in anticipation of the caller filling
148 /// nElements in the page.
149 /// When reading a page from disk, GrowUnchecked is used to set the actual number of elements. In this case, the
150 /// return value is ignored.
151 void *GrowUnchecked(std::uint32_t nElements)
152 {
153 assert(fNElements + nElements <= fMaxElements);
154 auto offset = GetNBytes();
155 fNElements += nElements;
156 return static_cast<unsigned char *>(fBuffer) + offset;
157 }
158 /// Seek the page to a certain position of the column
159 void SetWindow(const NTupleSize_t rangeFirst, const RClusterInfo &clusterInfo) {
160 fClusterInfo = clusterInfo;
161 fRangeFirst = rangeFirst;
162 }
163 /// Forget all currently stored elements (size == 0) and set a new starting index.
164 void Reset(NTupleSize_t rangeFirst) { fNElements = 0; fRangeFirst = rangeFirst; }
165 void ResetCluster(const RClusterInfo &clusterInfo) { fNElements = 0; fClusterInfo = clusterInfo; }
166
167 /// Return a pointer to the page zero buffer used if there is no on-disk data for a particular deferred column
168 static const void *GetPageZeroBuffer();
169
170 bool IsNull() const { return fBuffer == nullptr; }
171 bool IsEmpty() const { return fNElements == 0; }
172 bool operator ==(const RPage &other) const { return fBuffer == other.fBuffer; }
173 bool operator !=(const RPage &other) const { return !(*this == other); }
174}; // class RPage
175
176} // namespace Internal
177} // namespace Experimental
178} // namespace ROOT
179
180#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:165
bool operator!=(const RPage &other) const
Definition RPage.hxx:173
void Reset(NTupleSize_t rangeFirst)
Forget all currently stored elements (size == 0) and set a new starting index.
Definition RPage.hxx:164
bool operator==(const RPage &other) const
Definition RPage.hxx:172
std::size_t GetCapacity() const
Definition RPage.hxx:118
RPage(void *buffer, RPageAllocator *pageAllocator, std::uint32_t elementSize, std::uint32_t maxElements)
Definition RPage.hxx:82
RPage & operator=(const RPage &)=delete
RPage & operator=(RPage &&other)
Definition RPage.hxx:98
std::size_t GetNBytes() const
The space taken by column elements in the buffer.
Definition RPage.hxx:114
static constexpr size_t kPageZeroSize
Definition RPage.hxx:51
NTupleSize_t GetGlobalRangeFirst() const
Definition RPage.hxx:125
const RClusterInfo & GetClusterInfo() const
Definition RPage.hxx:129
bool Contains(RClusterIndex clusterIndex) const
Definition RPage.hxx:135
void * GrowUnchecked(std::uint32_t nElements)
Increases the number elements in the page.
Definition RPage.hxx:151
std::uint32_t GetElementSize() const
Definition RPage.hxx:122
NTupleSize_t GetClusterRangeFirst() const
Definition RPage.hxx:127
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:123
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:131
void SetWindow(const NTupleSize_t rangeFirst, const RClusterInfo &clusterInfo)
Seek the page to a certain position of the column.
Definition RPage.hxx:159
NTupleSize_t GetGlobalRangeLast() const
Definition RPage.hxx:126
NTupleSize_t GetClusterRangeLast() const
Definition RPage.hxx:128
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:124
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
DescriptorId_t GetClusterId() const
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
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...