actions
Loading...
Searching...
No Matches
gEventAction.h
Go to the documentation of this file.
1#pragma once
2
3// geant4
4#include "G4UserEventAction.hh"
5
6// gemc
7#include <gemc/gbase/gbase.h>
9
10// c++
11#include <chrono>
12
14
22constexpr const char* EVENTACTION_LOGGER = "geventaction";
23
32constexpr const char* LOG_EVERY_OPTION = "log_every";
33constexpr const char* SAVE_ORIGINAL_TRACK_SWITCH = "save_original_track";
34constexpr const char* SAVE_ALL_ANCESTORS_SWITCH = "save_all_ancestors";
35
41namespace geventaction {
49
50 std::string help = "Print a progress log line every N events, with the average event rate.\n \n";
51 help += GTAB;
52 help += "The value is a string of the form N or N-NTH, where N is the log module:\n";
53 help += GTABTAB;
54 help += "N : every worker thread prints 'Starting event n. <k> in thread <tid>.\n";
55 help += GTABTABTAB;
56 help += "Average rate: <r> events / second' every time it has processed a multiple\n";
57 help += GTABTABTAB;
58 help += "of N events. <k> is that thread's own 1-based event count (not the global\n";
59 help += GTABTABTAB;
60 help += "Geant4 event id), and <r> is that thread's average rate.\n";
61 help += GTABTAB;
62 help += "N-NTH : as above, but only the worker thread with id NTH prints. NTH must be\n";
63 help += GTABTABTAB;
64 help += "in the range [0, nthreads-1].\n \n";
65 help += GTAB;
66 help += "Examples: -log_every=100 (all threads, every 100 events)\n";
67 help += GTABTAB;
68 help += "-log_every=100-2 (only thread 2, every 100 events)\n";
69 goptions.defineOption(
71 "log module: print event progress and average rate every N events per thread"),
72 help);
73
75 "save the original Geant4 track ID in each true-information hit");
77 "save initial information for hit-producing tracks and all their ancestors");
78
79 return goptions;
80 }
81} // namespace geventaction
82
83
108class GEventAction : public GBase<GEventAction>, public G4UserEventAction
109{
110public:
119 explicit GEventAction(const std::shared_ptr<GOptions>& gopt, GRunAction* run_a,
120 std::shared_ptr<GTrackProvenance> provenance = nullptr);
121
122 ~GEventAction() override = default;
123
124 GEventAction(const GEventAction&) = delete;
128
137 void BeginOfEventAction(const G4Event* event) override;
138
153 void EndOfEventAction(const G4Event* event) override;
154
155private:
161 void publish_event_data(const std::shared_ptr<GEventDataCollection>& event_data) const;
162
175 void log_event_start(int thread_id);
176
180 long long log_events_seen = 0;
181
185 std::chrono::steady_clock::time_point log_start_time;
186
190 std::shared_ptr<GOptions> goptions;
191
195 int log_every_n = 0;
196
200 int log_every_thread = -1;
201
210 GRunAction* run_action = nullptr;
211
213 std::shared_ptr<GTrackProvenance> track_provenance;
214
215 bool save_original_track = false;
216 bool save_all_ancestors = false;
217};
218
219// looping over output factories
220// for (auto [factoryName, streamerFactory] : *gstreamerFactoryMap) {
221// if (streamerFactory->getStreamType() == "event") {
222// logSummary("Writing event data using streamer factory >" + factoryName + "<");
223// map<string, bool> streamReport = streamerFactory->publishEventRunData(goptions, theRun->getRunData());
224//
225// for (auto [reportName, result] : streamReport) {
226// string resultString = result ? " success" : " failure";
227// logSummary("Factory <" + factoryName + "> " + reportName + resultString);
228// }
229// }
230// }
Handles event begin/end callbacks, hit digitization, and event-level publication.
GEventAction & operator=(const GEventAction &)=delete
GEventAction(GEventAction &&)=delete
void EndOfEventAction(const G4Event *event) override
Called by Geant4 at the end of an event.
GEventAction & operator=(GEventAction &&)=delete
~GEventAction() override=default
GEventAction(const std::shared_ptr< GOptions > &gopt, GRunAction *run_a, std::shared_ptr< GTrackProvenance > provenance=nullptr)
Constructs the event action.
GEventAction(const GEventAction &)=delete
void BeginOfEventAction(const G4Event *event) override
Called by Geant4 at the beginning of an event.
Handles run begin/end callbacks and creates the thread-local GRun object.
Definition gRunAction.h:67
Worker-local, event-scoped track ancestry registry.
constexpr const char * EVENTACTION_LOGGER
constexpr const char * LOG_EVERY_OPTION
Name of the option controlling periodic per-event log messages.
constexpr const char * SAVE_ORIGINAL_TRACK_SWITCH
constexpr const char * SAVE_ALL_ANCESTORS_SWITCH
Declares GRunAction, the run-lifecycle action for the GEMC actions module.
#define GTABTABTAB
#define UNINITIALIZEDSTRINGQUANTITY
#define GTAB
#define GTABTAB
Namespace containing helpers related to event-action configuration.
GOptions defineOptions()
Returns the options associated with the event-action logger scope.