Print from sub branch using cout

I am reading from my input file:

TFile* file = TFile::Open(argv[1], “READ”);
myTree myInfo = myTree::ReadFrom(“myTree”, *file);
myTreeReader tree(*file);

I would like to print some information from a sub-sub branch of myTree. How would I do that? I know that to read “Information” from my top tree, I would do something like:

cout << Form(“Some Information”, myInfo.Information) << endl;

but I want to read from a sub-sub branch of this tree. How would I modify this print statement to do so?

Hi,

RDataFrame might help:

ROOT::RDataFrame r("myTree",argv[1]);
r.Foreach([](typeOfInfo &i){cout << Form(“Some Information”, myInfo.Information) << endl;},{"myInfo.Information"});

Cheers

Cheers

Hi, thanks for your help! In my root file, my tree structure is:

myTree1
—myBranch1
------mySubBranch1
---------mySubSubBranch1
------------myInfo1
------------myInfo2
------------…
myTree2

How do I access myInfo1, myInfo2, etc.? I just need to print them using cout. I’m not sure I understand how your reply reaches into those sub sub branches.

Hi,

I think you can access the nested data using dots. If you have dictionaries around for your classes, in the C++ code:

r.Foreach([](typeOfBranch &branch){cout << Form(“Some Information”, branch.subbranch1.myInfo1) << endl;},{"branch"});

if you do not, you can access them via the branch name:

r.Foreach([](typeOfInfo1 &i){cout << Form(“Some Information”, i) << endl;},{"branch.subbranch1.myInfo1"});

Cheers

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.