pbisio
March 14, 2023, 3:22pm
1
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:
Hi!
I have issues analyzing a tree with a friend tree using the RDF with ImplicitMT enabled. The reason seems to be that the trees are not saved in the same directory in the file. Here is a code which demonstrates the behavior:
#include <TROOT.h>
#include <ROOT/RDataFrame.hxx>
#include <ROOT/RVec.hxx>
#include <TNtuple.h>
#include <TFile.h>
void create_file()
{
// Setting up trees
auto f = TFile::Open("myfile.root", "RECREATE");
TNtuple* t = new TNtuple("main", "", "val");
TNtuple…
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 ,
pbisio:
//fout->cd();
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.
pbisio
March 14, 2023, 4:31pm
3
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
pbisio
March 15, 2023, 10:02am
5
Dear @vpadulan and @jalopezg ,
Thanks for your help, the code now works.
Cheers,
Pietro
1 Like
system
Closed
March 29, 2023, 10:02am
6
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.