Read/Write event object with a TClonesarray to/from a TTree

Hi. I am new to root and c++. I got an event file which is a modified/simplified version of the event file which came with root. I already received a number of root files (with those simplified event objects) from an experiment and now I am trying to learn how to work with them. I can create my event objects, add them to a TTree and write the tree to a TFile. Then I even managed to read them back. Problem appears (or at least seems to appear) when I attempt to close everything up. For tree with splitlevel=0 or 1 my little test program comes back with a segmentation fault (For higher splitlevel everything appears to run smoothly). For a very simple version I can run through my test program once and then on a second pass it crashes. I placed a lot of print out statements everywhere and to my inexperience eye it looks like TClonesarrays in my event object are not destroyed or not destroyed correctly. Any and all help would be highly appreciated.

Maciek

MacOSX 10.56
ROOT 5.22
Test.C (1.94 KB)
XEvent.cxx (2.7 KB)
XEvent.h (3.78 KB)

Hi,

The problem is the handling of the static data member. Those must be allocated and deleted exactly once. Also since you use static data members that are shared between event object, you must never create more than one event object at a time. (Alternatively, do not use static data members).

Cheers,
Philippe.