Read single leaves from a branch

I have to read a branch form a file, which has been written as a simple object containing scalar members:

******************************************************************************
*Tree    :Data      : Data                                                   *
*Entries :    50000 : Total =        34020559 bytes  File  Size =   13110598 *
*        :          : Tree compression factor =   2.59                       *
******************************************************************************
*Branch  :Results                                                            *
*Entries :    50000 : BranchElement (see below)                              *
*............................................................................*
*Br    0 :TObject   : BASE                                                   *
*Entries :    50000 : Total  Size=     701836 bytes  File Size  =      75677 *
*Baskets :       15 : Basket Size=      64000 bytes  Compression=   9.27     *
*............................................................................*
*Br    1 :Nparticles : Int_t                                                 *
*Entries :    50000 : Total  Size=     200806 bytes  File Size  =       1421 *
*Baskets :        4 : Basket Size=      64000 bytes  Compression= 140.96     *
*............................................................................*

Is it possible in the structure above to read only NParticles? I don’t have the original definition of the Results class, I would have to rewrite the definition starting from the printout, then generate the dictionary etc. and I would like to avoid this overhead since I only need to read a few leaves. Is this possible and eventually how can I do it? I tried with:

root [1] int Nparticles = -1
root [2] Data->GetBranch("Nparticles")->SetAddress(&Nparticles)
root [3] Data->GetBranch("Nparticles")->GetEntry(0)
(Int_t)4
root [4] Nparticles
(int)(-1)

which does not work since Nparticles is 1 for the first entry:

root [5] Data->Scan("Nparticles")
************************
*    Row   * Nparticle *
************************
*        0 *         1 *

Thanks for the help.

Hi Nicola,

could you share the rootfile containing the tree?

D

Hi Danilo, here is a link to the file:

hightail.com/download/bXBiQ … NUpOeDhUQw

Thank you.

Try first:
Data->SetMakeClass(1);

Hi Coyote, your voodoo ritual works:

root [1] int Nparticles = -1
root [2] Data->SetMakeClass(1)
root [3] Data->GetBranch("Nparticles")->SetAddress(&Nparticles)
root [4] Data->GetBranch("Nparticles")->GetEntry(0)
(Int_t)4
root [5] Nparticles
(int)1

Thank you, I would never have guessed that this sort of black magic was necessary to make my code work :wink: