RootTalk


ROOT Discussion Forums

Subdirectories

Discuss installing and running ROOT here. Please post bug reports here.

Moderator: rootdev

Subdirectories

Unread postby cmosquer » Fri Feb 15, 2013 22:49

Hello
I am trying to create a subdirectory ( a directory inside another directory) and write data to it. I am not sure what i am doing wrong:

Code: Select all
  TFile *file = fChain->GetCurrentFile();

  file->cd();
  file->mkdir("Thermal/");
  file->cd("Thermal/");
  AnalysisResultTuple.Write("",TObject::kOverwrite);

  file->cd();
  file->mkdir("Thermal/Zdepth");
  file->cd("/Thermal/Zdepth/");
  thermal_depthSlicesHist->Write("",TObject::kOverwrite);
  thermal_depthSliceEkinHist->Write("",TObject::kOverwrite);
  thermal_depthSliceEdepHist->Write("",TObject::kOverwrite);



Using a TBrowser, files are not written in the proper subdirectory. They are written at the file.root:/ level directory. What am I doing wrong??

Thxs,
cmosquer
 
Posts: 138
Joined: Tue May 01, 2007 18:34

Re: Subdirectories

Unread postby Wile E. Coyote » Fri Feb 15, 2013 23:05

Right before doing "Something->Write(...);", try to call "Something->SetDirectory(gDirectory);"
Wile E. Coyote
 
Posts: 469
Joined: Sun Sep 30, 2012 10:50

Re: Subdirectories

Unread postby cmosquer » Sat Feb 16, 2013 0:45

Great Thanks. However, TObjArrays do not have that method? Is there any other way to set the directory before writing objects?
cmosquer
 
Posts: 138
Joined: Tue May 01, 2007 18:34

Re: Subdirectories

Unread postby Wile E. Coyote » Sat Feb 16, 2013 1:39

I'm afraid you need to loop over all objects from your TObjArray and for each of them call "SetDirectory(gDirectory)".

Maybe a better solution would be to make sure that all histograms are "associated" with "gROOT" or with "nothing" at their creation time. Before you call "new Something(...)", make sure that you "gROOT->cd();", or after you call "new Something(...)" make sure that you call "SetDirectory(gROOT)" or "SetDirectory(0)" for this newly created object.
You could also execute the static method TDirectory::AddDirectory(kFALSE); in advance, before you create any histograms (then there's no need to call "SetDirectory(0)" for them).
Wile E. Coyote
 
Posts: 469
Joined: Sun Sep 30, 2012 10:50


Return to ROOT Support

Who is online

Users browsing this forum: No registered users and 2 guests