Logo ROOT  
Reference Guide
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 <vector>
25
26namespace ROOT {
27namespace Experimental {
28
29namespace Detail {
30
31// clang-format off
32/**
33\class ROOT::Experimental::Detail::RPagePool
34\ingroup NTuple
35\brief A thread-safe cache of column pages.
36
37The page pool provides memory tracking for data written into an ntuple or read from an ntuple. Adding and removing
38pages is thread-safe. The page pool does not allocate the memory -- allocation and deallocation is performed by the
39page storage, which might do it in a way optimized to the backing store (e.g., mmap()).
40Multiple page caches can coexist.
41
42TODO(jblomer): it should be possible to register pages and to find them by column and index; this would
43facilitate pre-filling a cache, e.g. by read-ahead.
44*/
45// clang-format on
46class RPagePool {
47private:
48 /// TODO(jblomer): should be an efficient index structure that allows
49 /// - random insert
50 /// - random delete
51 /// - searching by page
52 /// - searching by tree index
53 std::vector<RPage> fPages;
54 std::vector<std::uint32_t> fReferences;
55 std::vector<RPageDeleter> fDeleters;
56
57public:
58 RPagePool() = default;
59 RPagePool(const RPagePool&) = delete;
60 RPagePool& operator =(const RPagePool&) = delete;
61 ~RPagePool() = default;
62
63 /// Adds a new page to the pool together with the function to free its space. Upon registration,
64 /// the page pool takes ownership of the page's memory. The new page has its reference counter set to 1.
65 void RegisterPage(const RPage &page, const RPageDeleter &deleter);
66 /// Tries to find the page corresponding to column and index in the cache. If the page is found, its reference
67 /// counter is increased
68 RPage GetPage(ColumnId_t columnId, NTupleSize_t globalIndex);
69 RPage GetPage(ColumnId_t columnId, const RClusterIndex &clusterIndex);
70 /// Give back a page to the pool and decrease the reference counter. There must not be any pointers anymore into
71 /// this page. If the reference counter drops to zero, the page pool might decide to call the deleter given in
72 /// during registration.
73 void ReturnPage(const RPage &page);
74};
75
76} // namespace Detail
77
78} // namespace Experimental
79} // namespace ROOT
80
81#endif
A closure that can free the memory associated with a mapped page.
A thread-safe cache of column pages.
Definition: RPagePool.hxx:46
std::vector< RPageDeleter > fDeleters
Definition: RPagePool.hxx:55
std::vector< std::uint32_t > fReferences
Definition: RPagePool.hxx:54
RPagePool & operator=(const RPagePool &)=delete
void ReturnPage(const RPage &page)
Give back a page to the pool and decrease the reference counter.
Definition: RPagePool.cxx:30
RPagePool(const RPagePool &)=delete
RPage GetPage(ColumnId_t columnId, NTupleSize_t globalIndex)
Tries to find the page corresponding to column and index in the cache.
Definition: RPagePool.cxx:52
std::vector< RPage > fPages
TODO(jblomer): should be an efficient index structure that allows.
Definition: RPagePool.hxx:53
void RegisterPage(const RPage &page, const RPageDeleter &deleter)
Adds a new page to the pool together with the function to free its space.
Definition: RPagePool.cxx:23
A page is a slice of a column that is mapped into memory.
Definition: RPage.hxx:41
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
Definition: RNTupleUtil.hxx:83
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
Definition: RNTupleUtil.hxx:43
std::int64_t ColumnId_t
Uniquely identifies a physical column within the scope of the current process, used to tag pages.
Definition: RNTupleUtil.hxx:75
VSD Structures.
Definition: StringConv.hxx:21