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
25
26ROOT::Internal::RColumn::RColumn(ENTupleColumnType type, std::uint32_t columnIndex, std::uint16_t representationIndex)
27 : fType(type), fIndex(columnIndex), fRepresentationIndex(representationIndex), fTeam({this})
28{
29}
30
38
40 ROOT::NTupleSize_t firstElementIndex)
41{
43 if (fInitialNElements < 1) {
44 throw RException(R__FAIL("initial page size is too small for at least one element"));
45 }
46
47 fPageSink = &pageSink;
48 fFirstElementIndex = firstElementIndex;
49 fHandleSink = fPageSink->AddColumn(fieldId, *this);
50 fOnDiskId = fPageSink->GetColumnId(fHandleSink);
52 if (fWritePage.IsNull())
53 throw RException(R__FAIL("page buffer memory budget too small"));
54}
55
57{
58 fPageSource = &pageSource;
59 fHandleSource = fPageSource->AddColumn(fieldId, *this);
60 fNElements = fPageSource->GetNElements(fHandleSource);
61 fOnDiskId = fPageSource->GetColumnId(fHandleSource);
62 {
63 auto descriptorGuard = fPageSource->GetSharedDescriptorGuard();
64 fFirstElementIndex = descriptorGuard->GetColumnDescriptor(fOnDiskId).GetFirstElementIndex();
65 }
66}
67
69{
70 if (fWritePage.GetNElements() == 0)
71 return;
72
73 fPageSink->CommitPage(fHandleSink, fWritePage);
75 R__ASSERT(!fWritePage.IsNull());
77}
78
80{
81 fPageSink->CommitSuppressedColumn(fHandleSink);
82}
83
85{
86 const auto nTeam = fTeam.size();
87 std::size_t iTeam = 1;
88 do {
89 fReadPageRef = fPageSource->LoadPage(fTeam.at(fLastGoodTeamIdx)->GetHandleSource(), globalIndex);
90 if (!fReadPageRef.Get().IsNull())
91 break;
92 fLastGoodTeamIdx = (fLastGoodTeamIdx + 1) % nTeam;
93 iTeam++;
94 } while (iTeam <= nTeam);
95
96 return fReadPageRef.Get().Contains(globalIndex);
97}
98
100{
101 const auto nTeam = fTeam.size();
102 std::size_t iTeam = 1;
103 do {
104 fReadPageRef = fPageSource->LoadPage(fTeam.at(fLastGoodTeamIdx)->GetHandleSource(), localIndex);
105 if (!fReadPageRef.Get().IsNull())
106 break;
107 fLastGoodTeamIdx = (fLastGoodTeamIdx + 1) % nTeam;
108 iTeam++;
109 } while (iTeam <= nTeam);
110
111 return fReadPageRef.Get().Contains(localIndex);
112}
113
115{
116 // We are working on very small vectors here, so quadratic complexity works
117 for (auto *c : other.fTeam) {
118 if (std::find(fTeam.begin(), fTeam.end(), c) == fTeam.end())
119 fTeam.emplace_back(c);
120 }
121
122 for (auto c : fTeam) {
123 if (c == this)
124 continue;
125 c->fTeam = fTeam;
126 }
127}
#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:299
#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:125
The available trivial, native content types of a column.
RColumn(ROOT::ENTupleColumnType type, std::uint32_t columnIndex, std::uint16_t representationIndex)
void MergeTeams(RColumn &other)
Definition RColumn.cxx:114
std::vector< RColumn * > fTeam
The column team is a set of columns that serve the same column index for different representation IDs...
Definition RColumn.hxx:70
std::size_t fLastGoodTeamIdx
Points into fTeam to the column that successfully returned the last page.
Definition RColumn.hxx:72
void ConnectPageSource(ROOT::DescriptorId_t fieldId, ROOT::Internal::RPageSource &pageSource)
Connect the column to a page source.
Definition RColumn.cxx:56
ROOT::Internal::RPageSource * fPageSource
Definition RColumn.hxx:46
ROOT::Internal::RPageRef fReadPageRef
The currently mapped page for reading.
Definition RColumn.hxx:59
ROOT::Internal::RPage fWritePage
The page into which new elements are being written.
Definition RColumn.hxx:53
ROOT::Internal::RPageSink * fPageSink
Definition RColumn.hxx:45
ROOT::DescriptorId_t fOnDiskId
The column id in the column descriptor, once connected to a sink or source.
Definition RColumn.hxx:61
bool TryMapPage(ROOT::NTupleSize_t globalIndex)
Definition RColumn.cxx:84
ROOT::Internal::RPageStorage::ColumnHandle_t fHandleSink
Definition RColumn.hxx:47
ROOT::NTupleSize_t fFirstElementIndex
Global index of the first element in this column; usually == 0, unless it is a deferred column.
Definition RColumn.hxx:63
ROOT::NTupleSize_t fNElements
The number of elements written resp. available in the column.
Definition RColumn.hxx:57
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:39
ROOT::Internal::RPageStorage::ColumnHandle_t fHandleSource
Definition RColumn.hxx:48
std::unique_ptr< ROOT::Internal::RColumnElementBase > fElement
Used to pack and unpack pages on writing/reading.
Definition RColumn.hxx:65
ROOT::NTupleSize_t fInitialNElements
The initial number of elements in a page.
Definition RColumn.hxx:55
Abstract interface to write data into an ntuple.
const ROOT::RNTupleWriteOptions & GetWriteOptions() const
Returns the sink's write options.
Abstract interface to read data from an ntuple.
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.