From 34a5563c7d797f2a07eb08b473ba75f5275c2bb9 Mon Sep 17 00:00:00 2001 From: silverweed Date: Tue, 17 Jun 2025 11:05:58 +0200 Subject: [PATCH] [ntuple] Add some Internal helpers needed for Attributes - const version of GetProjectedFieldsOfModel() - RPageSink::GetUnderlyingDirectory() --- tree/ntuple/inc/ROOT/RMiniFile.hxx | 5 +++++ tree/ntuple/inc/ROOT/RNTupleModel.hxx | 2 ++ tree/ntuple/inc/ROOT/RPageStorage.hxx | 2 ++ tree/ntuple/inc/ROOT/RPageStorageFile.hxx | 2 ++ tree/ntuple/src/RMiniFile.cxx | 8 ++++++++ tree/ntuple/src/RNTupleModel.cxx | 6 ++++++ 6 files changed, 25 insertions(+) diff --git a/tree/ntuple/inc/ROOT/RMiniFile.hxx b/tree/ntuple/inc/ROOT/RMiniFile.hxx index 02d07862e9055..6197906abd74c 100644 --- a/tree/ntuple/inc/ROOT/RMiniFile.hxx +++ b/tree/ntuple/inc/ROOT/RMiniFile.hxx @@ -33,7 +33,10 @@ class TVirtualStreamerInfo; namespace ROOT { namespace Internal { +class RNTupleFileWriter; class RRawFile; + +TDirectory *GetUnderlyingDirectory(ROOT::Internal::RNTupleFileWriter &writer); } class RNTupleWriteOptions; @@ -104,6 +107,8 @@ A stand-alone version of RNTuple can remove the TFile based writer. */ // clang-format on class RNTupleFileWriter { + friend TDirectory *GetUnderlyingDirectory(ROOT::Internal::RNTupleFileWriter &writer); + public: /// The key length of a blob. It is always a big key (version > 1000) with class name RBlob. static constexpr std::size_t kBlobKeyLen = 42; diff --git a/tree/ntuple/inc/ROOT/RNTupleModel.hxx b/tree/ntuple/inc/ROOT/RNTupleModel.hxx index 8192cc4d2ca99..4cf0b14272bd4 100644 --- a/tree/ntuple/inc/ROOT/RNTupleModel.hxx +++ b/tree/ntuple/inc/ROOT/RNTupleModel.hxx @@ -46,6 +46,7 @@ class RProjectedFields; ROOT::RFieldZero &GetFieldZeroOfModel(RNTupleModel &model); RProjectedFields &GetProjectedFieldsOfModel(RNTupleModel &model); +const RProjectedFields &GetProjectedFieldsOfModel(const RNTupleModel &model); // clang-format off /** @@ -139,6 +140,7 @@ that were used for writing and are no longer connected to a page sink. class RNTupleModel { friend ROOT::RFieldZero &Internal::GetFieldZeroOfModel(RNTupleModel &); friend Internal::RProjectedFields &Internal::GetProjectedFieldsOfModel(RNTupleModel &); + friend const Internal::RProjectedFields &Internal::GetProjectedFieldsOfModel(const RNTupleModel &); public: /// User-provided function that describes the mapping of existing source fields to projected fields in terms diff --git a/tree/ntuple/inc/ROOT/RPageStorage.hxx b/tree/ntuple/inc/ROOT/RPageStorage.hxx index 6fcf41f646128..1e8307a8d9c8c 100644 --- a/tree/ntuple/inc/ROOT/RPageStorage.hxx +++ b/tree/ntuple/inc/ROOT/RPageStorage.hxx @@ -313,6 +313,8 @@ public: virtual ROOT::NTupleSize_t GetNEntries() const = 0; + virtual TDirectory *GetUnderlyingDirectory() const { return nullptr; } + /// Physically creates the storage container to hold the ntuple (e.g., a keys a TFile or an S3 bucket) /// Init() associates column handles to the columns referenced by the model void Init(RNTupleModel &model) diff --git a/tree/ntuple/inc/ROOT/RPageStorageFile.hxx b/tree/ntuple/inc/ROOT/RPageStorageFile.hxx index b223d008f0c07..6174e221e29de 100644 --- a/tree/ntuple/inc/ROOT/RPageStorageFile.hxx +++ b/tree/ntuple/inc/ROOT/RPageStorageFile.hxx @@ -98,6 +98,8 @@ public: RPageSinkFile(RPageSinkFile &&) = default; RPageSinkFile &operator=(RPageSinkFile &&) = default; ~RPageSinkFile() override; + + TDirectory *GetUnderlyingDirectory() const final { return ROOT::Internal::GetUnderlyingDirectory(*fWriter); } }; // class RPageSinkFile // clang-format off diff --git a/tree/ntuple/src/RMiniFile.cxx b/tree/ntuple/src/RMiniFile.cxx index 5191d82f449a0..3d154a312e5d3 100644 --- a/tree/ntuple/src/RMiniFile.cxx +++ b/tree/ntuple/src/RMiniFile.cxx @@ -1548,3 +1548,11 @@ void ROOT::Internal::RNTupleFileWriter::WriteTFileSkeleton(int defaultCompressio fileSimple.Write(&padding, sizeof(padding)); fileSimple.fKeyOffset = fileSimple.fFilePos; } + +TDirectory *ROOT::Internal::GetUnderlyingDirectory(ROOT::Internal::RNTupleFileWriter &writer) +{ + if (auto *proper = std::get_if(&writer.fFile)) { + return proper->fDirectory; + } + return nullptr; +} diff --git a/tree/ntuple/src/RNTupleModel.cxx b/tree/ntuple/src/RNTupleModel.cxx index 2878866ffb3ef..049762aed0ffc 100644 --- a/tree/ntuple/src/RNTupleModel.cxx +++ b/tree/ntuple/src/RNTupleModel.cxx @@ -40,6 +40,12 @@ ROOT::RFieldZero &ROOT::Internal::GetFieldZeroOfModel(ROOT::RNTupleModel &model) } ROOT::Internal::RProjectedFields &ROOT::Internal::GetProjectedFieldsOfModel(ROOT::RNTupleModel &model) +{ + return const_cast( + GetProjectedFieldsOfModel(const_cast(model))); +} + +const ROOT::Internal::RProjectedFields &ROOT::Internal::GetProjectedFieldsOfModel(const ROOT::RNTupleModel &model) { if (model.IsExpired()) { throw RException(R__FAIL("invalid use of expired model"));