LeafList in custom class finds only branch

Hi experts,
I have created a class, imported it into root via pragma links, and LinkDef and DictGen etc. I have made a tree with the branch structure determined by this class. For some reason I cannot read the leaves on the structure. For example,

void analyzer::Init(TFile *inFile,Option_t *options[])
{
 inTree       = (TTree*)inFile->Get("usertree");
 mainBranchIn = (TBranch*)inTree->FindBranch("midasBranch");
 nLeavesIn    = (int)mainBranchIn->GetNleaves();
 leafListIn   = (TList*)mainBranchIn->GetListOfLeaves();
 cout << "nleaves is : " << nLeavesIn << "\n";
 for (int i = 0 ; i <nLeavesIn;i++) cout <<"\n"<< leafListIn->At(i)->GetName()<< "\n";
 nevents=(int)inTree->GetEntries();
}

When I run this I get nleaves=1. And the leaf list has only one element–“midasBranch”.

I define my class as follows:

class midasEvent{
 public :
  Double32_t adc[392];   //[0,  0, 32] 
  Short_t tdc[384];     
  Double32_t cath[640];  //[0,  4096, 12] 
  UShort_t rdgt_b0[1000];
  UShort_t rdgt_deg[1000];
  UShort_t rdgt_tgt[1000]; 

  midasEvent();
  virtual ~midaEvent();
  };

To set branches according to this class I use:

 mevent = new midasEvent();  
 int buffersize = 16000;
 int splitlevel = 4;
 usertree->Branch("midasBranch", "midasEvent", &mevent, buffersize, splitlevel);  

I know this is successfully written, because I can read the file. A snapshot of the root browser with the output is attached.

Many thanks for any help you can offer!


Dear mg4vce,

Your tree is splitted so you should get the leaves at the top level. What happens if you do

leafListIn   = (TList*) inTree->GetListOfLeaves();

G Ganis

This allows me to read the branches. Of course I must shift to a different cout method using Titer, instead of explicit loops, because I cannot GetNleaves() from a tree (method only applies for a branch). Also, for some reason, it continues to include the main branch in the list. That is, the cout statement gives:
midasBranch
adc
tdc
cath
rdgt_b0
rdgt_deg09_10
rdgt_tgt

Not exactly a problem per se, but a nuisance. Any way of omitting mainBranch from leaf list?

Many thanks for your help!

Dear mg4vce,

You can use TLeafElement::IsOnTerminalBranch to distinguish between a terminal leaf and an intermediate branch. This should print only the leaves:

void analyzer::Init(TFile *inFile,Option_t *options[])
{
    TTree *inTree       = (TTree*)inFile->Get("usertree");
    TList *leafListIn   = (TList*)inTree->GetListOfLeaves();
    Int_t nLeavesIn = leafListIn ? leafListIn->GetSize() : 0
    cout << "nleaves is : " << nLeavesIn << "\n";
    for (int i = 0 ; i <nLeavesIn;i++) {
        TLeafElement *le = (TLeafElement *) leafListIn->At(i);
        if (le->IsOnTerminalBranch()) cout <<"\n"<< le->GetName()<< "\n";
    }
    Long64_t nevents=(int)inTree->GetEntries();
}

G Ganis

That works fine! Thanks!