10#include "G4UserRunAction.hh"
13#include <gemc/gbase/gbase.h>
14#include <gemc/ganalysis/gAnalysisAccumulator.h>
15#include <gemc/gdynamicDigitization/gdynamicdigitization.h>
16#include <gemc/gstreamer/gstreamer.h>
17#include <gemc/gdata/run/gRunDataCollection.h>
79 explicit GRunAction(std::shared_ptr<GOptions> gopts,
80 std::shared_ptr<gdynamicdigitization::dRoutinesMap> digi_map,
81 std::shared_ptr<GAnalysisAccumulator> analysis_accumulator =
nullptr);
102 return digitization_routines_map;
115 -> std::shared_ptr<const
gstreamer::gstreamersMap> {
116 if (!gstreamer_threads_map) {
119 return gstreamer_threads_map;
123 return gstreamer_threads_map !=
nullptr;
131 if (analysis_shard !=
nullptr) {
132 analysis_shard->recordDigitized(requiredAnalysisRunNumber(), detector, data);
138 if (analysis_shard !=
nullptr) {
139 analysis_shard->recordTrueInformation(requiredAnalysisRunNumber(), detector, data);
154 std::unique_ptr<GDigitizedData> digi_data) {
155 if (run_data ==
nullptr) {
157 " run_data is null - cannot collect run-level payload for collection ", hcSDName);
160 run_data->collect_event_data_collections(
162 std::move(digi_data));
172 if (run_data ==
nullptr) {
174 " run_data is null - cannot increment processed events.");
177 auto& header = run_data->getHeader();
178 if (header ==
nullptr) {
180 " run_data header is null - cannot increment processed events.");
183 header->increment_events_processed();
193 if (run_data ==
nullptr) {
195 " run_data is null - cannot increment payload events.");
198 auto& header = run_data->getHeader();
199 if (header ==
nullptr) {
201 " run_data header is null - cannot increment payload events.");
204 header->increment_events_with_payload();
208 using CompletedRunData = std::vector<std::unique_ptr<GRunDataCollection>>;
216 void stash_worker_run_data();
226 [[nodiscard]] CompletedRunData take_completed_worker_run_data();
236 G4Run* GenerateRun()
override;
257 void BeginOfRunAction(
const G4Run*
run)
override;
273 void EndOfRunAction(
const G4Run*
run)
override;
280 void publish_run_data(
const std::shared_ptr<GRunDataCollection>& run_data)
const;
290 std::shared_ptr<gdynamicdigitization::dRoutinesMap> digitization_routines_map;
293 std::shared_ptr<GAnalysisAccumulator> analysis_accumulator;
296 std::unique_ptr<GAnalysisShard> analysis_shard;
299 std::optional<int> analysis_run_number;
301 [[nodiscard]]
int requiredAnalysisRunNumber()
const {
302 if (!analysis_run_number) {
303 throw std::logic_error(
"Analyzer data recorded before the simulation run number was published");
305 return *analysis_run_number;
311 std::shared_ptr<const gstreamer::gstreamersMap> gstreamer_threads_map;
316 std::shared_ptr<const gstreamer::gstreamersMap> gstreamer_run_map;
324 std::unique_ptr<GRunDataCollection> run_data;
329 bool need_a_thread_streamer =
false;
334 bool need_a_run_streamer =
false;
339 static std::mutex completed_run_data_mutex;
347 static CompletedRunData completed_worker_run_data;
367 void normalize_run_data(
const std::shared_ptr<GRunDataCollection>& run_data)
const;
370 std::unordered_map<std::string, std::vector<std::string>> to_normalize;
GBase(const std::shared_ptr< GOptions > &gopt, std::string logger_name="")
std::shared_ptr< GLogger > log
GRunAction & operator=(GRunAction &&)=delete
void record_analysis_digitized(const std::string &detector, const GDigitizedData &data)
Discover digitized variables in one accepted record and add them to this thread's shard.
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
bool analysis_enabled() const
Return whether this run action has a GUI Analyzer shard.
void record_analysis_true(const std::string &detector, const GTrueInfoData &data)
Discover true-information variables in one record and add them to this thread's shard.
GRunAction & operator=(const GRunAction &)=delete
GRunAction(std::shared_ptr< GOptions > gopts, std::shared_ptr< gdynamicdigitization::dRoutinesMap > digi_map, std::shared_ptr< GAnalysisAccumulator > analysis_accumulator=nullptr)
Constructs the run action.
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.
constexpr const char * GRUNACTION_LOGGER
Defines error codes used by the GEMC actions module.
constexpr int ERR_STREAMERMAP_NOT_EXISTING
constexpr int ERR_GRUNACTION_NOT_EXISTING
Namespace containing helpers related to run-action configuration.
GOptions defineOptions()
Returns the options associated with the run-action logger scope.