Creating TDirs in a rootfile via a cycle

Hi,
I am using pyroot and I want to:

  • open an output file
  • on a loop: open a TDirectory with a name defined in the loop, write in it
  • save the file

All the TDris have to be at the same level, in the file.

Can you send me a scratch of code to do this? I am doing:

outfile = ROOT.TFile(outputdir + folder.split("/")[-1],"RECREATE")
for basename in basenames:
    TDir = ROOT.TDirectory(basename, "")
    TDir.Write()
outfile.Write()
outfile.Close()

but I in the end do not see the TDirs in the file. Am I doing something wrong?

Thanks, Giovanni


ROOT Version: 6.24/08


You meant:

outfile = ROOT.TFile(outputdir + folder.split("/")[-1],"RECREATE")
for basename in basenames:
    TDir = outfile.mkdir(basename)
outfile.Write()
outfile.Close()

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.