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 <vector>
26
27namespace ROOT {
28namespace Experimental {
29
30namespace Internal {
31
32// clang-format off
33/**
34\class ROOT::Experimental::Internal::RPagePool
35\ingroup NTuple
36\brief A thread-safe cache of pages loaded from the page source.
37
38The page pool is used as a cache for pages loaded from a page source.
39In this way, identical page needed at the same time, only need to be loaded once.
40Page sources also use the page pool to stage (preload) pages unsealed by IMT tasks.
41*/
42// clang-format on
43class RPagePool {
44 friend class RPageRef;
45
46 /// TODO(jblomer): should be an efficient index structure that allows
47 /// - random insert
48 /// - random delete
49 /// - searching by page
50 std::vector<RPage> fPages;
51 std::vector<std::int32_t> fReferences;
52 std::mutex fLock;
53
54 /// Give back a page to the pool and decrease the reference counter. There must not be any pointers anymore into
55 /// this page. If the reference counter drops to zero, the page pool might decide to call the deleter given in
56 /// during registration. Called by the RPageRef destructor.
57 void ReleasePage(const RPage &page);
58
59public:
60 RPagePool() = default;
61 RPagePool(const RPagePool&) = delete;
62 RPagePool& operator =(const RPagePool&) = delete;
63 ~RPagePool() = default;
64
65 /// Adds a new page to the pool. Upon registration, the page pool takes ownership of the page's memory.
66 /// The new page has its reference counter set to 1.
68 /// Like RegisterPage() but the reference counter is initialized to 0
69 void PreloadPage(RPage page);
70 /// Tries to find the page corresponding to column and index in the cache. If the page is found, its reference
71 /// counter is increased
72 RPageRef GetPage(ColumnId_t columnId, NTupleSize_t globalIndex);
73 RPageRef GetPage(ColumnId_t columnId, RClusterIndex clusterIndex);
74};
75
76// clang-format off
77/**
78\class ROOT::Experimental::Internal::RPageRef
79\ingroup NTuple
80\brief Reference to a page stored in the page pool
81
82The referenced page knows about its page pool and decreases the reference counter on destruction.
83*/
84// clang-format on
85class RPageRef {
86 friend class RPagePool;
87
89 RPagePool *fPagePool = nullptr;
90
91 // Called as delegated constructor and directly by the page pool
92 RPageRef(const RPage &page, RPagePool *pagePool) : fPagePool(pagePool)
93 {
94 // We leave the fPage::fPageAllocator member unset (nullptr), since fPage is a non-owning view on the page
96 fPage.fBuffer = page.fBuffer;
102 }
103
104public:
105 RPageRef() = default;
106 RPageRef(const RPageRef &other) = delete;
107 RPageRef &operator=(const RPageRef &other) = delete;
108
109 RPageRef(RPageRef &&other) : RPageRef(other.fPage, other.fPagePool) { other.fPagePool = nullptr; }
110
112 {
113 if (this != &other) {
114 std::swap(fPage, other.fPage);
115 std::swap(fPagePool, other.fPagePool);
116 }
117 return *this;
118 }
119
121 {
122 if (fPagePool)
124 }
125
126 /// Used by the friend virtual page source to map the physical column and cluster IDs to ther virtual counterparts
127 void ChangeIds(DescriptorId_t columnId, DescriptorId_t clusterId)
128 {
129 fPage.fColumnId = columnId;
131 }
132
133 const RPage &Get() const { return fPage; }
134};
135
136} // namespace Internal
137
138} // namespace Experimental
139} // namespace ROOT
140
141#endif
A thread-safe cache of pages loaded from the page source.
Definition RPagePool.hxx:43
std::vector< RPage > fPages
TODO(jblomer): should be an efficient index structure that allows.
Definition RPagePool.hxx:50
RPagePool & operator=(const RPagePool &)=delete
RPageRef RegisterPage(RPage page)
Adds a new page to the pool.
Definition RPagePool.cxx:24
RPageRef GetPage(ColumnId_t columnId, NTupleSize_t globalIndex)
Tries to find the page corresponding to column and index in the cache.
Definition RPagePool.cxx:60
std::vector< std::int32_t > fReferences
Definition RPagePool.hxx:51
RPagePool(const RPagePool &)=delete
void ReleasePage(const RPage &page)
Give back a page to the pool and decrease the reference counter.
Definition RPagePool.cxx:39
void PreloadPage(RPage page)
Like RegisterPage() but the reference counter is initialized to 0.
Definition RPagePool.cxx:32
Reference to a page stored in the page pool.
Definition RPagePool.hxx:85
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)
Definition RPagePool.hxx:92
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...