Custom Streamer + custom splitting in TTree

Dear fellow rooters,

This may take a while to explain, and it may well be that I am attempting something not possible with the current framework. As an attempt at a quick summary: I want to be able to decide at run-time how much of a class to save to a tree (which I think I understand) and have that also determine the splittings of sub-branches in a TTree (which might not be possible.)

So, let’s say I have the following class definition:

class EventData{
     short            verbosity;
     Info             generic;
     MoreInfo         more;
     EvenMoreInfo     evenmore;


Each of the Info, MoreInfo, and EvenMoreInfo classes are composed purely of fundamental types (or possible vectors of fundamentals). Most of the time, I just want to store the generic info for the class, but I can also throw a switch somewhere to get more verbose output for debugging/etc.

So, my custom Streamer would look something like:

void EventData::Streamer(TBuffer& b)
        if(verbosity > 0)   b>>more;
        if(verbosity > 1)   b>>evenmore;

All well and good so far. But, if I want to use this class in a TTree, I have to use splitting=-1 in TTree::Branch(). (As an aside, just what DOES get called here if splitting>0?)

But this puts just one top-level branch into my tree (let’s say “event”), so I can no longer use functions like tree->Draw(“energy”,“id > 2000”). (Assuming of course that the Info class contains ‘energy’ and ‘id’ members).

So, is there any way to selectively decide how much of my class to write while still using a high split level (or preserving in some other way the Draw, Scan, etc. functions of TTree with sub-branches)?


You can try the following:

gROOT->GetClass("EventData")->GetDataMember("somename")->ResetBit(TObject::kWriteDelete); and test the persistency with:


Thank you very much for the quick reply!

This seems to be a VERY powerful and flexible technique, and much simpler than the schemes I had in mind. I can for instance now simply have a text file with a list of all the members which I want to exclude/include from the tree. Unless there’s something I’m not seeing, it seems I can even mix trees with different verbosity levels into a single TChain, assuming I then only look at branches common to all the individual trees. Wow!