Class persistency

Dear support, I have a class, histoManager, (that owns histograms and maps of pointers to those histograms) that is made persistent with the following mechanism:

treeOut = new TTree("HManagerTree","Example of a class persistency"); branch = treeOut->Branch("hM", "HManager",&histoManager,bufsize,split); treeOut->Fill() ; TFile * fileOut = new TFile("temp.root","RECREATE") ; treeOut->Write(); fileOut->Close() ; delete fileOut ; delete treeOut ;

Then I read back the file by restarting the program from scratch: if i do it once, there is no problem, I can access all my histograms. If, however, I read it twice in a row, the second time I get a crash. Here is how I do it:

if(fileIn != NULL) { fileIn->Close(); delete fileIn; if(histoManager != NULL) { delete histoManager; } } fileIn = new TFile(fileName.c_str(),"READ") ; (TTree*)fileIn->Get(...)" << endl ; treeIn = (TTree*)fileIn->Get("HManagerTree") ; branch = treeIn->GetBranch("hM") ; branch->SetAddress(&histoManager) ; int entries = treeIn->GetEntries() ; for(int i=0; i<entries; i++) { entry += treeIn->GetEntry(i); }

I call this snippet of code two times: the first time the file is not yet open, the first if statement is not executed and everithing is fine. The second time, the file is already open, I close it and clean up my histoManager class. Since closing the file deletes references to histograms in it, in the destructor of histoManager I take care of clearing the stl maps and vectors that contain pointers to histograms (which are now dangling).

The crash happens with the following traceback during the call to treeIn->GetEntry(i):

*** Break *** segmentation violation Generating stack trace... 0x03432f13 in TClass::Destructor(void*, bool) + 0x57 from /usr/local/root/lib/ 0x03370c49 in TBuffer::ReadFastArray(void**, TClass const*, int, bool, TMemberStreamer*) + 0x8f from /usr/local/root/lib/ 0x03450936 in int TStreamerInfo::ReadBuffer<char**>(TBuffer&, char** const&, int, int, int, int) + 0x330e from /usr/local/root/lib/ 0x00c9ec9b in TBranchElement::ReadLeaves(TBuffer&) + 0xd0b from /usr/local/root/lib/ 0x00c93810 in TBranch::GetEntry(long long, int) + 0x260 from /usr/local/root/lib/ 0x00c9d1ae in TBranchElement::GetEntry(long long, int) + 0x13e from /usr/local/root/lib/ 0x00c9d14c in TBranchElement::GetEntry(long long, int) + 0xdc from /usr/local/root/lib/ 0x00ccc102 in TTree::GetEntry(long long, int) + 0x98 from /usr/local/root/lib/ 0x00a435e1 in Persistency::readHistograms(std::basic_string<char, std::char_traits<char>, std::allocator<char> >) at src/Persistency.cpp:126 from /raid2/users/menasce/renaissance/hManager/lib/ 0x0804b026 in main + 0x5f6 from ./testRealHManager 0x03f38770 in __libc_start_main + 0xf0 from /lib/tls/ 0x0804a9a1 in Persistency::Persistency[in-charge]() + 0x31 from ./testRealHManager Abort (core dumped)

Hope this is sufficient to get some help. Thanks in advance, Dario Menasce

after “delete histoManager”, set “histoManager = 0;”.
Cheers, Axel.