Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RPagePool.cxx
Go to the documentation of this file.
1/// \file RPagePool.cxx
2/// \ingroup NTuple ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2018-10-04
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#include <ROOT/RPagePool.hxx>
17#include <ROOT/RColumn.hxx>
18
19#include <TError.h>
20
21#include <cstdlib>
22
24{
25 std::lock_guard<std::mutex> lockGuard(fLock);
26 fPages.emplace_back(page);
27 fReferences.emplace_back(1);
28 fDeleters.emplace_back(deleter);
29}
30
32{
33 std::lock_guard<std::mutex> lockGuard(fLock);
34 fPages.emplace_back(page);
35 fReferences.emplace_back(0);
36 fDeleters.emplace_back(deleter);
37}
38
40{
41 if (page.IsNull()) return;
42 std::lock_guard<std::mutex> lockGuard(fLock);
43
44 unsigned int N = fPages.size();
45 for (unsigned i = 0; i < N; ++i) {
46 if (fPages[i] != page) continue;
47
48 if (--fReferences[i] == 0) {
49 fDeleters[i](fPages[i]);
50 fPages[i] = fPages[N-1];
51 fReferences[i] = fReferences[N-1];
52 fDeleters[i] = fDeleters[N-1];
53 fPages.resize(N-1);
54 fReferences.resize(N-1);
55 fDeleters.resize(N-1);
56 }
57 return;
58 }
59 R__ASSERT(false);
60}
61
63 ColumnId_t columnId, NTupleSize_t globalIndex)
64{
65 std::lock_guard<std::mutex> lockGuard(fLock);
66 unsigned int N = fPages.size();
67 for (unsigned int i = 0; i < N; ++i) {
68 if (fReferences[i] < 0) continue;
69 if (fPages[i].GetColumnId() != columnId) continue;
70 if (!fPages[i].Contains(globalIndex)) continue;
71 fReferences[i]++;
72 return fPages[i];
73 }
74 return RPage();
75}
76
78 ColumnId_t columnId, const RClusterIndex &clusterIndex)
79{
80 std::lock_guard<std::mutex> lockGuard(fLock);
81 unsigned int N = fPages.size();
82 for (unsigned int i = 0; i < N; ++i) {
83 if (fReferences[i] < 0) continue;
84 if (fPages[i].GetColumnId() != columnId) continue;
85 if (!fPages[i].Contains(clusterIndex)) continue;
86 fReferences[i]++;
87 return fPages[i];
88 }
89 return RPage();
90}
#define R__ASSERT(e)
Definition TError.h:120
#define N
A closure that can free the memory associated with a mapped page.
std::vector< std::int32_t > fReferences
Definition RPagePool.hxx:55
std::vector< RPageDeleter > fDeleters
Definition RPagePool.hxx:56
void PreloadPage(const RPage &page, const RPageDeleter &deleter)
Like RegisterPage() but the reference counter is initialized to 0.
Definition RPagePool.cxx:31
void ReturnPage(const RPage &page)
Give back a page to the pool and decrease the reference counter.
Definition RPagePool.cxx:39
RPage GetPage(ColumnId_t columnId, NTupleSize_t globalIndex)
Tries to find the page corresponding to column and index in the cache.
Definition RPagePool.cxx:62
std::vector< RPage > fPages
TODO(jblomer): should be an efficient index structure that allows.
Definition RPagePool.hxx:54
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...
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
std::int64_t ColumnId_t
Uniquely identifies a physical column within the scope of the current process, used to tag pages.