gDirectory null in terminate after TProofOutputFile

Hello,

I’m trying to understand how to use TProofOutputFile to automatically handle the merging of worker output. I have got it working, but my current code is leaving my gDirectory set to 0 and this is preventing me doing various things in the Terminate step, where I might want to make some histograms or something (the constructors all fail…I think it’s because the gDirectory is 0). Could an expert quickly check this over and tell me if this is the correct way to do things…

SlaveBegin:

   fProofFile = new TProofOutputFile("dummyFile.root","M"); //'M' means merge the produced files
   fProofFile->SetOutputFileName("output.merge.root");

   if( !(fFile=fProofFile->OpenFile("RECREATE"))) {
      Warning("SlaveBegin","problem opening file: %s/%s",fProofFile->GetDir(),fProofFile->GetFileName());
   }
   //prepare output TTree
   eeTree = new TTree("eeTree","eeTree");
   eeTree->Branch("mybranch",&mybranch);
   eeTree->SetDirectory(fFile);
   eeTree->AutoSave();

eeTree is then filled as part of the Process.

SlaveTerminate:

   if(fFile) {
      if(eeTree->GetEntries()>0) { //only write the tree if it had entries
         fFile->cd();eeTree->Write();fProofFile->Print();fOutput->Add(fProofFile);
      }
      fFile->Close();
   }

Terminate:

  if(gDirectory) gDirectory->Print();
  else Error("Terminate","No gDirectory?"); //THIS GETS PRINTED!!!??

  TTree* myTree = new TTree("myTree","myTree"); //This Crashes

I think I’ve become muddled about what happens to the current directory during all this merging.

Thanks!

Hi,

This is weird.
Terminate is run on the client only, the other two methods on the workers, i.e. on completely independent processes.
Your way of doing looks fine.
Did you try to comment out the TProofOutputFile stuff and see what it does?

G. Ganis

If I comment out that stuff, the gDirectory appears to be valid, and it then the print command seems to result in the following:


*Tree :RateNtuple: Rate progress info *
*Entries : 7 : Total = 4243 bytes File Size = 0 *

???

After the processing, if I do .ls, I see the following:

[quote] OBJ: TNtuple RateNtuple Rate progress info : 0 at: 0x1b737370
OBJ: TNtupleD CircNtuple Circular progress info : 0 at: 0x1bf83220
OBJ: TTree myTree myTree : 0 at: 0x1ba78ce0
[/quote]

Ok, I see, this happens in PROOF-Lite and is due to a ‘feature’ of TFileMerger.
I am preparing a fix.
As workaround, add a TDirectory * member to your selector and assign it to gDirectory in Begin. You can then use that in Terminate.

G. Ganis

Thanks. That temporary fix does the trick. Glad I wasn’t doing something stupid with the TProofOutputFile.