Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleFillContext.hxx
Go to the documentation of this file.
1/// \file ROOT/RNTupleFillContext.hxx
2/// \ingroup NTuple ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2024-02-22
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-2024, 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#ifndef ROOT7_RNTupleFillContext
17#define ROOT7_RNTupleFillContext
18
19#include <ROOT/RConfig.hxx> // for R__unlikely
20#include <ROOT/REntry.hxx>
21#include <ROOT/RError.hxx>
24#include <ROOT/RNTupleModel.hxx>
25#include <ROOT/RNTupleUtil.hxx>
26
27#include <cstddef>
28#include <cstdint>
29#include <memory>
30
31namespace ROOT {
32namespace Experimental {
33
34namespace Internal {
35class RPageSink;
36}
37
38// clang-format off
39/**
40\class ROOT::Experimental::RNTupleFillContext
41\ingroup NTuple
42\brief A context for filling entries (data) into clusters of an RNTuple
43
44An output cluster can be filled with entries. The caller has to make sure that the data that gets filled into a cluster
45is not modified for the time of the Fill() call. The fill call serializes the C++ object into the column format and
46writes data into the corresponding column page buffers. Writing of the buffers to storage is deferred and can be
47triggered by CommitCluster() or by destructing the context. On I/O errors, an exception is thrown.
48
49Instances of this class are not meant to be used in isolation and can be created from an RNTupleParallelWriter. For
50sequential writing, please refer to RNTupleWriter.
51*/
52// clang-format on
54 friend class RNTupleWriter;
56
57private:
58 std::unique_ptr<Internal::RPageSink> fSink;
59 /// Needs to be destructed before fSink
60 std::unique_ptr<RNTupleModel> fModel;
61
63
66 /// Keeps track of the number of bytes written into the current cluster
67 std::size_t fUnzippedClusterSize = 0;
68 /// The total number of bytes written to storage (i.e., after compression)
69 std::uint64_t fNBytesCommitted = 0;
70 /// The total number of bytes filled into all the so far committed clusters,
71 /// i.e. the uncompressed size of the written clusters
72 std::uint64_t fNBytesFilled = 0;
73 /// Limit for committing cluster no matter the other tunables
75 /// Estimator of uncompressed cluster size, taking into account the estimated compression ratio
77
78 RNTupleFillContext(std::unique_ptr<RNTupleModel> model, std::unique_ptr<Internal::RPageSink> sink);
81
82public:
84
85 /// Fill an entry into this context, but don't commit the cluster. The calling code must pass an RNTupleFillStatus
86 /// and check RNTupleFillStatus::ShouldCommitCluster.
87 ///
88 /// This method will perform a light check whether the entry comes from the context's own model.
90 {
91 if (R__unlikely(entry.GetModelId() != fModel->GetModelId()))
92 throw RException(R__FAIL("mismatch between entry and model"));
93
94 const std::size_t bytesWritten = entry.Append();
95 fUnzippedClusterSize += bytesWritten;
96 fNEntries++;
97
100 status.fLastEntrySize = bytesWritten;
101 status.fShouldCommitCluster =
103 }
104 /// Fill an entry into this context. This method will perform a light check whether the entry comes from the
105 /// context's own model.
106 /// \return The number of uncompressed bytes written.
107 std::size_t Fill(REntry &entry)
108 {
109 RNTupleFillStatus status;
110 FillNoCommit(entry, status);
111 if (status.ShouldCommitCluster())
113 return status.GetLastEntrySize();
114 }
115 /// Ensure that the data from the so far seen Fill calls has been written to storage
116 void CommitCluster();
117
118 std::unique_ptr<REntry> CreateEntry() { return fModel->CreateEntry(); }
119
120 /// Return the entry number that was last committed in a cluster.
122 /// Return the number of entries filled so far.
124
126 const Detail::RNTupleMetrics &GetMetrics() const { return fMetrics; }
127}; // class RNTupleFillContext
128
129} // namespace Experimental
130} // namespace ROOT
131
132#endif // ROOT7_RNTupleFillContext
#define R__unlikely(expr)
Definition RConfig.hxx:578
#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
A collection of Counter objects with a name, a unit, and a description.
The REntry is a collection of values in an ntuple corresponding to a complete row in the data set.
Definition REntry.hxx:46
std::uint64_t GetModelId() const
Definition REntry.hxx:198
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
A context for filling entries (data) into clusters of an RNTuple.
std::size_t fUnzippedClusterSize
Keeps track of the number of bytes written into the current cluster.
void FillNoCommit(REntry &entry, RNTupleFillStatus &status)
Fill an entry into this context, but don't commit the cluster.
std::uint64_t fNBytesFilled
The total number of bytes filled into all the so far committed clusters, i.e.
RNTupleFillContext(const RNTupleFillContext &)=delete
std::size_t fUnzippedClusterSizeEst
Estimator of uncompressed cluster size, taking into account the estimated compression ratio.
RNTupleFillContext & operator=(const RNTupleFillContext &)=delete
void CommitCluster()
Ensure that the data from the so far seen Fill calls has been written to storage.
std::size_t Fill(REntry &entry)
Fill an entry into this context.
std::uint64_t fNBytesCommitted
The total number of bytes written to storage (i.e., after compression)
std::unique_ptr< RNTupleModel > fModel
Needs to be destructed before fSink.
std::size_t fMaxUnzippedClusterSize
Limit for committing cluster no matter the other tunables.
const Detail::RNTupleMetrics & GetMetrics() const
NTupleSize_t GetNEntries() const
Return the number of entries filled so far.
NTupleSize_t GetLastCommitted() const
Return the entry number that was last committed in a cluster.
std::unique_ptr< Internal::RPageSink > fSink
A status object after filling an entry.
NTupleSize_t fNEntriesSinceLastCommit
Number of entries written into the current cluster.
std::size_t fUnzippedClusterSize
Number of bytes written into the current cluster.
std::size_t fLastEntrySize
Number of bytes written for the last entry.
bool ShouldCommitCluster() const
Return true if the caller should call CommitCluster.
std::size_t GetLastEntrySize() const
Return the number of bytes for the last entry.
A writer to fill an RNTuple from multiple contexts.
An RNTuple that gets filled with entries (data) and writes them to storage.
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...