actions
Loading...
Searching...
No Matches
gaction.cc
Go to the documentation of this file.
1// gemc
2#include "gaction.h"
5#include "run/gRunAction.h"
8#include "gparticle_options.h"
9
10// Construct the action initializer and keep shared services available for later
11// action registration on worker and master execution contexts.
12GAction::GAction(std::shared_ptr<GOptions> gopts,
13 std::shared_ptr<gdynamicdigitization::dRoutinesMap> digi_map) :
14 GBase(gopts, GACTION_LOGGER),
15 goptions(std::move(gopts)),
16 digitization_routines_map(std::move(digi_map)),
17 sharedParticles_(std::make_shared<std::vector<GparticlePtr>>(
18 gparticle::getGParticlesFromOption(goptions, log))) {
19
21
22}
23
24
25// Register the master-thread actions.
26// In GEMC, the master needs only the run action because it does not execute
27// primary generation or per-event processing.
30
31 SetUserAction(new GRunAction(goptions, digitization_routines_map));
32}
33
34// Register the worker-thread actions.
35// Workers execute the full event lifecycle, so they need the primary generator,
36// the run action, and the event action.
37void GAction::Build() const {
38 const auto thread_id = G4Threading::G4GetThreadId();
39
40 log->debug(NORMAL, FUNCTION_NAME, "thread id: " + std::to_string(thread_id));
41
42 // Primary generation is event-scoped and therefore worker-owned.
43 SetUserAction(new GPrimaryGeneratorAction(goptions, sharedParticles_));
44
45 // The run action is shared conceptually across the worker-thread lifecycle and
46 // is passed to the event action so event processing can access run services.
47 auto* run_action = new GRunAction(goptions, digitization_routines_map);
48 SetUserAction(run_action);
49
50 std::shared_ptr<GTrackProvenance> track_provenance;
51 const bool save_ancestors = goptions->getSwitch(SAVE_ALL_ANCESTORS_SWITCH);
52 if (goptions->getSwitch(SAVE_ORIGINAL_TRACK_SWITCH) || save_ancestors) {
53 track_provenance = std::make_shared<GTrackProvenance>(save_ancestors);
54 SetUserAction(new GTrackingAction(track_provenance));
55 }
56
57 // The event action consumes the run action as a non-owning dependency.
58 SetUserAction(new GEventAction(goptions, run_action, track_provenance));
59}
GAction(std::shared_ptr< GOptions > gopts, std::shared_ptr< gdynamicdigitization::dRoutinesMap > digi_map)
Constructs the action initializer used by the Geant4 run manager.
Definition gaction.cc:12
void Build() const override
Registers the user actions required by worker threads and sequential execution.
Definition gaction.cc:37
void BuildForMaster() const override
Registers the user actions required by the master thread.
Definition gaction.cc:28
std::shared_ptr< GLogger > log
Handles event begin/end callbacks, hit digitization, and event-level publication.
void debug(debug_type type, Args &&... args) const
Generates the primary vertices for each Geant4 event.
Handles run begin/end callbacks and creates the thread-local GRun object.
Definition gRunAction.h:67
Records initial track provenance for one Geant4 worker.
Declares GEventAction, the per-event processing action for the GEMC actions module.
constexpr const char * SAVE_ORIGINAL_TRACK_SWITCH
constexpr const char * SAVE_ALL_ANCESTORS_SWITCH
Declares GPrimaryGeneratorAction, the primary-particle generation action for the GEMC actions module.
Declares GRunAction, the run-lifecycle action for the GEMC actions module.
Declares GAction, the Geant4 action-initialization entry point for the GEMC actions module.
constexpr const char * GACTION_LOGGER
Definition gaction.h:29
#define FUNCTION_NAME
CONSTRUCTOR
NORMAL
std::shared_ptr< Gparticle > GparticlePtr