Bug With Root Dictionaries-Cannot Get An Object From TFile


I created a custom class TICoolOut, created a dictionary and used the ClassDef and ClassImp macros as required. I then saved an object of TICoolOut type to a TFile. Using the interpreter in root, retrieving the file works file as per below:

gSystem.Load("/Users/Jon/Documents/Physics Research/BNL Research/Developer/Icool Tools/lib/libRoot Import.dylib")
TFile f("/Users/Jon/Desktop/BP_Cooling_Files_Work/icoolout.root"); TICoolOut *myti; f->GetObject(“TICoolOut;1”,myti)
int r=myti->get_particles_end()

HOWEVER, when I try to retrieve the object in compiled code, everything crashes:
Here is my code:

TICoolOut *icool_data=new TICoolOut(10000,input_path, true, root_output_file, “Final Cooling Channel”, for009_file, ecalc9_file);
TFile *f=new TFile("/Users/Jon/Desktop/BP_Cooling_Files_Work/icoolout.root");
f->GetListOfKeys()->Print(); //this line works and the keys are there

The error I am getting is BAD ACCESS CODE on the following ROOT line:

template inline void GetObject(const char* namecycle, T*& ptr) // See TDirectory::Get for information
ptr = (T*)GetObjectChecked(namecycle,TBuffer::GetClass(typeid(T)));

What am I doing wrong?



you must initialize the pointer myti=0


I don’t think one needs to initialize “myti” (i.e. TDirectoryFile::GetObject does not need it at all).


I tried initializing myti=0. This didn’t fix the problem. It works perfectly fine from the interpreter. Why wouldn’t it work in my compiled code? Any help would be greatly appreciated. Thanks in advance.


Does anyone have any ideas what may be going wrong here? I am simply trying to read an object from a TFile and it doesn’t work. What is wrong with my code? It works in the interpreter. I am on MacOS. The object I am reading is implemented as a shared library. Any help would be greatly appreciated.

Hi Jon,

If I recall correctly, this issue was resolved by tweaking the TICoolOut implementation.