TFile::GetDirectory() in ROOT v4


In my standalone code, which is linked against ROOT 5.13/03, I create a new file, get a pointer to the file directory and then create subdirectories in the file a la:

fout = new TFile("outfile_histograms.root","RECREATE");
TDirectory *dir = fout->GetDirectory("");

TDirectory *dir_ntag0 = dir->mkdir("NTag0");
TDirectory *dir_ntag1 = dir->mkdir("NTag1");
TDirectory *dir_ntag2 = dir->mkdir("NTag2");

However, I also need to link my program against ROOT 4.04/02b, and in that version TFile has no member GetDirectory(). What would be the corresponding procedure that works in both ROOT versions?

Thank you very much,


Easy. Simply replace the line:


fout->cd(""); or concrete path in file TDirectory *dir = gDirectory;

Note that you do not need to cd("") or Get(""). These are just dummy calls inside the current dir.