#include "TFile.h" #include "TKey.h" #include "TSystem.h" Int_t loadRecursive(TDirectory *); TFile *loadFileContent(const char *fn) { // Initial memory usage ProcInfo_t pi0; gSystem->GetProcInfo(&pi0); // Open the file TFile *f = TFile::Open(fn); if (!f || f->IsZombie()) { SafeDelete(f); return (TFile *)0; } // Load recursively Int_t nobj = loadRecursive(f); // Final memory usage ProcInfo_t pi1; gSystem->GetProcInfo(&pi1); // Notify Printf("Footprint of file content (%d objects loaded): %ld kB (res), %ld KB (virt)", nobj, pi1.fMemResident - pi0.fMemResident, pi1.fMemVirtual - pi0.fMemVirtual); // Done return f; } Int_t loadRecursive(TDirectory *d) { // Recursive load of the content of d. // Return number of objects read Int_t no = 0; TIter nxk(d->GetListOfKeys()); TKey *k = 0; while ((k = (TKey *) nxk())) { TClass *cl = TClass::GetClass(k->GetClassName()); if (cl->InheritsFrom("TDirectory")) { TDirectory *dr = (TDirectory *) k->ReadObj(); no += loadRecursive(dr); } else { k->ReadObj(); no++; } } // Done return no; }