Hi,
Using the attached code (and file) I am able to crash in a way I was not expecting. To summarize the source code, I load a TH1F from a file, then I get the TClass pointer for TH1F, then I get the list of bases, and then I look at the TH1 class from there, and when I get its list of bases I get back “CDCDCDCD” (on Windows) which is the value for an uninitalized word of memory. Is this behaving correctly? If so, how can I know before hand that the list of bases is going to be invalid like this? If this is expected behavior, is there anyway I can force it to load up whatever it needs so I get a valid class chain back?
I run this code with the command “root -l -b -q testload.cpp+”
And here is the code (also attached along with the file):
[code]#include
#include “TFile.h”
#include “TClass.h”
#include “TList.h”
using std::cout;
using std::endl;
void testload()
{
TFile *f = new TFile(“plots.root”, “READ”);
if (!f->IsOpen()) {
cout << “Error opening file” << endl;
return;
}
TObject *o = f->Get("anint_2");
if (o == 0) {
cout << "Unable to load the object" << endl;
return;
}
TClass *c = o->IsA();
if (c == 0) {
cout << "Unable to get the class of the object" << endl;
return;
}
cout << "Class is " << c->GetName() << endl; // Should be TH1F
TList *bases = c->GetListOfBases();
cout << "Bases pointer is " << bases << endl; // Should be valid pointer
cout << " Bases length is " << bases->GetEntries() << endl; // Should be 2
c = static_cast<TClass*>(bases->At(0));
cout << "Subclass is " << c->GetName() << endl;
if (!c->IsLoaded()) {
cout << "Expecting class to be loaded" << endl;
return;
}
bases = c->GetListOfBases();
cout << "Bases pointer is " << bases << endl; // Should be valid pointer
cout << " Bases length is " << bases->GetEntries() << endl; // Should be 2
f->Close();
}
[/code]
Thanks in advaice!
plots.root (3.49 KB)
testload.cpp (1.12 KB)