40 fBufferedPages.clear();
47 :
RPageSink(inner->GetNTupleName(), inner->GetWriteOptions()), fInnerSink(std::move(inner))
54 "wall clock time spent in critical sections"),
56 "CPU time spent compressing"),
58 "timeCpuCriticalSection",
"ns",
"CPU time spent in critical section")});
79 f.SetOnDiskId(fNFields);
82 for (
auto *
f : fields) {
84 for (
auto &descendant : *
f) {
85 connectField(descendant);
88 fBufferedColumns.resize(fNColumns);
93 return fInnerSink->GetDescriptor();
100 fInnerModel = model.Clone();
101 fInnerSink->Init(*fInnerModel);
112 auto cloned = field->Clone(field->GetFieldName());
115 auto parent = field->GetParent();
118 auto &innerParent = fInnerModel->GetMutableField(parent->GetQualifiedFieldName());
122 fInnerModel->AddField(std::move(cloned));
127 auto cloned = field->
Clone(field->GetFieldName());
131 fieldMap[
p] = &fInnerModel->GetConstField(projectedFields.GetSourceField(field)->GetQualifiedFieldName());
132 auto targetIt = cloned->begin();
133 for (
auto &
f : *field)
134 fieldMap[&(*targetIt++)] =
135 &fInnerModel->GetConstField(projectedFields.GetSourceField(&
f)->GetQualifiedFieldName());
140 fInnerModel->Unfreeze();
142 std::back_inserter(innerChangeset.fAddedFields), cloneAddField);
144 std::back_inserter(innerChangeset.fAddedProjectedFields), cloneAddProjectedField);
145 fInnerModel->Freeze();
146 fInnerSink->UpdateSchema(innerChangeset, firstEntry);
152 RNTuplePlainTimer timer(fCounters->fTimeWallCriticalSection, fCounters->fTimeCpuCriticalSection);
153 fInnerSink->UpdateExtraTypeInfo(extraTypeInfo);
158 fSuppressedColumns.emplace_back(physicalColumnId);
166 auto &zipItem = fBufferedColumns.at(physicalColumnId).BufferPage();
167 std::size_t maxSealedPageBytes =
170 auto &sealedPage = fBufferedColumns.at(physicalColumnId).RegisterSealedPage();
172 auto allocateBuf = [&zipItem, maxSealedPageBytes]() {
173 zipItem.fBuf = MakeUninitArray<unsigned char>(maxSealedPageBytes);
176 auto shrinkSealedPage = [&zipItem, maxSealedPageBytes, &sealedPage]() {
179 auto sealedBufferSize = sealedPage.GetBufferSize();
180 if (sealedBufferSize < maxSealedPageBytes) {
181 auto buf = MakeUninitArray<unsigned char>(sealedBufferSize);
182 memcpy(buf.get(), sealedPage.GetBuffer(), sealedBufferSize);
183 zipItem.fBuf = std::move(buf);
184 sealedPage.SetBuffer(zipItem.fBuf.get());
191 std::size_t bufferedUncompressed = fBufferedUncompressed.load();
192 bool enoughWork = bufferedUncompressed > GetWriteOptions().GetApproxZippedClusterSize();
194 if (!fTaskScheduler || enoughWork) {
198 config.
fPage = &page;
201 config.
fWriteChecksum = GetWriteOptions().GetEnablePageChecksums();
203 config.
fBuffer = zipItem.fBuf.get();
205 RNTupleAtomicTimer timer(fCounters->fTimeWallZip, fCounters->fTimeCpuZip);
206 sealedPage = SealPage(config);
209 zipItem.fSealedPage = &sealedPage;
215 fBufferedUncompressed += page.
GetNBytes();
221 assert(zipItem.fPage.GetNBytes() == page.
GetNBytes());
224 fCounters->fParallelZip.SetValue(1);
227 fTaskScheduler->AddTask([
this, &zipItem, &sealedPage, &elem, allocateBuf, shrinkSealedPage] {
230 fBufferedUncompressed -= zipItem.fPage.GetNBytes();
234 config.
fPage = &zipItem.fPage;
237 config.
fWriteChecksum = GetWriteOptions().GetEnablePageChecksums();
240 config.
fBuffer = zipItem.fBuf.get();
243 sealedPage = SealPage(config);
245 zipItem.fSealedPage = &sealedPage;
247 zipItem.fPage =
RPage();
268 assert(fBufferedUncompressed == 0 &&
"all buffered pages should have been processed");
270 std::vector<RSealedPageGroup> toCommit;
271 toCommit.reserve(fBufferedColumns.size());
272 for (std::size_t physicalColumnId = 0; physicalColumnId < fBufferedColumns.size(); ++physicalColumnId) {
273 R__ASSERT(fBufferedColumns[physicalColumnId].HasSealedPagesOnly());
274 const auto &sealedPages = fBufferedColumns[physicalColumnId].GetSealedPages();
275 toCommit.emplace_back(physicalColumnId, sealedPages.cbegin(), sealedPages.cend());
280 RNTuplePlainTimer timer(fCounters->fTimeWallCriticalSection, fCounters->fTimeCpuCriticalSection);
281 fInnerSink->CommitSealedPageV(toCommit);
283 for (
auto physicalColumnId : fSuppressedColumns)
284 fInnerSink->CommitSuppressedColumn(physicalColumnId);
285 fSuppressedColumns.clear();
290 for (
auto &bufColumn : fBufferedColumns)
291 bufColumn.DropBufferedPages();
296 std::uint64_t nbytes;
297 FlushClusterImpl([&] { nbytes = fInnerSink->CommitCluster(nNewEntries); });
304 FlushClusterImpl([&] { stagedCluster = fInnerSink->StageCluster(nNewEntries); });
305 return stagedCluster;
311 RNTuplePlainTimer timer(fCounters->fTimeWallCriticalSection, fCounters->fTimeCpuCriticalSection);
312 fInnerSink->CommitStagedClusters(clusters);
318 RNTuplePlainTimer timer(fCounters->fTimeWallCriticalSection, fCounters->fTimeCpuCriticalSection);
319 fInnerSink->CommitClusterGroup();
325 RNTuplePlainTimer timer(fCounters->fTimeWallCriticalSection, fCounters->fTimeCpuCriticalSection);
326 return fInnerSink->CommitDataset();
331 return fInnerSink->ReservePage(column, nElements);
334std::unique_ptr<ROOT::Internal::RPageSink>
337 return fInnerSink->CloneAsHidden(
name, opts);
342 fInnerSink->CommitAttributeSet(attrSetName, attrAnchorInfo);
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
winID h TVirtualViewer3D TVirtualGLPainter p
A thread-safe integral performance counter.
A collection of Counter objects with a name, a unit, and a description.
void ObserveMetrics(RNTupleMetrics &observee)
CounterPtrT MakeCounter(const std::string &name, Args &&... args)
A non thread-safe integral performance counter.
Record wall time and CPU time between construction and destruction.
A column element encapsulates the translation between basic C++ types and their column representation...
A column is a storage-backed array of a simple, fixed-size type, from which pages can be mapped into ...
virtual void Wait()=0
Blocks until all scheduled tasks finished.
std::unique_ptr< RPageSink > CloneAsHidden(std::string_view name, const RNTupleWriteOptions &opts) const final
Creates a new sink with the same underlying storage as this but writing to a different RNTuple named ...
void CommitStagedClusters(std::span< RStagedCluster > clusters) final
Commit staged clusters, logically appending them to the ntuple descriptor.
std::unique_ptr< RCounters > fCounters
std::uint64_t CommitCluster(ROOT::NTupleSize_t nNewEntries) final
Finalize the current cluster and create a new one for the following data.
void UpdateSchema(const RNTupleModelChangeset &changeset, ROOT::NTupleSize_t firstEntry) final
Incorporate incremental changes to the model into the ntuple descriptor.
void FlushClusterImpl(const std::function< void(void)> &FlushClusterFn)
RNTupleTaskScheduler * fTaskScheduler
For parallel page compression.
void CommitSealedPage(ROOT::DescriptorId_t physicalColumnId, const RSealedPage &sealedPage) final
Write a preprocessed page to storage. The column must have been added before.
RPageSinkBuf(std::unique_ptr< RPageSink > inner)
void CommitPage(DescriptorId_t physicalColumnId, const RColumnElementBase &elem, const RPage &page) final
Write a page to the storage. The column must have been added before.
void CommitSuppressedColumn(DescriptorId_t physicalColumnId) final
Commits a suppressed column for the current cluster.
void CommitAttributeSet(std::string_view attrSetName, const RNTupleLink &attrAnchorInfo) final
Adds the given anchor information (name + locator) into the main RNTuple's descriptor as an attribute...
RNTupleLink CommitDatasetImpl() final
const ROOT::RNTupleDescriptor & GetDescriptor() const final
Return the RNTupleDescriptor being constructed.
RPage ReservePage(RWriteColumn &column, std::size_t nElements) final
Get a new, empty page for the given column that can be filled with up to nElements; nElements must be...
void UpdateExtraTypeInfo(const ROOT::RExtraTypeInfoDescriptor &extraTypeInfo) final
Adds an extra type information record to schema.
DescriptorId_t AddColumn(ROOT::DescriptorId_t fieldId, const RColumn &column) final
Add a column belonging to a certain field to the descriptor and return its on-disk ID.
RStagedCluster StageCluster(ROOT::NTupleSize_t nNewEntries) final
Stage the current cluster and create a new one for the following data.
void CommitClusterGroup() final
Write out the page locations (page list envelope) for all the committed clusters since the last call ...
void InitImpl(ROOT::RNTupleModel &model) final
void CommitSealedPageV(std::span< RSealedPageGroup > ranges) final
Write a vector of preprocessed pages to storage. The corresponding columns must have been added befor...
std::unique_ptr< RPageSink > fInnerSink
The inner sink, responsible for actually performing I/O.
void ConnectFields(const std::vector< ROOT::RFieldBase * > &fields, ROOT::NTupleSize_t firstEntry)
An RAII wrapper used to synchronize a page sink. See GetSinkGuard().
Abstract interface to write data into an ntuple.
ROOT::Experimental::Detail::RNTupleMetrics fMetrics
A page is a slice of a column that is mapped into memory.
std::uint32_t GetNElements() const
std::size_t GetNBytes() const
The space taken by column elements in the buffer.
std::uint32_t GetElementSize() const
std::unordered_map< const ROOT::RFieldBase *, const ROOT::RFieldBase * > FieldMap_t
The map keys are the projected target fields, the map values are the backing source fields Note that ...
RResult< void > Add(std::unique_ptr< ROOT::RFieldBase > field, const FieldMap_t &fieldMap)
Adds a new projected field.
Base class for all ROOT issued exceptions.
A field translates read and write calls from/to underlying columns to/from tree values.
The container field for an ntuple model, which itself has no physical representation.
The on-storage metadata of an RNTuple.
The RNTupleModel encapulates the schema of an RNTuple.
Common user-tunable settings for storing RNTuples.
The field for an untyped record.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
ROOT::RFieldZero & GetFieldZeroOfModel(RNTupleModel &model)
void AddItemToRecord(RRecordField &record, std::unique_ptr< RFieldBase > newItem)
RProjectedFields & GetProjectedFieldsOfModel(RNTupleModel &model)
void CallConnectPageSinkOnField(RFieldBase &, ROOT::Internal::RPageSink &, ROOT::NTupleSize_t firstEntry=0)
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
The incremental changes to a RNTupleModel
std::vector< ROOT::RFieldBase * > fAddedProjectedFields
Points to the projected fields in fModel that were added as part of an updater transaction.
std::vector< ROOT::RFieldBase * > fAddedFields
Points to the fields in fModel that were added as part of an updater transaction.
I/O performance counters that get registered in fMetrics.
Parameters for the SealPage() method.
bool fWriteChecksum
Adds a 8 byte little-endian xxhash3 checksum to the page payload.
std::uint32_t fCompressionSettings
Compression algorithm and level to apply.
void * fBuffer
Location for sealed output. The memory buffer has to be large enough.
const ROOT::Internal::RPage * fPage
Input page to be sealed.
bool fAllowAlias
If false, the output buffer must not point to the input page buffer, which would otherwise be an opti...
const ROOT::Internal::RColumnElementBase * fElement
Corresponds to the page's elements, for size calculation etc.
Cluster that was staged, but not yet logically appended to the RNTuple.
A sealed page contains the bytes of a page as written to storage (packed & compressed).
static constexpr std::size_t kNBytesPageChecksum
The page checksum is a 64bit xxhash3.