Logo ROOT  
Reference Guide
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>
18#include <ROOT/RPageStorage.hxx>
19
20#include <TError.h>
21
22#include <iostream>
23
25 : fModel(model), fIndex(index)
26{
27}
28
30{
31 if (!fWritePage[0].IsNull())
32 fPageSink->ReleasePage(fWritePage[0]);
33 if (!fWritePage[1].IsNull())
34 fPageSink->ReleasePage(fWritePage[1]);
35 if (!fReadPage.IsNull())
36 fPageSource->ReleasePage(fReadPage);
37 if (fHandleSink)
38 fPageSink->DropColumn(fHandleSink);
39 if (fHandleSource)
40 fPageSource->DropColumn(fHandleSource);
41}
42
44{
45 switch (pageStorage->GetType()) {
47 fPageSink = static_cast<RPageSink*>(pageStorage); // the page sink initializes fWritePage on AddColumn
48 fHandleSink = fPageSink->AddColumn(fieldId, *this);
49 fApproxNElementsPerPage = fPageSink->GetWriteOptions().GetApproxUnzippedPageSize() / fElement->GetSize();
50 if (fApproxNElementsPerPage < 2)
51 throw RException(R__FAIL("page size too small for writing"));
52 // We now have 0 < fApproxNElementsPerPage / 2 < fApproxNElementsPerPage
53 fWritePage[0] = fPageSink->ReservePage(fHandleSink, fApproxNElementsPerPage + fApproxNElementsPerPage / 2);
54 fWritePage[1] = fPageSink->ReservePage(fHandleSink, fApproxNElementsPerPage + fApproxNElementsPerPage / 2);
55 break;
57 fPageSource = static_cast<RPageSource*>(pageStorage);
58 fHandleSource = fPageSource->AddColumn(fieldId, *this);
59 fNElements = fPageSource->GetNElements(fHandleSource);
60 fColumnIdSource = fPageSource->GetColumnId(fHandleSource);
61 break;
62 default:
63 R__ASSERT(false);
64 }
65}
66
68{
69 auto otherIdx = 1 - fWritePageIdx;
70 if (fWritePage[fWritePageIdx].IsEmpty() && fWritePage[otherIdx].IsEmpty())
71 return;
72
73 if ((fWritePage[fWritePageIdx].GetNElements() < fApproxNElementsPerPage / 2) && !fWritePage[otherIdx].IsEmpty()) {
74 // Small tail page: merge with previously used page; we know that there is enough space in the shadow page
75 void *dst = fWritePage[otherIdx].GrowUnchecked(fWritePage[fWritePageIdx].GetNElements());
76 RColumnElementBase elem(fWritePage[fWritePageIdx].GetBuffer(), fWritePage[fWritePageIdx].GetElementSize());
77 elem.WriteTo(dst, fWritePage[fWritePageIdx].GetNElements());
78 fWritePage[fWritePageIdx].Reset(0);
79 std::swap(fWritePageIdx, otherIdx);
80 }
81
82 R__ASSERT(fWritePage[otherIdx].IsEmpty());
83 fPageSink->CommitPage(fHandleSink, fWritePage[fWritePageIdx]);
84 fWritePage[fWritePageIdx].Reset(fNElements);
85}
86
88{
89 fPageSource->ReleasePage(fReadPage);
90 fReadPage = fPageSource->PopulatePage(fHandleSource, index);
91}
92
94{
95 fPageSource->ReleasePage(fReadPage);
96 fReadPage = fPageSource->PopulatePage(fHandleSource, clusterIndex);
97}
#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:291
#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 WriteTo(void *destination, std::size_t count) const
Write one or multiple column elements into destination.
void Connect(DescriptorId_t fieldId, RPageStorage *pageStorage)
Definition: RColumn.cxx:43
void MapPage(const NTupleSize_t index)
Definition: RColumn.cxx:87
RColumn(const RColumnModel &model, std::uint32_t index)
Definition: RColumn.cxx:24
Abstract interface to write data into an ntuple.
ColumnHandle_t AddColumn(DescriptorId_t fieldId, const RColumn &column) final
Register a new column.
Abstract interface to read data from an ntuple.
ColumnHandle_t AddColumn(DescriptorId_t fieldId, const RColumn &column) override
Register a new column.
Common functionality of an ntuple storage for both reading and writing.
virtual EPageStorageType GetType()=0
Whether the concrete implementation is a sink or a source.
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
Definition: RNTupleUtil.hxx:87
Holds the static meta-data of a column in a tree.
Base class for all ROOT issued exceptions.
Definition: RError.hxx:114
Py_ssize_t GetBuffer(PyObject *pyobject, char tc, int size, void *&buf, bool check=true)
Definition: Utility.cxx:615
void swap(RDirectoryEntry &e1, RDirectoryEntry &e2) noexcept
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
Definition: RNTupleUtil.hxx:47
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
Definition: RNTupleUtil.hxx:83