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>
23#include <ROOT/RNTupleModel.hxx>
24#include <ROOT/RNTupleUtil.hxx>
25
26#include <cstddef>
27#include <cstdint>
28#include <memory>
29
30namespace ROOT {
31namespace Experimental {
32
33namespace Internal {
34class RPageSink;
35}
36
37// clang-format off
38/**
39\class ROOT::Experimental::RNTupleFillContext
40\ingroup NTuple
41\brief A context for filling entries (data) into clusters of an RNTuple
42
43An output cluster can be filled with entries. The caller has to make sure that the data that gets filled into a cluster
44is not modified for the time of the Fill() call. The fill call serializes the C++ object into the column format and
45writes data into the corresponding column page buffers. Writing of the buffers to storage is deferred and can be
46triggered by CommitCluster() or by destructing the context. On I/O errors, an exception is thrown.
47
48Instances of this class are not meant to be used in isolation and can be created from an RNTupleParallelWriter. For
49sequential writing, please refer to RNTupleWriter.
50*/
51// clang-format on
53 friend class RNTupleWriter;
55
56private:
57 std::unique_ptr<Internal::RPageSink> fSink;
58 /// Needs to be destructed before fSink
59 std::unique_ptr<RNTupleModel> fModel;
60
62
65 /// Keeps track of the number of bytes written into the current cluster
66 std::size_t fUnzippedClusterSize = 0;
67 /// The total number of bytes written to storage (i.e., after compression)
68 std::uint64_t fNBytesCommitted = 0;
69 /// The total number of bytes filled into all the so far committed clusters,
70 /// i.e. the uncompressed size of the written clusters
71 std::uint64_t fNBytesFilled = 0;
72 /// Limit for committing cluster no matter the other tunables
74 /// Estimator of uncompressed cluster size, taking into account the estimated compression ratio
76
77 RNTupleFillContext(std::unique_ptr<RNTupleModel> model, std::unique_ptr<Internal::RPageSink> sink);
80
81public:
83
84 /// Fill an entry into this context. This method will perform a light check whether the entry comes from the
85 /// context's own model.
86 /// \return The number of uncompressed bytes written.
87 std::size_t Fill(REntry &entry)
88 {
89 if (R__unlikely(entry.GetModelId() != fModel->GetModelId()))
90 throw RException(R__FAIL("mismatch between entry and model"));
91
92 const std::size_t bytesWritten = entry.Append();
93 fUnzippedClusterSize += bytesWritten;
94 fNEntries++;
97 return bytesWritten;
98 }
99 /// Ensure that the data from the so far seen Fill calls has been written to storage
100 void CommitCluster();
101
102 std::unique_ptr<REntry> CreateEntry() { return fModel->CreateEntry(); }
103
104 /// Return the entry number that was last committed in a cluster.
106 /// Return the number of entries filled so far.
108
110 const Detail::RNTupleMetrics &GetMetrics() const { return fMetrics; }
111}; // class RNTupleFillContext
112
113} // namespace Experimental
114} // namespace ROOT
115
116#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:45
std::uint64_t GetModelId() const
Definition REntry.hxx:192
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.
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 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...