Re: Using stored class member funcs in TTrees

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Mar 08 2000 - 22:19:30 MET


Hi Gene,
In addition to Suzanne's answer, Let me add the following:
We assume that if you are in split mode and have access
to the individual attributes, it is better to do directly
tree.Draw("var") rather than calling a member function.
However, one could perfectly imagine to call any member function
of a class in the Tree, even in split mode. We plan to
implement this possibility.

Rene Brun

On Wed, 8 Mar 2000, Gene Van Buren wrote:

> Hi - I'm wondering if there's something special
> I need to do in order to be able to use member
> functions of a class I store with a TTree in the Draw()
> or Scan() functions of the TTree???
> 
> I'm using Root 2.23/12.
> 
> I have tried storing a class (StGG) with just four members;
> a function Gene() wihich returns the float 3.5
> a float data member val1
> a function Val() which returns val1
> a function Add() which adds 1.0 to val1
> 
> When I store a bunch of these in a TTree, save it
> to a file, and then look at the TTree in the file:
> All the values of val1 appear to be correct,
> but both Gene() and Val() return garbage.
> 
> I store the class in a macro like this:
> 
> {
> gSystem->Load("...");
> TFile a1("gg.root","RECREATE");
> StGG* v1 = new StGG();
> TTree* m1 = new TTree("myTree","This is my tree");
> m1->Branch("br1","StGG",&v1,64000,1);
> for (int i=0; i<25; i++) {
>   v1->Add();
>   m1->Fill();
> }
> a1.Write();
> a1.Close();
> }
> 
> I then read it back into memory in another Root
> session:
> 
> gSystem->Load("...");
> TFile a1("gg.root");
> TTree* m1 = (TTree*) a1.Get("myTree");
> 
> If I type:
> m1->Scan("val1");
> everything looks like I expect. But if I type
> m1->Scan("br1.Val()");
> or
> m1->Scan("br1.Gene()");
> all 25 values come out as zero or garbage.
> Scan() doesn't even complain if I enter a
> bogus member name -  spits back
> zeros or garbage also! Draw() at least
> requires that I get the member name
> correct (e.g., Draw("Val()") returns an
> error, while Draw("br1.Val()") draws a hist
> with 25 entries at zero).
> 
> If I actually allocate an instance of the class,
> set the TTree branch address to it, and then
> call GetEvent() on the TTree, then the member
> functions work correctly on the instance of
> the class...
> 
> ...Just not in the Draw() and Scan() of the TTree.
> Anyone know why?
> 
> -Gene Van Buren
> 



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