OpenGATE / Gate

Official public repository of Gate
http://www.opengatecollaboration.org
GNU Lesser General Public License v3.0
232 stars 262 forks source link

segmentation fault when using SinglesDigitizer and ROOT output #647

Open bl0x opened 10 months ago

bl0x commented 10 months ago

I see a segfault when using a SinglesDigitizer together with ROOT output:

/usr/include/c++/13.2.1/bits/stl_vector.h:1125: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = GateHitTree*; _Alloc = std::allocator<GateHitTree*>; reference = GateHitTree*&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.

This originates from accessing the first element of m_treesHit in GateToRoot::RecordEndOfAcquisition(). However, m_treesHit is cleared in GateToRoot::RecordEndOfRun(), so the access fails and produces a segfault.

Perhaps clearing m_treesHit at the end of a run is not good in this case:

https://github.com/OpenGATE/Gate/blob/a1f0a36ab9d46a1396d718f0506497ddf42de498/source/digits_hits/src/GateToRoot.cc#L682

I am not sure about the sequence of which methods get called when, but I am reckoning that

RecordBeginOfAcquisiton() and RecordEndOfAcquisition()

are called on a greater scope compared to the

RecordBeginOfRun() and RecordEndOfRun()

methods.


This would imply, that when RecordEndOfAcquisition() is called, m_treesHit has been cleared from the last invocation of RecordEndOfRun().

Perhaps it is better to call m_treesHit.clear() right before the container is filled in RecordBeginOfRun().

kochebina commented 10 months ago

Dear Bastien,

Indeed I need to fix it! Could you, please, share your macros that I could reproduce the seg fault? (possible by email : kochebina at gmail dot com)

For the sequence it is: RecordBeginOfAcquisiton() RecordBeginOfRun() RecordBeginOfEvent() RecordBeginOfEvent() RecordEndOfRun() RecordEndOfAcquisition()

I started to clear m_treesHit in RecordEndOfRun() for the case when one wants to simulate several runs un the same aquisition. I'll check what to do with that

Cheers, Olga