TDirectory?

Dear Rooters

I am just reading the new release notes of root 5.12/02 with warnings regarding io directory.

The ROOT documents have always compared TFile with a UNIX directory, where you can create
directories and subdirectories. Since TDirectory is now declared to be an abstract class,
does this mean that all applications creating subdirectories in TFile will break and be
backward incompatible???

For example, in my application I am creating a directory in the following way:

      TDirectory *dir = fFile->GetDirectory(setname);
      if (!dir) fFile->mkdir(setname, fType);
      fFile->cd(setname);

I suppose this code will break and be backward incompatible. Is this correct?

Furthermore, I have often the follwing code:

   TDirectory *savedir = gDirectory;

   //do something

   savedir->cd();

This will break, too??

Maybe, calling the abstract directory “TBaseDirectory” and deriving “TDirectory” from
"TBaseDirectory" would have avoided these problems?

Best regards
Christian

Wrong! The code you show will continue to work.
Only in case you have a call like “new TDirectory”, you have to replace it
by “new TDirectoryFile”. Same for TBuffer.

Rene

Dear Rene

Thank you for this fast clarification, now I understand what the release notes say:
Only, if you create your own directory by calling “new TDirectory”, you have to change your code.

Best regards
Christian

Hi Christian,

Independently of the changes that were recently made, you should consider replacing (or using in future code):

TDirectory::TContext ctxt(0); // or directory you want to cd toinstead of using your savedir pattern. This new syntax insure that the savedir->cd() is always done when you exit the scope (aka you will never forgot to add it when you add a new return statement to your functions.

Cheers,
Philippe.

Dear Philippe
Thank you for this tip.
Christian