Writing to a new branch directly from an existing leaf

Hello,

I have a TTree named dataTree, from which I want to take some data into a new TTree named newTree.

One way to do it is:

newTree->Branch("X",&var);
var = dataLeaf->GetValue();
newTree->Fill();

I am looking to cut var out of this with something like:

newTree->Branch("X",&dataLeaf->GetValue());
newTree->Fill();

Any ideas?

Thanks.

Hi,
maybe something like

int var;
inputTree->SetBranchAddress("x", &var);
outputTree->Branch("x", &var);
inputTree->GetEntry(n);
outputTree->Fill();

(this is basically pseudo-code and I haven’t tested it). I know var is still there but it’s shared among the two trees.

But what is your goal here? That extra variable is definitely not hurting your performance or memory usage, and it’s very possible that the compiler optimize it away anyway.

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