Alexis,
When closing the file, all objects in memory associated with this file (in
your case, tree and tree2) are automatically deleted.
In your case, you could do:
tree=(TTree*)tree2->Clone();
tree->SetDirectory(0); //<<<<<<<<<
delete tree2;
f->Close();
and the statement
entries=tree->GetEntries();
cout << entries << endl;
will work because the number of entries is stored in the TTree header object in
memory.
However, you will not be able to do:
tree->GetEntry(..);
because the file will not be available anymore.
Rene Brun
Mignon Alexis wrote:
>
> Hi,
>
> I've probleme with the TTree::GetEntries() method.
> In the following code, _entries_ is set to nan.
>
> TFile *f;
> TTree *tree,*tree2;
>
> double entries;
>
> f= new TFile("path to file");
> tree2=(TTree*)f->Get(hname);
> tree=(TTree*)tree2->Clone();
> delete tree2;
> f->Close();
>
> entries=tree->GetEntries();
> cout << entries << endl;
>
> Does anyone have an idea ? Could it be a compilator problem ?
>
> --
> Alexis Mignon
> GANIL
> Bd Henri Becqurel
> 14076 CAEN Cedex 5
> France
> tel: +(33) (0)231454680
> e-mail : mignon@ganil.fr
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:42 MET