RE: building trees

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Mon, 24 Jan 2005 12:19:21 -0600


> What's missing is the ability to say "make a new
> empty branch", and "put the following leaf inside some particular
> branch", though clearly it is doable, the rootcint-generated code does it.

Technically, this is never done. What the case you refer to as 'the rootcint' case does is create a branch that holds an object/class and this branch create (or does not create in the case of unsplit) a series of sub-branch corresponding to the data members.

If you were to attempts what you describing you might just need to call directly the branch constructor and add the new branch object to the list of branches.

An easier way it likely to be to just compile a small header using ACLiC.

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk_at_pcroot.cern.ch [mailto:owner-roottalk_at_pcroot.cern.ch] On Behalf Of troy d. straszheim
Sent: Sunday, January 23, 2005 4:30 PM
To: roottalk_at_pcroot.cern.ch
Subject: [ROOT] building trees

Hey roottalk,

The following script creates a prettytree and an uglytree. The prettytree is pretty because it has branches, the uglytree is ugly because it is flat, it has no branches, just leaves.

Is there any way to make the uglytree look like the prettytree if I am unable to create dictionaries for my classes? I have a routine that does, one data member at a time, a depth-first walk through the datastructure. That is, in the example below it would see:

HasXYZ

HasXYZ.f
HasXYZ.xyz
HasXYZ.xyz.x
HasXYZ.xyz.y
HasXYZ.xyz.z

and it would call, for each, the old-style "branch" function

Branch(const char* bname, void *add, const char *leaflist) (which is actually a "leaf" function if I understand correctly) on each one. Or something like that. What's missing is the ability to say "make a new empty branch", and "put the following leaf inside some particular branch", though clearly it is doable, the rootcint-generated code does it. I see in the some functions like GetSubBranch(), but I can't figure this out. Any ideas?

Thanks,

troy d. straszheim

#include <TObject.h>
#include <TTree.h>
#include <TFile.h>

struct XYZ { 
      float x, y, z;
};
      
struct HasXYZ {
      XYZ xyz;
      float f;

};

TTree *prettytree, *uglytree;
void nicetree()
{
  prettytree = new TTree("prettytree", "prettytree", 10000);

  HasXYZ hxyz, *hxyz_p(&hxyz);

  prettytree->Branch("HasXYZ", "HasXYZ", &hxyz_p);
  prettytree->Fill();
  prettytree->StartViewer();

  float f;

  uglytree = new TTree("uglytree", "uglytree", 10000);
  uglytree->Branch("HasXYZ.f", &f, "HasXYZ.f/F");
  uglytree->Branch("HasXYZ.xyz.x", &f, "HasXYZ.xyz.x/F");
  uglytree->Branch("HasXYZ.xyz.y", &f, "HasXYZ.xyz.y/F");
  uglytree->Branch("HasXYZ.xyz.z", &f, "HasXYZ.xyz.z/F");
  uglytree->Fill();
  uglytree->StartViewer();

} Received on Mon Jan 24 2005 - 19:21:04 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:04 MET