RootTalk


ROOT Discussion Forums

TTree::ResetBranchAddress/TBranch::ResetAddress not behaving

Discuss installing and running ROOT here. Please post bug reports here.

Moderator: rootdev

TTree::ResetBranchAddress/TBranch::ResetAddress not behaving

Unread postby gwatts » Wed Jan 05, 2011 0:38

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: Select all
   /// 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;
   }


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!
Attachments
resetbranchtest.C
(1.42 KiB) Downloaded 42 times
gwatts
 
Posts: 229
Joined: Thu Sep 01, 2005 17:48
Location: University of Washington

Re: TTree::ResetBranchAddress/TBranch::ResetAddress not beha

Unread postby pcanal » Fri Jan 21, 2011 17:50

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.

// b->ResetAddress(); - doesn't seem to do anything
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.
pcanal
 
Posts: 6288
Joined: Wed Aug 27, 2003 14:22
Location: Fermilab

Re: TTree::ResetBranchAddress/TBranch::ResetAddress not beha

Unread postby gwatts » Fri Jan 21, 2011 18:09

Thanks a lot!!
gwatts
 
Posts: 229
Joined: Thu Sep 01, 2005 17:48
Location: University of Washington


Return to ROOT Support

Who is online

Users browsing this forum: Google [Bot], pamputt and 4 guests