Re: Subclasses in TBranch: Browsing / arrays

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Aug 19 1999 - 14:44:03 MEST


Hi Ingo,
Please read the limitations of the automatic split mode at URL:
   http://root.cern.ch/root/HowtoWriteTree.html
      see section "Making a Tree with many branches"
see other comments below

Rene Brun

Ingo Froehlich wrote:
> 
> Hello,
> 
> I have two questions concerning subclasses in a TBranch. If I have a
> pointer to a subclass, like
> 
> ClassB * class_b;
> (in a ClassA.h)
> 
> and fill a tree with a Branch "ClassA", the class_b does not appear as a
> folder, even though I defined:
> 
> Bool_t IsFolder() {return kTRUE;}

If ClassA derives from TObject (I assume it does since you can call
IsFolder!)
this should work. However, if a branch is a TObject*, when this object
is
analyzed by TTree::Branch, all its data members are assigned to a
different
branch. If a data member is a TClonesArray*, a second level of branches
is created for each data member of the class referenced by the
TClonesArray.
But a second level of branches is not automatic when the data member
is a TObject*.

In this case you must split manually this object. This is to avoid
an exponential increase in the number of branches in such situations.
It could be a good idea to test if the object IsFolder to automatically
generate a branch in this case.

> 
> (this has been suggested in a Mail "Re: Can't browse sub objects" 1997
> oct)
> 
> the data write and re-read works fine, but it would be very nice if one is
> able to browse a complete event like I saw this in the web-page of the
> atlas simulation programm.
> 
> The second question is more important for me. If I define an array of
> subclasses in ClassA.h, like
> 
> ClassB class_b[5];
> 
> it is not able to get the data from this array:
> 
> Warning in <TTree::Branch>: Cannot process member:class_b[5]
> 

Yes, and this is listed as one of the restrictions in the reference
above.
Again here, one could automatically assign a branch to each element of
the array.

> But it would be difficult for me to switch to TClonesArray (like it is
> done in the Event example). Does anybody know a workaround? Or did I made
> something wrong?

The workaround consists in creating the branches yourself instead of
using the automatic split algorithm.

> 
> Thanks for your help & best regards,
> 
> Ingo Froehlich
> 
> --
> Ingo Froehlich, II. Physikalisches Institut, Universitaet Giessen
> Heinrich-Buff-Ring 16, D-35392 Giessen           |  Tel.: 0641 - 99 33250
> EMail: Ingo.Froehlich@exp2.physik.uni-giessen.de |  Fax : 0641 - 99 33209
> Sekretariat II. Physik: 0641 - 99 33261          |                    :-)



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