RE: SetBranchAddress question

From: Anton Fokin (fokin@tsl.uu.se)
Date: Sun Feb 27 2000 - 13:02:45 MET


Ooops, sorry. In fact I said I have seen the answer to my question in some
place. So well, my problem is rather common for rooters, i.e. root
documentation. By the way, I am also involved in the web design ... somehow
:) and in any related book the golden rule of two clicks is always pointed
out on the very first page. This rule means that if a user is not able to
get to any place/info on the site within two mouse clicks, you will lose a
number of site visitors. In the root case it means you will get stupid
questions like mine one :)

In fact I was looking at the event example and I was curious about
SetBranchAddress and address of pointer, so I checked documentation on
SetBranchAddress and

void SetBranchAddress(const char *bname, void *add)

*-*-*-*-*-*-*-*-*Set branch address*-*-*-*-*-*-*-*
*-*              ==================

      If object is a TTree, this function is only an interface to
TBranch::SetAddress
      Function overloaded by TChain.



It is not easy to realise that the right ref is in TTree description. Also,
the description does not contain a reason why you use address of a pointer.
That was my question and now I know why. Thanks :)

/Anton


-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Rene Brun
Sent: Sunday, February 27, 2000 9:35 AM
To: Anton Fokin
Cc: Rene Brun; roottalk@pcroot.cern.ch
Subject: Re: SetBranchAddress question



Anton,
What is your question? problem ?
It is stated in the documentation of TTree::Branch (class case) that you
must
pass the address of the pointer and not the pointer itself.
The reason is that we authorize a construct like
   Event *event = 0;
   T->SetBranchAddress("event", &event);
When reading the corresponding branch via T->GetEntry(), an event
object will be automatically created and hooked  at event.
Another use is when you have saved in successive files classes
derived from a base class Event and you want to process these files
in a TChain. In this case, the right object of the right class will
be automatically created at the address given by event.

Rene Brun


On Sat, 26 Feb 2000, Anton Fokin wrote:

> Hi!
>
> could you tell me why you are using &event when calling
>
> void SetBranchAddress(const char *bname, void *add)
>
>    Event *event = new Event();
>    T->SetBranchAddress("event", &event);
>
>
> it looks like you are setting address of pointer to the branch instead of
> address of branch (or address of pointer to the object from where
read/write
> data?). Is it something with terminology? When I looked at this function
for
> the very first time, I wanted to do
>
> Event event;
> T->SetBranchAddress("event", &event);
>
> I remember I've seen some related comments in one of the root
> tutorials/examples but I am not able to find it now. Hmmm... where is our
> nice documentation about root i/o? :)
>
> Best,
> Anton
>



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:20 MET