# Nested structure of custom classes

**URL:** <https://root-forum.cern.ch/t/nested-structure-of-custom-classes/40560>\
**Category:** Newbie\
**Tags:** tree\
**Created:** [July 21, 2020, 8:58pm UTC](https://root-forum.cern.ch/t/nested-structure-of-custom-classes/40560 "2020-07-21T20:58:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gramotey](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/b2d939/32.png) [@Gramotey](https://root-forum.cern.ch/u/Gramotey)\
**Post date:** [July 21, 2020, 8:58pm UTC](https://root-forum.cern.ch/t/nested-structure-of-custom-classes/40560/1 "2020-07-21T20:58:40Z")

</div>

Dear all -

Thank you for your past help… as I progress, I get stuck on the next complexity level 🙂

1. Problem.  
I would like to record the following structure:

- I have TMyEvent class that holds TCloneArrays of another class, TMySample
- Each TMySample holds a certain number of TMyAxis objects, also as TClonesArray (suggestions welcome)
- each of the TMyAxis holds some data, such as arrays of floats

So my goal is to have:

```auto
TMyEvent (nevent, nsample, TClonesArray *fSamples)
               | ____ TMySample (sampleid, naxis, TClonesArray *fAxes)
                                            | ____ TMyAxis (axisid, nchannels, chdata [nchannels] )

```

You have helped me with the TMyAxis (axisid, nchannels, chdata [nchannels] ) portion and it works.  
But now I just tried to do “monkey see / monkey do” approach and extend this to one more nested level with classes… and failing to do so.

I attach the example and the classes definition and the nestedclass.C  
It creates the shared object but crashes when I try to add the first TMySample.

Please help me to make such storage structure.  
I am not hell-bent on this solution, so if there is a different and more elegant way to achieve the nested structure, I would welcome all suggestions!  
I could think this is something common (Event has Jets, each Jet has Tracks, track has particles in them…) I just did not find a good example that would define such structure.

Thank you, best -  
Evgeny.  
[nestedclass.h](https://root-forum.cern.ch/uploads/short-url/4zj22NLSunX87WKRoDglP7UL6Nh.h) (2.8 KB)  
[nestedclass.C](https://root-forum.cern.ch/uploads/short-url/pMOZtZ3yOG97sTW8QAzax0uhmqC.C) (2.5 KB)

ROOT Version: 6.20/02  
Built for linuxx8664gcc on Mar 15 2020, 15:25:34  
From tags/v6-20-02@v6-20-02  
Platform:\_ Debian 10

* * *

---

<div class="post-metadata">

**Author:** ![Gramotey](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/b2d939/32.png) [@Gramotey](https://root-forum.cern.ch/u/Gramotey)\
**Post date:** [July 23, 2020, 12:58am UTC](https://root-forum.cern.ch/t/nested-structure-of-custom-classes/40560/2 "2020-07-23T00:58:00Z")

</div>

The topic is closed,  
I did find a good example that I was able to use, by Rene Brun and [his Jet class](https://root.cern.ch/root/html608/jets_8C.html).

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [July 23, 2020, 7:36am UTC](https://root-forum.cern.ch/t/nested-structure-of-custom-classes/40560/3 "2020-07-23T07:36:53Z")

</div>

Hi Evgeny,  
glad to hear that, and sorry for our slow response!

Cheers,  
Enrico
