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

Cannot create a RNtuple into a TDirectory #14007

Open
1 task done
ktf opened this issue Nov 2, 2023 · 0 comments · May be fixed by #16838
Open
1 task done

Cannot create a RNtuple into a TDirectory #14007

ktf opened this issue Nov 2, 2023 · 0 comments · May be fixed by #16838
Assignees

Comments

@ktf
Copy link
Contributor

ktf commented Nov 2, 2023

Check duplicate issues.

  • Checked for duplicates

Description

I am naively trying to create a RNTuple inside a TDirectory, and I fail to do so. Moreover, when looking at the produced TFile with TBrowser, I see some weird recursive structure.

image

Reproducer

I tried a few permutations of the following, all giving me weird results.

#include <TFile.h>
#include <TTree.h>
#include <TDirectory.h>
#include <ROOT/RNTuple.hxx>
#include <ROOT/RNTupleModel.hxx>
#undef NDEBUG
#include <cassert>

int writeTree()
{
  TFile* f;
  int x = 0;
  f = new TFile("foo.root", "RECREATE");
  auto* dir = f->mkdir("dir");
  dir->cd();
  auto* tree = new TTree("T", "a Tree");
  tree->Branch("x", &x, "x/D");
  for (int i = 0; i < 10; i++) {
    x = i;
    tree->Fill();
  }
  tree->Write();

  using namespace ROOT::Experimental;
  // Create and fill an RNTuple
  auto model = RNTupleModel::Create();
  auto wrPt = model->MakeField<float>("pt", 42.0);

  {
    RNTupleWriteOptions options;
    options.SetContainerFormat(ENTupleContainerFormat::kBare);
    auto* bar = f->mkdir("bar");
    bar->cd();
    
    auto ntuple = RNTupleWriter::Append(std::move(model), "f", *f, options);
    bool ok = bar->cd();

    ntuple->Fill();
    ntuple->CommitCluster();
    *wrPt = 24.0;
    ntuple->Fill();
    *wrPt = 12.0;
    ntuple->Fill();
    ntuple->CommitCluster();
  }

  return 0;
}

ROOT version

   ------------------------------------------------------------------
  | Welcome to ROOT 6.28/04                        https://root.cern |
  | (c) 1995-2022, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for macosxarm64 on Nov 01 2023, 10:33:00                   |
  | From tags/v6-28-04-alice3@v6-28-04-3-g186ec88ba4                 |
  | With Apple clang version 15.0.0 (clang-1500.0.40.1)              |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------

Installation method

aliBuild

Operating system

macOS Ventura

Additional context

No response

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

Successfully merging a pull request may close this issue.

3 participants