Logo ROOT   6.18/05
Reference Guide
RNTuple.cxx
Go to the documentation of this file.
1/// \file RNTuple.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/RNTuple.hxx"
17
18#include "ROOT/RNTupleModel.hxx"
19#include "ROOT/RPageStorage.hxx"
21
22#include <iomanip>
23#include <sstream>
24#include <string>
25#include <utility>
26
27ROOT::Experimental::Detail::RNTuple::RNTuple(std::unique_ptr<ROOT::Experimental::RNTupleModel> model)
28 : fModel(std::move(model))
29 , fNEntries(0)
30{
31}
32
34{
35}
36
37//------------------------------------------------------------------------------
38
40 std::unique_ptr<ROOT::Experimental::RNTupleModel> model,
41 std::unique_ptr<ROOT::Experimental::Detail::RPageSource> source)
42 : ROOT::Experimental::Detail::RNTuple(std::move(model))
43 , fSource(std::move(source))
44{
45 fSource->Attach();
46 for (auto& field : *fModel->GetRootField()) {
47 field.ConnectColumns(fSource.get());
48 }
49 fNEntries = fSource->GetNEntries();
50}
51
52ROOT::Experimental::RNTupleReader::RNTupleReader(std::unique_ptr<ROOT::Experimental::Detail::RPageSource> source)
53 : ROOT::Experimental::Detail::RNTuple(nullptr)
54 , fSource(std::move(source))
55{
56 fSource->Attach();
57 fModel = fSource->GenerateModel();
58 for (auto& field : *fModel->GetRootField()) {
59 field.ConnectColumns(fSource.get());
60 }
61 fNEntries = fSource->GetNEntries();
62}
63
65{
66}
67
68std::unique_ptr<ROOT::Experimental::RNTupleReader> ROOT::Experimental::RNTupleReader::Open(
69 std::unique_ptr<RNTupleModel> model,
70 std::string_view ntupleName,
71 std::string_view storage)
72{
73 // TODO(jblomer): heuristics based on storage
74 return std::make_unique<RNTupleReader>(
75 std::move(model), std::make_unique<Detail::RPageSourceRoot>(ntupleName, storage));
76}
77
78std::unique_ptr<ROOT::Experimental::RNTupleReader> ROOT::Experimental::RNTupleReader::Open(
79 std::string_view ntupleName,
80 std::string_view storage)
81{
82 return std::make_unique<RNTupleReader>(std::make_unique<Detail::RPageSourceRoot>(ntupleName, storage));
83}
84
86 std::ostringstream os;
87 auto name = fSource->GetDescriptor().GetName();
88
89 switch (what) {
91 os << "****************************** NTUPLE *******************************" << std::endl
92 << "* Name: " << name << std::setw(57 - name.length()) << "*" << std::endl
93 << "* Entries: " << std::setw(10) << fNEntries << std::setw(47) << "*" << std::endl
94 << "********************************************************************" << std::endl;
95 return os.str();
96 default:
97 // Unhandled case, internal error
98 assert(false);
99 }
100 // Never here
101 return "";
102}
103
104//------------------------------------------------------------------------------
105
107 std::unique_ptr<ROOT::Experimental::RNTupleModel> model,
108 std::unique_ptr<ROOT::Experimental::Detail::RPageSink> sink)
109 : ROOT::Experimental::Detail::RNTuple(std::move(model))
110 , fSink(std::move(sink))
111 , fClusterSizeEntries(kDefaultClusterSizeEntries)
112 , fLastCommitted(0)
113{
114 fSink->Create(fModel.get());
115}
116
118{
119 CommitCluster();
120 fSink->CommitDataset();
121}
122
123
124std::unique_ptr<ROOT::Experimental::RNTupleWriter> ROOT::Experimental::RNTupleWriter::Recreate(
125 std::unique_ptr<RNTupleModel> model,
126 std::string_view ntupleName,
127 std::string_view storage)
128{
129 // TODO(jblomer): heuristics based on storage
130 TFile *file = TFile::Open(std::string(storage).c_str(), "RECREATE");
132 settings.fFile = file;
133 settings.fTakeOwnership = true;
134 return std::make_unique<RNTupleWriter>(
135 std::move(model), std::make_unique<Detail::RPageSinkRoot>(ntupleName, settings));
136}
137
138
140{
141 if (fNEntries == fLastCommitted) return;
142 for (auto& field : *fModel->GetRootField()) {
143 field.Flush();
144 field.CommitCluster();
145 }
146 fSink->CommitCluster(fNEntries);
147 fLastCommitted = fNEntries;
148}
149
150
151//------------------------------------------------------------------------------
152
153
155 : fOffset(0), fDefaultEntry(std::move(defaultEntry))
156{
157}
char name[80]
Definition: TGX11.cxx:109
NTupleSize_t fNEntries
The number of entries is constant for reading and reflects the sum of Fill() operations when writing.
Definition: RNTuple.hxx:58
RNTuple(std::unique_ptr< RNTupleModel > model)
Only the derived RNTupleReader and RNTupleWriter can be instantiated.
Definition: RNTuple.cxx:27
std::unique_ptr< RNTupleModel > fModel
Definition: RNTuple.hxx:56
RCollectionNTuple(std::unique_ptr< REntry > defaultEntry)
Definition: RNTuple.cxx:154
static std::unique_ptr< RNTupleReader > Open(std::unique_ptr< RNTupleModel > model, std::string_view ntupleName, std::string_view storage)
Definition: RNTuple.cxx:68
std::unique_ptr< Detail::RPageSource > fSource
Definition: RNTuple.hxx:96
RNTupleReader(std::unique_ptr< RNTupleModel > model, std::unique_ptr< Detail::RPageSource > source)
The user imposes an ntuple model, which must be compatible with the model found in the data on storag...
Definition: RNTuple.cxx:39
std::string GetInfo(const ENTupleInfo what=ENTupleInfo::kSummary)
Definition: RNTuple.cxx:85
void CommitCluster()
Ensure that the data from the so far seen Fill calls has been written to storage.
Definition: RNTuple.cxx:139
RNTupleWriter(std::unique_ptr< RNTupleModel > model, std::unique_ptr< Detail::RPageSink > sink)
Definition: RNTuple.cxx:106
static std::unique_ptr< RNTupleWriter > Recreate(std::unique_ptr< RNTupleModel > model, std::string_view ntupleName, std::string_view storage)
Definition: RNTuple.cxx:124
std::unique_ptr< Detail::RPageSink > fSink
Definition: RNTuple.hxx:173
The RNTuple represents a live dataset, whose structure is defined by an RNTupleModel.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:48
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3980
basic_string_view< char > string_view
ENTupleInfo
Listing of the different options that can be returned by RNTupleReader::GetInfo()
Definition: RNTuple.hxx:77
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Definition: file.py:1