[quote=“brun”]Just move the statement “TH!f h” after the craetion of TFile.
Histograms are created in teh current directory.
Rene[/quote]
Hi Rene,
thank you for the fast answer.
I used to do it as you said, the code I sent
was only meant as an example.
Nevertheless: am I right that it should work
in principle ?
What I really would like to do is the following
// does not crash, but histograms do not
// get written to the file
// or with the SetDirectory statements
// crashes at exit
TFile *f = new TFile(“test.root”, “recreate” );
f->cd();
TH1D *h;
// with or without the constructor parameters
// seems anyway that cint ignores them
// but i tried also with a compiler
h = new TH1D[2](“t”, “t”, 1, 0, 1 );
h[0]->SetName(“t1”);
h[1]->SetName(“t2”);
f->ls();
// they were not created in the
// current directory, although I
// expected it
h[0]->SetDirectory( &f );
h[1]->SetDirectory( &f );
f->ls();
//now they are in the current directory
Hi Rene,
thanks for your really fast help.
It works fine as you said.
I still did not quite understand why
the other thing was wrong
but since it works …