Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RColumn.cxx
Go to the documentation of this file.
1/// \file RColumn.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/RColumn.hxx>
17#include <ROOT/RColumnModel.hxx>
19#include <ROOT/RPageStorage.hxx>
20
21#include <TError.h>
22
24 : fModel(model), fIndex(index)
25{
26}
27
29{
30 if (!fWritePage[0].IsNull())
31 fPageSink->ReleasePage(fWritePage[0]);
32 if (!fWritePage[1].IsNull())
33 fPageSink->ReleasePage(fWritePage[1]);
34 if (!fReadPage.IsNull())
35 fPageSource->ReleasePage(fReadPage);
36 if (fHandleSink)
37 fPageSink->DropColumn(fHandleSink);
38 if (fHandleSource)
39 fPageSource->DropColumn(fHandleSource);
40}
41
43 NTupleSize_t firstElementIndex)
44{
45 fPageSink = &pageSink; // the page sink initializes fWritePage on AddColumn
46 fFirstElementIndex = firstElementIndex;
47 fHandleSink = fPageSink->AddColumn(fieldId, *this);
48 fApproxNElementsPerPage = fPageSink->GetWriteOptions().GetApproxUnzippedPageSize() / fElement->GetSize();
50 throw RException(R__FAIL("page size too small for writing"));
51 // We now have 0 < fApproxNElementsPerPage / 2 < fApproxNElementsPerPage
54}
55
57{
58 fPageSource = &pageSource;
59 fHandleSource = fPageSource->AddColumn(fieldId, *this);
60 fNElements = fPageSource->GetNElements(fHandleSource);
62 {
63 auto descriptorGuard = fPageSource->GetSharedDescriptorGuard();
64 fFirstElementIndex = descriptorGuard->GetColumnDescriptor(fColumnIdSource).GetFirstElementIndex();
65 }
66}
67
69{
70 auto otherIdx = 1 - fWritePageIdx;
71 if (fWritePage[fWritePageIdx].IsEmpty() && fWritePage[otherIdx].IsEmpty())
72 return;
73
74 if ((fWritePage[fWritePageIdx].GetNElements() < fApproxNElementsPerPage / 2) && !fWritePage[otherIdx].IsEmpty()) {
75 // Small tail page: merge with previously used page; we know that there is enough space in the shadow page
76 auto &thisPage = fWritePage[fWritePageIdx];
77 void *dst = fWritePage[otherIdx].GrowUnchecked(thisPage.GetNElements());
78 memcpy(dst, thisPage.GetBuffer(), thisPage.GetNBytes());
79 thisPage.Reset(0);
80 std::swap(fWritePageIdx, otherIdx);
81 }
82
83 R__ASSERT(fWritePage[otherIdx].IsEmpty());
86}
87
89{
90 fPageSource->ReleasePage(fReadPage);
91 // Set fReadPage to an empty page before populating it to prevent double destruction of the previously page in case
92 // the page population fails.
93 fReadPage = RPage();
94 fReadPage = fPageSource->PopulatePage(fHandleSource, index);
95 R__ASSERT(fReadPage.Contains(index));
96}
97
99{
100 fPageSource->ReleasePage(fReadPage);
101 // Set fReadPage to an empty page before populating it to prevent double destruction of the previously page in case
102 // the page population fails.
103 fReadPage = RPage();
104 fReadPage = fPageSource->PopulatePage(fHandleSource, clusterIndex);
105 R__ASSERT(fReadPage.Contains(clusterIndex));
106}
#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:290
#define R__ASSERT(e)
Definition TError.h:118
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
void ConnectPageSink(DescriptorId_t fieldId, RPageSink &pageSink, NTupleSize_t firstElementIndex=0U)
Connect the column to a page sink.
Definition RColumn.cxx:42
std::unique_ptr< RColumnElementBase > fElement
Used to pack and unpack pages on writing/reading.
Definition RColumn.hxx:76
ColumnId_t fColumnIdSource
The column id is used to find matching pages with content when reading.
Definition RColumn.hxx:72
int fWritePageIdx
Index of the current write page.
Definition RColumn.hxx:62
RPageStorage::ColumnHandle_t fHandleSource
Definition RColumn.hxx:54
NTupleSize_t fNElements
The number of elements written resp. available in the column.
Definition RColumn.hxx:68
void MapPage(const NTupleSize_t index)
Definition RColumn.cxx:88
std::uint32_t fIndex
Columns belonging to the same field are distinguished by their order.
Definition RColumn.hxx:50
void ConnectPageSource(DescriptorId_t fieldId, RPageSource &pageSource)
Connect the column to a page source.
Definition RColumn.cxx:56
std::uint32_t fApproxNElementsPerPage
For writing, the targeted number of elements, given by fApproxNElementsPerPage (in the write options)...
Definition RColumn.hxx:66
RColumn(const RColumnModel &model, std::uint32_t index)
Definition RColumn.cxx:23
RPageStorage::ColumnHandle_t fHandleSink
Definition RColumn.hxx:53
RPage fWritePage[2]
A set of open pages into which new elements are being written.
Definition RColumn.hxx:60
NTupleSize_t GetNElements() const
Definition RColumn.hxx:324
RPage fReadPage
The currently mapped page for reading.
Definition RColumn.hxx:70
NTupleSize_t fFirstElementIndex
Global index of the first element in this column; usually == 0, unless it is a deferred column.
Definition RColumn.hxx:74
Abstract interface to write data into an ntuple.
Abstract interface to read data from an ntuple.
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...
Holds the static meta-data of an RNTuple column.
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.