Dear Rooters,
I seem to have a memory leak problem while opening .root Files in a loop. Just opening and closing with TFile is not a problems but getting the Canvas from the respective TFile I can see how the virtual and the real memory are increasing with each loop. The error I am getting is the following:
Symbol G__exception is not defined in current scope /users/schultz/macros/MAGICIIReflectorPSF.C:73:
Error: type G__exception not defined FILE:/users/schultz/macros/MAGICIIReflectorPSF.C LIN
Here is the code I am using:
The aim is to retrieve a 2D histogram from a Subpad of a Canvas which I want to draw together with the histograms of the other .root Files in one new Canvas in a special way. I will also attach one of those .root files.
Thanks for your help.
Cornelia
[code]#include
#include
#include “TPaveStats.h”
#include “TCanvas.h”
#include “TStyle.h”
#include “TLatex.h”
#include “TH2F.h”
#include “TCanvas.h”
#include “TFile.h”
using namespace std;
void MAGICIIReflectorPSF()
{
int position[17][17]={145,128,111,94,77,60,43,26,9,162,179,196,213,230,247,264,281,
146,129,112,95,78,61,44,27,10,163,180,197,214,231,248,265,282,
147,130,113,96,79,62,45,28,11,164,181,198,215,232,249,266,283,
148,131,114,97,80,63,46,29,12,165,182,199,216,233,250,267,284,
149,132,115,98,81,64,47,30,13,166,183,200,217,234,251,268,285,
150,133,116,99,82,65,48,31,14,167,184,201,218,235,252,269,286,
151,134,117,100,83,66,49,32,15,168,185,202,219,236,253,270,287,
152,135,118,101,84,67,50,33,16,169,186,203,220,237,254,271,288,
153,136,119,102,85,68,51,34,17,170,187,204,221,238,255,272,289,
144,127,110,93,76,59,42,25,8,161,178,195,212,229,246,263,280,
143,126,109,92,75,58,41,24,7,160,177,194,211,228,245,262,279,
142,125,108,91,74,57,40,23,6,159,176,193,210,227,244,261,278,
141,124,107,90,73,56,39,22,5,158,175,192,209,226,243,260,277,
140,123,106,89,72,55,38,21,4,157,174,191,208,225,242,259,276,
139,122,105,88,71,54,37,20,3,156,173,190,207,224,241,258,275,
138,121,104,87,70,53,36,19,2,155,172,189,206,223,240,257,274,
137,120,103,86,69,52,35,18,1,154,171,188,205,222,239,256,273};
TCanvas *c0 = new TCanvas(“c0”,“PSF of MAGIC Reflector”,800,800);
gStyle->SetOptStat(0);
c0->SetFillColor(0);
c0->SetBorderSize(0);
c0->Divide(17,17,0,0);
listFile=string(“Files.txt”);
ifstream fCheck(listFile.c_str() );
if( !fCheck ) {
cout <<“Error opening " << listFile << " for input. Creating it!” << endl;
system(“ls mirror???.root > Files.txt”);
}
FILE *fpdata=fopen(“Files.txt”,“r”);
char line[15],file[15], pos[4];
int posx,posy,x,y;
while (fgets(line, 16, fpdata) != NULL) {
sscanf(line, “%s”,file);
strncpy(pos,&file[6],4);
pos[4] = ‘\0’;
sscanf(pos,"%d %d",&posx,&posy);
x=posx;
y=posy;
if(x<0)
{
x=TMath::Abs(x)+8;
}
if(y<0)
{
y=TMath::Abs(y)+8;
}
FILE *fp;
if ((fp=fopen(line,"r"))!=NULL) {
TString *string=new TString(line,15);
TFile *tfile= TFile::Open(*string,"R");
TCanvas *c1 = ( TCanvas*)tfile->Get("Data presentation");
TCanvas *c2 =(TCanvas*)c1->GetPrimitive("Data presentation_4");
TH2F *h2=(TH2F*)c2->FindObject("SBIG image cleaned and background corrected");
c0->cd(position[x][y]);
h2->GetXaxis()->SetAxisColor(0);
h2->GetXaxis()->SetLabelColor(0);
h2->GetXaxis()->SetLabelSize(0);
h2->GetXaxis()->SetNdivisions(0);
h2->GetYaxis()->SetAxisColor(0);
h2->GetYaxis()->SetLabelColor(0);
h2->GetYaxis()->SetLabelSize(0);
h2->GetYaxis()->SetNdivisions(0);
h2->DrawCopy("col");
c0->Update();
tfile->Close("R");
tfile->Clear();
tfile->DeleteAll();
delete h2;
delete c2;
tfile->Close("R");
tfile->Clear();
delete tfile;
gSystem->ProcessEvents();
c1->Clear();
c1->Close();
delete c1;
delete string;
fclose(fp);
}
}
}[/code]