Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RPageStorageFile.hxx
Go to the documentation of this file.
1/// \file ROOT/RPageStorageFile.hxx
2/// \author Jakob Blomer <jblomer@cern.ch>
3/// \date 2019-11-21
4
5/*************************************************************************
6 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#ifndef ROOT_RPageStorageFile
14#define ROOT_RPageStorageFile
15
16#include <ROOT/RMiniFile.hxx>
17#include <ROOT/RNTuple.hxx>
19#include <ROOT/RNTupleZip.hxx>
20#include <ROOT/RPageStorage.hxx>
21#include <ROOT/RRawFile.hxx>
22#include <string_view>
23
24#include <array>
25#include <cstdio>
26#include <memory>
27#include <mutex>
28#include <optional>
29#include <string>
30#include <utility>
31
32class TDirectory;
33
34namespace ROOT {
35class RNTuple; // for making RPageSourceFile a friend of RNTuple
36class RNTupleLocator;
37
38namespace Experimental {
39class RFile;
40}
41
42namespace Internal {
43class RRawFile;
44class RPageAllocatorHeap;
45
46const ROOT::RNTuple *GetAnchorFromFile(const RPageSourceFile &source);
47
48// clang-format off
49/**
50\class ROOT::Internal::RPageSinkFile
51\ingroup NTuple
52\brief Storage provider that write ntuple pages into a file
53
54The written file can be either in ROOT format or in RNTuple bare format.
55*/
56// clang-format on
58private:
59 // A set of pages to be committed together in a vector write.
60 // Currently we assume they're all sequential (although they may span multiple ranges).
61 struct CommitBatch {
62 /// The list of pages to commit
63 std::vector<const RSealedPage *> fSealedPages;
64 /// Total size in bytes of the batch
65 size_t fSize;
66 /// Total uncompressed size of the elements in the page batch
68 };
69
70 std::unique_ptr<ROOT::Internal::RNTupleFileWriter> fWriter;
71 /// Number of bytes committed to storage in the current cluster
72 std::uint64_t fNBytesCurrentCluster = 0;
73 /// On UpdateSchema(), the new class fields register the corresponding streamer info here so that the
74 /// streamer info records in the file can be properly updated on dataset commit
76
77 RPageSinkFile(std::string_view ntupleName, const ROOT::RNTupleWriteOptions &options);
78 RPageSinkFile(std::unique_ptr<ROOT::Internal::RNTupleFileWriter> writer, const ROOT::RNTupleWriteOptions &options);
79
80 /// We pass bytesPacked so that TFile::ls() reports a reasonable value for the compression ratio of the corresponding
81 /// key. It is not strictly necessary to write and read the sealed page.
82 RNTupleLocator WriteSealedPage(const RPageStorage::RSealedPage &sealedPage, std::size_t bytesPacked);
83
84 /// Subroutine of CommitSealedPageVImpl, used to perform a vector write of the (multi-)range of pages
85 /// contained in `batch`. The locators for the written pages are appended to `locators`.
86 /// This procedure also updates some internal metrics of the page sink, hence it's not const.
87 /// `batch` gets reset to size 0 after the writing is done (but its begin and end are not updated).
88 void CommitBatchOfPages(CommitBatch &batch, std::vector<RNTupleLocator> &locators);
89
90protected:
92 void InitImpl(unsigned char *serializedHeader, std::uint32_t length) final;
94 CommitSealedPageImpl(ROOT::DescriptorId_t physicalColumnId, const RPageStorage::RSealedPage &sealedPage) override;
95 std::vector<RNTupleLocator>
96 CommitSealedPageVImpl(std::span<RPageStorage::RSealedPageGroup> ranges, const std::vector<bool> &mask) final;
97 std::uint64_t StageClusterImpl() final;
98 RNTupleLocator CommitClusterGroupImpl(unsigned char *serializedPageList, std::uint32_t length) final;
100 RNTupleLink CommitDatasetImpl(unsigned char *serializedFooter, std::uint32_t length) final;
101
102public:
103 RPageSinkFile(std::string_view ntupleName, std::string_view path, const ROOT::RNTupleWriteOptions &options);
104 RPageSinkFile(std::string_view ntupleName, TDirectory &fileOrDirectory, const ROOT::RNTupleWriteOptions &options);
105 RPageSinkFile(std::string_view ntupleName, ROOT::Experimental::RFile &file, std::string_view ntupleDir,
106 const ROOT::RNTupleWriteOptions &options);
107 RPageSinkFile(const RPageSinkFile &) = delete;
108 RPageSinkFile &operator=(const RPageSinkFile &) = delete;
110 RPageSinkFile &operator=(RPageSinkFile &&) = default;
111 ~RPageSinkFile() override;
112
113 void UpdateSchema(const ROOT::Internal::RNTupleModelChangeset &changeset, ROOT::NTupleSize_t firstEntry) final;
114
115 std::unique_ptr<RPageSink>
116 CloneAsHidden(std::string_view name, const ROOT::RNTupleWriteOptions &opts) const override;
117}; // class RPageSinkFile
118
119// clang-format off
120/**
121\class ROOT::Internal::RPageSourceFile
122\ingroup NTuple
123\brief Storage provider that reads ntuple pages from a file
124*/
125// clang-format on
127 friend class ROOT::RNTuple;
129
130private:
131 /// Either provided by CreateFromAnchor, or read from the ROOT file given the ntuple name
132 std::optional<RNTuple> fAnchor;
133 /// The last cluster from which a page got loaded. Points into fClusterPool->fPool
134 ROOT::Internal::RCluster *fCurrentCluster = nullptr;
135 /// An RRawFile is used to request the necessary byte ranges from a local or a remote file
136 std::unique_ptr<RRawFile> fFile;
137 /// Takes the fFile to read ntuple blobs from it
139 /// The descriptor is created from the header and footer either in AttachImpl or in CreateFromAnchor
141 /// Tracks the last read offset for seek distance calculation
142 std::uint64_t fLastOffset = 0;
143 /// Protects the raw file, the reader, and fLastOffset
144 std::mutex fReaderLock;
145
146 /// File-specific I/O performance counters
153 std::unique_ptr<RFileCounters> fFileCounters;
154 /// Total file size, set once in AttachImpl()
155 std::int64_t fFileSize = 0;
156
157 RPageSourceFile(std::string_view ntupleName, const ROOT::RNTupleReadOptions &options);
158
159 /// Helper function for LoadClusters: it prepares the memory buffer (page map) and the
160 /// read requests for a given cluster and columns. The reead requests are appended to
161 /// the provided vector. This way, requests can be collected for multiple clusters before
162 /// sending them to RRawFile::ReadV().
163 std::unique_ptr<ROOT::Internal::RCluster>
164 PrepareSingleCluster(const ROOT::Internal::RCluster::RKey &clusterKey, std::vector<RRawFile::RIOVec> &readRequests);
165
166 // Helper to calculate the distance between fLastOffset and offset and to update the skip counter accordingly
167 void UpdateSkipCounter(std::uint64_t offset);
168
169protected:
170 void LoadStructureImpl() final;
171 ROOT::RNTupleDescriptor AttachImpl() final;
172 /// The cloned page source creates a new raw file and reader and opens its own file descriptor to the data.
173 std::unique_ptr<RPageSource> CloneImpl() const final;
174
175 void LoadPageListImpl(const RNTupleLocator &locator, unsigned char *buffer) final;
176 void LoadSealedPageImpl(const RNTupleLocator &locator, RSealedPage &sealedPage) final;
177
178public:
179 RPageSourceFile(std::string_view ntupleName, std::string_view path, const ROOT::RNTupleReadOptions &options);
180 RPageSourceFile(std::string_view ntupleName, std::unique_ptr<RRawFile> file,
181 const ROOT::RNTupleReadOptions &options);
182 /// Used from the RNTuple class to build a datasource if the anchor is already available.
183 /// Requires the RNTuple object to be streamed from a file.
184 static std::unique_ptr<RPageSourceFile>
185 CreateFromAnchor(const RNTuple &anchor, const ROOT::RNTupleReadOptions &options = ROOT::RNTupleReadOptions());
186
188 RPageSourceFile &operator=(const RPageSourceFile &) = delete;
190 RPageSourceFile &operator=(RPageSourceFile &&) = delete;
191 ~RPageSourceFile() override;
192
193 std::unique_ptr<RPageSource> OpenWithDifferentAnchor(const ROOT::Internal::RNTupleLink &anchorLink,
194 const ROOT::RNTupleReadOptions &options = {}) final;
195
196 std::vector<std::unique_ptr<ROOT::Internal::RCluster>>
197 LoadClusters(std::span<ROOT::Internal::RCluster::RKey> clusterKeys) final;
198}; // class RPageSourceFile
199
200} // namespace Internal
201} // namespace ROOT
202
203#endif
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
char name[80]
Definition TGX11.cxx:142
A thread-safe integral performance counter.
A metric element that computes its floating point value from other counters.
An in-memory subset of the packed and compressed pages of a cluster.
Definition RCluster.hxx:147
Read RNTuple data blocks from a TFile container, provided by a RRawFile.
Definition RMiniFile.hxx:60
A helper class for piece-wise construction of an RNTupleDescriptor.
std::map< Int_t, TVirtualStreamerInfo * > StreamerInfoMap_t
Base class for a sink with a physical storage backend.
virtual void InitImpl(unsigned char *serializedHeader, std::uint32_t length)=0
Storage provider that write ntuple pages into a file.
std::uint64_t fNBytesCurrentCluster
Number of bytes committed to storage in the current cluster.
void CommitBatchOfPages(CommitBatch &batch, std::vector< RNTupleLocator > &locators)
Subroutine of CommitSealedPageVImpl, used to perform a vector write of the (multi-)range of pages con...
RPageSinkFile(std::string_view ntupleName, const ROOT::RNTupleWriteOptions &options)
std::unique_ptr< RPageSink > CloneAsHidden(std::string_view name, const ROOT::RNTupleWriteOptions &opts) const override
Creates a new sink with the same underlying storage as this but writing to a different RNTuple named ...
RNTupleLocator CommitSealedPageImpl(ROOT::DescriptorId_t physicalColumnId, const RPageStorage::RSealedPage &sealedPage) override
std::uint64_t StageClusterImpl() final
Returns the number of bytes written to storage (excluding metadata)
void InitImpl(unsigned char *serializedHeader, std::uint32_t length) final
RNTupleLocator WriteSealedPage(const RPageStorage::RSealedPage &sealedPage, std::size_t bytesPacked)
We pass bytesPacked so that TFile::ls() reports a reasonable value for the compression ratio of the c...
RNTupleLocator CommitClusterGroupImpl(unsigned char *serializedPageList, std::uint32_t length) final
Returns the locator of the page list envelope of the given buffer that contains the serialized page l...
RNTupleLink CommitDatasetImpl() final
std::unique_ptr< ROOT::Internal::RNTupleFileWriter > fWriter
void UpdateSchema(const ROOT::Internal::RNTupleModelChangeset &changeset, ROOT::NTupleSize_t firstEntry) final
Incorporate incremental changes to the model into the ntuple descriptor.
std::vector< RNTupleLocator > CommitSealedPageVImpl(std::span< RPageStorage::RSealedPageGroup > ranges, const std::vector< bool > &mask) final
Vector commit of preprocessed pages.
ROOT::Internal::RNTupleSerializer::StreamerInfoMap_t fInfosOfClassFields
On UpdateSchema(), the new class fields register the corresponding streamer info here so that the str...
Abstract interface to write data into an ntuple.
Storage provider that reads ntuple pages from a file.
RNTupleDescriptorBuilder fDescriptorBuilder
The descriptor is created from the header and footer either in AttachImpl or in CreateFromAnchor.
std::unique_ptr< RFileCounters > fFileCounters
std::mutex fReaderLock
Protects the raw file, the reader, and fLastOffset.
std::unique_ptr< RRawFile > fFile
An RRawFile is used to request the necessary byte ranges from a local or a remote file.
std::optional< RNTuple > fAnchor
Either provided by CreateFromAnchor, or read from the ROOT file given the ntuple name.
ROOT::Internal::RMiniFileReader fReader
Takes the fFile to read ntuple blobs from it.
Abstract interface to read data from an ntuple.
The RRawFile provides read-only access to local and remote files.
Definition RRawFile.hxx:43
The on-storage metadata of an RNTuple.
Generic information about the physical location of data.
Common user-tunable settings for reading RNTuples.
Common user-tunable settings for storing RNTuples.
Representation of an RNTuple data set in a ROOT file.
Definition RNTuple.hxx:67
Describe directory structure in memory.
Definition TDirectory.h:45
const ROOT::RNTuple * GetAnchorFromFile(const RPageSourceFile &source)
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 identifiers that specifies the content of a (partial) cluster.
Definition RCluster.hxx:151
The incremental changes to a RNTupleModel
size_t fSize
Total size in bytes of the batch.
std::vector< const RSealedPage * > fSealedPages
The list of pages to commit.
size_t fBytesPacked
Total uncompressed size of the elements in the page batch.
File-specific I/O performance counters.
ROOT::Experimental::Detail::RNTupleCalcPerf & fSparseness
ROOT::Experimental::Detail::RNTupleCalcPerf & fSzFile
ROOT::Experimental::Detail::RNTupleAtomicCounter & fSzSkip
ROOT::Experimental::Detail::RNTupleCalcPerf & fRandomness
A sealed page contains the bytes of a page as written to storage (packed & compressed).