# Problem accesing tree data in makeclass Loop

**URL:** <https://root-forum.cern.ch/t/problem-accesing-tree-data-in-makeclass-loop/53839>\
**Category:** Newbie\
**Tags:** tree\
**Created:** [March 1, 2023, 9:11pm UTC](https://root-forum.cern.ch/t/problem-accesing-tree-data-in-makeclass-loop/53839 "2023-03-01T21:11:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zvonko](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/f6c823/32.png) [@Zvonko](https://root-forum.cern.ch/u/Zvonko)\
**Post date:** [March 1, 2023, 9:11pm UTC](https://root-forum.cern.ch/t/problem-accesing-tree-data-in-makeclass-loop/53839/1 "2023-03-01T21:11:59Z")

</div>

Hi,  
I am experiencing issues while trying to access data stored in Ttree.  
I am using Loop function in makeClass. My Ttree consists of:

```auto
// Declaration of leaf types
   Int_t info_iev;
   Int_t info_len1;
   Int_t info_len2;
   Int_t info_len3;
   Int_t info_len4;
   Int_t info_loop;
   ULong64_t info_trigTime;
   Double_t info_xscale[4];
   Double_t info_yscale[4];
   Double_t info_yoffset[4];
   //Float_t info_timer1;
   //Float_t info_timer2;
   Short_t y1[20002]; //[len1]
   Short_t y2[0]; //[len2]
   Short_t y3[20002]; //[len3]
   Short_t y4[0]; //[len4]
   Int_t debug;
   Int_t fMode;

```

when i try to access data, i get the right values for all but info\_xscale and info\_yscale.  
The two arrays return the same incorrect value everytime. I am trying to access these arrays with the following code:

```auto
for (Long64_t jentry=1; jentry<nentries;jentry++) 
   {  
      Long64_t ientry = LoadTree(jentry);
      if (ientry < 0) break;
      nb = fChain->GetEntry(jentry); nbytes += nb;
      fChain->Show(jentry);
      for (int i=0; i<4; i++) {
        cout<<info_xscale[i]<<"\n";
      }

```

when creating a tree I set the problematic branch like this:

```auto
T2c->Branch("info", &info, "iev/I:len1/I:len2/I:len3/I:len4/I:loop/I:trigTime/l:xscale[4]/D:yscale[4]/D:yoffset[4]/D");

```

When using fChain-\>Show(jentry) function I get the output that has correct values for all leafs. the problem only occurs when trying to access individual array od info\_xscale and info\_yscale.  
I assume the problem is in how I access these arrays, since the Tree seems to be initialized correctly.  
I would appriciate any advice on how to approach these problem.  
Thank you in advance.

\_ROOT Version: 6.28/00  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 2, 2023, 7:57am UTC](https://root-forum.cern.ch/t/problem-accesing-tree-data-in-makeclass-loop/53839/2 "2023-03-02T07:57:42Z")

</div>

The “`y2[0]`” and “`y4[0]`” look weird.  
Attach your ROOT file for inspection.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [March 2, 2023, 7:57am UTC](https://root-forum.cern.ch/t/problem-accesing-tree-data-in-makeclass-loop/53839/3 "2023-03-02T07:57:58Z")

</div>

Welcome to the ROOT Forum!  
And you don’t have issues with `info_yoffset` and other arrays? Can you try to change the type of `info_trigTime` to `ULong_t`?

---

<div class="post-metadata">

**Author:** ![Zvonko](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/f6c823/32.png) [@Zvonko](https://root-forum.cern.ch/u/Zvonko)\
**Post date:** [March 2, 2023, 10:21am UTC](https://root-forum.cern.ch/t/problem-accesing-tree-data-in-makeclass-loop/53839/4 "2023-03-02T10:21:29Z")

</div>

Thank you for your response!  
The files are quite large. The zero length of some y arrays is ok, this is so because the program that crates the tree samples multiple oscilloscope channels. The ones set not to be sampled result in eg. “`y4[0]` ”.  
I can attach a file if you still think it is necessary.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 2, 2023, 10:39am UTC](https://root-forum.cern.ch/t/problem-accesing-tree-data-in-makeclass-loop/53839/5 "2023-03-02T10:39:36Z")

</div>

Try:

```cpp
// ...
   Int_t dummy_align_8B; //!
// Declaration of leaf types
   Int_t info_iev;
// ...

```

---

<div class="post-metadata">

**Author:** ![Zvonko](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/f6c823/32.png) [@Zvonko](https://root-forum.cern.ch/u/Zvonko)\
**Post date:** [March 2, 2023, 11:01am UTC](https://root-forum.cern.ch/t/problem-accesing-tree-data-in-makeclass-loop/53839/6 "2023-03-02T11:01:40Z")

</div>

Thank you for replying!  
Actually, the same issue is with `info_yoffset`, I just haven’t noticed it, because if ALL `info_yoffset` array elements are zero (0), the values returned are also 0 - correct. This was almost always the case. Otherwise, the values returned are eg.

```auto
info_yoffset[i]=

```

5.25596e-315  
-1.49167e-154  
5.28452e-315  
0  
and similar for `info_xscale` and `info_yscale` as well.  
The `y1,y2,y3,y4` arrays are ok.  
Also, tried changing `info_trigTime` as proposed, unfortunately doesn’t result in any change, but was helpful to remind me that `info_trigTime` is also returned incorrectly (no matter the datatype).

---

<div class="post-metadata">

**Author:** ![Zvonko](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/f6c823/32.png) [@Zvonko](https://root-forum.cern.ch/u/Zvonko)\
**Post date:** [March 2, 2023, 11:12am UTC](https://root-forum.cern.ch/t/problem-accesing-tree-data-in-makeclass-loop/53839/8 "2023-03-02T11:12:40Z")

</div>

// …  
Int\_t dummy\_align\_8B; //!  
// Declaration of leaf types  
Int\_t info\_iev;  
// …

Thank you, this makes everything work as it should!  
How did you think of this?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 2, 2023, 8:46pm UTC](https://root-forum.cern.ch/t/problem-accesing-tree-data-in-makeclass-loop/53839/9 "2023-03-02T20:46:42Z")

</div>

I assumed that before the “Declaration of leaf types”, you only had (8 + 4 Bytes): `TTree *fChain; Int_t fCurrent;`  
I added another “`Int_t`” (4 Bytes) to make the “`info_iev`” (and then also the arrays) aligned at the 8 Bytes boundary.
