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 {
27
28namespace Detail {
29
30// clang-format off
31/**
32\class ROOT::Experimental::Detail::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. The memory buffer is not managed by the page. It is normally registered
39with the page pool and allocated/freed by the page storage.
40*/
41// clang-format on
42class RPage {
43public:
44 static constexpr size_t kPageZeroSize = 64 * 1024;
45
46 /**
47 * Stores information about the cluster in which this page resides.
48 */
50 private:
51 /// The cluster number
53 /// The first element index of the column in this cluster
55 public:
56 RClusterInfo() = default;
57 RClusterInfo(NTupleSize_t id, NTupleSize_t indexOffset) : fId(id), fIndexOffset(indexOffset) {}
58 NTupleSize_t GetId() const { return fId; }
60 };
61
62private:
64 void *fBuffer;
65 std::uint32_t fElementSize;
66 std::uint32_t fNElements;
67 /// The capacity of the page in number of elements
68 std::uint32_t fMaxElements;
71
72public:
75 {}
76 RPage(ColumnId_t columnId, void* buffer, ClusterSize_t::ValueType elementSize, ClusterSize_t::ValueType maxElements)
77 : fColumnId(columnId), fBuffer(buffer), fElementSize(elementSize), fNElements(0), fMaxElements(maxElements),
79 {}
80 ~RPage() = default;
81
82 ColumnId_t GetColumnId() const { return fColumnId; }
83 /// The space taken by column elements in the buffer
84 std::uint32_t GetNBytes() const { return fElementSize * fNElements; }
85 std::uint32_t GetElementSize() const { return fElementSize; }
86 std::uint32_t GetNElements() const { return fNElements; }
87 std::uint32_t GetMaxElements() const { return fMaxElements; }
93 }
94 const RClusterInfo& GetClusterInfo() const { return fClusterInfo; }
95
96 bool Contains(NTupleSize_t globalIndex) const {
97 return (globalIndex >= fRangeFirst) && (globalIndex < fRangeFirst + NTupleSize_t(fNElements));
98 }
99
100 bool Contains(const RClusterIndex &clusterIndex) const {
101 if (fClusterInfo.GetId() != clusterIndex.GetClusterId())
102 return false;
103 auto clusterRangeFirst = ClusterSize_t(fRangeFirst - fClusterInfo.GetIndexOffset());
104 return (clusterIndex.GetIndex() >= clusterRangeFirst) &&
105 (clusterIndex.GetIndex() < clusterRangeFirst + fNElements);
106 }
107
108 void* GetBuffer() const { return fBuffer; }
109 /// Called during writing: returns a pointer after the last element and increases the element counter
110 /// in anticipation of the caller filling nElements in the page. It is the responsibility of the caller
111 /// to prevent page overflows, i.e. that fNElements + nElements <= fMaxElements
113 auto offset = GetNBytes();
114 fNElements += nElements;
115 return static_cast<unsigned char *>(fBuffer) + offset;
116 }
117 /// Seek the page to a certain position of the column
118 void SetWindow(const NTupleSize_t rangeFirst, const RClusterInfo &clusterInfo) {
119 fClusterInfo = clusterInfo;
120 fRangeFirst = rangeFirst;
121 }
122 /// Forget all currently stored elements (size == 0) and set a new starting index.
123 void Reset(NTupleSize_t rangeFirst) { fNElements = 0; fRangeFirst = rangeFirst; }
124 void ResetCluster(const RClusterInfo &clusterInfo) { fNElements = 0; fClusterInfo = clusterInfo; }
125
126 /// Used by virtual page sources to map the physical column and cluster IDs to ther virtual counterparts
127 void ChangeIds(DescriptorId_t columnId, DescriptorId_t clusterId)
128 {
129 fColumnId = columnId;
131 }
132
133 /// Make a 'zero' page for column `columnId` (that is comprised of 0x00 bytes only). The caller is responsible for
134 /// invoking `GrowUnchecked()` and `SetWindow()` as appropriate.
136 {
137 return RPage{columnId, const_cast<void *>(GetPageZeroBuffer()), elementSize,
138 /*maxElements=*/(kPageZeroSize / elementSize)};
139 }
140 /// Return a pointer to the page zero buffer used if there is no on-disk data for a particular deferred column
141 static const void *GetPageZeroBuffer();
142
143 bool IsNull() const { return fBuffer == nullptr; }
144 bool IsPageZero() const { return fBuffer == GetPageZeroBuffer(); }
145 bool IsEmpty() const { return fNElements == 0; }
146 bool operator ==(const RPage &other) const { return fBuffer == other.fBuffer; }
147 bool operator !=(const RPage &other) const { return !(*this == other); }
148};
149
150} // namespace Detail
151
152} // namespace Experimental
153} // namespace ROOT
154
155#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
Stores information about the cluster in which this page resides.
Definition RPage.hxx:49
DescriptorId_t fId
The cluster number.
Definition RPage.hxx:52
RClusterInfo(NTupleSize_t id, NTupleSize_t indexOffset)
Definition RPage.hxx:57
NTupleSize_t fIndexOffset
The first element index of the column in this cluster.
Definition RPage.hxx:54
A page is a slice of a column that is mapped into memory.
Definition RPage.hxx:42
ClusterSize_t::ValueType GetClusterRangeLast() const
Definition RPage.hxx:91
ColumnId_t GetColumnId() const
Definition RPage.hxx:82
std::uint32_t GetNBytes() const
The space taken by column elements in the buffer.
Definition RPage.hxx:84
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:135
std::uint32_t fMaxElements
The capacity of the page in number of elements.
Definition RPage.hxx:68
void ChangeIds(DescriptorId_t columnId, DescriptorId_t clusterId)
Used by virtual page sources to map the physical column and cluster IDs to ther virtual counterparts.
Definition RPage.hxx:127
static constexpr size_t kPageZeroSize
Definition RPage.hxx:44
std::uint32_t GetMaxElements() const
Definition RPage.hxx:87
std::uint32_t GetElementSize() const
Definition RPage.hxx:85
RPage(ColumnId_t columnId, void *buffer, ClusterSize_t::ValueType elementSize, ClusterSize_t::ValueType maxElements)
Definition RPage.hxx:76
bool Contains(NTupleSize_t globalIndex) const
Definition RPage.hxx:96
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:112
const RClusterInfo & GetClusterInfo() const
Definition RPage.hxx:94
std::uint32_t GetNElements() const
Definition RPage.hxx:86
bool operator==(const RPage &other) const
Definition RPage.hxx:146
void SetWindow(const NTupleSize_t rangeFirst, const RClusterInfo &clusterInfo)
Seek the page to a certain position of the column.
Definition RPage.hxx:118
void ResetCluster(const RClusterInfo &clusterInfo)
Definition RPage.hxx:124
void Reset(NTupleSize_t rangeFirst)
Forget all currently stored elements (size == 0) and set a new starting index.
Definition RPage.hxx:123
NTupleSize_t GetGlobalRangeFirst() const
Definition RPage.hxx:88
bool Contains(const RClusterIndex &clusterIndex) const
Definition RPage.hxx:100
NTupleSize_t GetGlobalRangeLast() const
Definition RPage.hxx:89
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
ClusterSize_t::ValueType GetClusterRangeFirst() const
Definition RPage.hxx:90
bool operator!=(const RPage &other) const
Definition RPage.hxx:147
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.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.