Eddy,
I have modified your second macro. You should not do file->Get("dir").
Simply change the directory. Deleting the file containing the Tree
will also delete the Tree object from memory.
Rene Brun
{
for (Int_t i=1; i >0; i++)
{
TFile *hfile = new TFile("foo.root","READ");
hfile->cd("dir");
TTree *tree = (TTree*) dir->Get("T");
Int_t tmp;
tree->SetBranchAddress("B",&tmp);
tree->GetEvent(0);
printf("i tmp = %d %d\n",i,tmp);
delete hfile;
}
}
> {
> gROOT->Reset();
>
> Int_t split = 0;
> Int_t bsize = 32000;
>
> TFile *hfile = new TFile("foo.root","RECREATE");
>
> TDirectory *dir = hfile->mkdir("dir");
> dir->cd();
>
> TTree *tree = new TTree( "T", "this is a tree" );
>
> Int_t tmp = 100;
> TBranch *branch = tree->Branch("B",&tmp,"tmp/I",bsize);
> tree->Fill();
>
> hfile->Write();
> hfile->Close();
> delete hfile;
> }
>
> {
> for (Int_t i=1; i >0; i++)
> {
> TFile *hfile = new TFile("foo.root","READ");
> TDirectory *dir = (TDirectory *) hfile->Get("dir");
> dir->cd();
>
> TTree *tree = (TTree*) dir->Get("T");
>
> Int_t tmp;
> tree->SetBranchAddress("B",&tmp);
> tree->GetEvent(0);
> printf("i tmp = %d %d\n",i,tmp);
>
> delete tree;
> delete dir;
> hfile->Close();
> delete hfile;
> }
> }