Re: [ROOT] SetAutoDelete & TChain

From: Thomas Bretz (tbretz@uni-sw.gwdg.de)
Date: Thu Nov 08 2001 - 15:38:46 MET


Hi Rene,

if I understood you correctly code like :
----------
TFile file(...);
MyObj *myobjptr = new MyObj;
file->Get("Tree")->GetBranch("branch")->SetAutoDelete();
file->Get("Tree")->GetBranch("branch")->SetAdress(&myobjectptr);
for (int i=0; i<100; i++) file->Get("Tree")->GetEntry(i);
----------
should result in a call to ~MyObj every time a new event is read. But in
my case SetAutoDelete is completely ignored:
----------
TChain chain("Tree");
chain.Add("file.root");
MyObj *myobjptr = new MyObj;
chain.GetBranch("branch")->SetAutoDelete();
chain.SetBranchAddress("branch", &myobjectptr);
for (int i=0; i<100; i++) chain.GetEntry(i);
----------
does only result in _one_ call to the destructor of MyObj. That's the
problem. 

In my opinion the problem is due to the fact that when LoadTree switches
files (also from no file to the first file) the information stored in
TBranch (set via TBranch::SetAutoDelete()) is lost. Maybe I'm wrong.

Thomas.

> > I'm using a TChain to access my tree and its branches. I was wondering,
> > why the destructors of my functions are not called independant of the
> > Setting of TChain::GetBranch->SetAutoDelete. From a look at the code of
> > TChain::GetEntry/LoadTree it seems to me, that the setting of the
> > autodelete flag is skipped at least when a new File is opened and the
> > TChainElement settings are copied to the TBranch of the new file. Am I
> > right, or was the way of setting these flag incorrect?



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:06 MET