building trees

From: troy d. straszheim <>
Date: Sun, 23 Jan 2005 17:30:19 -0500

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:



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?


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);

  float f;

  uglytree = new TTree("uglytree", "uglytree", 10000);
  uglytree->Branch("HasXYZ.f", &f, "HasXYZ.f/F");
  uglytree->Branch("", &f, "");
  uglytree->Branch("", &f, "");
  uglytree->Branch("", &f, "");

} Received on Sun Jan 23 2005 - 23:30:41 MET

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