Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RPagePool.hxx
Go to the documentation of this file.
1/// \file ROOT/RPagePool.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_RPagePool
17#define ROOT7_RPagePool
18
19#include <ROOT/RPage.hxx>
21#include <ROOT/RNTupleUtil.hxx>
22
23#include <cstddef>
24#include <mutex>
25#include <typeindex>
26#include <typeinfo>
27#include <vector>
28
29namespace ROOT {
30namespace Experimental {
31
32namespace Internal {
33
34// clang-format off
35/**
36\class ROOT::Experimental::Internal::RPagePool
37\ingroup NTuple
38\brief A thread-safe cache of pages loaded from the page source.
39
40The page pool is used as a cache for pages loaded from a page source.
41In this way, identical page needed at the same time, only need to be loaded once.
42Page sources also use the page pool to stage (preload) pages unsealed by IMT tasks.
43*/
44// clang-format on
45class RPagePool {
46 friend class RPageRef;
47
48 // TODO(jblomer): move column ID from RPage to this struct
49 struct RPageInfo {
50 std::type_index fInMemoryType = std::type_index(typeid(void));
51 };
52
53 /// TODO(jblomer): should be an efficient index structure that allows
54 /// - random insert
55 /// - random delete
56 /// - searching by page
57 std::vector<RPage> fPages;
58 std::vector<RPageInfo> fPageInfos;
59 std::vector<std::int32_t> fReferences;
60 std::mutex fLock;
61
62 /// Give back a page to the pool and decrease the reference counter. There must not be any pointers anymore into
63 /// this page. If the reference counter drops to zero, the page pool might decide to call the deleter given in
64 /// during registration. Called by the RPageRef destructor.
65 void ReleasePage(const RPage &page);
66
67public:
68 RPagePool() = default;
69 RPagePool(const RPagePool&) = delete;
70 RPagePool& operator =(const RPagePool&) = delete;
71 ~RPagePool() = default;
72
73 /// Adds a new page to the pool. Upon registration, the page pool takes ownership of the page's memory.
74 /// The new page has its reference counter set to 1.
75 RPageRef RegisterPage(RPage page, std::type_index inMemoryType);
76 /// Like RegisterPage() but the reference counter is initialized to 0
77 void PreloadPage(RPage page, std::type_index inMemoryType);
78 /// Tries to find the page corresponding to column and index in the cache. If the page is found, its reference
79 /// counter is increased
80 RPageRef GetPage(ColumnId_t columnId, std::type_index inMemoryType, NTupleSize_t globalIndex);
81 RPageRef GetPage(ColumnId_t columnId, std::type_index inMemoryType, RClusterIndex clusterIndex);
82};
83
84// clang-format off
85/**
86\class ROOT::Experimental::Internal::RPageRef
87\ingroup NTuple
88\brief Reference to a page stored in the page pool
89
90The referenced page knows about its page pool and decreases the reference counter on destruction.
91*/
92// clang-format on
93class RPageRef {
94 friend class RPagePool;
95
97 RPagePool *fPagePool = nullptr;
98
99 // Called as delegated constructor and directly by the page pool
100 RPageRef(const RPage &page, RPagePool *pagePool) : fPagePool(pagePool)
101 {
102 // We leave the fPage::fPageAllocator member unset (nullptr), since fPage is a non-owning view on the page
104 fPage.fBuffer = page.fBuffer;
110 }
111
112public:
113 RPageRef() = default;
114 RPageRef(const RPageRef &other) = delete;
115 RPageRef &operator=(const RPageRef &other) = delete;
116
117 RPageRef(RPageRef &&other) : RPageRef(other.fPage, other.fPagePool) { other.fPagePool = nullptr; }
118
120 {
121 if (this != &other) {
122 std::swap(fPage, other.fPage);
123 std::swap(fPagePool, other.fPagePool);
124 }
125 return *this;
126 }
127
129 {
130 if (fPagePool)
132 }
133
134 /// Used by the friend virtual page source to map the physical column and cluster IDs to ther virtual counterparts
135 void ChangeIds(DescriptorId_t columnId, DescriptorId_t clusterId)
136 {
137 fPage.fColumnId = columnId;
139 }
140
141 const RPage &Get() const { return fPage; }
142};
143
144} // namespace Internal
145
146} // namespace Experimental
147} // namespace ROOT
148
149#endif
A thread-safe cache of pages loaded from the page source.
Definition RPagePool.hxx:45
std::vector< RPage > fPages
TODO(jblomer): should be an efficient index structure that allows.
Definition RPagePool.hxx:57
RPagePool & operator=(const RPagePool &)=delete
RPageRef GetPage(ColumnId_t columnId, std::type_index inMemoryType, NTupleSize_t globalIndex)
Tries to find the page corresponding to column and index in the cache.
Definition RPagePool.cxx:64
std::vector< std::int32_t > fReferences
Definition RPagePool.hxx:59
RPagePool(const RPagePool &)=delete
void ReleasePage(const RPage &page)
Give back a page to the pool and decrease the reference counter.
Definition RPagePool.cxx:42
RPageRef RegisterPage(RPage page, std::type_index inMemoryType)
Adds a new page to the pool.
Definition RPagePool.cxx:25
void PreloadPage(RPage page, std::type_index inMemoryType)
Like RegisterPage() but the reference counter is initialized to 0.
Definition RPagePool.cxx:34
std::vector< RPageInfo > fPageInfos
Definition RPagePool.hxx:58
Reference to a page stored in the page pool.
Definition RPagePool.hxx:93
void ChangeIds(DescriptorId_t columnId, DescriptorId_t clusterId)
Used by the friend virtual page source to map the physical column and cluster IDs to ther virtual cou...
RPageRef(const RPage &page, RPagePool *pagePool)
RPageRef & operator=(const RPageRef &other)=delete
RPageRef & operator=(RPageRef &&other)
RPageRef(const RPageRef &other)=delete
Stores information about the cluster in which this page resides.
Definition RPage.hxx:55
A page is a slice of a column that is mapped into memory.
Definition RPage.hxx:46
std::uint32_t fMaxElements
The capacity of the page in number of elements.
Definition RPage.hxx:76
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
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.
std::int64_t ColumnId_t
Uniquely identifies a physical column within the scope of the current process, used to tag pages.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...