Made many methods const
, GetTrack, GetHits methods now return a constant reference
#41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently very few methods in the framework are marked as
const
. I have tried in the past to make the methods related to the event / track / hits const but its impossible unless you basically make all of them const, since they call each other multiple times, especially methods such asGetTrack
etc. This is also why this PR is very large.This PR makes the necessary changes in Geant4Lib so that the getters on
TRestGeant4Event
,TRestGeant4Track
andTRestGeant4Hits
are marked asconst
.In order to do this I had to also modify:
I only had to introduce a significant change to the framework: methods such as
TRestGeant4Event::GetTrack
orTRestGeant4Track::GetHits
now return a constant reference. Previously they returned a pointer, but this is incompatible with having all getters marked asconst
and it makes little sense in my opinion.This means that before you wrote:
TRestGeant4Track* event.GetTrack();
and now you write:
TRestGeant4Track event.GetTrack();
in 99% of usage its not necessary to modify this returned track, as you generally use it for analysis. I only found one instance where its necessary to modify it, on the
restG4
package. I created the methodTRestGeant4Event::GetTrackPointer
which works as the previousGetTrack
to solve this issue.