I’m trying to dump on a .root file some histograms created and filled in a program, but I’ve got this error:
Error in TROOT::WriteTObject: The current directory (root) is not associated with a file. The object (lambda_1) has not been written.
What does this mean? Could someone help me fixing the problem?
I’m adding the significant lines of code…
Sara
// useful histograms
TH1F * hlambda[30];
int iterNum = 10;
int main()
{
// init histograms
for(int i=0; i<iterNum; i++)
{
string name = “lambda_”;
name += i +‘0’;
hlambda[i] = new TH1F(name.c_str(),“lambda values”,1000,0.,0.02);
}
[…]
if(dump_root)
{
// *** Draw histograms just for sanity check and save them to file
fout = new TFile(“EM.root”,“recreate”);
for(int i=0; i<iterNum; i++)
{
hlambda[i]->Write();
fout->Close();
}
}
return 0;
}
I compile this code along with some classes I’m using, and link to ROOT libraries with the makefile in attachment. Then I just execute the executable “runEM”. No script is involved.
Let me know if you need more details.
Regards
Sara Makefile.txt (1.31 KB)
I do not want a Makefile. I need the shortest piece of R U N N I N G code reproducing the problem
Response time is proportional to the square of the number of lines of code :
Sorry for misunderstanding… here is the shortest piece of code, it does reproduce the error, but it gives segmentation fault too in the end… argh!
Let me know if you could help me…
Sara Makefile.txt (1.31 KB) test.c (1.18 KB)
Uhm! you should not close teh output file in the loop !!
Do:
if(dump_root)
{
// *** Draw histograms just for sanity check and save them to file
for(int i=0; i<iterNum; i++)
{
hlambda[i]->Write();
}
fout->Close();
}