Hello ROOT,
just another lost newbie here. I’m trying to access two TH1D histograms stored in two different root files within a function, but am having issues loading the root files from within the function. With the basic test code below, the root files are not loading correctly (only 18 bytes of over 2000 are loading).
`
void myFunction(string file1, string hist1, string file2, string hist2){
TFile *f = new TFile(file1.c_str(), “READ”); // opens the root file
TH1F *h1 = (TH1F *)f->Get(hist1.c_str());
TFile *g = new TFile(file2.c_str(), "READ"); // opens the root file
TH1F *h2 = (TH1F *)g->Get(hist2.c_str());
cout << h1->GetNbinsX() << endl;
cout << h2->GetNbinsX() << endl;
delete f;
delete g;
}
`
give errors:
Error in <TBufferFile::CheckByteCount>: object of class TNamed read too few bytes: 18 instead of 2540 Error in <TBufferFile::CheckByteCount>: object of class TNamed read too few bytes: 18 instead of 2540
Strangely, I notice that if I simply use GetBinCenter(someInt_t) at some point in the function, the root files load properly. The code below works…
`
void myFunction(string file1, string hist1, string file2, string hist2){
TFile *f = new TFile(file1.c_str(), “READ”); // opens the root file
TH1F *h1 = (TH1F *)f->Get(hist1.c_str());
TFile *g = new TFile(file2.c_str(), "READ"); // opens the root file
TH1F *h2 = (TH1F *)g->Get(hist2.c_str());
cout << h1->GetNbinsX() << endl;
cout << h2->GetNbinsX() << endl;
Double_t blah;
blah = h1->GetBinCenter(3);
delete f;
delete g;
}
`
I would greatly appreciate it if somebody could help me make sense of this!
best, jss