Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RColumn.cxx
Go to the documentation of this file.
1/// \file RColumn.cxx
2/// \author Jakob Blomer <jblomer@cern.ch>
3/// \date 2018-10-04
4
5/*************************************************************************
6 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#include <ROOT/RColumn.hxx>
15#include <ROOT/RPageStorage.hxx>
16
17#include <TError.h>
18
19#include <algorithm>
20#include <cassert>
21#include <utility>
22
28
30 ROOT::NTupleSize_t firstElementIndex)
31{
32 fInitialNElements = pageSink.GetWriteOptions().GetInitialUnzippedPageSize() / fElement->GetSize();
33 if (fInitialNElements < 1) {
34 throw RException(R__FAIL("initial page size is too small for at least one element"));
35 }
36
37 fPageSink = &pageSink;
38 fFirstElementIndex = firstElementIndex;
39 fOnDiskId = fPageSink->AddColumn(fieldId, *this).fPhysicalId;
40 fWritePage = fPageSink->ReservePage(MakeHandle(), fInitialNElements);
41 if (fWritePage.IsNull())
42 throw RException(R__FAIL("page buffer memory budget too small"));
43}
44
46{
47 if (fWritePage.GetNElements() == 0)
48 return;
49
50 fPageSink->CommitPage(MakeHandle(), fWritePage);
51 fWritePage = fPageSink->ReservePage(MakeHandle(), fInitialNElements);
52 R__ASSERT(!fWritePage.IsNull());
53 fWritePage.Reset(fNElements);
54}
55
57{
58 fPageSink->CommitSuppressedColumn(MakeHandle());
59}
60
62{
63 fPageSource = &pageSource;
64 fOnDiskId = fPageSource->AddColumn(fieldId, *this).fPhysicalId;
65}
66
68{
69 if (fPageSource)
70 fPageSource->DropColumn(MakeHandle());
71}
72
74{
75 if (!fTeam) {
76 fReadPageRef = fPageSource->LoadPage(MakeHandle(), globalIndex);
77 return fReadPageRef.Get().Contains(globalIndex);
78 }
79
80 const auto nTeam = fTeam->fMembers.size();
81 std::size_t iTeam = 1;
82 do {
83 fReadPageRef = fPageSource->LoadPage(fTeam->fMembers.at(fTeam->fLastGoodTeamIdx)->MakeHandle(), globalIndex);
84 if (!fReadPageRef.Get().IsNull())
85 break;
86 fTeam->fLastGoodTeamIdx = (fTeam->fLastGoodTeamIdx + 1) % nTeam;
87 iTeam++;
88 } while (iTeam <= nTeam);
89
90 return fReadPageRef.Get().Contains(globalIndex);
91}
92
94{
95 if (!fTeam) {
96 fReadPageRef = fPageSource->LoadPage(MakeHandle(), localIndex);
97 return fReadPageRef.Get().Contains(localIndex);
98 }
99
100 const auto nTeam = fTeam->fMembers.size();
101 std::size_t iTeam = 1;
102 do {
103 fReadPageRef = fPageSource->LoadPage(fTeam->fMembers.at(fTeam->fLastGoodTeamIdx)->MakeHandle(), localIndex);
104 if (!fReadPageRef.Get().IsNull())
105 break;
106 fTeam->fLastGoodTeamIdx = (fTeam->fLastGoodTeamIdx + 1) % nTeam;
107 iTeam++;
108 } while (iTeam <= nTeam);
109
110 return fReadPageRef.Get().Contains(localIndex);
111}
112
114{
115 if (!fTeam) {
116 fTeam = std::make_unique<RTeam>();
117 fTeam->fMembers.emplace_back(this);
118 }
119 if (!other.fTeam) {
120 other.fTeam = std::make_unique<RTeam>();
121 other.fTeam->fMembers.emplace_back(&other);
122 }
123
124 // We are working on very small vectors here, so quadratic complexity works
125 for (auto *c : other.fTeam->fMembers) {
126 if (std::find(fTeam->fMembers.begin(), fTeam->fMembers.end(), c) == fTeam->fMembers.end())
127 fTeam->fMembers.emplace_back(c);
128 }
129
130 for (auto c : fTeam->fMembers) {
131 if (c == this)
132 continue;
133 c->fTeam->fMembers = fTeam->fMembers;
134 }
135}
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
Definition RError.hxx:322
#define c(i)
Definition RSha256.hxx:101
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:139
ROOT::Internal::RPageStorage::ColumnHandle_t MakeHandle()
Definition RColumn.hxx:58
Abstract interface to write data into an ntuple.
const ROOT::RNTupleWriteOptions & GetWriteOptions() const
Returns the sink's write options.
void DropColumn(ColumnHandle_t) final
Unregisters a column.
Abstract interface to read data from an ntuple.
ColumnHandle_t AddColumn(ROOT::DescriptorId_t fieldId, ROOT::Internal::RColumn &column) override
Register a new column.
virtual ColumnHandle_t AddColumn(ROOT::DescriptorId_t fieldId, ROOT::Internal::RColumn &column)=0
Register a new column.
void MergeTeams(RReadColumn &other)
Definition RColumn.cxx:113
std::unique_ptr< RTeam > fTeam
As an optimization, if unset the team contains consists of this column only.
Definition RColumn.hxx:111
bool TryMapPage(ROOT::NTupleSize_t globalIndex)
Definition RColumn.cxx:73
void ConnectPageSource(ROOT::DescriptorId_t fieldId, ROOT::Internal::RPageSource &pageSource)
Connect the column to a page source.
Definition RColumn.cxx:61
ROOT::Internal::RPageSink * fPageSink
Definition RColumn.hxx:311
void ConnectPageSink(ROOT::DescriptorId_t fieldId, ROOT::Internal::RPageSink &pageSink, ROOT::NTupleSize_t firstElementIndex=0U)
Connect the column to a page sink.
Definition RColumn.cxx:29
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
std::size_t GetInitialUnzippedPageSize() const
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.