Logo ROOT  
Reference Guide
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 
24 namespace ROOT {
25 namespace Experimental {
26 
27 namespace Detail {
28 
29 // clang-format off
30 /**
31 \class ROOT::Experimental::Detail::RPage
32 \ingroup NTuple
33 \brief A page is a slice of a column that is mapped into memory
34 
35 The page provides an opaque memory buffer for uncompressed, unpacked data. It does not interpret
36 the contents but it does now about the size (and thus the number) of the elements inside as well as the element
37 number range within the backing column/cluster. The memory buffer is not managed by the page. It is normally registered
38 with the page pool and allocated/freed by the page storage.
39 */
40 // clang-format on
41 class RPage {
42 public:
43  /**
44  * Stores information about the cluster in which this page resides.
45  */
46  class RClusterInfo {
47  private:
48  /// The cluster number
50  /// The first element index of the column in this cluster
52  public:
53  RClusterInfo() = default;
54  RClusterInfo(NTupleSize_t id, NTupleSize_t indexOffset) : fId(id), fIndexOffset(indexOffset) {}
55  NTupleSize_t GetId() const { return fId; }
57  };
58 
59 private:
61  void *fBuffer;
67 
68 public:
70  {}
71  RPage(ColumnId_t columnId, void* buffer, ClusterSize_t::ValueType capacity, ClusterSize_t::ValueType elementSize)
72  : fColumnId(columnId), fBuffer(buffer), fCapacity(capacity), fElementSize(elementSize), fNElements(0),
73  fRangeFirst(0)
74  {}
75  ~RPage() = default;
76 
77  ColumnId_t GetColumnId() const { return fColumnId; }
78  /// The total space available in the page
80  /// The space taken by column elements in the buffer
89  }
90  const RClusterInfo& GetClusterInfo() const { return fClusterInfo; }
91 
92  bool Contains(NTupleSize_t globalIndex) const {
93  return (globalIndex >= fRangeFirst) && (globalIndex < fRangeFirst + NTupleSize_t(fNElements));
94  }
95 
96  bool Contains(const RClusterIndex &clusterIndex) const {
97  if (fClusterInfo.GetId() != clusterIndex.GetClusterId())
98  return false;
99  auto clusterRangeFirst = ClusterSize_t(fRangeFirst - fClusterInfo.GetIndexOffset());
100  return (clusterIndex.GetIndex() >= clusterRangeFirst) &&
101  (clusterIndex.GetIndex() < clusterRangeFirst + fNElements);
102  }
103 
104  void* GetBuffer() const { return fBuffer; }
105  /// Return a pointer after the last element that has space for nElements new elements. If there is not enough capacity,
106  /// return nullptr
108  auto offset = GetSize();
109  auto nbyte = nElements * fElementSize;
110  if (offset + nbyte > fCapacity) {
111  return nullptr;
112  }
113  fNElements += nElements;
114  return static_cast<unsigned char *>(fBuffer) + offset;
115  }
116  /// Seek the page to a certain position of the column
117  void SetWindow(const NTupleSize_t rangeFirst, const RClusterInfo &clusterInfo) {
118  fClusterInfo = clusterInfo;
119  fRangeFirst = rangeFirst;
120  }
121  /// Forget all currently stored elements (size == 0) and set a new starting index.
122  void Reset(NTupleSize_t rangeFirst) { fNElements = 0; fRangeFirst = rangeFirst; }
123  void ResetCluster(const RClusterInfo &clusterInfo) { fNElements = 0; fClusterInfo = clusterInfo; }
124 
125  bool IsNull() const { return fBuffer == nullptr; }
126  bool operator ==(const RPage &other) const { return fBuffer == other.fBuffer; }
127  bool operator !=(const RPage &other) const { return !(*this == other); }
128 };
129 
130 } // namespace Detail
131 
132 } // namespace Experimental
133 } // namespace ROOT
134 
135 #endif
ROOT::Experimental::Detail::RPage::fNElements
ClusterSize_t::ValueType fNElements
Definition: RPage.hxx:64
ROOT::Experimental::Detail::RPage::RClusterInfo::RClusterInfo
RClusterInfo()=default
ROOT::Experimental::Detail::RPage
A page is a slice of a column that is mapped into memory.
Definition: RPage.hxx:41
ROOT::Experimental::Detail::RPage::operator==
bool operator==(const RPage &other) const
Definition: RPage.hxx:126
ROOT::Experimental::Detail::RPage::TryGrow
void * TryGrow(ClusterSize_t::ValueType nElements)
Return a pointer after the last element that has space for nElements new elements.
Definition: RPage.hxx:107
ROOT::Experimental::Detail::RPage::RPage
RPage()
Definition: RPage.hxx:69
ROOT::Experimental::Detail::RPage::RPage
RPage(ColumnId_t columnId, void *buffer, ClusterSize_t::ValueType capacity, ClusterSize_t::ValueType elementSize)
Definition: RPage.hxx:71
ROOT::Experimental::DescriptorId_t
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
Definition: RNTupleUtil.hxx:91
ROOT::Experimental::Detail::RPage::RClusterInfo::fIndexOffset
NTupleSize_t fIndexOffset
The first element index of the column in this cluster.
Definition: RPage.hxx:51
ROOT::Experimental::NTupleSize_t
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
Definition: RNTupleUtil.hxx:55
ROOT::Experimental::Detail::RPage::fCapacity
ClusterSize_t::ValueType fCapacity
Definition: RPage.hxx:62
ROOT::Experimental::Detail::RPage::RClusterInfo::GetId
NTupleSize_t GetId() const
Definition: RPage.hxx:55
ROOT::Experimental::Detail::RPage::fColumnId
ColumnId_t fColumnId
Definition: RPage.hxx:60
ROOT::Experimental::kInvalidColumnId
constexpr ColumnId_t kInvalidColumnId
Definition: RNTupleUtil.hxx:88
ROOT::Experimental::RClusterIndex::GetIndex
ClusterSize_t::ValueType GetIndex() const
Definition: RNTupleUtil.hxx:116
id
XFontStruct * id
Definition: TGX11.cxx:109
ROOT::Experimental::Detail::RPage::fRangeFirst
NTupleSize_t fRangeFirst
Definition: RPage.hxx:65
ROOT::Experimental::RClusterSize::ValueType
std::uint32_t ValueType
Definition: RNTupleUtil.hxx:59
ROOT::Experimental::Detail::RPage::RClusterInfo::RClusterInfo
RClusterInfo(NTupleSize_t id, NTupleSize_t indexOffset)
Definition: RPage.hxx:54
ROOT::Experimental::Detail::RPage::GetClusterInfo
const RClusterInfo & GetClusterInfo() const
Definition: RPage.hxx:90
ROOT::Experimental::Detail::RPage::fBuffer
void * fBuffer
Definition: RPage.hxx:61
ROOT::Experimental::Detail::RPage::GetBuffer
void * GetBuffer() const
Definition: RPage.hxx:104
ROOT::Experimental::Detail::RPage::GetElementSize
ClusterSize_t::ValueType GetElementSize() const
Definition: RPage.hxx:82
ROOT::Experimental::Detail::RPage::GetGlobalRangeFirst
NTupleSize_t GetGlobalRangeFirst() const
Definition: RPage.hxx:84
ROOT::Experimental::RClusterIndex::GetClusterId
DescriptorId_t GetClusterId() const
Definition: RNTupleUtil.hxx:115
ROOT::Experimental::Detail::RPage::fClusterInfo
RClusterInfo fClusterInfo
Definition: RPage.hxx:66
ROOT::Experimental::Detail::RPage::GetClusterRangeLast
ClusterSize_t::ValueType GetClusterRangeLast() const
Definition: RPage.hxx:87
ROOT::Experimental::Detail::RPage::Contains
bool Contains(NTupleSize_t globalIndex) const
Definition: RPage.hxx:92
ROOT::Experimental::Detail::RPage::RClusterInfo::GetIndexOffset
NTupleSize_t GetIndexOffset() const
Definition: RPage.hxx:56
RNTupleUtil.hxx
ROOT::Experimental::RClusterIndex
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
Definition: RNTupleUtil.hxx:95
ROOT::Experimental::Detail::RPage::Reset
void Reset(NTupleSize_t rangeFirst)
Forget all currently stored elements (size == 0) and set a new starting index.
Definition: RPage.hxx:122
ROOT::Experimental::Detail::RPage::GetColumnId
ColumnId_t GetColumnId() const
Definition: RPage.hxx:77
ROOT::Experimental::Detail::RPage::GetGlobalRangeLast
NTupleSize_t GetGlobalRangeLast() const
Definition: RPage.hxx:85
ROOT::Experimental::Detail::RPage::SetWindow
void SetWindow(const NTupleSize_t rangeFirst, const RClusterInfo &clusterInfo)
Seek the page to a certain position of the column.
Definition: RPage.hxx:117
ROOT::Experimental::Detail::RPage::fElementSize
ClusterSize_t::ValueType fElementSize
Definition: RPage.hxx:63
ROOT::Experimental::ClusterSize_t
RClusterSize ClusterSize_t
Definition: RNTupleUtil.hxx:70
ROOT::Experimental::Detail::RPage::RClusterInfo::fId
DescriptorId_t fId
The cluster number.
Definition: RPage.hxx:49
ROOT::Experimental::Detail::RPage::GetClusterRangeFirst
ClusterSize_t::ValueType GetClusterRangeFirst() const
Definition: RPage.hxx:86
ROOT::Experimental::Detail::RPage::RClusterInfo
Stores information about the cluster in which this page resides.
Definition: RPage.hxx:46
ROOT::Experimental::Detail::RPage::GetNElements
ClusterSize_t::ValueType GetNElements() const
Definition: RPage.hxx:83
ROOT::Experimental::Detail::RPage::operator!=
bool operator!=(const RPage &other) const
Definition: RPage.hxx:127
ROOT::Experimental::Detail::RPage::IsNull
bool IsNull() const
Definition: RPage.hxx:125
ROOT::Experimental::Detail::RPage::GetSize
ClusterSize_t::ValueType GetSize() const
The space taken by column elements in the buffer.
Definition: RPage.hxx:81
ROOT::Experimental::ColumnId_t
std::int64_t ColumnId_t
Uniquely identifies a physical column within the scope of the current process, used to tag pages.
Definition: RNTupleUtil.hxx:87
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
ROOT::Experimental::Detail::RPage::ResetCluster
void ResetCluster(const RClusterInfo &clusterInfo)
Definition: RPage.hxx:123
ROOT::Experimental::Detail::RPage::Contains
bool Contains(const RClusterIndex &clusterIndex) const
Definition: RPage.hxx:96
ROOT::Experimental::Detail::RPage::~RPage
~RPage()=default
ROOT::Experimental::Detail::RPage::GetCapacity
ClusterSize_t::ValueType GetCapacity() const
The total space available in the page.
Definition: RPage.hxx:79