40#include <unordered_map>
51 fTaskGroup = std::make_unique<TTaskGroup>();
56 fTaskGroup->Run(taskFunc);
76 fSource->GetSharedDescriptorGuard()->FindFieldId(field.GetName(), field.GetParent()->GetOnDiskId()));
78 field.ConnectPageSource(*fSource);
86 fUnzipTasks = std::make_unique<RNTupleImtTaskScheduler>();
87 fSource->SetTaskScheduler(fUnzipTasks.get());
91 fMetrics.ObserveMetrics(fSource->GetMetrics());
95 std::unique_ptr<ROOT::Experimental::Detail::RPageSource> source)
96 : fSource(std::move(source)), fModel(std::move(model)), fMetrics(
"RNTupleReader")
104 if (!
fModel->GetProjectedFields().IsEmpty()) {
105 throw RException(
R__FAIL(
"model has projected fields, which is incompatible with providing a read model"));
113 : fSource(std::move(source)), fModel(nullptr), fMetrics(
"RNTupleReader")
123std::unique_ptr<ROOT::Experimental::RNTupleReader>
130std::unique_ptr<ROOT::Experimental::RNTupleReader>
137std::unique_ptr<ROOT::Experimental::RNTupleReader>
140 return std::make_unique<RNTupleReader>(ntuple->
MakePageSource(options));
143std::unique_ptr<ROOT::Experimental::RNTupleReader>
146 std::vector<std::unique_ptr<Detail::RPageSource>> sources;
147 for (
const auto &
n : ntuples) {
150 return std::make_unique<RNTupleReader>(std::make_unique<Detail::RPageSourceFriends>(
"_friends", sources));
156 fModel = fSource->GetSharedDescriptorGuard()->GenerateModel();
157 ConnectModel(*fModel);
166 char frameSymbol =
'*';
177 std::unique_ptr<RNTupleModel> fullModel;
179 auto descriptorGuard = fSource->GetSharedDescriptorGuard();
180 name = descriptorGuard->GetName();
181 fullModel = descriptorGuard->GenerateModel();
184 for (
int i = 0; i < (
width / 2 +
width % 2 - 4); ++i)
187 for (
int i = 0; i < (
width / 2 - 4); ++i)
194 << frameSymbol << std::endl;
202 fullModel->GetFieldZero()->AcceptVisitor(prepVisitor);
209 for (
int i = 0; i <
width; ++i)
212 fullModel->GetFieldZero()->AcceptVisitor(printVisitor);
213 for (
int i = 0; i <
width; ++i)
229 fDisplayReader = Clone();
230 return fDisplayReader.get();
235 auto reader = GetDisplayReader();
236 auto entry = reader->GetModel()->GetDefaultEntry();
238 reader->LoadEntry(
index);
240 for (
auto iValue = entry->begin(); iValue != entry->end();) {
243 iValue->GetField()->AcceptVisitor(visitor);
245 if (++iValue == entry->end()) {
252 output <<
"}" << std::endl;
257 auto descriptorGuard = fSource->GetSharedDescriptorGuard();
258 if (!fCachedDescriptor || fCachedDescriptor->GetGeneration() != descriptorGuard->GetGeneration())
259 fCachedDescriptor = descriptorGuard->
Clone();
260 return fCachedDescriptor.get();
266 std::unique_ptr<ROOT::Experimental::Detail::RPageSink> sink)
267 : fSink(std::move(sink)), fModel(std::move(model)), fMetrics(
"RNTupleWriter")
278 fZipTasks = std::make_unique<RNTupleImtTaskScheduler>();
285 const auto &writeOpts =
fSink->GetWriteOptions();
288 const int scale = writeOpts.GetCompression() ? 2 : 1;
295 CommitCluster(
true );
296 fSink->CommitDataset();
302std::unique_ptr<ROOT::Experimental::RNTupleWriter>
309std::unique_ptr<ROOT::Experimental::RNTupleWriter>
313 auto sink = std::make_unique<Detail::RPageSinkFile>(ntupleName,
file, options);
315 auto bufferedSink = std::make_unique<Detail::RPageSinkBuf>(std::move(sink));
316 return std::make_unique<RNTupleWriter>(std::move(model), std::move(bufferedSink));
318 return std::make_unique<RNTupleWriter>(std::move(model), std::move(sink));
323 if (fNEntries == fLastCommittedClusterGroup)
325 fSink->CommitClusterGroup();
326 fLastCommittedClusterGroup = fNEntries;
331 if (fNEntries == fLastCommitted) {
332 if (commitClusterGroup)
333 CommitClusterGroup();
336 if (fSink->GetWriteOptions().GetHasSmallClusters() &&
339 throw RException(
R__FAIL(
"invalid attempt to write a cluster > 512MiB with 'small clusters' option enabled"));
341 for (
auto &field : *fModel->GetFieldZero()) {
342 field.CommitCluster();
344 fNBytesCommitted += fSink->CommitCluster(fNEntries);
345 fNBytesFilled += fUnzippedClusterSize;
348 const float compressionFactor =
349 std::min(1000.f,
static_cast<float>(fNBytesFilled) /
static_cast<float>(fNBytesCommitted));
350 fUnzippedClusterSizeEst =
351 compressionFactor *
static_cast<float>(fSink->GetWriteOptions().GetApproxZippedClusterSize());
353 fLastCommitted = fNEntries;
354 fUnzippedClusterSize = 0;
356 if (commitClusterGroup)
357 CommitClusterGroup();
363 : fOffset(0), fDefaultEntry(std::move(defaultEntry))
371 static TClassRef RNTupleAnchorClass(
"ROOT::Experimental::Internal::RFileNTupleAnchor");
382std::unique_ptr<ROOT::Experimental::Detail::RPageSource>
391 auto path = fFile->GetEndpointUrl()->GetFile();
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
#define R__LOG_ERROR(...)
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 SetOnDiskId(DescriptorId_t id)
void ObserveMetrics(RNTupleMetrics &observee)
static std::unique_ptr< RPageSink > Create(std::string_view ntupleName, std::string_view location, const RNTupleWriteOptions &options=RNTupleWriteOptions())
Guess the concrete derived page source from the file name (location)
static std::unique_ptr< RPageSourceFile > CreateFromAnchor(const Internal::RFileNTupleAnchor &anchor, std::string_view path, const RNTupleReadOptions &options)
Used from the RNTuple class to build a datasource if the anchor is already available.
static std::unique_ptr< RPageSource > Create(std::string_view ntupleName, std::string_view location, const RNTupleReadOptions &options=RNTupleReadOptions())
Guess the concrete derived page source from the file name (location)
RCollectionNTupleWriter(std::unique_ptr< REntry > defaultEntry)
std::string GetReport() const
Format a dignostics report, e.g. for an exception message.
Base class for all ROOT issued exceptions.
const RError & GetError() const
The on-storage meta-data of an ntuple.
std::unique_ptr< RNTupleDescriptor > Clone() const
void Reset() final
Start a new set of tasks.
void AddTask(const std::function< void(void)> &taskFunc) final
Take a callable that represents a task.
RNTupleImtTaskScheduler()
void Wait() final
Blocks until all scheduled tasks finished.
The RNTupleModel encapulates the schema of an ntuple.
RFieldZero * GetFieldZero() const
Common user-tunable settings for reading ntuples.
An RNTuple that is used to read data from storage.
static std::unique_ptr< RNTupleReader > OpenFriends(std::span< ROpenSpec > ntuples)
Open RNTuples as one virtual, horizontally combined ntuple.
RNTupleReader * GetDisplayReader()
void Show(NTupleSize_t index, std::ostream &output=std::cout)
Shows the values of the i-th entry/row, starting with 0 for the first entry.
const RNTupleDescriptor * GetDescriptor()
Returns a cached copy of the page source descriptor.
static std::unique_ptr< RNTupleReader > Open(std::unique_ptr< RNTupleModel > model, std::string_view ntupleName, std::string_view storage, const RNTupleReadOptions &options=RNTupleReadOptions())
Throws an exception if the model is null.
std::unique_ptr< Detail::RPageSource > fSource
void ConnectModel(const RNTupleModel &model)
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...
RNTupleModel * GetModel()
void PrintInfo(const ENTupleInfo what=ENTupleInfo::kSummary, std::ostream &output=std::cout)
Prints a detailed summary of the ntuple, including a list of fields.
std::unique_ptr< RNTupleModel > fModel
Needs to be destructed before fSource.
Common user-tunable settings for storing ntuples.
static constexpr std::uint64_t kMaxSmallClusterSize
A maximum size of 512MB still allows for a vector of bool to be stored in a small cluster.
bool GetUseBufferedWrite() const
NTupleSize_t fUnzippedClusterSizeEst
Estimator of uncompressed cluster size, taking into account the estimated compression ratio.
RNTupleWriter(std::unique_ptr< RNTupleModel > model, std::unique_ptr< Detail::RPageSink > sink)
Throws an exception if the model or the sink is null.
std::size_t fMaxUnzippedClusterSize
Limit for committing cluster no matter the other tunables.
void CommitCluster(bool commitClusterGroup=false)
Ensure that the data from the so far seen Fill calls has been written to storage.
std::unique_ptr< RNTupleModel > fModel
Needs to be destructed before fSink.
void CommitClusterGroup()
Detail::RNTupleMetrics fMetrics
std::unique_ptr< Detail::RPageSink > fSink
static std::unique_ptr< RNTupleWriter > Recreate(std::unique_ptr< RNTupleModel > model, std::string_view ntupleName, std::string_view storage, const RNTupleWriteOptions &options=RNTupleWriteOptions())
Throws an exception if the model is null.
std::unique_ptr< Detail::RPageStorage::RTaskScheduler > fZipTasks
The page sink's parallel page compression scheduler if IMT is on.
static std::unique_ptr< RNTupleWriter > Append(std::unique_ptr< RNTupleModel > model, std::string_view ntupleName, TFile &file, const RNTupleWriteOptions &options=RNTupleWriteOptions())
Throws an exception if the model is null.
Representation of an RNTuple data set in a ROOT file.
std::unique_ptr< Detail::RPageSource > MakePageSource(const RNTupleReadOptions &options=RNTupleReadOptions())
Create a page source from the RNTuple object.
Visitor used for a pre-processing run to collect information needed by another visitor class.
unsigned int GetDeepestLevel() const
unsigned int GetNumFields() const
Contains settings for printing and prints a summary of an RField instance.
void SetDeepestLevel(int d)
void SetFrameSymbol(char s)
Renders a JSON value corresponding to the field.
Buffer base class used for serializing objects.
TObject * GetParent() const
Return pointer to parent of this buffer.
TClassRef is used to implement a permanent reference to a TClass object.
Int_t ReadBuffer(TBuffer &b, void *pointer, Int_t version, UInt_t start, UInt_t count)
Function called by the Streamer functions to deserialize information from buffer b into object at p.
Int_t WriteBuffer(TBuffer &b, void *pointer, const char *info="")
Function called by the Streamer functions to serialize object at p to buffer b.
A ROOT file is composed of a header, followed by consecutive data records (TKey instances) with a wel...
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.
ENTupleInfo
Listing of the different options that can be printed by RNTupleReader::GetInfo()
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
constexpr DescriptorId_t kInvalidDescriptorId
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.
Entry point for an RNTuple in a ROOT file.