The pointer to a tree becomes invalid in the middle of a program

CheckCurrent.C (1.6 KB)

I have a bash file to run this code for multiple root files one by one. It works normally for a long list of root files, but then it would crushed for a roof file which used to return correct values. The error message is:

CheckCurrent.C:32:9: warning: invalid memory pointer passed to a callee:
T->GetEntry(beamup->GetEntry(ii));
^

Before this line, all the values from the T tree are reasonable. Any idea why this happened?
Thanks!


_ROOT Version: root 6
_Platform: RedHat
_Compiler: C


Could you split it in two lines and check the validity of beamup's and T's files before and after both GetEntry calls?

auto bu_value = beamup->GetEntry(ii);
T->GetEntry(bu);

It could be that somehow a TFile that should stay open is closed too early.

I’m not sure how to check the validity of these, so I cout the pointers’ addresses. The program could run successfully with the fixed pointers’ address. Even after I comment the cout, it works normally…No idea how it fixed itself…

Well, the same issue shows up for the other root file…

You should check the validity of their respective files, not of the pointers themselves: I suspect somehow a TFile that should stay open is closed too early.

Alternatively: try to remove as many code lines as possible and to do at most one function call per line while keeping the issue, and then post here the minimal reproducer and a file that we can run the reproducer on, so we can check out what’s wrong.

Cheers,
Enrico

I found the bug in my code which leads to this error. It’s because the numbers saved in Current[] is out of array index. Thanks for your attention!

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