EnableImplicitMT & Ttree AddFriend

Hi,

In running this code:

void test(){
  //TH1::AddDirectory(kFALSE);
  ROOT::EnableImplicitMT();
  std::unique_ptr<TFile> inf( TFile::Open("ifile.root"));
  TTree *tcrs = inf->Get<TTree>("poker_crs");
  TTree *thcal= inf->Get<TTree>("poker_hcal");
  tcrs->AddFriend(thcal,"hcal");
  ROOT::RDataFrame d(*tcrs);
 

  auto h1 = d.Histo1D("dene");
  auto h2 = d.Histo1D("hcal.dene");
  
  TFile *fout=new TFile("ofile.root","recreate");  

  //fout->cd();
  //fout->mkdir("mydir");
  
  h1->Write();
  h2->Write();
  
  //gDirectory->pwd();
  fout->Close();

}

I encountered this error:

Error in TROOT::WriteTObject: The current directory (Rint) is not associated with a file. The object (dene) has not been written.
Error in TROOT::WriteTObject: The current directory (Rint) is not associated with a file. The object (hcal.dene) has not been written.

You can find the ifile.root file here: CERNBox
I have noticed that If I remove line 3 “ROOT::EnableImplicitMT();” the code works.

It seems similar to what was reported in:

https://sft.its.cern.ch/jira/browse/ROOT-10152
But this problem should have been fixed for the ROOT version (6.24/06) that I use.

Do you have any advice or suggestions?

Thanks,
Pietro


ROOT Version: 6.24/06
Platform: Linux CentOS7
Compiler: gcc (GCC) 11.2.0


Hi @pbisio,

Is there any reason why the quoted line is commented out? Alternatively, you should be able to replace the Write() calls on h1 and h2 by:

  fout->WriteObject(h1, "h1");
  fout->WriteObject(h2, "h2");

Cheers,
J.

Dear @jalopezg ,

The quoted line is commented out because I was trying to make some changes.
Even if I add it to the code I get the same error I reported.

I have tried to replace the Write() command with WriteObject() but I find these errors:

Thanks!
Cheers,
Pietro

Dear @pbisio ,

Please try by actually passing a TH1D* to the function, as the error suggests:

fout->WriteObject(h1.GetPtr(), "h1");

See the RResultPtr docs

Dear @vpadulan and @jalopezg,
Thanks for your help, the code now works.
Cheers,
Pietro

1 Like

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