#include #include #include #include #include void LeakMemory(const char *fname = "/afs/cern.ch/user/c/clantz/public/ZDCBeamTestRun171.root") { if (!(fname && fname[0])) return; // just a precaution TFile *f = TFile::Open(fname); if ((!f) || f->IsZombie()) { delete f; return; } // just a precaution TTree *tree; f->GetObject("tree", tree); if (!tree) { delete f; return; } // just a precaution // I have 20 branches of vectors that I care about in my tree, 20 that I don't unsigned int nCh = 20; std::vector< std::vector* > pvWF; pvWF.resize(nCh, 0); // make sure all pointers are "initialized" tree->SetBranchStatus("*", 0); for(unsigned int ch = 0; ch < nCh; ch++) { tree->SetBranchStatus(Form("RawSignal%d", ch), 1); tree->SetBranchAddress(Form("RawSignal%d", ch), &pvWF[ch]); // if (!pvWF[ch]) std::cout << Form("Warning: branch RawSignal%d not found.", ch) << std::endl; } MemInfo_t memInfo; for(Long64_t ev = 0; ev < tree->GetEntries(); ev++) { tree->GetEntry(ev); if(ev%100 == 0) { gSystem->GetMemInfo(&memInfo); std::cout << "\r" << std::left << Form("Event %5lld, RAM: %5.1f / %5.1f GB", ev, (double)memInfo.fMemUsed/1024, (double)memInfo.fMemTotal/1024) << std::flush; } } std::cout << std::endl; delete f; // automatically deletes the "tree", too for(unsigned int ch = 0; ch < nCh; ch++) delete pvWF[ch]; // "cleanup" }