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 switch (pageStorage->GetType()) {
47 fFirstElementIndex = firstElementIndex;
48 fPageSink = static_cast<RPageSink*>(pageStorage); // the page sink initializes fWritePage on AddColumn
49 fHandleSink = fPageSink->AddColumn(fieldId, *this);
50 fApproxNElementsPerPage = fPageSink->GetWriteOptions().GetApproxUnzippedPageSize() / fElement->GetSize();
51 if (fApproxNElementsPerPage < 2)
52 throw RException(R__FAIL("page size too small for writing"));
53 // We now have 0 < fApproxNElementsPerPage / 2 < fApproxNElementsPerPage
54 fWritePage[0] = fPageSink->ReservePage(fHandleSink, fApproxNElementsPerPage + fApproxNElementsPerPage / 2);
55 fWritePage[1] = fPageSink->ReservePage(fHandleSink, fApproxNElementsPerPage + fApproxNElementsPerPage / 2);
56 break;
58 fPageSource = static_cast<RPageSource*>(pageStorage);
59 fHandleSource = fPageSource->AddColumn(fieldId, *this);
60 fNElements = fPageSource->GetNElements(fHandleSource);
61 fColumnIdSource = fPageSource->GetColumnId(fHandleSource);
62 {
63 auto descriptorGuard = fPageSource->GetSharedDescriptorGuard();
64 fFirstElementIndex = descriptorGuard->GetColumnDescriptor(fColumnIdSource).GetFirstElementIndex();
65 }
66 break;
67 default:
68 R__ASSERT(false);
69 }
70}
71
73{
74 auto otherIdx = 1 - fWritePageIdx;
75 if (fWritePage[fWritePageIdx].IsEmpty() && fWritePage[otherIdx].IsEmpty())
76 return;
77
78 if ((fWritePage[fWritePageIdx].GetNElements() < fApproxNElementsPerPage / 2) && !fWritePage[otherIdx].IsEmpty()) {
79 // Small tail page: merge with previously used page; we know that there is enough space in the shadow page
80 auto &thisPage = fWritePage[fWritePageIdx];
81 void *dst = fWritePage[otherIdx].GrowUnchecked(thisPage.GetNElements());
82 memcpy(dst, thisPage.GetBuffer(), thisPage.GetElementSize() * thisPage.GetNElements());
83 thisPage.Reset(0);
84 std::swap(fWritePageIdx, otherIdx);
85 }
86
87 R__ASSERT(fWritePage[otherIdx].IsEmpty());
88 fPageSink->CommitPage(fHandleSink, fWritePage[fWritePageIdx]);
89 fWritePage[fWritePageIdx].Reset(fNElements);
90}
91
93{
94 fPageSource->ReleasePage(fReadPage);
95 fReadPage = fPageSource->PopulatePage(fHandleSource, index);
96 R__ASSERT(fReadPage.Contains(index));
97}
98
100{
101 fPageSource->ReleasePage(fReadPage);
102 fReadPage = fPageSource->PopulatePage(fHandleSource, clusterIndex);
103 R__ASSERT(fReadPage.Contains(clusterIndex));
104}
#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:303
#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 Connect(DescriptorId_t fieldId, RPageStorage *pageStorage, NTupleSize_t firstElementIndex=0U)
Connect the column to a page storage.
Definition RColumn.cxx:42
void MapPage(const NTupleSize_t index)
Definition RColumn.cxx:92
RColumn(const RColumnModel &model, std::uint32_t index)
Definition RColumn.cxx:23
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...
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.