|
Celeritas 0.7.0-3+develop.835656ac1
|
Receive notifications when the Geant4 application state changes. More...
#include <StateDependent.hh>

Public Types | |
| enum class | Mode { raw , lifecycle } |
| How to dispatch Geant4 state changes. | |
| enum class | LifecycleRole { global , local } |
| Lifecycle cleanup scope owned by this monitor. | |
Public Member Functions | |
| StateDependent (LocalGeantStateChangeFunc cb, Mode mode, LifecycleRole lifecycle_role) | |
| Construct with a stream ID and state-change callback. | |
| StateDependent (LocalGeantStateChangeFunc cb) | |
| Construct locally in raw mode with a state-change callback. | |
| StateDependent (StateDependent const &)=delete | |
| StateDependent & | operator= (StateDependent const &)=delete |
| StateDependent (StateDependent &&)=delete | |
| StateDependent & | operator= (StateDependent &&)=delete |
| G4bool | Notify (G4ApplicationState state) final |
| Handle a Geant4 state transition notification. | |
| StreamId | local_stream () const |
| Stream that created this state dependent. | |
Receive notifications when the Geant4 application state changes.
This thread-local wrapper observes Geant4 application state transitions and calls a shared user-provided function for the creating stream. Raw mode dispatches every encoded state transition; lifecycle mode dispatches the filtered run lifecycle used by automatic Celeritas setup.
G4StateManager singleton keeps a pointer (via the G4VStateDependent base constructor) to this local instance and calls delete on it when it's deleted as the run manager shuts down. Therefore this class must be deleted before G4StateManager ends.G4StateManager without checking for validity, so the destructor of this class after deleting the run manager will also crash the code.To bypass the first failure path, we use Notify to deregister ourselves when we see the run manager is about to exit or abort.
The owner must keep the instance on the creating thread and callbacks must not delete the active state-dependent object. In lifecycle mode this object should be owned explicitly, similarly to Geant4 UI messenger objects.
In Mode::lifecycle this class filters raw Geant4 state changes into the lifecycle transitions needed by Celeritas automatic setup: begin_run, end_run, and end_program.
| celeritas::StateDependent::StateDependent | ( | LocalGeantStateChangeFunc | cb, |
| Mode | mode, | ||
| LifecycleRole | lifecycle_role | ||
| ) |
Construct with a stream ID and state-change callback.