# How to read a tree with a split-level branch?

**URL:** <https://root-forum.cern.ch/t/how-to-read-a-tree-with-a-split-level-branch/40138>\
**Category:** Newbie\
**Tags:** tree\
**Created:** [June 29, 2020, 4:50pm UTC](https://root-forum.cern.ch/t/how-to-read-a-tree-with-a-split-level-branch/40138 "2020-06-29T16:50:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bassam](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/b38774/32.png) [@Bassam](https://root-forum.cern.ch/u/Bassam)\
**Post date:** [June 29, 2020, 4:50pm UTC](https://root-forum.cern.ch/t/how-to-read-a-tree-with-a-split-level-branch/40138/1 "2020-06-29T16:50:04Z")

</div>

I want to see if I am thinking about this correctly:

Let’s consider the following example:

We have a tree with a branch named `Events` that stores events of class `MyEvent.` In this class, there are member functions `RunId()`, `EventId()`, etc.

When the data is written to the branch `Events`, a split-level is performed so that `mRunId`, `mEventId`, etc, are all stored in sub-branches.

Now we have a tree `MyTree` with a branch named `Events` and within the branch `Events`, we have sub-branches . One sub-branch has all the `mRunId` values, another sub-branch has all the `mEventId` value, etc.

Would this be the right way to process a branch from `MyTree` ?

```auto
TChain* eventChain = new Chain("MyTree")

eventChain -> Add(eventFile.root) // Assuming that other files will be chained too.

MyEvent* event = 0;
eventChain->SetBranchAddress("Events", &event)

eventChain->GetEvent(1)

event->RunId() // Where RunId() is a member function of the class MyEvent and it returns the value `mRunId`
event->EventId() // Where EventId() is a member function of the class MyEvent and it returns the value `mEventId`

```

I am providing this example in an attempt to see if:

**a)** I need to assign a pointer to each sub-branch,

**b)** or if I can still have one pointer of class `MyEvent` and all the information from the sub-branches can be accessed using one pointer, in this case the pointer would be `event`, since one entry of the sub-branches corresponds to all the data members of class `MyEvent` and the pointer `event` is of type `MyEvent` .

Can you please let me know if I am thinking about reading the tree correctly, and if either my interpretation in **a** or **b** is correct? If not, what is the correct way to go about it?

---

<div class="post-metadata">

**Author:** ![jblomer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jblomer](https://root-forum.cern.ch/u/jblomer)\
**Post date:** [June 29, 2020, 8:32pm UTC](https://root-forum.cern.ch/t/how-to-read-a-tree-with-a-split-level-branch/40138/2 "2020-06-29T20:32:15Z")

</div>

Hi Bassam,

Your assumptions are correct (modulo typos in the code sample). You only need the `MyEvent` pointer, ROOT populates the class members from sub branches automatically. If your `MyEvent` class contains many more members and you are only interested in reading a few of them, you can use the `SetBranchStatus()` method in order to optimize the performance by reading only necessary branches. Like so

```
eventChain->SetBranchStatus("*", 0); // disable all sub branches
eventChain->SetBranchStatus("mRunId", 1); // but enable mRunId
eventChain->SetBranchStatus("mEventId", 1); // as well as mEventId

```

Note that the indexing starts with 0, so in your code sample you’d read the second event.

Cheers,  
Jakob

---

<div class="post-metadata">

**Author:** ![Bassam](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/b38774/32.png) [@Bassam](https://root-forum.cern.ch/u/Bassam)\
**Post date:** [June 29, 2020, 9:04pm UTC](https://root-forum.cern.ch/t/how-to-read-a-tree-with-a-split-level-branch/40138/3 "2020-06-29T21:04:30Z")

</div>

Thank you very much! I really appreciate the detailed response!
