File indexing completed on 2025-09-17 09:14:32
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 RPageSinkFile(std::string_view ntupleName, const ROOT::RNTupleWriteOptions &options);
0069
0070
0071
0072 RNTupleLocator WriteSealedPage(const RPageStorage::RSealedPage &sealedPage, std::size_t bytesPacked);
0073
0074
0075
0076
0077
0078 void CommitBatchOfPages(CommitBatch &batch, std::vector<RNTupleLocator> &locators);
0079
0080 protected:
0081 using RPagePersistentSink::InitImpl;
0082 void InitImpl(unsigned char *serializedHeader, std::uint32_t length) final;
0083 RNTupleLocator CommitPageImpl(ColumnHandle_t columnHandle, const RPage &page) override;
0084 RNTupleLocator
0085 CommitSealedPageImpl(ROOT::DescriptorId_t physicalColumnId, const RPageStorage::RSealedPage &sealedPage) final;
0086 std::vector<RNTupleLocator>
0087 CommitSealedPageVImpl(std::span<RPageStorage::RSealedPageGroup> ranges, const std::vector<bool> &mask) final;
0088 std::uint64_t StageClusterImpl() final;
0089 RNTupleLocator CommitClusterGroupImpl(unsigned char *serializedPageList, std::uint32_t length) final;
0090 using RPagePersistentSink::CommitDatasetImpl;
0091 void CommitDatasetImpl(unsigned char *serializedFooter, std::uint32_t length) final;
0092
0093 public:
0094 RPageSinkFile(std::string_view ntupleName, std::string_view path, const ROOT::RNTupleWriteOptions &options);
0095 RPageSinkFile(std::string_view ntupleName, TDirectory &fileOrDirectory, const ROOT::RNTupleWriteOptions &options);
0096 RPageSinkFile(const RPageSinkFile &) = delete;
0097 RPageSinkFile &operator=(const RPageSinkFile &) = delete;
0098 RPageSinkFile(RPageSinkFile &&) = default;
0099 RPageSinkFile &operator=(RPageSinkFile &&) = default;
0100 ~RPageSinkFile() override;
0101 };
0102
0103
0104
0105
0106
0107
0108
0109
0110 class RPageSourceFile : public RPageSource {
0111 friend class ROOT::RNTuple;
0112
0113 private:
0114
0115 struct RStructureBuffer {
0116 std::unique_ptr<unsigned char[]> fBuffer;
0117 void *fPtrHeader = nullptr;
0118 void *fPtrFooter = nullptr;
0119
0120
0121 void Reset()
0122 {
0123 RStructureBuffer empty;
0124 std::swap(empty, *this);
0125 }
0126 };
0127
0128
0129 std::optional<RNTuple> fAnchor;
0130
0131 ROOT::Internal::RCluster *fCurrentCluster = nullptr;
0132
0133 std::unique_ptr<RRawFile> fFile;
0134
0135 ROOT::Internal::RMiniFileReader fReader;
0136
0137 RNTupleDescriptorBuilder fDescriptorBuilder;
0138
0139 std::unique_ptr<ROOT::Internal::RClusterPool> fClusterPool;
0140
0141 RStructureBuffer fStructureBuffer;
0142
0143 RPageSourceFile(std::string_view ntupleName, const ROOT::RNTupleReadOptions &options);
0144
0145
0146
0147
0148
0149 std::unique_ptr<ROOT::Internal::RCluster>
0150 PrepareSingleCluster(const ROOT::Internal::RCluster::RKey &clusterKey, std::vector<RRawFile::RIOVec> &readRequests);
0151
0152 protected:
0153 void LoadStructureImpl() final;
0154 ROOT::RNTupleDescriptor AttachImpl(RNTupleSerializer::EDescriptorDeserializeMode mode) final;
0155
0156 std::unique_ptr<RPageSource> CloneImpl() const final;
0157
0158 RPageRef
0159 LoadPageImpl(ColumnHandle_t columnHandle, const RClusterInfo &clusterInfo, ROOT::NTupleSize_t idxInCluster) final;
0160
0161 public:
0162 RPageSourceFile(std::string_view ntupleName, std::string_view path, const ROOT::RNTupleReadOptions &options);
0163 RPageSourceFile(std::string_view ntupleName, std::unique_ptr<RRawFile> file,
0164 const ROOT::RNTupleReadOptions &options);
0165
0166
0167 static std::unique_ptr<RPageSourceFile>
0168 CreateFromAnchor(const RNTuple &anchor, const ROOT::RNTupleReadOptions &options = ROOT::RNTupleReadOptions());
0169
0170 RPageSourceFile(const RPageSourceFile &) = delete;
0171 RPageSourceFile &operator=(const RPageSourceFile &) = delete;
0172 RPageSourceFile(RPageSourceFile &&) = delete;
0173 RPageSourceFile &operator=(RPageSourceFile &&) = delete;
0174 ~RPageSourceFile() override;
0175
0176 void
0177 LoadSealedPage(ROOT::DescriptorId_t physicalColumnId, RNTupleLocalIndex localIndex, RSealedPage &sealedPage) final;
0178
0179 std::vector<std::unique_ptr<ROOT::Internal::RCluster>>
0180 LoadClusters(std::span<ROOT::Internal::RCluster::RKey> clusterKeys) final;
0181 };
0182
0183 }
0184 }
0185
0186 #endif