I have made a root file of about 860 MB that contains many TH1s, TH2s, and THnSparse. I want to extract these THnSparse in another program I made in order to add them with other THnSparse I’ve made other places.
I only noticed an issue when I started running into segfaults part way through my 145 indexed loop (one loop (i) of 29 and a nested loop (j) of 5). I checked the original file I was reading from to make sure the THnSparse I was trying to pull from was there, and it was.
Upon further inspection, I found that this root file was having some problems when being read in. It said
Warning in <TFile::Init>: <FILENAME> probably not closed, trying to recover
and then would go through every TH1, TH2, and THnSparse present in the file saying that it recovered them at a given address.
I’ve looked at some other posts regarding issues with files not closing, but didn’t find anything that seemed relevant to me upon my reading of it.
(anything not explicitly defined I’ve already defined in my .hpp and if it’s supposed to have values I’ve already made and extracted them prior to this part of the code. I can include all of that if need be)
Here is how I’m reading these in
TFile *exp_tree_= new TFile(flags.Flags::Exp_File().c_str());
TFile *empty_tree_ = new TFile(flags.Flags::Empty_File().c_str());
TFile *hole_tree_ = new TFile(flags.Flags::Holes_File().c_str()); //This is the file I'm having problems with
for(int i=0; i<29; i++){
for(int j=0; j<5; j++){
sprintf(hname,"<exp hist name>",<relevant parameters>);
std::cout<<"extracting " <<hname <<"\n";
_exp_data_5d_pos[i][j] = (THnSparseD *)exp_tree_->Get(hname);
_empty_5d_pos[i][j] = (THnSparseD *)empty_tree_->Get(hname);
sprintf(hname, <THnSparse new name>",<relevant parameters>);
std::cout<<"making " <<hname <<"\n";
_N_5d_local_holes_pos[i][j] = (THnSparseD*)_exp_data_5d_pos[i][j]->Clone();
_N_5d_local_holes_pos[i][j]->SetNameTitle(hname,hname);
_N_5d_local_holes_pos[i][j]->Add(_empty_5d_pos[i][j],-flags_.Flags::Qr());//Empty target subtraction
_N_5d_local_holes_pos[i][j]->Divide(_acceptance_5d[i][j]);
sprintf(hname,"<hole name>",<relevant parameters>);
std::cout<<"adding " <<hname <<"\n";
_N_5d_local_holes_pos[i][j]->Add((THnSparseD *)hole_tree->Get(hname));
What happens is I will get to i=20 and j = 1. I’ll print that last cout saying “adding hname” and then hit a segfault.
I feel like whatever the issue is it’s very obvious, but I cannot see it. I’d also rather not restructure everything unless I know that will actually solve the issue, as that will take some time.
Thank you,
Chris
ROOT Version:_6.26.04
Platform:* macOS Ventura 13.0
Compiler:* g++