Getting filename from TTree or TChain

Hi @roy.brener ,

the reproducer is not self-contained so I cannot run it, but I can add some more information that might help you.

A TTree is a single dataset. A TChain is a vertical concatenation of (usually multiple) TTrees (so you get a larger logical dataset that has the same columns as the trees that make up the chain and the union of their rows).

A TTree will usually have one associated file (sometimes it will have no associated file, but that’s not relevant here). A TChain will have multiple associated files, and the current file depends on which entry is loaded in the chain, if any. Since you never loaded an entry in the chain, there is no current TTree, and no current file (that’s why fChain->GetCurrentFile() returns a null pointer (or 0), and then of course fChain->GetCurrentFile()->GetName() errors out because you are calling ->GetName() on a null pointer.

For your actual problem:

  • you can get a list of all files associated to the TChain with fChain->GetListOfFiles(), or maybe better
  • you can simply use a TTree

You can also call fChain->LoadTree(0) to load the tree that contains entry 0 in the chain and then fChain->GetCurrentFile() will return something meaningful.

I hope this helps!
Enrico