TChain can't add a root file with a name not ended with .root?

Hi,
When I try to add a root file named as “xxx.root.2” to a TChain, I get an error later: “Error in TFile::TFile: xxx.root.2/tree does not exist”. However, it works if I create an soft link of the file, but name it as “xxx.root”.

Is it true that TChain::Add does not work for root files with a name not ended with “.root”? Or it’s due to some mistakes in my code? Thanks.

Dongliang

Update:
Seems the problem appears in root6 (6.06.02-x86_64-slc6-gcc49-opt) but not in 5.34.25-x86_64-slc6-gcc48-opt.

This kind of name seems for:

root [0] TChain C
(TChain &) Name:  Title: 
root [1] C.Add("hsimple.root.2")
(Int_t) 1

Can you post a small reproducer ?

Hello Dongliang, Olivier,

Dongliang, do you give the tree name at the end of the filename?

Unfortunately I believe there is a regression; there is a form with this suffix that isn’t accepted now. If you confirm that is indeed how you need to use it then I think this will explain the problem you’ve discovered. I’ll fix it in a subsequent release. As a workaround for now you could either

give the tree name in the TChain constructor, not as a part of each filename, e.g.

TChain c(“tree”);
c.Add(“xxx.root.2”);

or use TChain::AddFile, giving the tree name as the third argument, e.g.

c.AddFile(“xxx.root.2”, TChain::kBigNumber, “tree”);

Yours,
David

Hi David, Olivier,

Yes. I gave the tree name at the end of the filename. I just tried without treename. It works fine.
Thanks for the quick replies.

Regards,
Dongliang

Hi,

I’m seeing a similiar issue in case the directory name of the file i want to add contains “.root”. Unfortunately in this case i can’t solve it by using the function without treename.

Example:

root -l -q $ROOTSYS/tutorials/tree/ntuple1.C
mv hsimple.root hsimple.root.2
mkdir hsimple.root
mv hsimple.root.2 hsimple.root

root -l
TChain* c = new TChain()
(TChain *) 0x2f13fb0
root [1] c->AddFile("hsimple.root/hsimple.root.2")
(int) 1
root [2] c->Print()
******************************************************************************
*Chain   :          : hsimple.root                                           *
******************************************************************************
SysError in <TFile::ReadBuffer>: error reading from file hsimple.root (Is a directory)
Error in <TFile::Init>: hsimple.root failed to read the file type data.

Cheers,
Nikolai

TChain* c = new TChain("ntuple");

This seems to work at first, but if i actually do something with the TChain i get the same error:

root [0] TChain* c = new TChain("ntuple")
(TChain *) 0x20f8ae0
root [1] c->AddFile("hsimple.root/hsimple.root.2")
(int) 1
root [2] c->Print()
******************************************************************************
*Chain   :ntuple    : hsimple.root                                           *
******************************************************************************
SysError in <TFile::ReadBuffer>: error reading from file hsimple.root (Is a directory)
Error in <TFile::Init>: hsimple.root failed to read the file type data.
root [3] c->Draw("px")
SysError in <TFile::ReadBuffer>: error reading from file hsimple.root (Is a directory)
Error in <TFile::Init>: hsimple.root failed to read the file type data.

Try ROOT 5.34/36 (or newer) or ROOT 6.08/06 or ROOT 6.14/00 (and possibly newer).

See also:

I tried 6.08/06 and 6.14/00 - seems to work! Thanks a lot.