C++ Program with own class

Hey,

I wrote my own class TEvent, which I want to use in a C++ program.
The TEvent class inherit from the TObject class.
The program should create tree with objects of this class.

I wrote my own makefile and I am able to compile the program. I use a LinkdDef File (all this #pragma stuff),I create an libTEvent.so
All this thinks seems to work fine. I can open root, include the TEvent.hh header file and create objects of the TEvent class.

In the c++ program I am creating a new tree. Afterwars I try to create a Branch with a TEvent object:

TFile* file=new TFile("test.root","RECREATE"); TTree* tree=new TTree("testTree",""); TEvent* pEvent=0; tree->Branch("event","TEvent",&pEvent);
This does not work, the program crashes. It gives a seg-fault with following message:

#5  0x00002ad6ff57faed in TBuildRealData::Inspect(TClass*, char const*, char const*, void const*) () from /opt/root/lib/libCore.so
#6  0x00002ad6fe73bcf3 in ROOT::pairlEintcOfloatgR_ShowMembers (obj=0x61ef240, 
    R__insp=...) at TEventDict.cpp:466
#7  0x00002ad6ff5751df in TClass::CallShowMembers(void*, TMemberInspector&, int) const () from /opt/root/lib/libCore.so
#8  0x00002ad6ff576320 in TClass::BuildRealData(void*, bool) ()
   from /opt/root/lib/libCore.so
#9  0x00002ad6ff57fe4d in TBuildRealData::Inspect(TClass*, char const*, char const*, void const*) () from /opt/root/lib/libCore.so
#10 0x00002ad6fe73c402 in TCluster::ShowMembers (this=0x62eb260, R__insp=...)
    at TEventDict.cpp:641
#11 0x00002ad6ff575316 in TClass::CallShowMembers(void*, TMemberInspector&, int) const () from /opt/root/lib/libCore.so
#12 0x00002ad6ff576320 in TClass::BuildRealData(void*, bool) ()
   from /opt/root/lib/libCore.so
#13 0x00002ad6ff57fe4d in TBuildRealData::Inspect(TClass*, char const*, char const*, void const*) () from /opt/root/lib/libCore.so
#14 0x00002ad6fe73c2f9 in TPlane::ShowMembers (this=0x6291240, R__insp=...)
    at TEventDict.cpp:713
#15 0x00002ad6ff575316 in TClass::CallShowMembers(void*, TMemberInspector&, int) const () from /opt/root/lib/libCore.so
#16 0x00002ad6ff576320 in TClass::BuildRealData(void*, bool) ()
   from /opt/root/lib/libCore.so
#17 0x00002ad6ff57fe4d in TBuildRealData::Inspect(TClass*, char const*, char const*, void const*) () from /opt/root/lib/libCore.so
#18 0x00002ad6fe73c1de in TEvent::ShowMembers (this=0x61feb80, R__insp=...)
    at TEventDict.cpp:759
#19 0x00002ad6ff575316 in TClass::CallShowMembers(void*, TMemberInspector&, int) const () from /opt/root/lib/libCore.so
#20 0x00002ad6ff576320 in TClass::BuildRealData(void*, bool) ()
   from /opt/root/lib/libCore.so
#21 0x00002ad70201dc00 in TTree::BuildStreamerInfo(TClass*, void*, bool) ()
   from /opt/root/lib/libTree.so
#22 0x00002ad70201e00e in TTree::BronchExec(char const*, char const*, void*, bool, int, int) () from /opt/root/lib/libTree.so
#23 0x00002ad70200fbba in TTree::Bronch(char const*, char const*, void*, int, int) () from /opt/root/lib/libTree.so
#24 0x00000000004c7491 in TTree::Branch<TEvent> (this=0x61fb650, 
    name=0x4d88c4 "event", classname=0x4d88bd "TEvent", addobj=0x7fff1640fef0, 
    bufsize=32000, splitlevel=99) at /opt/root/include/TTree.h:316
#25 0x00000000004cf753 in main (argc=1, argv=0x7fff16410078)
    at diamondAnalysis.cpp:118

If I start ROOT, include the header and type this commands, it works and I can write a tree with TEvent-Objects in it.

I downloaded ROOT via svn, so I have ROOT version 5.33/01, svn-Version: 336129

Do you have any Idea what could be the problem?
Best
Felix

Hi,

My first guess is that one of the default constructor (of your classes) is not initializing properly all the pointers.

One thing you can do to pinpoint the problem is to run your example via valgrind. (Alternatively, you could upload a complete running example showing the problem).

Cheers,
Philippe.