Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ntuple] allow for writing into TFile subdir (WIP) #16838

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jblomer
Copy link
Contributor

@jblomer jblomer commented Nov 6, 2024

Work in progress.

With the patch, RNTupleWriter::Append() can process a directory and a name like "subdir/ntpl". On the reading side, if the RNTupleReader uses the anchor directly, reading already works.

Fixes #14007

@jblomer jblomer self-assigned this Nov 6, 2024
@jblomer jblomer marked this pull request as draft November 6, 2024 15:05
Copy link

github-actions bot commented Nov 6, 2024

Test Results

    17 files      17 suites   3d 17h 29m 37s ⏱️
 2 664 tests  2 664 ✅ 0 💤 0 ❌
43 592 runs  43 592 ✅ 0 💤 0 ❌

Results for commit 535f543.

@@ -1124,7 +1139,9 @@ void ROOT::Experimental::Internal::RNTupleFileWriter::Commit()
{
if (fFileProper) {
// Easy case, the ROOT file header and the RNTuple streaming is taken care of by TFile
fFileProper.fFile->WriteObject(&fNTupleAnchor, fNTupleName.c_str());
auto dir = fFileProper.fFile->GetDirectory(fFileProper.fDirectory.c_str());
dir->cd();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A priori the cd is not needed. If it is then we need to use also a TDirectory::TContext to make the function have no net effect on gDirectory.

std::unique_ptr<ROOT::Experimental::Internal::RNTupleFileWriter>
ROOT::Experimental::Internal::RNTupleFileWriter::Append(std::string_view ntupleName, TFile &file,
std::uint64_t maxKeySize)
{
auto writer = std::unique_ptr<RNTupleFileWriter>(new RNTupleFileWriter(ntupleName, maxKeySize));
auto [dir, name] = SplitNTupleName(ntupleName);
Copy link
Member

@pcanal pcanal Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that it would also be nice to have:

ROOT::Experimental::Internal::RNTupleFileWriter::Append(std::string_view ntupleName, TDIrectory &dir,
                                                        std::uint64_t maxKeySize) 
{
     if (!dir.GetFile())
        throw "We need a file";
   auto writer = std::unique_ptr<RNTupleFileWriter>(new RNTupleFileWriter(name, maxKeySize));
   writer->fFileProper.fFile = dir->GetFile();
   writer->fFileProper.fDirectory = &dir; 

(oups the type of fDirectory is wrong).

@@ -104,6 +104,7 @@ class RNTupleFileWriter {
private:
struct RFileProper {
TFile *fFile = nullptr;
std::string fDirectory;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either

Suggested change
std::string fDirectory;
TDirectory* fDirectory;

or

Suggested change
std::string fDirectory;
std::string fDirectoryPath;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot create a RNtuple into a TDirectory
2 participants