-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Protect against failed cast #162
Conversation
I would say that in the interactive mode there is no need to use |
What we could do is, instead of adding a protection, adding a meaningful error message and let the program crash. |
Agree. What do you think about placing such an error before the |
I don't like it vey much, I would prefer to keep the code in the |
@gondiaz, what about this PR? Are you going to add the comment to the crash or shall we close it? |
At least not in the next two weeks |
This doesn't answer my question :-). |
The answer is yes then, but I don't know when. |
It's not annoying, I just want to know if you forgot about it or you are going to finish it at some point. |
91e01c5
to
54b53fe
Compare
source/actions/DefaultEventAction.cc
Outdated
// but the trajectories will not cast to Trajectory | ||
Trajectory* trj = dynamic_cast<Trajectory*>((*tc)[0]); | ||
if (trj == nullptr){ | ||
G4Exception("[DefaultEventAction]", "EndOfEventAction", FatalException, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the nexus convention, the second argument of G4Exception
should be the function, so ()
should be added.
source/actions/DefaultEventAction.cc
Outdated
Trajectory* trj = dynamic_cast<Trajectory*>((*tc)[0]); | ||
if (trj == nullptr){ | ||
G4Exception("[DefaultEventAction]", "EndOfEventAction", FatalException, | ||
"Adequate TrackingAction not registered for DefaultEventAction"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say explicitly which one is the correct action, something like "DefaultTrackingAction is required when using DefaultEventAction".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR adds a useful error message when DefaultTrackingAction
is not used together with DefaultEventAction
. Approved!
In interactive mode, you might want to use DefaultEventAction without DefaultTrackingAction. Since you are in interactive mode, Geant4 will provide a not empty
G4TrajectoryContainer
, which is a vector ofG4VTrajectory
. The dowcast fails sinceTrajectory
is a nexus class.