# Problem with reading complex data structure as a sub-branch of a root tree

**URL:** <https://root-forum.cern.ch/t/problem-with-reading-complex-data-structure-as-a-sub-branch-of-a-root-tree/48765>\
**Category:** Newbie\
**Tags:** tree, root\
**Created:** [February 11, 2022, 2:08pm UTC](https://root-forum.cern.ch/t/problem-with-reading-complex-data-structure-as-a-sub-branch-of-a-root-tree/48765 "2022-02-11T14:08:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabio\_Crespi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fabio_crespi/32/27734_2.png) [@Fabio\_Crespi](https://root-forum.cern.ch/u/Fabio_Crespi)\
**Post date:** [February 11, 2022, 2:08pm UTC](https://root-forum.cern.ch/t/problem-with-reading-complex-data-structure-as-a-sub-branch-of-a-root-tree/48765/1 "2022-02-11T14:08:27Z")

</div>

We are trying to read data from a .root file with a tree having a sub-branch that is  
a `vector<g2IntPt> xtals_intpts[kMaxxtals]`.

We are doing so by producing “.C” and “.h” files using datatree-\>MakeClass(“analysis”)  
and loading the proper addition library:  
.L /rec-data-b/analysis\_14C/goddessSort/build/libGRETINA.so

Using the created analysis.C we can access properly all the other variables/leafs of  
the tree but not those in " vector xtals\_intpts[kMaxxtals] ".  
In particular, the problem is that the variables in this structures are always zero (empty).

Here below the relevant code lines in the created file “analysis.h”:

```auto
/ **************************************************** /

.....

vector<g2IntPt> xtals_intpts[kMaxxtals];

........

TBranch *b_xtals_intpts; //!

......

fChain->SetBranchAddress("xtals.intpts", xtals_intpts, &b_xtals_intpts);

/ **************************************************** /

Here below the relevant code lines in the created file "analysis.C":

/ **************************************************** /
void analysis::Loop()
{
           
..... 

     b_xtals_intpts->GetEntry(ientry);
      
      
........     
  
      for(Int_t j=0; j<kMaxxtals; j++){
      	for(Int_t i=0; i<40; i++){
	
		cout << " "<< xtals_intpts[j].at(i).segE;
		
	}

......
/ **************************************************** /

```

Are we doing some trivial error?

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [February 11, 2022, 3:27pm UTC](https://root-forum.cern.ch/t/problem-with-reading-complex-data-structure-as-a-sub-branch-of-a-root-tree/48765/2 "2022-02-11T15:27:26Z")

</div>

MakeClass can not ‘read’ those branches (MakeClass does not support reading any full object).

You can try `MakeSelector` or better yet `RDataFrame`.

---

<div class="post-metadata">

**Author:** ![Fabio\_Crespi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fabio_crespi/32/27734_2.png) [@Fabio\_Crespi](https://root-forum.cern.ch/u/Fabio_Crespi)\
**Post date:** [February 21, 2022, 9:36am UTC](https://root-forum.cern.ch/t/problem-with-reading-complex-data-structure-as-a-sub-branch-of-a-root-tree/48765/3 "2022-02-21T09:36:50Z")

</div>

Thanks. Unfortunately also MakeSelector doesn’t work.  
We succesfully accessed the data with:  
teb-\>Draw(“g2.xtals.intpts.segE:g2.xtals.intpts.segNum\>\>(36,0,36,1000,0,3000”,“g2.xtals.crystalNum==22”,“colz”)

Using RDataFrame, would be:

ROOT::RDataFrame df(“teb”, “myfileToBeRead.root”);  
auto entries1 = df.Count(“teb.g2”);  
auto h = df.Histo1D(“teb.g2.xtals.intpts.segE[0]”);

(?) …but it gives to us seg fault…

I specify that we correctly loaded the external library with:  
gSystem-\>Load(“libGRETINA.so”);

---

<div class="post-metadata">

**Author:** ![Fabio\_Crespi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fabio_crespi/32/27734_2.png) [@Fabio\_Crespi](https://root-forum.cern.ch/u/Fabio_Crespi)\
**Post date:** [February 23, 2022, 7:31am UTC](https://root-forum.cern.ch/t/problem-with-reading-complex-data-structure-as-a-sub-branch-of-a-root-tree/48765/4 "2022-02-23T07:31:30Z")

</div>

More particularly, when I do

---

<div class="post-metadata">

**Author:** ![Fabio\_Crespi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fabio_crespi/32/27734_2.png) [@Fabio\_Crespi](https://root-forum.cern.ch/u/Fabio_Crespi)\
**Post date:** [February 23, 2022, 7:33am UTC](https://root-forum.cern.ch/t/problem-with-reading-complex-data-structure-as-a-sub-branch-of-a-root-tree/48765/5 "2022-02-23T07:33:34Z")

</div>

ROOT::RDataFrame df(“teb”,“test.root”);  
df.GetColumnNames()

it returns:

ROOT::RDF::RInterface::ColumnNames\_t) { “g2.TObject.fUniqueID”, “fUniqueID”, “g2.TObject.fBits”, “fBits”, “g2.TObject”, “TObject”, “g2.runNumber”, “runNumber”, “g2.xtals.xtals.fUniqueID”, “xtals.fUniqueID”, “g2.xtals.xtals.fBits”, “xtals.fBits”, “g2.xtals.xtals.crystalID”, “xtals.crystalID”, “g2.xtals.xtals.crystalNum”, “xtals.crystalNum”, “g2.xtals.xtals.quadNum”, “xtals.quadNum”, “g2.xtals.xtals.timestamp”, “xtals.timestamp”, “g2.xtals.xtals.t0”, “xtals.t0”, “g2.xtals.xtals.chiSq”, “xtals.chiSq”, “g2.xtals.xtals.normChiSq”, “xtals.normChiSq”, “g2.xtals.xtals.bl”, “xtals.bl”, “g2.xtals.xtals.error”, “xtals.error”, …

I guess g2.xtals.xtals.error", “xtals.error” means that we cannot use also RDataFrame, right?

---

<div class="post-metadata">

**Author:** ![Fabio\_Crespi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fabio_crespi/32/27734_2.png) [@Fabio\_Crespi](https://root-forum.cern.ch/u/Fabio_Crespi)\
**Post date:** [February 24, 2022, 10:04am UTC](https://root-forum.cern.ch/t/problem-with-reading-complex-data-structure-as-a-sub-branch-of-a-root-tree/48765/6 "2022-02-24T10:04:28Z")

</div>

We managed to solve the problem:

we read the whole “xtals” structure as 1 single block (MakeSelector and MakeClass  
“divide” it), using: TTreeReaderArray XXg2CrystalEvent xtalsXX = {fReader, “xtals”};

Sorry the 2 " XX" signs above have to be substituted by “smaller than” and “larger than” symbols, I don’t know why this signs did not appear in the post

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [February 28, 2022, 1:59pm UTC](https://root-forum.cern.ch/t/problem-with-reading-complex-data-structure-as-a-sub-branch-of-a-root-tree/48765/7 "2022-02-28T13:59:24Z")

</div>

It’s still weird that RDataFrame wasn’t able to access that data. Is there a chance that you could share that tree with us - one entry is enough!  
Cheers, Axel

---

<div class="post-metadata">

**Author:** ![Fabio\_Crespi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fabio_crespi/32/27734_2.png) [@Fabio\_Crespi](https://root-forum.cern.ch/u/Fabio_Crespi)\
**Post date:** [March 3, 2022, 9:06am UTC](https://root-forum.cern.ch/t/problem-with-reading-complex-data-structure-as-a-sub-branch-of-a-root-tree/48765/8 "2022-03-03T09:06:49Z")

</div>

I think is useful idea. I have to ask formally permission to the spokesperson of the experiment before.  
Would you sent me an email with such request?  
Additional information is that we also tried with different root version (we are using v6-22-06). we tried with v6-24 and is the same. Instead with previous root6.14 we find no “xtals.error” but also without any ColumnNames for “xtals” appearing.
