Hi Ole, TTree::GetEntry (or TBranch::GetEntry) read at the place indicated by the previous TBranch::SetAddress. It cannot read and store at multiple addresses. You must call GetEntry for each address. Also, in read mode, never do MyEvent* e1 = new MyEvent(); b->SetAddress(&e1); but MyEvent* e1 = 0; b->SetAddress(&e1); otherwise, you run the risk of memory leaks. In your case, do: TBranch* b = Physics->GetBranch("Event"); ----- at one place ------ MyEvent* e1 = 0; b->SetAddress(&e1); b->GetEntry(i); ------------------------- --- at another place ---- MyEvent* e2 = 0; b->SetAddress(&e2); b->GetEntry(i); ------------------------- Rene Brun On Fri, 20 Sep 2002, Ole Streicher wrote: > 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