TTree::ResetBranchAddress/TBranch::ResetAddress not behaving

Hi,
I’m having some trouble - I don’t understand how ResetBranchAddress and ResetAdress work. Basically, I’d like to use TTree::SetBranchAddress to hook up a variable. Some way through the tree I don’t need that variable any longer - so I’d like to “unhook” it from the tree. I’d hoped to be able to use ResetAddress on the branch I’d done the set address on. However, that has no effect. TTree::SetBranchAddresses, on the other hand works as I would have expected (but is no good in my final solution as I’ve got other things in the Tree that I don’t want reset!).

I’ve uploaded a small stand-alone program, but the relavent code is here:

[code] /// Create the chain that we will be reading in
auto c = new TChain(“ntup”);
c->AddFile(“n1.root”);
c->AddFile(“n2.root”);

TBranch *b;
c->SetBranchAddress("val", &gValue, &b);

int ent = c->GetEntries();
cout << "Total Entries " << ent << endl;

/// Run through most of the index
int index = 0;
for (index = 0; index < ent - 50; index++) {
	c->GetEntry(index);
}

/// Now, reset the address and then re-go
// b->ResetAddress(); - doesn't seem to do anything
//c->ResetBranchAddress(b); // This doesn't either
c->ResetBranchAddresses(); // THis actuall works!!
for (index = 0; index < ent - 50; index++) {
	c->GetEntry(index);
	cout << gValue << endl;
}

[/code]

At the end are teh three Reset method calls. I would have expected the result to the same no matter what I did - that gValue should have stopped incrementing b/c the tree is no longer filling it.

So… how can I modify the above sample so that only the “val” branch is “unhooked”?

Many thanks!
resetbranchtest.C (1.42 KB)

Hi Gordon,

Thanks for reporting this problem. Indeed TChain::ResetBranchAddress should have work as you expected. It is fixed by revision 37836 of the trunk and in the v5.28 patch branch.

[quote]// b->ResetAddress(); - doesn’t seem to do anything[/quote]Is intentional as the Branch objects of a TChain are short-lived and any operation done on the branch object directly does not survive the opening of the next file/tree in the chain.

Cheers,
Philippe.

Thanks a lot!!