Hi there,
I wanted to know if there is a method to persistently keep objects in memory after reading from a TFile, so that the TFile can be closed.
As an example, my current code is as below (there is a global TChain called T1). When I try to get the file (in GetCutList) after having saved it (with SaveCutList), the routine crashes on the line where I try to use TEventList::GetN() immediately after closing the file.
void SaveCutList(TCut cuttosave, bool append, string filename) {
TEventList * eventsfrom = new TEventList("eventsfrom", "eventsfrom");
T1->Draw(">>eventsfrom", cuttosave);
string openopt = append ? "UPDATE": "RECREATE";
TFile fs(filename.c_str(), openopt.c_str());
fs.SetCompressionLevel(0);
eventsfrom->Write(cuttosave.GetName(),TObject::kOverwrite);
fs.Close();
delete eventsfrom;
}
TEventList * GetCutList(TCut cuttoget, string filename) {
TEventList * returnlist(0);
TFile * fs = new TFile(filename.c_str(), "READ");
if (fs->IsZombie()) {
cout <<"Could not find file: " << filename <<endl;
return returnlist;
}
TList * klist = fs->GetListOfKeys();
if (klist->Contains(cuttoget.GetName())) {
returnlist = new TEventList("eventsfrom","eventsfrom");
returnlist->Read(cuttoget.GetName());
}
else cout << "Could not find list!" << endl;
cout << "Try 1 " << returnlist->GetN() << endl;
fs->Close();
cout << "Try 2 " << returnlist->GetN() << endl;
return returnlist;
}
Any help would be appreciated.