[ROOT] TBranch::SetAddress() problems

From: Ole Streicher (ole@ifh.de)
Date: Fri Sep 20 2002 - 17:38:35 MEST


Hi Rooters!

I have a problem with the "SetAddress()" stuff of the branch.

In need to access some variables in the branches at different points
in my program. What I do is

TBranch* b = Physics->GetBranch("Event");

----- at one place ------
MyEvent* e1 = new MyEvent();
b->SetAddress(&e1);
-------------------------

--- at another place ----
MyEvent* e2 = new MyEvent();
b->SetAddress(&e2);
-------------------------

But, when I do a "Physics->GetEntry(...)", only the second event gets
filled. The first one remains at the initialization.

How can I avoid that and have the both (resp. all needed) events
filled or set them to the same address?

And: who "owns" the events e1 and e2? Is it safe to do a "delete e1"
and "delete e2" at the end of the event processing or will it destroy
something inside of the branch? The tutorial unfortunately shows only
the creation, not the deletion of these objects.

I also saw (I guess in a mail of Rene Brun) a variant where these
pointers are initialized with 0. Is this "better" (or recommended)?
And, will the branch then also take care about the deletion of the
object? 

Ole



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:10 MET