I have a ROOT TFile which contains a TList which contains about 50 TObjects, mostly TH1Fs. My function GetObject opens the file, gets the list, and gets the TObject without a problem.
The problem is that I can’t close and delete the TFile without getting a seg. fault.
How do I tell ROOT to copy the TH1D into memory and disassociate it from the TFile so that I can close and delete the TFile?
[code]////////////////////////////////////////////////////////////////
/// GetObject
////////////////////////////////////////////////////////////////
/// Retrieves the ROOT TObject obj from the examine’s temporary
/// file /
///
///@param objName the name of the object to retrieve
///@param obj ROOT object
///@param runType 0 for TrigSim. 1 for x13 data mode
///
///@return 1 if object with data is retrieved. 0 otherwise.
////////////////////////////////////////////////////////////////
int GetObject(string objName, TObject * &obj, int runType){
char rootFilePath[300];
char *type[] = { "trigsim", "x13" };
sprintf(rootFilePath, "/tmp/cttObjects_%s.root", type[runType]);
TFile *rootOutputFile = new TFile(rootFilePath, "READ");
if( ! rootOutputFile->IsOpen() ){
cout << "\n\nERROR: Could not open data file " << rootFilePath << ".\n\n";
cout << "Failed to retrieve "<< objName <<".\n\n";
return 0;
}
TList *list = (TList *)rootOutputFile->Get("ctt_examine");
cout<<list>GetEntries() <<" entries in "<<rootFilePath<<" ctt_examine TList . . ."<<endl>FindObject( objName.c_str() );
//rootOutputFile->Close();
//delete rootOutputFile;
if( obj ){
return 1;
}else{
cout<<"\nERROR: couldn't find ["<<objName.c_str()<<"] in "<<outputFilePath<<".\n"<<endl;
return 0;
}
}/// End of GetObject
////////////////////////////////////////////////////////////////[/code]