What is the proper way to read a custom object from a TFile

Hi,

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()
std::cout<<r
8607

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
f->GetObject(“TICoolOut;1”,icool_data);

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?

Thanks.

-Jon