Logo ROOT   6.18/05
Reference Guide
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
23ROOT::Experimental::Detail::RPagePool::RPagePool(std::size_t pageSize, std::size_t nPages)
24 : fMemory(nullptr), fPageSize(pageSize), fNPages(nPages)
25{
26 if (nPages > 0) {
27 fMemory = malloc(pageSize * nPages);
28 R__ASSERT(fMemory != nullptr);
29 fPages.resize(nPages);
30 fReferences.resize(nPages, 0);
31 }
32}
33
34
36{
37 free(fMemory);
38}
39
40
42{
43 RPage result;
44 for (std::size_t i = 0; i < fNPages; ++i) {
45 if (fPages[i].IsNull()) {
46 void* buffer = static_cast<unsigned char *>(fMemory) + (fPageSize * i);
47 result = RPage(column->GetColumnIdSource(), buffer, fPageSize, column->GetModel().GetElementSize());
48 fPages[i] = result;
49 return result;
50 }
51 }
52 /// No space left
53 return result;
54}
55
56
58{
59 for (unsigned i = 0; i < fNPages; ++i) {
60 if (fPages[i] == page) {
61 fReferences[i] = 1;
62 return;
63 }
64 }
65 R__ASSERT(false);
66}
67
69{
70 if (page.IsNull()) return;
71 for (unsigned i = 0; i < fNPages; ++i) {
72 if (fPages[i] == page) {
73 if (--fReferences[i] == 0) {
74 fPages[i] = RPage();
75 }
76 return;
77 }
78 }
79 R__ASSERT(false);
80}
81
83{
84 for (unsigned i = 0; i < fNPages; ++i) {
85 if (fReferences[i] == 0) continue;
86 if (fPages[i].GetColumnId() != column->GetColumnIdSource()) continue;
87 if (!fPages[i].Contains(index)) continue;
88 fReferences[i]++;
89 return fPages[i];
90 }
91 RPage newPage = ReservePage(column);
92 column->GetPageSource()->PopulatePage(column->GetHandleSource(), index, &newPage);
93 CommitPage(newPage);
94 return newPage;
95}
#define R__ASSERT(e)
Definition: TError.h:96
#define free
Definition: civetweb.c:1539
#define malloc
Definition: civetweb.c:1536
RPageStorage::ColumnHandle_t GetHandleSource() const
Definition: RColumn.hxx:169
const RColumnModel & GetModel() const
Definition: RColumn.hxx:166
ColumnId_t GetColumnIdSource() const
Definition: RColumn.hxx:167
RPageSource * GetPageSource() const
Definition: RColumn.hxx:168
RPage GetPage(RColumn *column, NTupleSize_t index)
Tries to find the page corresponding to column and index in the cache.
Definition: RPagePool.cxx:82
std::vector< std::uint32_t > fReferences
Definition: RPagePool.hxx:57
void ReleasePage(const RPage &page)
Give back a page to the pool. There must not be any pointers anymore into this page.
Definition: RPagePool.cxx:68
std::vector< RPage > fPages
TODO(jblomer): should be an efficient index structure that allows.
Definition: RPagePool.hxx:56
RPagePool(std::size_t pageSize, std::size_t nPages)
Definition: RPagePool.cxx:23
RPage ReservePage(RColumn *column)
Get a new, empty page from the cache. Return a "null Page" if there is no more free space.
Definition: RPagePool.cxx:41
void CommitPage(const RPage &page)
Registers a page that has previously been acquired by ReservePage() and was meanwhile filled with con...
Definition: RPagePool.cxx:57
virtual void PopulatePage(ColumnHandle_t columnHandle, NTupleSize_t index, RPage *page)=0
Fills a page starting with index rangeStart; the corresponding column is taken from the page object.
A page is a fixed size slice of a column that is mapped into memory.
Definition: RPage.hxx:40
std::size_t GetElementSize() const
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
Definition: RNTupleUtil.hxx:44