Skip to content

Commit 6f39f4f

Browse files
committed
testing changes - mostly doxygen updates
1 parent bad73d7 commit 6f39f4f

17 files changed

Lines changed: 554 additions & 101 deletions

actions/event/gEventAction.cc

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "gEventAction.h"
2+
#include "actions/gactionConventions.h"
23

34
// geant4
45
#include "G4EventManager.hh"
@@ -11,45 +12,66 @@ GEventAction::GEventAction(const std::shared_ptr<GOptions>& gopt, GRunAction* ru
1112
GBase(gopt, EVENTACTION_LOGGER),
1213
goptions(gopt),
1314
run_action(run_a) {
15+
// Constructor: store shared config and a non-owning pointer to the run action for this thread.
1416
auto desc = "GEventAction " + std::to_string(G4Threading::G4GetThreadId());
1517
log->debug(CONSTRUCTOR, FUNCTION_NAME, desc);
1618
}
1719

1820
void GEventAction::BeginOfEventAction([[maybe_unused]] const G4Event* event) {
21+
// Begin-of-event hook: logs event id and thread id for tracing.
1922
int thread_id = G4Threading::G4GetThreadId();
2023
int eventID = event->GetEventID();
2124

2225
log->debug(CONSTRUCTOR, FUNCTION_NAME, " event id ", eventID, " in thread ", thread_id);
2326
}
2427

2528
void GEventAction::EndOfEventAction([[maybe_unused]] const G4Event* event) {
29+
// End-of-event hook: collect hit collections, digitize hits, and publish the event to streamers.
2630
G4HCofThisEvent* HCsThisEvent = event->GetHCofThisEvent();
2731
if (!HCsThisEvent) return;
32+
if (!run_action) {
33+
log->error(ERR_GRUNACTION_NOT_EXISTING, FUNCTION_NAME, " run_action is null - cannot access digitization routines or streamers.");
34+
}
2835

2936
int thread_id = G4Threading::G4GetThreadId();
3037
int eventID = event->GetEventID();
3138

39+
// Create the event data container that will receive digitized data and truth information.
3240
auto gevent_header = std::make_unique<GEventHeader>(goptions, eventID, thread_id);
3341
auto eventDataCollection = std::make_shared<GEventDataCollection>(goptions, std::move(gevent_header));
3442

35-
// looping over all collections
43+
// Loop over all hit collections produced by sensitive detectors in this event.
3644
for (G4int hci = 0; hci < HCsThisEvent->GetNumberOfCollections(); hci++) {
3745
auto thisGHC = (GHitsCollection*)HCsThisEvent->GetHC(hci);
3846

3947
if (thisGHC) {
4048
std::string hcSDName = thisGHC->GetSDname();
4149
auto digi_map = run_action->get_digitization_routines_map();
50+
if (!digi_map) {
51+
log->error(ERR_GDIGIMAP_NOT_EXISTING, FUNCTION_NAME, " no digitization routines map available for collection ", hcSDName,
52+
" in thread ", thread_id);
53+
}
4254

4355
log->info(2, FUNCTION_NAME, " worker ", thread_id,
4456
" for event number ", eventID,
4557
" for collection number ", hci + 1,
4658
" collection name: ", hcSDName);
4759

48-
auto digitization_routine = digi_map->at(hcSDName);
60+
// Select the digitization routine by hit collection name, then publish through all streamers.
61+
auto it = digi_map->find(hcSDName);
62+
if (it == digi_map->end()) {
63+
log->error(ERR_GDIGIMAP_NOT_EXISTING, FUNCTION_NAME, " no digitization routine registered for collection ", hcSDName,
64+
" in thread ", thread_id);
65+
}
66+
auto digitization_routine = it->second;
67+
4968
auto gstreamers_map = run_action->get_streamer_map();
69+
if (!gstreamers_map) {
70+
log->error(ERR_STREAMERMAP_NOT_EXISTING, FUNCTION_NAME, " no gstreamer map available in thread ", thread_id);
71+
}
5072

5173
if (digitization_routine != nullptr) {
52-
// looping over hits in this collection
74+
// Loop over hits in this collection and append produced data to the event container.
5375
for (size_t hitIndex = 0; hitIndex < thisGHC->GetSize(); hitIndex++) {
5476
auto thisHit = (GHit*)thisGHC->GetHit(hitIndex);
5577
// PRAGMA TODO: switch these on/off with options
@@ -60,7 +82,7 @@ void GEventAction::EndOfEventAction([[maybe_unused]] const G4Event* event) {
6082
}
6183

6284
for (const auto& [name, gstreamer] : *gstreamers_map) {
63-
// publish the event to the gstreamer
85+
// Publish the event to the gstreamer.
6486
gstreamer->publishEventData(eventDataCollection);
6587
}
6688
}

actions/event/gEventAction.h

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,96 @@
77
#include "gbase.h"
88
#include "../run/gRunAction.h"
99

10+
/**
11+
* @file gEventAction.h
12+
* @brief Declares GEventAction, responsible for per-event lifecycle hooks and event publication.
13+
*
14+
* @ingroup gactions_module
15+
*/
16+
1017
constexpr const char* EVENTACTION_LOGGER = "geventaction";
1118

19+
/**
20+
* @brief Namespace collecting helpers for the event action.
21+
*
22+
* @ingroup gactions_module
23+
*/
1224
namespace geventaction {
25+
/**
26+
* @brief Returns the options associated with the event action.
27+
*
28+
* @return A GOptions instance for the event action logger scope.
29+
*/
1330
inline GOptions defineOptions() { return GOptions(EVENTACTION_LOGGER); }
14-
}
31+
} // namespace geventaction
32+
1533

16-
// Local thread classes
34+
/**
35+
* @class GEventAction
36+
* @brief Handles event begin/end callbacks and triggers digitization + streaming.
37+
*
38+
* Responsibilities:
39+
* - At event begin: optionally log event/thread identification.
40+
* - At event end:
41+
* - Retrieve the hit collections for the event.
42+
* - For each hit collection:
43+
* - Resolve the digitization routine associated with the collection name.
44+
* - Convert hits into digitized data and true-information data.
45+
* - Add these products to the event data container.
46+
* - Publish the completed event data to all configured streamers for the thread.
47+
*
48+
* Ownership:
49+
* - The run_action pointer is non-owning; it is expected to remain valid for the
50+
* lifetime of the thread actions (it is created and registered by GAction).
51+
*
52+
* @ingroup gactions_module
53+
*/
1754
class GEventAction : public GBase<GEventAction>, public G4UserEventAction {
1855
public:
56+
/**
57+
* @brief Constructs the event action.
58+
*
59+
* @param gopt Shared configuration used to construct event data containers and control logging.
60+
* @param run_a Non-owning pointer to the thread's GRunAction instance, used to access
61+
* digitization routines and the streamer map.
62+
*/
1963
GEventAction(const std::shared_ptr<GOptions>& gopt, GRunAction* run_a);
2064

65+
/**
66+
* @brief Called by Geant4 at the beginning of an event.
67+
*
68+
* Typical usage in this module is logging and lightweight per-event bookkeeping.
69+
*
70+
* @param event The Geant4 event descriptor.
71+
*/
2172
void BeginOfEventAction(const G4Event* event) override;
73+
74+
/**
75+
* @brief Called by Geant4 at the end of an event.
76+
*
77+
* This method performs the event-level workflow:
78+
* - Collect hit collections.
79+
* - Digitize hits and collect truth information.
80+
* - Publish the resulting event data to streamers.
81+
*
82+
* @param event The Geant4 event descriptor.
83+
*/
2284
void EndOfEventAction(const G4Event* event) override;
2385

2486
private:
25-
std::shared_ptr<GOptions> goptions; // keeping the goption pointer to construct gdata
26-
GRunAction* run_action; // non-owning, valid for the thread lifetime
87+
/**
88+
* @brief Shared configuration used for constructing event products and controlling logging.
89+
*/
90+
std::shared_ptr<GOptions> goptions;
2791

92+
/**
93+
* @brief Non-owning pointer to the thread's run action.
94+
*
95+
* This is used to access:
96+
* - The digitization routines map (collection name -> routine).
97+
* - The per-thread streamer map.
98+
*/
99+
GRunAction* run_action;
28100
};
29101

30102

@@ -39,4 +111,4 @@ class GEventAction : public GBase<GEventAction>, public G4UserEventAction {
39111
// logSummary("Factory <" + factoryName + "> " + reportName + resultString);
40112
// }
41113
// }
42-
// }
114+
// }

actions/gaction.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ GAction::GAction(std::shared_ptr<GOptions> gopts, std::shared_ptr<gdynamicdigiti
1212

1313

1414
void GAction::BuildForMaster() const {
15+
// Master-thread registration: register the run action only.
1516
log->debug(NORMAL, FUNCTION_NAME);
1617

1718
SetUserAction(new GRunAction(goptions, digitization_routines_map));
1819
}
1920

2021

2122
void GAction::Build() const {
23+
// Worker-thread registration: primary generator, run action, then event action.
2224
auto thread_id = G4Threading::G4GetThreadId();
2325

2426
log->debug(NORMAL, FUNCTION_NAME, "thread id: " + std::to_string(thread_id));

actions/gaction.h

Lines changed: 82 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,39 @@
1414
#include "run/gRun.h"
1515
#include "generator/gPrimaryGeneratorAction.h"
1616

17-
// G4VUserActionInitialization is a newly introduced class for the user to instantiate
18-
// user action classes (both mandatory and optional).
19-
//
20-
// All the user action classes are thread-local and instantiated only for worker treads,
21-
// with the only exception of UserRunAction, which could be instantiated also for the master thread.
22-
// All user actions must be registered through SetUserAction() protected method defined in the
23-
// G4VUserActionInitialization base class.
24-
//
25-
// G4VUserActionInitialization has two virtual methods to be implemented:
26-
// - Build() should be used for defining user action classes for worker threads
27-
// as well as for the sequential mode.
28-
// - BuildForMaster() should be used for defining only the UserRunAction for the master thread.
17+
/**
18+
* @file gaction.h
19+
* @brief Declares GAction, the Geant4 action-initialization entry point for GEMC.
20+
*
21+
* GAction derives from the Geant4 action initialization interface (\c G4VUserActionInitialization)
22+
* and wires together the run, event, and primary generation actions used by GEMC.
23+
*
24+
* @ingroup gactions_module
25+
*/
2926

3027
constexpr const char* GACTION_LOGGER = "gaction";
3128

29+
/**
30+
* @brief Namespace collecting helpers for the actions subsystem.
31+
*
32+
* @ingroup gactions_module
33+
*/
3234
namespace gaction {
35+
36+
/**
37+
* @brief Builds and returns the complete set of options required by the actions subsystem.
38+
*
39+
* This helper is intended to be used by the application/module setup to define all
40+
* actions-related options in one place.
41+
*
42+
* It aggregates:
43+
* - event action options
44+
* - run action options
45+
* - primary generator options
46+
* - run container options
47+
*
48+
* @return A GOptions instance populated with the union of all action-related options.
49+
*/
3350
inline GOptions defineOptions() {
3451
auto goptions = GOptions(GACTION_LOGGER);
3552
goptions += geventaction::defineOptions();
@@ -38,21 +55,70 @@ inline GOptions defineOptions() {
3855
goptions += grun::defineOptions();
3956
return goptions;
4057
}
41-
}
58+
} // namespace gaction
4259

4360

61+
/**
62+
* @class GAction
63+
* @brief Registers GEMC user actions for worker and master threads.
64+
*
65+
* Geant4 uses an action initialization class (\c G4VUserActionInitialization) to instantiate
66+
* user action objects. These action objects are typically thread-local:
67+
*
68+
* - Build() is invoked for worker threads and also for sequential mode.
69+
* - BuildForMaster() is invoked for the master thread, and is commonly used to register
70+
* only the run action.
71+
*
72+
* This class holds:
73+
* - A shared pointer to GOptions, used by the constructed actions to read runtime configuration.
74+
* - A shared pointer to the digitization routines map, used by the run and event actions to
75+
* digitize hits and publish results.
76+
*
77+
* @ingroup gactions_module
78+
*/
4479
class GAction : public GBase<GAction>, public G4VUserActionInitialization {
4580
public:
81+
/**
82+
* @brief Constructs the action initializer.
83+
*
84+
* @param gopts Shared configuration object used by all actions constructed by this initializer.
85+
* @param digi_map Shared map from sensitive detector / hit collection name to digitization routines.
86+
*/
4687
GAction(std::shared_ptr<GOptions> gopts, std::shared_ptr<gdynamicdigitization::dRoutinesMap> digi_map);
4788

89+
/**
90+
* @brief Registers user actions for worker threads (and sequential mode).
91+
*
92+
* Expected registrations include:
93+
* - The primary generator action.
94+
* - The run action.
95+
* - The event action.
96+
*
97+
* The constructed actions receive the shared configuration and digitization map.
98+
*/
4899
void Build() const override;
49100

101+
/**
102+
* @brief Registers user actions for the master thread.
103+
*
104+
* In multithreaded mode, the master thread typically registers only the run action.
105+
*/
50106
void BuildForMaster() const override;
51107

52108
private:
53-
std::shared_ptr<GOptions> goptions; // keeping the goption pointer to construct the other actions
109+
/**
110+
* @brief Shared configuration used to construct and configure all action objects.
111+
*
112+
* This pointer is kept so that Build() and BuildForMaster() can construct the action objects
113+
* using the same configuration instance.
114+
*/
115+
std::shared_ptr<GOptions> goptions;
54116

55-
// digitization map, populated in ConstructSDandField
117+
/**
118+
* @brief Digitization routines map used by run/event actions to digitize hit collections.
119+
*
120+
* The map is populated elsewhere (e.g., during sensitive detector and field construction)
121+
* and is shared across threads as a read-mostly structure.
122+
*/
56123
std::shared_ptr<gdynamicdigitization::dRoutinesMap> digitization_routines_map;
57-
58124
};

actions/gactionConventions.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* \name Error codes
3+
* \brief Module-level exit/status codes.
4+
*
5+
* Values are in the 200s range and are used by the logger error path to provide
6+
* stable identifiers for common failure modes.
7+
*/
8+
///@{
9+
#define ERR_GRUNACTION_NOT_EXISTING 1201
10+
#define ERR_GDIGIMAP_NOT_EXISTING 1202
11+
#define ERR_STREAMERMAP_NOT_EXISTING 1203
12+
///@}

0 commit comments

Comments
 (0)