building trees

From: troy d. straszheim <troy_at_resophonic.com>
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:

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