I try to get a TH2D named “Bh2_Deta_Dphi_%d” from a root file.
However, it failed and get a warning that null passed to a callee that requires a non-null argument [-Wnonnull]
Strangely, for the TH2D name “Sh2_Deta_Dphi_%i”, it works.
I posted the codes and corresponding input root file.
Looking forward to your help.
In the code you uploaded what doesn’t work is actually the Sh2 part, but not because of the name; you are trying to Add to h2S[i] when it has not been created, unlike h2B[i]. This works, for instance:
for(int k=0; k<nfile; k++){
h2S[k] = new TH2D(Form("h2S_%d",k), Form("h2S_%d", k), 100,-1.6,1.6,200,-1.5,2.*PI-1.5);
h2B[k] = new TH2D(Form("h2B_%d",k), Form("h2B_%d", k), 100,-1.6,1.6,200,-1.5,2.*PI-1.5);
}
Sorry for my ignore. Actually, In the original version, h2S[i] also has been created.
I checked the code, and find the problem will occur when the code like
below: sprintf(finName,"%s/result_%s.root", chose1[ic], chose2[ic]); fin[ic] = new TFile(finName,"READ");
When I try to change into fin[ic] = new TFile(Form("%s/result_%s.root", chose1[ic], chose2[ic]),"READ"); or
fin[ic] = TFile::Open("./file.root");
`
The problem will be resolved.
I am not sure where the problem coming from?
There is something different?
or become the write and read of root file, I use the
different version, I used the 5.34 version to write root file,
and 6.22 to read.
sprintf(finName,"%s/result_%s.root", chose1[ic], chose2[ic]);
fin[ic] = new TFile(finName,"READ");
doesn’t work but
fin[ic] = new TFile(Form("%s/result_%s.root", chose1[ic], chose2[ic]),"READ");
works, then I guess that finName results in a wrong filename in the first case.
You could print it to check what its value is. You should also check the value of fin[ic].IsZombie(): if it’s true, the file was not opened correctly.
The problem does not seem to be related to the ROOT version used.