8#include "G4UserRunAction.hh"
11#include <gemc/gbase/gbase.h>
12#include <gemc/gdynamicDigitization/gdynamicdigitization.h>
13#include <gemc/gstreamer/gstreamer.h>
14#include <gemc/gdata/run/gRunDataCollection.h>
75 explicit GRunAction(std::shared_ptr<GOptions> gopts,
76 std::shared_ptr<gdynamicdigitization::dRoutinesMap> digi_map);
97 return digitization_routines_map;
110 -> std::shared_ptr<const
gstreamer::gstreamersMap> {
111 if (!gstreamer_threads_map) {
114 return gstreamer_threads_map;
118 return gstreamer_threads_map !=
nullptr;
132 std::unique_ptr<GDigitizedData> digi_data) {
133 if (run_data ==
nullptr) {
135 " run_data is null - cannot collect run-level payload for collection ", hcSDName);
140 std::move(digi_data));
150 if (run_data ==
nullptr) {
152 " run_data is null - cannot increment processed events.");
156 if (header ==
nullptr) {
158 " run_data header is null - cannot increment processed events.");
161 header->increment_events_processed();
171 if (run_data ==
nullptr) {
173 " run_data is null - cannot increment payload events.");
177 if (header ==
nullptr) {
179 " run_data header is null - cannot increment payload events.");
182 header->increment_events_with_payload();
186 using CompletedRunData = std::vector<std::unique_ptr<GRunDataCollection>>;
194 void stash_worker_run_data();
204 [[nodiscard]] CompletedRunData take_completed_worker_run_data();
214 G4Run* GenerateRun()
override;
235 void BeginOfRunAction(
const G4Run* run)
override;
251 void EndOfRunAction(
const G4Run* run)
override;
258 void publish_run_data(
const std::shared_ptr<GRunDataCollection>& run_data)
const;
268 std::shared_ptr<gdynamicdigitization::dRoutinesMap> digitization_routines_map;
273 std::shared_ptr<const gstreamer::gstreamersMap> gstreamer_threads_map;
278 std::shared_ptr<const gstreamer::gstreamersMap> gstreamer_run_map;
286 std::unique_ptr<GRunDataCollection> run_data;
291 bool need_a_thread_streamer =
false;
296 bool need_a_run_streamer =
false;
301 static std::mutex completed_run_data_mutex;
309 static CompletedRunData completed_worker_run_data;
329 void normalize_run_data(
const std::shared_ptr<GRunDataCollection>& run_data)
const;
332 std::unordered_map<std::string, std::vector<std::string>> to_normalize;
std::shared_ptr< GLogger > log
void error(int exit_code, Args &&... args) const
Handles run begin/end callbacks and creates the thread-local GRun object.
GRunAction & operator=(GRunAction &&)=delete
void increment_run_events_with_payload()
Increments the number of events that produced run-mode payload.
void increment_run_events_processed()
Increments the number of events processed by the current thread for this run.
GRunAction(GRunAction &&)=delete
auto get_digitization_routines_map() const -> std::shared_ptr< gdynamicdigitization::dRoutinesMap >
Returns the shared digitization-routine map used by this run action.
bool has_streamer_threads_map() const
GRunAction & operator=(const GRunAction &)=delete
GRunAction(const GRunAction &)=delete
void collect_event_data_collections(const std::string &hcSDName, std::unique_ptr< GDigitizedData > digi_data)
Adds one run-mode digitized payload to the current thread run-data collection.
~GRunAction() override=default
auto get_streamer_threads_map() const -> std::shared_ptr< const gstreamer::gstreamersMap >
Returns the worker-thread streamer map, if it has been instantiated.
GRunAction(std::shared_ptr< GOptions > gopts, std::shared_ptr< gdynamicdigitization::dRoutinesMap > digi_map)
Constructs the run action.
void collect_event_data_collections(const std::string &sdName, std::unique_ptr< GDigitizedData > ddata)
auto getHeader() const -> const std::unique_ptr< GRunHeader > &
constexpr const char * GRUNACTION_LOGGER
Defines error codes used by the GEMC actions module.
#define ERR_GRUNACTION_NOT_EXISTING
#define ERR_STREAMERMAP_NOT_EXISTING
Namespace containing helpers related to run-action configuration.
GOptions defineOptions()
Returns the options associated with the run-action logger scope.