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
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2018-10-09
5
6/*************************************************************************
7 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
8 * All rights reserved. *
9 * *
10 * For the licensing terms see $ROOTSYS/LICENSE. *
11 * For the list of contributors see $ROOTSYS/README/CREDITS. *
12 *************************************************************************/
13
14#ifndef ROOT_RPage
15#define ROOT_RPage
16
17#include <ROOT/RNTupleUtil.hxx>
18
19#include <cassert>
20#include <cstddef>
21#include <cstdint>
22#include <memory>
23
24namespace ROOT {
25namespace Internal {
26
27class RPageAllocator;
28class RPageRef;
29
30// clang-format off
31/**
32\class ROOT::Internal::RPage
33\ingroup NTuple
34\brief A page is a slice of a column that is mapped into memory
35
36The page provides an opaque memory buffer for uncompressed, unpacked data. It does not interpret
37the contents but it does now about the size (and thus the number) of the elements inside as well as the element
38number range within the backing column/cluster.
39For reading, pages are allocated and filled by the page source and then registered with the page pool.
40For writing, the page sink allocates uninitialized pages of a given size.
41The page has a pointer to its memory allocator so that it can release itself.
42*/
43// clang-format on
44class RPage {
45 friend class RPageRef;
46
47public:
48 static constexpr size_t kPageZeroSize = 64 * 1024;
49
50 /**
51 * Stores information about the cluster in which this page resides.
52 */
54 private:
55 /// The cluster number
57 /// The first element index of the column in this cluster
59
60 public:
61 RClusterInfo() = default;
63 ROOT::NTupleSize_t GetId() const { return fId; }
65 };
66
67private:
68 void *fBuffer = nullptr;
69 /// The allocator used to allocate fBuffer. Can be null if the buffer doesn't need to be freed.
71 std::uint32_t fElementSize = 0;
72 std::uint32_t fNElements = 0;
73 /// The capacity of the page in number of elements
74 std::uint32_t fMaxElements = 0;
77
78public:
79 RPage() = default;
83 RPage(const RPage &) = delete;
84 RPage &operator=(const RPage &) = delete;
86 {
87 fBuffer = other.fBuffer;
88 fPageAllocator = other.fPageAllocator;
89 fElementSize = other.fElementSize;
90 fNElements = other.fNElements;
91 fMaxElements = other.fMaxElements;
92 fRangeFirst = other.fRangeFirst;
93 fClusterInfo = other.fClusterInfo;
94 other.fPageAllocator = nullptr;
95 }
97 {
98 if (this != &other) {
99 std::swap(fBuffer, other.fBuffer);
100 std::swap(fPageAllocator, other.fPageAllocator);
101 std::swap(fElementSize, other.fElementSize);
102 std::swap(fNElements, other.fNElements);
103 std::swap(fMaxElements, other.fMaxElements);
104 std::swap(fRangeFirst, other.fRangeFirst);
105 std::swap(fClusterInfo, other.fClusterInfo);
106 }
107 return *this;
108 }
109 ~RPage();
110
111 /// The space taken by column elements in the buffer
112 std::size_t GetNBytes() const
113 {
114 return static_cast<std::size_t>(fElementSize) * static_cast<std::size_t>(fNElements);
115 }
116 std::size_t GetCapacity() const
117 {
118 return static_cast<std::size_t>(fElementSize) * static_cast<std::size_t>(fMaxElements);
119 }
120 std::uint32_t GetElementSize() const { return fElementSize; }
121 std::uint32_t GetNElements() const { return fNElements; }
122 std::uint32_t GetMaxElements() const { return fMaxElements; }
127 const RClusterInfo& GetClusterInfo() const { return fClusterInfo; }
128
133
135 {
136 if (fClusterInfo.GetId() != localIndex.GetClusterId())
137 return false;
139 return (localIndex.GetIndexInCluster() >= clusterRangeFirst) &&
140 (localIndex.GetIndexInCluster() < clusterRangeFirst + fNElements);
141 }
142
143 void* GetBuffer() const { return fBuffer; }
144 /// Increases the number elements in the page. The caller is responsible to respect the page capacity,
145 /// i.e. to ensure that fNElements + nElements <= fMaxElements.
146 /// Returns a pointer after the last element, which is used during writing in anticipation of the caller filling
147 /// nElements in the page.
148 /// When reading a page from disk, GrowUnchecked is used to set the actual number of elements. In this case, the
149 /// return value is ignored.
150 void *GrowUnchecked(std::uint32_t nElements)
151 {
153 auto offset = GetNBytes();
155 return static_cast<unsigned char *>(fBuffer) + offset;
156 }
157 /// Seek the page to a certain position of the column
163 /// Forget all currently stored elements (size == 0) and set a new starting index.
170
171 /// Return a pointer to the page zero buffer used if there is no on-disk data for a particular deferred column
172 static const void *GetPageZeroBuffer();
173
174 bool IsNull() const { return fBuffer == nullptr; }
175 bool IsEmpty() const { return fNElements == 0; }
176 bool operator ==(const RPage &other) const { return fBuffer == other.fBuffer; }
177 bool operator !=(const RPage &other) const { return !(*this == other); }
178}; // class RPage
179
180} // namespace Internal
181} // namespace ROOT
182
183#endif
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
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:53
ROOT::NTupleSize_t GetIndexOffset() const
Definition RPage.hxx:64
ROOT::NTupleSize_t GetId() const
Definition RPage.hxx:63
ROOT::NTupleSize_t fIndexOffset
The first element index of the column in this cluster.
Definition RPage.hxx:58
RClusterInfo(ROOT::NTupleSize_t id, ROOT::NTupleSize_t indexOffset)
Definition RPage.hxx:62
ROOT::DescriptorId_t fId
The cluster number.
Definition RPage.hxx:56
A page is a slice of a column that is mapped into memory.
Definition RPage.hxx:44
bool IsNull() const
Definition RPage.hxx:174
ROOT::NTupleSize_t GetGlobalRangeLast() const
Definition RPage.hxx:124
RPage(void *buffer, RPageAllocator *pageAllocator, std::uint32_t elementSize, std::uint32_t maxElements)
Definition RPage.hxx:80
std::uint32_t GetNElements() const
Definition RPage.hxx:121
RClusterInfo fClusterInfo
Definition RPage.hxx:76
std::size_t GetNBytes() const
The space taken by column elements in the buffer.
Definition RPage.hxx:112
void * GrowUnchecked(std::uint32_t nElements)
Increases the number elements in the page.
Definition RPage.hxx:150
RPage & operator=(RPage &&other)
Definition RPage.hxx:96
bool operator==(const RPage &other) const
Definition RPage.hxx:176
RPage(RPage &&other)
Definition RPage.hxx:85
std::uint32_t fNElements
Definition RPage.hxx:72
void Reset(ROOT::NTupleSize_t rangeFirst)
Forget all currently stored elements (size == 0) and set a new starting index.
Definition RPage.hxx:164
void * GetBuffer() const
Definition RPage.hxx:143
ROOT::NTupleSize_t GetLocalRangeLast() const
Definition RPage.hxx:126
static constexpr size_t kPageZeroSize
Definition RPage.hxx:48
std::uint32_t GetElementSize() const
Definition RPage.hxx:120
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:23
std::uint32_t GetMaxElements() const
Definition RPage.hxx:122
std::size_t GetCapacity() const
Definition RPage.hxx:116
RPageAllocator * fPageAllocator
The allocator used to allocate fBuffer. Can be null if the buffer doesn't need to be freed.
Definition RPage.hxx:70
std::uint32_t fMaxElements
The capacity of the page in number of elements.
Definition RPage.hxx:74
RPage & operator=(const RPage &)=delete
bool Contains(ROOT::NTupleSize_t globalIndex) const
Definition RPage.hxx:129
ROOT::NTupleSize_t fRangeFirst
Definition RPage.hxx:75
bool operator!=(const RPage &other) const
Definition RPage.hxx:177
RPage(const RPage &)=delete
void SetWindow(const ROOT::NTupleSize_t rangeFirst, const RClusterInfo &clusterInfo)
Seek the page to a certain position of the column.
Definition RPage.hxx:158
std::uint32_t fElementSize
Definition RPage.hxx:71
const RClusterInfo & GetClusterInfo() const
Definition RPage.hxx:127
ROOT::NTupleSize_t GetGlobalRangeFirst() const
Definition RPage.hxx:123
ROOT::NTupleSize_t GetLocalRangeFirst() const
Definition RPage.hxx:125
bool Contains(RNTupleLocalIndex localIndex) const
Definition RPage.hxx:134
bool IsEmpty() const
Definition RPage.hxx:175
void ResetCluster(const RClusterInfo &clusterInfo)
Definition RPage.hxx:169
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.