28#include <unordered_map>
33bool StrEndsWith(
const std::string &str,
const std::string &suffix)
35 if (str.size() < suffix.size())
37 return (str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0);
66 if (StrEndsWith(std::string(location),
".root"))
67 return std::make_unique<RPageSourceRoot>(ntupleName, location, options);
68 return std::make_unique<RPageSourceRaw>(ntupleName, location, options);
75 auto columnId = fDescriptor.FindColumnId(fieldId, column.
GetIndex());
82 return fDescriptor.GetNEntries();
87 return fDescriptor.GetNElements(columnHandle.
fId);
93 return columnHandle.
fId;
112 if (StrEndsWith(std::string(location),
".root"))
113 return std::make_unique<RPageSinkRoot>(ntupleName, location, options);
114 return std::make_unique<RPageSinkRaw>(ntupleName, location, options);
120 auto columnId = fLastColumnId++;
128 fDescriptorBuilder.SetNTuple(fNTupleName, model.
GetDescription(),
"undefined author",
131 std::unordered_map<const RFieldBase *, DescriptorId_t> fieldPtr2Id;
133 fDescriptorBuilder.AddField(fLastFieldId, rootField.GetFieldVersion(), rootField.GetTypeVersion(),
134 rootField.GetName(), rootField.GetType(), rootField.GetNRepetitions(), rootField.GetStructure());
135 fieldPtr2Id[&rootField] = fLastFieldId++;
137 fDescriptorBuilder.AddField(fLastFieldId,
f.GetFieldVersion(),
f.GetTypeVersion(),
f.GetName(),
f.GetType(),
138 f.GetNRepetitions(),
f.GetStructure());
139 fDescriptorBuilder.AddFieldLink(fieldPtr2Id[
f.GetParent()], fLastFieldId);
142 fieldPtr2Id[&
f] = fLastFieldId++;
145 auto nColumns = fLastColumnId;
152 fOpenColumnRanges.emplace_back(columnRange);
155 fOpenPageRanges.emplace_back(std::move(pageRange));
164 auto locator = DoCommitPage(columnHandle, page);
166 auto columnId = columnHandle.
fId;
167 fOpenColumnRanges[columnId].fNElements += page.
GetNElements();
171 fOpenPageRanges[columnId].fPageInfos.emplace_back(pageInfo);
177 auto locator = DoCommitCluster(nEntries);
180 fDescriptorBuilder.AddCluster(fLastClusterId,
RNTupleVersion(), fPrevClusterNEntries,
182 fDescriptorBuilder.SetClusterLocator(fLastClusterId, locator);
183 for (
auto &range : fOpenColumnRanges) {
184 fDescriptorBuilder.AddClusterColumnRange(fLastClusterId, range);
185 range.fFirstElementIndex += range.fNElements;
186 range.fNElements = 0;
188 for (
auto &range : fOpenPageRanges) {
192 fDescriptorBuilder.AddClusterPageRange(fLastClusterId, std::move(fullRange));
195 fPrevClusterNEntries = nEntries;
const RColumnModel & GetModel() const
std::uint32_t GetIndex() const
RNTupleVersion GetVersion() const
static void Connect(DescriptorId_t fieldId, RPageStorage &pageStorage, RFieldBase &field)
RPageSink(std::string_view ntupleName, const RNTupleWriteOptions &options)
void CommitPage(ColumnHandle_t columnHandle, const RPage &page)
Write a page to the storage. The column must have been added before.
void CommitCluster(NTupleSize_t nEntries)
Finalize the current cluster and create a new one for the following data.
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)
ColumnHandle_t AddColumn(DescriptorId_t fieldId, const RColumn &column) final
Register a new column.
NTupleSize_t GetNEntries()
ColumnHandle_t AddColumn(DescriptorId_t fieldId, const RColumn &column) final
Register a new column.
NTupleSize_t GetNElements(ColumnHandle_t columnHandle)
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)
RPageSource(std::string_view ntupleName, const RNTupleReadOptions &fOptions)
ColumnId_t GetColumnId(ColumnHandle_t columnHandle)
Common functionality of an ntuple storage for both reading and writing.
RPageStorage(std::string_view name)
A page is a slice of a column that is mapped into memory.
ClusterSize_t::ValueType GetNElements() const
The RNTupleModel encapulates the schema of an ntuple.
std::string GetDescription() const
RFieldRoot * GetRootField() const
RNTupleUuid GetUuid() const
RNTupleVersion GetVersion() const
Common user-tunable settings for reading ntuples.
For forward and backward compatibility, attach version information to the consitituents of the file f...
Common user-tunable settings for storing ntuples.
basic_string_view< char > string_view
void swap(RDirectoryEntry &e1, RDirectoryEntry &e2) noexcept
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
RClusterSize ClusterSize_t
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
std::int64_t ColumnId_t
Uniquely identifies a physical column within the scope of the current process, used to tag pages.
constexpr DescriptorId_t kInvalidDescriptorId
The window of element indexes of a particular column in a particular cluster.
std::int64_t fCompressionSettings
The usual format for ROOT compression settings (see Compression.h).
NTupleSize_t fFirstElementIndex
A 64bit element index.
ClusterSize_t fNElements
A 32bit value for the number of column elements in the cluster.