Re: TTree::GetEvent without creating new objects?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Oct 30 1997 - 18:51:22 MET


Robert Casties wrote:

> On Thu, 30 Oct 1997, Rene Brun wrote:
>
> > We give an example in $ROOTSYS/test/Event.
> > TFile f("file.root");
> > TTree *tree = (TTree*)f.Get("T");  if your Tree was called "T"
> > Event *event = 0;   // fundamental to preset the pointer to 0
> ^^^^^^^^^^^^^^^^^^^^^^
> Okay this was my error!
>
> SetBranchAddress takes the address of a pointer instead of a pointer (as
> in the case of simple datatypes).
>

Right !

> But if I give it the address of an existing object the objects destructor
> is properly called and the object is recreated at the same place. Is it
> pure coincidence or is this implied?
>

This is implied. You do not need to create an object before the loop.Root
will create it automatically (again see $ROOTSYS/test/Event).

> Maybe the documentation should make the differences in behaviour more
> clear between TTrees split/unsplit with objects/simple types :-)
>

Agreed.  We are so busy these days with a massive number of new users!I want
to rewrite the HowtoWrite and ReadTree sections on the Web.

> So what do i have to do if I want to split my object myself to have the
> ability to read back only parts of it? And how do I read only a selected
> part of an object into the object?
>

You can do it.  It is your responsability to create yourself your own
branches,
using the TTree::Branch functions (3 at your disposal).
    1- for basic data types
    2- for TObjects
    3- for pointers to TClonesArray

To read only a selected part of a tree, use TTree::SetBranchStatus
For example:
    tree->SetBranchStatus("*",0)   //  diasable all branches
   tree->SetBranchStatus("branch1",1);
   tree->SetBranchStatus("branch7",1)

now tree->GetEvent will only read 2 branches (branch1 and branch7).
When you create branches yourself, it is your responsability to
set the branch addresses for each of your branch.

We STRONGLY discourage this approach. The only point for us
in supporting branches with basic types is to give the possibility
to users coming from Fortran to create branches with data sitting
in some common blocks or C-structs.

Designing a good  top-level model  is a key issue. It should be very
flexible.
We are open to discussion, if you think that our automatic split mode
should support more options than teh 3 mentionned above.

Rene Brun



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:22 MET