File indexing completed on 2025-12-08 10:36:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef ROOT_RPageStorageFile
0015 #define ROOT_RPageStorageFile
0016
0017 #include <ROOT/RMiniFile.hxx>
0018 #include <ROOT/RNTuple.hxx>
0019 #include <ROOT/RNTupleSerialize.hxx>
0020 #include <ROOT/RNTupleZip.hxx>
0021 #include <ROOT/RPageStorage.hxx>
0022 #include <ROOT/RRawFile.hxx>
0023 #include <string_view>
0024
0025 #include <array>
0026 #include <cstdio>
0027 #include <memory>
0028 #include <optional>
0029 #include <string>
0030 #include <utility>
0031
0032 class TDirectory;
0033
0034 namespace ROOT {
0035 class RNTuple;
0036 class RNTupleLocator;
0037
0038 namespace Internal {
0039 class RClusterPool;
0040 class RRawFile;
0041 class RPageAllocatorHeap;
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 class RPageSinkFile : public RPagePersistentSink {
0053 private:
0054
0055
0056 struct CommitBatch {
0057
0058 std::vector<const RSealedPage *> fSealedPages;
0059
0060 size_t fSize;
0061
0062 size_t fBytesPacked;
0063 };
0064
0065 std::unique_ptr<ROOT::Internal::RNTupleFileWriter> fWriter;
0066
0067 std::uint64_t fNBytesCurrentCluster = 0;
0068
0069
0070 ROOT::Internal::RNTupleSerializer::StreamerInfoMap_t fInfosOfClassFields;
0071
0072 RPageSinkFile(std::string_view ntupleName, const ROOT::RNTupleWriteOptions &options);
0073
0074
0075
0076 RNTupleLocator WriteSealedPage(const RPageStorage::RSealedPage &sealedPage, std::size_t bytesPacked);
0077
0078
0079
0080
0081
0082 void CommitBatchOfPages(CommitBatch &batch, std::vector<RNTupleLocator> &locators);
0083
0084 protected:
0085 using RPagePersistentSink::InitImpl;
0086 void InitImpl(unsigned char *serializedHeader, std::uint32_t length) final;
0087 RNTupleLocator CommitPageImpl(ColumnHandle_t columnHandle, const RPage &page) override;
0088 RNTupleLocator
0089 CommitSealedPageImpl(ROOT::DescriptorId_t physicalColumnId, const RPageStorage::RSealedPage &sealedPage) final;
0090 std::vector<RNTupleLocator>
0091 CommitSealedPageVImpl(std::span<RPageStorage::RSealedPageGroup> ranges, const std::vector<bool> &mask) final;
0092 std::uint64_t StageClusterImpl() final;
0093 RNTupleLocator CommitClusterGroupImpl(unsigned char *serializedPageList, std::uint32_t length) final;
0094 using RPagePersistentSink::CommitDatasetImpl;
0095 void CommitDatasetImpl(unsigned char *serializedFooter, std::uint32_t length) final;
0096
0097 public:
0098 RPageSinkFile(std::string_view ntupleName, std::string_view path, const ROOT::RNTupleWriteOptions &options);
0099 RPageSinkFile(std::string_view ntupleName, TDirectory &fileOrDirectory, const ROOT::RNTupleWriteOptions &options);
0100 RPageSinkFile(const RPageSinkFile &) = delete;
0101 RPageSinkFile &operator=(const RPageSinkFile &) = delete;
0102 RPageSinkFile(RPageSinkFile &&) = default;
0103 RPageSinkFile &operator=(RPageSinkFile &&) = default;
0104 ~RPageSinkFile() override;
0105
0106 void UpdateSchema(const ROOT::Internal::RNTupleModelChangeset &changeset, ROOT::NTupleSize_t firstEntry) final;
0107 };
0108
0109
0110
0111
0112
0113
0114
0115
0116 class RPageSourceFile : public RPageSource {
0117 friend class ROOT::RNTuple;
0118
0119 private:
0120
0121 struct RStructureBuffer {
0122 std::unique_ptr<unsigned char[]> fBuffer;
0123 void *fPtrHeader = nullptr;
0124 void *fPtrFooter = nullptr;
0125
0126
0127 void Reset()
0128 {
0129 RStructureBuffer empty;
0130 std::swap(empty, *this);
0131 }
0132 };
0133
0134
0135 std::optional<RNTuple> fAnchor;
0136
0137 ROOT::Internal::RCluster *fCurrentCluster = nullptr;
0138
0139 std::unique_ptr<RRawFile> fFile;
0140
0141 ROOT::Internal::RMiniFileReader fReader;
0142
0143 RNTupleDescriptorBuilder fDescriptorBuilder;
0144
0145 std::unique_ptr<ROOT::Internal::RClusterPool> fClusterPool;
0146
0147 RStructureBuffer fStructureBuffer;
0148
0149 RPageSourceFile(std::string_view ntupleName, const ROOT::RNTupleReadOptions &options);
0150
0151
0152
0153
0154
0155 std::unique_ptr<ROOT::Internal::RCluster>
0156 PrepareSingleCluster(const ROOT::Internal::RCluster::RKey &clusterKey, std::vector<RRawFile::RIOVec> &readRequests);
0157
0158 protected:
0159 void LoadStructureImpl() final;
0160 ROOT::RNTupleDescriptor AttachImpl(RNTupleSerializer::EDescriptorDeserializeMode mode) final;
0161
0162 std::unique_ptr<RPageSource> CloneImpl() const final;
0163
0164 RPageRef
0165 LoadPageImpl(ColumnHandle_t columnHandle, const RClusterInfo &clusterInfo, ROOT::NTupleSize_t idxInCluster) final;
0166
0167 public:
0168 RPageSourceFile(std::string_view ntupleName, std::string_view path, const ROOT::RNTupleReadOptions &options);
0169 RPageSourceFile(std::string_view ntupleName, std::unique_ptr<RRawFile> file,
0170 const ROOT::RNTupleReadOptions &options);
0171
0172
0173 static std::unique_ptr<RPageSourceFile>
0174 CreateFromAnchor(const RNTuple &anchor, const ROOT::RNTupleReadOptions &options = ROOT::RNTupleReadOptions());
0175
0176 RPageSourceFile(const RPageSourceFile &) = delete;
0177 RPageSourceFile &operator=(const RPageSourceFile &) = delete;
0178 RPageSourceFile(RPageSourceFile &&) = delete;
0179 RPageSourceFile &operator=(RPageSourceFile &&) = delete;
0180 ~RPageSourceFile() override;
0181
0182 void
0183 LoadSealedPage(ROOT::DescriptorId_t physicalColumnId, RNTupleLocalIndex localIndex, RSealedPage &sealedPage) final;
0184
0185 std::vector<std::unique_ptr<ROOT::Internal::RCluster>>
0186 LoadClusters(std::span<ROOT::Internal::RCluster::RKey> clusterKeys) final;
0187 };
0188
0189 }
0190 }
0191
0192 #endif