Hi everyone, While trying to loop over all objects in a .root file (in order to dump all histograms at once), I seem to have an unexspected problem. The below code results in a 'segmentation fault' every second or third run. The problem has nothing to do with the assignment to currentObject because the commented line in the code does the same (apart from leaking...). Replacing GetObject() with GetKeyName() gives no problems, the iterator is fine and when it does run, the values that come out are right. I have looked through roottalks and tried debugging but I must be missing something, anybody have a clue? Thanks in advance, Jeroen { // Load the library we need for TFileIter gSystem->Load("libStar"); TObject* currentObject = NULL; TFile* inFile = new TFile("hsimple.root","READ"); TFileIter* iter = new TFileIter(inFile); Int_t nrOfObjects = iter->TotalKeys(); // Loop over all objects in inFile. for (iter->Reset(); (int)(*iter) < nrOfObjects; iter->SkipObjects()) { cout << "\ngoing to extract object #" << (int)(*iter) << "\n"; // cout << iter->GetObject() << "\n"; if (currentObject = (iter->GetObject())) { cout << "current object extracted\n"; }; if (currentObject) { currentObject->Delete(); }; }; // (End of object-loop.) if (inFile->IsOpen()) { inFile->Close(); }; delete inFile; };
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:07 MET