Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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>
20 #include <ROOT/RPageAllocator.hxx>
21 #include <ROOT/RNTupleUtil.hxx>
22 
23 #include <cstddef>
24 #include <vector>
25 
26 namespace ROOT {
27 namespace Experimental {
28 
29 namespace 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 
37 The page pool provides memory tracking for data written into an ntuple or read from an ntuple. Adding and removing
38 pages is thread-safe. The page pool does not allocate the memory -- allocation and deallocation is performed by the
39 page storage, which might do it in a way optimized to the backing store (e.g., mmap()).
40 Multiple page caches can coexist.
41 
42 TODO(jblomer): it should be possible to register pages and to find them by column and index; this would
43 facilitate pre-filling a cache, e.g. by read-ahead.
44 */
45 // clang-format on
46 class RPagePool {
47 private:
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 
57 public:
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