Root Classes and Inheritance

Hello,

I am trying to figure out how to make a root class that inherits from another class. I have successfully made my own root class which inherits from TObject, with its own dictionary that I store as a shared object. What I want to do now is have two classes one which inherits from the other but I am unsure exactly what needs to be done. I assume that I need to make dictionaries of both, but what do I need in my linkdef statements for each class? Does each need a ClassDef macro? Does each need to inherit from TObject? For my single class (which is working fine now) my linkdef is below.

#ifdef CINT
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class vector< vector <Double_t> >+;
#pragma link C++ class vector< vector <UShort_t> >+;
#pragma link C++ class LendaEvent+;
#endif

Thanks in advance!

[url]Simple way to create and merge shared libraries?
[url]Adding a class: hand holding requested

[url]Storing 2D vector [--> vector<vector<...> >] into a TTree
[url]Problem in getting the vector < vector <string> > branch

Thank you for the quick reply
I have read the above links, but I am still having trouble with this. Everything compiles fine and I can open root and instatiate my object. It’s members and it’s parents members appear to be all there. I can write the object to file fine as well. The trouble happens when I try to read the object back in from the file. IE

root
root [0] LendaEvent e
root [1] TFile f(“temp.root”,“recreate”)
root [2] e.Write()
(Int_t)329
root [3] .q
<hake:Introspective >root temp.root
root [0]
Attaching file temp.root as _file0…
gDirectory->Get(“LendaEvent”)

At which points it memory dumps giving this error
*** glibc detected *** /soft/x86_64/lucid/root/5.26.00/bin/root.exe: free(): invalid pointer: 0x00000000025eaec8 **
my linkdef file is
#ifdef CINT
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class vector< vector <Double_t> >+;
#pragma link C++ class vector< vector <UShort_t> >+;
#pragma link C++ class CorrectionInfo+;
#pragma link C++ class std::vector+;
#pragma link C++ class Introspective+;
#pragma link C++ class LendaEvent+;
#endif

If the very first line is:
root [0] LendaEvent e
how is ROOT supposed to know what “LendaEvent” is?
You don’t seem to load dictionaries for your classes (e.g. “.L SomeLibraryWithDictionaries.so”), before using them.

Sorry. .L libLendaEvent.so is called in my start up file.

And what do you get when you try:
root [0] TFile *f = TFile::Open(“temp.root”)
root [1] f->ls()

root [0] TFile * f =TFile::Open(“temp.root”)
root [1] f->ls()
TFile** temp.root
TFile* temp.root
KEY: LendaEvent LendaEvent;1
root [2]

Then try:
root [2] LendaEvent *e; f->GetObject(“LendaEvent”, e);
root [3] e

root [0] TFile * f=TFile::Open(“temp.root”) root [1] LendaEvent *e
root [2] f->GetObject(“LendaEvent”,e) *** glibc detected *** /soft/x86_64/lucid/root/5.26.00/bin/root.exe: free(): invalid pointer: 0x00000000023c4548 ***
======= Backtrace: =========
/lib/libc.so.6(+0x78bb6)[0x7f6449a77bb6]
/lib/libc.so.6(cfree+0x73)[0x7f6449a7e483]
/soft/x86_64/lucid/root/5.26.00/lib/root/libRIO.so(_ZN19TGenCollectionProxy5ClearEPKc+0xc6)[0x7f64489817a6]
/soft/x86_64/lucid/root/5.26.00/lib/root/libRIO.so(_ZN22TGenCollectionStreamer8StreamerER7TBuffer+0x106)[0x7f6448989326]
/soft/x86_64/lucid/root/5.26.00/lib/root/libRIO.so(_ZN19TCollectionStreamer8StreamerER7TBufferPviP6TClass+0x56)[0x7f64489660b6]
/soft/x86_64/lucid/root/5.26.00/lib/root/libRIO.so(ZN11TBufferFile13ReadFastArrayEPvPK6TClassiP15TMemberStreamerS3+0xc7)[0x7f6448962ef7]
/soft/x86_64/lucid/root/5.26.00/lib/root/libRIO.so(_ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_iiii+0x5585)[0x7f6448a0da95]
/soft/x86_64/lucid/root/5.26.00/lib/root/libRIO.so(ZN11TBufferFile15ReadClassBufferEPK6TClassPvS2+0xe1)[0x7f64489600c1]
/user/lipschut/Introspective/libLendaEvent-m64.so(_ZN13Introspective8StreamerER7TBuffer+0x57)[0x7f6448d08987]
/user/lipschut/Introspective/libLendaEvent-m64.so(_ZN13Introspective16StreamerNVirtualER7TBuffer+0x29)[0x7f6448d1f429]
/user/lipschut/Introspective/libLendaEvent-m64.so(+0x5ae4c)[0x7f6448d0ee4c]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCint.so.5.26(_ZN4Cint11G__CallFunc7ExecuteEPv+0xcf)[0x7f644b0004af]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCore.so.5.26(ZNK5TCint13CallFunc_ExecEPvS0+0xc)[0x7f644bb8ed2c]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCore.so.5.26(_ZN11TMethodCall7ExecuteEPv+0xfb)[0x7f644bb8031b]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCore.so.5.26(_ZN13TStreamerBase10ReadBufferER7TBufferPc+0x94)[0x7f644bb87514]
/soft/x86_64/lucid/root/5.26.00/lib/root/libRIO.so(_ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_iiii+0x45aa)[0x7f6448a0caba]
/soft/x86_64/lucid/root/5.26.00/lib/root/libRIO.so(ZN11TBufferFile15ReadClassBufferEPK6TClassPvS2+0xe1)[0x7f64489600c1]
/user/lipschut/Introspective/libLendaEvent-m64.so(_ZN10LendaEvent8StreamerER7TBuffer+0x57)[0x7f6448d08dc5]
/soft/x86_64/lucid/root/5.26.00/lib/root/libRIO.so(_ZN4TKey13ReadObjectAnyEPK6TClass+0x33b)[0x7f6448989f2b]
/soft/x86_64/lucid/root/5.26.00/lib/root/libRIO.so(_ZN14TDirectoryFile16GetObjectCheckedEPKcPK6TClass+0x1f4)[0x7f644896e1a4]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCore.so.5.26(+0x1bd533)[0x7f644bac8533]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCint.so.5.26(_ZN4Cint19G__ExceptionWrapperEPFiP8G__valuePKcP8G__paramiES1_PcS5_i+0x3e)[0x7f644afd1e1e]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCint.so.5.26(G__execute_call+0x61)[0x7f644b070a31]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCint.so.5.26(G__call_cppfunc+0x282)[0x7f644b072222]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCint.so.5.26(G__interpret_func+0x1cb8)[0x7f644b0501e8]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCint.so.5.26(G__getfunction+0x1959)[0x7f644b03fbb9]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCint.so.5.26(G__getstructmem+0x6ff)[0x7f644b126d0f]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCint.so.5.26(G__getvariable+0x9b7)[0x7f644b11c7e7]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCint.so.5.26(G__getitem+0x81)[0x7f644b01bdc1]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCint.so.5.26(G__getexpr+0x4d69)[0x7f644b021e49]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCint.so.5.26(G__exec_statement+0x62ea)[0x7f644b09e4ca]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCint.so.5.26(+0x88b66)[0x7f644b009b66]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCint.so.5.26(G__exec_tempfile_fp+0xe)[0x7f644b009e1e]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCint.so.5.26(G__process_cmd+0x15c3)[0x7f644b0a9b33]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCore.so.5.26(_ZN5TCint11ProcessLineEPKcPN12TInterpreter10EErrorCodeE+0x406)[0x7f644bb94cd6]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCore.so.5.26(_ZN12TApplication11ProcessLineEPKcbPi+0x301)[0x7f644bacb971]
/soft/x86_64/lucid/root/5.26.00/lib/root/libRint.so.5.26(_ZN5TRint15HandleTermInputEv+0x1a8)[0x7f644a966e58]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCore.so.5.26(_ZN11TUnixSystem16CheckDescriptorsEv+0x14e)[0x7f644bba6cae]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCore.so.5.26(_ZN11TUnixSystem16DispatchOneEventEb+0xd1)[0x7f644bba6fa1]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCore.so.5.26(_ZN7TSystem9InnerLoopEv+0x16)[0x7f644bb26536]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCore.so.5.26(_ZN7TSystem3RunEv+0x7b)[0x7f644bb2874b]
/soft/x86_64/lucid/root/5.26.00/lib/root/libCore.so.5.26(_ZN12TApplication3RunEb+0x1f)[0x7f644bac9dcf]
/soft/x86_64/lucid/root/5.26.00/lib/root/libRint.so.5.26(_ZN5TRint3RunEb+0x189)[0x7f644a967979]
/soft/x86_64/lucid/root/5.26.00/bin/root.exe(main+0x4c)[0x4011fc]
/lib/libc.so.6(__libc_start_main+0xfd)[0x7f6449a1dc4d]
/soft/x86_64/lucid/root/5.26.00/bin/root.exe[0x4010c9]
======= Memory map: ========
00400000-00402000 r-xp 00000000 00:2a 5142916 /soft/x86_64/lucid/root/5.26.00/bin/root.exe
00601000-00602000 r–p 00001000 00:2a 5142916 /soft/x86_64/lucid/root/5.26.00/bin/root.exe
00602000-00603000 rw-p 00002000 00:2a 5142916 /soft/x86_64/lucid/root/5.26.00/bin/root.exe
02233000-02b7c000 rw-p 00000000 00:00 0 [heap]
7f6440000000-7f6440021000 rw-p 00000000 00:00 0
7f6440021000-7f6444000000 —p 00000000 00:00 0
7f6447e21000-7f6447e45000 r-xp 00000000 00:2a 26722300 /soft/x86_64/lucid/root/5.26.00/lib/root/libvectorDict.so.5.26
7f6447e45000-7f6448045000 —p 00024000 00:2a 26722300 /soft/x86_64/lucid/root/5.26.00/lib/root/libvectorDict.so.5.26
7f6448045000-7f6448047000 r–p 00024000 00:2a 26722300 /soft/x86_64/lucid/root/5.26.00/lib/root/libvectorDict.so.5.26
7f6448047000-7f6448048000 rw-p 00026000 00:2a 26722300 /soft/x86_64/lucid/root/5.26.00/lib/root/libvectorDict.so.5.26
7f6448048000-7f6448049000 rw-p 00000000 00:00 0
7f6448049000-7f6448205000 r-xp 00000000 00:2a 5081446 /soft/x86_64/lucid/root/5.26.00/lib/root/cint/cint/stl/vector.so.5.26
7f6448205000-7f6448404000 —p 001bc000 00:2a 5081446 /soft/x86_64/lucid/root/5.26.00/lib/root/cint/cint/stl/vector.so.5.26
7f6448404000-7f6448405000 r–p 001bb000 00:2a 5081446 /soft/x86_64/lucid/root/5.26.00/lib/root/cint/cint/stl/vector.so.5.26
7f6448405000-7f644840c000 rw-p 001bc000 00:2a 5081446 /soft/x86_64/lucid/root/5.26.00/lib/root/cint/cint/stl/vector.so.5.26
7f644840c000-7f6448428000 r-xp 00000000 00:2a 13516424 /soft/x86_64/lucid/root/5.26.00/lib/root/libmapDict.so.5.26

Well, you could try to create the ROOT file using objects on the heap: LendaEvent *e = new LendaEvent(); TFile *f = TFile::Open("temp.root", "recreate"); e->Write(); delete f; delete e; and if it still dies when you try to “GetObject” afterwards, then you need to carefully inspect (valgrind ?) the “LendaEvent” class, I think.

[code]/*

Note: Save this source code as the “TrialEvent.cxx” file.

// create the ROOT file using objects on the stack
.L TrialEvent.cxx++
TrialEvent e;
TFile f(“temp.root”, “recreate”);
e.Write();
.q

// create the ROOT file using objects on the heap
.L TrialEvent.cxx++
TrialEvent *e = new TrialEvent();
TFile *f = TFile::Open(“temp.root”, “recreate”);
e->Write();
delete f;
delete e;
.q

// read the ROOT file
.L TrialEvent.cxx++
TFile *f = TFile::Open(“temp.root”);
f->ls();
TrialEvent *e;
f->GetObject(“TrialEvent”, e);
if (e) std::cout << "e->v = " << e->v << std::endl;
delete f;
delete e;
.q

*/

#include “TObject.h”

class TrialEvent: public TObject
{
public:
int v;
TrialEvent(int i = -1) { v = i; }
public:
ClassDef(TrialEvent, 1); // TrialEvent class
};[/code]

I have isolated the error but I am unsure how get rid of it. When LendaEvent constructs it builds a map
void LendaEvent::DefineMap(){
theMap[“TOF”]=&TOF;
theMap[“Dt”]=&Dt;

}
theMap (which is between strings and void*) is inherited froms its parent class. Removing this call in the constructor gets rid of the error (which consistently happens when the events are read back in from a file)