TTree::MergeTrees returns a null pointer

I’m trying to merge a set of TTrees held in memory (I construct the empty TTrees and SetDirectory(0) on each one before filling them). When I try to merge them with TTree::MergeTrees, a null pointer is returned.

EDIT: It seems this might happen when all the trees being merged happen to be empty.

Hi beojan,
I suggest you to use TChain class which is inherited by TTree class. You can fill a TChain in the same way of a TTree. Then for the merge you have only choose a main TChain and do

main_ch->Add(ch_1);
main_ch->Add(ch_2);
...
main_ch->Add(ch_n);

I know it’s not exactly what you were searching for, but I think this can solve your problem.

Cheers,
Stefano

I’m filling my TTrees entirely in memory, while a TChain is backed by a set of files.

The problem I’m trying to solve is filling a new TTree from a TDataFrame ForeachSlot operation. I can’t just use snapshot because the new tree has separate leaves for variables while the dataframe has a single column holding a struct of TLorentzVectors.

EDIT: It seems this might happen when all the trees being merged happen to be empty.

Indeed. TTree::MergeTrees ignores/skips TTrees with zero entries.

Cheers,
Philippe.

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