7#include "G4Threading.hh"
8#include "G4MTRunManager.hh"
12GRunAction::GRunAction(std::shared_ptr<GOptions> gopt, std::shared_ptr<gdynamicdigitization::dRoutinesMap> digi_map) :
15 digitization_routines_map(digi_map) {
16 auto desc= std::to_string(G4Threading::G4GetThreadId());
23G4Run* GRunAction::GenerateRun() {
30void GRunAction::BeginOfRunAction(
const G4Run* aRun) {
32 int thread_id = G4Threading::G4GetThreadId();
33 int run = aRun->GetRunID();
34 int neventsThisRun = aRun->GetNumberOfEventToBeProcessed();
37 if (!IsMaster() && gstreamer_map ==
nullptr) {
38 log->
info(0,
" Defining gstreamers for thread id ", thread_id);
45 if (gstreamer_map ==
nullptr) {
46 log->
error(1, FUNCTION_NAME,
" gstreamer_map is null in thread ", thread_id,
" - cannot open connections.");
48 for (
auto& [name,
gstreamer] : *gstreamer_map) {
57 std::string what_am_i = IsMaster() ?
"Master" :
"Worker";
59 log->
info(2, FUNCTION_NAME,
" ", what_am_i,
" [", thread_id,
"], for run ", run,
", events to be processed: ", neventsThisRun);
63void GRunAction::EndOfRunAction(
const G4Run* aRun) {
66 int thread_id = G4Threading::G4GetThreadId();
67 int run = aRun->GetRunID();
68 std::string what_am_i = IsMaster() ?
"Master" :
"Worker";
71 if (gstreamer_map ==
nullptr) {
74 for (
const auto& [name,
gstreamer] : *gstreamer_map) {
75 log->
info(2, FUNCTION_NAME,
" ", what_am_i,
" [", thread_id,
"], for run ", run,
76 " closing connection for gstreamer ", name);
78 log->
error(1,
"Failed to close connection for GStreamer ", name,
" in thread ", thread_id);
std::shared_ptr< GLogger > log
void debug(debug_type type, Args &&... args) const
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
GRunAction(std::shared_ptr< GOptions > gopts, std::shared_ptr< gdynamicdigitization::dRoutinesMap > digi_map)
Constructs the run action.
Thread-local run object created for each Geant4 run.
Declares GRunAction, responsible for run lifecycle hooks and run object creation.
constexpr const char * GRUNACTION_LOGGER
Declares GRun, the per-thread run container.
#define ERR_STREAMERMAP_NOT_EXISTING
std::shared_ptr< const gstreamersMap > gstreamersMapPtr(const std::shared_ptr< GOptions > &gopts, int thread_id)