Crash occurs when GetEntry is used from a second file

Dear rooters,
I have a code based on MakeClass, the code is designed to access a tree from a root file that has many trees,
I would like to access and process a second tree that contains few events to get a number, so in Notify function
vector *PDF4LHC15 = nullptr;
TTree inputtree = nullptr;
input->GetObject(“PDFsumWeights”, inputtree);
", 0);
inputtree->SetBranchStatus(“PDF4LHC15_nlo_30”, 1);
inputtree->SetBranchAddress(“PDF4LHC15_nlo_30”, &PDF4LHC15);
int lastEntry = inputtree->GetEntries();
for (int iEvent = 0; iEvent < lastEntry; ++iEvent) {
Long64_t ientry = inputtree->LoadTree(iEvent);
if (ientry < 0) {

//the following to extract a useful number
// if (Normalization.size() == 0) {
// Normalization.resize(PDF4LHC15->size());
// }
// for (size_t i = 0; i < PDF4LHC15->size(); i++) {
// Normalization[i] += (*PDF4LHC15)[i];
// cout << Normalization[i] << " ";
// }
PDF4LHC15 = nullptr;
inputtree = nullptr;
input = nullptr;
delete PDF4LHC15;
delete inputtree;
delete input;

return kTRUE;

The code compiles and works fine for one root file. However when it access the second root file it crashes and the crash occurs exactly at
If I comment this line it runs without problem but the code turns useless.
Any idea how to solve this problem.


When a TTree changes files, the branch address is invalidated due to the change of TDirectory when you change files. In order to use more than one file, you probably need to use a TChain instead.

I cannot use TChain because I have one file at the time.
In addition, you can look at the code and see that I redefine the vector and I connect to the branch every time the Notify function is called.

I found the problem :relieved:
simply I have to comment line
input = nullptr;
and then use
input->Close() instead

Ok, nice that you found a solution!

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