In ROOT 5.20: -> Cannot create key without file

Hi,

When changing from ROOT 5.16 to 5.20 I get now some errors I didn’t get before.
I produced a short example macro:

{
  Int_t a, b, c;

  TTree *t = new TTree( "aname", "atitle" );
  t->Branch( "var_a", &a, "var_a/I" );
  t->Branch( "var_b", &b, "var_b/I" );
  t->Branch( "var_c", &c, "var_c/I" );
  
  for( int i=0; i<10; i++ ){
     a = i;
     b = i*2;
     c = i*4;
     t->Fill();
  }
  
  t->Print();
  
  TFile *f = TFile::Open( "mytestfile.root", "RECREATE" );
  t->Write();
  f->Close();
}

This code produces in ROOT 5.16 the following output:

root [0] 
Processing mytester.C...
******************************************************************************
*Tree    :aname     : atitle                                                 *
*Entries :       10 : Total =            2259 bytes  File  Size =          0 *
*        :          : Tree compression factor =   1.00                       *
******************************************************************************
*Br    0 :var_a     : var_a/I                                                *
*Entries :       10 : Total  Size=        668 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    1 :var_b     : var_b/I                                                *
*Entries :       10 : Total  Size=        668 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    2 :var_c     : var_c/I                                                *
*Entries :       10 : Total  Size=        668 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
root [1] .q

but in ROOT 5.20 I get additionally some errors when writing the TTree to a file:

root [0] 
Processing mytester.C...
******************************************************************************
*Tree    :aname     : atitle                                                 *
*Entries :       10 : Total =            2283 bytes  File  Size =          0 *
*        :          : Tree compression factor =   1.00                       *
******************************************************************************
*Br    0 :var_a     : var_a/I                                                *
*Entries :       10 : Total  Size=        676 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    1 :var_b     : var_b/I                                                *
*Entries :       10 : Total  Size=        676 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    2 :var_c     : var_c/I                                                *
*Entries :       10 : Total  Size=        676 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
Error in <TBasket::Create>: Cannot create key without file
Error in <TBasket::Create>: Cannot create key without file
Error in <TBasket::Create>: Cannot create key without file
root [1] .q

Can you point me to the error I made or what I have to change when moving to 5.20 respectively.

Thanks,
Peter

There are no changes in this area between 5.16 and 5.20. It is likely that when running with the new version you have already a file open in readonly mode an the tree (when created) is connected to the current dir. Simply change your code to:

[code]{
Int_t a, b, c;

TFile *f = TFile::Open( “mytestfile.root”, “RECREATE” );
TTree *t = new TTree( “aname”, “atitle” );
t->Branch( “var_a”, &a, “var_a/I” );
t->Branch( “var_b”, &b, “var_b/I” );
t->Branch( “var_c”, &c, “var_c/I” );

for( int i=0; i<10; i++ ){
a = i;
b = i2;
c = i
4;
t->Fill();
}

t->Print();

t->Write();
f->Close();
} [/code]

Rene

Hi,

I can reproduce the problem will provide a fix shortly. Rene’s work-around is the correct solution for the moment.

Cheers,
Philippe.

Hi,

This problem has been fixed in the head of the SVN trunk and in the v5.20 patch branch.

Note that the error message was somewhat spurrious and the resulting file was still containing all the TTree data.

Another work around is to use:

TFile *f = TFile::Open( “mytestfile.root”, “RECREATE” );
t->SetDirectory(f); // Work around
t->Write();
f->Close();

Cheers,
Philippe