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.
#ifdefCINT #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
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
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 #ifdefCINT #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.
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
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)