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 Internal {
28
29class RPageAllocator;
30class RPageRef;
31
32// clang-format off
33/**
34\class ROOT::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
62 public:
63 RClusterInfo() = default;
65 ROOT::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;
85 RPage(const RPage &) = delete;
86 RPage &operator=(const RPage &) = delete;
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
135
137 {
138 if (fClusterInfo.GetId() != localIndex.GetClusterId())
139 return false;
141 return (localIndex.GetIndexInCluster() >= clusterRangeFirst) &&
142 (localIndex.GetIndexInCluster() < clusterRangeFirst + fNElements);
143 }
144
145 void* GetBuffer() const { return fBuffer; }
146 /// Increases the number elements in the page. The caller is responsible to respect the page capacity,
147 /// i.e. to ensure that fNElements + nElements <= fMaxElements.
148 /// Returns a pointer after the last element, which is used during writing in anticipation of the caller filling
149 /// nElements in the page.
150 /// When reading a page from disk, GrowUnchecked is used to set the actual number of elements. In this case, the
151 /// return value is ignored.
152 void *GrowUnchecked(std::uint32_t nElements)
153 {
155 auto offset = GetNBytes();
157 return static_cast<unsigned char *>(fBuffer) + offset;
158 }
159 /// Seek the page to a certain position of the column
165 /// Forget all currently stored elements (size == 0) and set a new starting index.
172
173 /// Return a pointer to the page zero buffer used if there is no on-disk data for a particular deferred column
174 static const void *GetPageZeroBuffer();
175
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 ROOT
184
185#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:55
ROOT::NTupleSize_t GetIndexOffset() const
Definition RPage.hxx:66
ROOT::NTupleSize_t GetId() const
Definition RPage.hxx:65
ROOT::NTupleSize_t fIndexOffset
The first element index of the column in this cluster.
Definition RPage.hxx:60
RClusterInfo(ROOT::NTupleSize_t id, ROOT::NTupleSize_t indexOffset)
Definition RPage.hxx:64
ROOT::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
bool IsNull() const
Definition RPage.hxx:176
ROOT::NTupleSize_t GetGlobalRangeLast() const
Definition RPage.hxx:126
RPage(void *buffer, RPageAllocator *pageAllocator, std::uint32_t elementSize, std::uint32_t maxElements)
Definition RPage.hxx:82
std::uint32_t GetNElements() const
Definition RPage.hxx:123
RClusterInfo fClusterInfo
Definition RPage.hxx:78
std::size_t GetNBytes() const
The space taken by column elements in the buffer.
Definition RPage.hxx:114
void * GrowUnchecked(std::uint32_t nElements)
Increases the number elements in the page.
Definition RPage.hxx:152
RPage & operator=(RPage &&other)
Definition RPage.hxx:98
bool operator==(const RPage &other) const
Definition RPage.hxx:178
RPage(RPage &&other)
Definition RPage.hxx:87
std::uint32_t fNElements
Definition RPage.hxx:74
void Reset(ROOT::NTupleSize_t rangeFirst)
Forget all currently stored elements (size == 0) and set a new starting index.
Definition RPage.hxx:166
void * GetBuffer() const
Definition RPage.hxx:145
ROOT::NTupleSize_t GetLocalRangeLast() const
Definition RPage.hxx:128
static constexpr size_t kPageZeroSize
Definition RPage.hxx:50
std::uint32_t GetElementSize() const
Definition RPage.hxx:122
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
std::size_t GetCapacity() const
Definition RPage.hxx:118
RPageAllocator * fPageAllocator
The allocator used to allocate fBuffer. Can be null if the buffer doesn't need to be freed.
Definition RPage.hxx:72
std::uint32_t fMaxElements
The capacity of the page in number of elements.
Definition RPage.hxx:76
RPage & operator=(const RPage &)=delete
bool Contains(ROOT::NTupleSize_t globalIndex) const
Definition RPage.hxx:131
ROOT::NTupleSize_t fRangeFirst
Definition RPage.hxx:77
bool operator!=(const RPage &other) const
Definition RPage.hxx:179
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:160
std::uint32_t fElementSize
Definition RPage.hxx:73
const RClusterInfo & GetClusterInfo() const
Definition RPage.hxx:129
ROOT::NTupleSize_t GetGlobalRangeFirst() const
Definition RPage.hxx:125
ROOT::NTupleSize_t GetLocalRangeFirst() const
Definition RPage.hxx:127
bool Contains(RNTupleLocalIndex localIndex) const
Definition RPage.hxx:136
bool IsEmpty() const
Definition RPage.hxx:177
void ResetCluster(const RClusterInfo &clusterInfo)
Definition RPage.hxx:171
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.