Sequence of loading ROOT file

The attached code : oo.C, produce the following error. If one swap the sequence of loading f0 and f1, i.e. mm.C
, then it runs OK. Any hints are appreciated.

oo.C (153 Bytes)
o1.root (9.1 KB)
o2.root (8.2 KB)
mm.C (153 Bytes)

Error in TBasket::Streamer: The value of fKeylen is incorrect (-23644) ; trying to recover by setting it to zero
Error in TBasket::Streamer: The value of fObjlen is incorrect (-2020426277) ; trying to recover by setting it to zero
Error in TBranch::GetBasket: File: o2.root at byte:3872444835, branch:m, entry:0, badread=1, nerrors=1, basketnumber=0

ROOT Version: 6.24/06
Platform: ubuntu
Compiler: g++


Try: TNtuple *B2Lc; f0.GetObject("B2Lc", B2Lc);

Hi @wx2017 .
thank you for the report. For some reason, calling Clone on a TNtuple coming from o1.root when o2.root is the current file is broken. This is likely a bug, I reported it at Reading entries on a cloned TNtuple broken if cloning happened when an unrelated file was the current file · Issue #9757 · root-project/root · GitHub .

As a workaround, making the file from which the TNtuple comes from the current file before calling Clone fixes the issue (switching the order in which you open the files as you do in mm.C has the same effect):

#include <TFile.h>
#include <TNtuple.h>
#include <iostream>

int main() {
  TFile f0("o1.root");
  TFile f1("o2.root");

  TNtuple *B2L = f0.Get<TNtuple>("B2Lc");
  std::cout << "No clone:\n";
  B2L->GetEntry(0);
  std::cout << "done\n";

  //f0.cd(); uncommenting this fixes the issue
  TNtuple *B2Lc = static_cast<TNtuple *>(B2L->Clone());
  f1.cd();
  std::cout << "Clone:\n";
  B2Lc->GetEntry(0);
  std::cout << "done\n";
  return 0;
}

I hope this helps!
Cheers,
Enrico

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.