|
9 | 9 |
|
10 | 10 |
|
11 | 11 | GEventAction::GEventAction(const std::shared_ptr<GOptions>& gopt, GRunAction* run_a) : |
12 | | - GBase(gopt, EVENTACTION_LOGGER), |
13 | | - goptions(gopt), |
14 | | - run_action(run_a) { |
15 | | - // Constructor: store shared config and a non-owning pointer to the run action for this thread. |
16 | | - auto desc = "GEventAction " + std::to_string(G4Threading::G4GetThreadId()); |
17 | | - log->debug(CONSTRUCTOR, FUNCTION_NAME, desc); |
| 12 | + GBase(gopt, EVENTACTION_LOGGER), |
| 13 | + goptions(gopt), |
| 14 | + run_action(run_a) { |
| 15 | + // Constructor: store shared config and a non-owning pointer to the run action for this thread. |
| 16 | + auto desc = "GEventAction " + std::to_string(G4Threading::G4GetThreadId()); |
| 17 | + log->debug(CONSTRUCTOR, FUNCTION_NAME, desc); |
18 | 18 | } |
19 | 19 |
|
20 | 20 | void GEventAction::BeginOfEventAction([[maybe_unused]] const G4Event* event) { |
21 | | - // Begin-of-event hook: logs event id and thread id for tracing. |
22 | | - int thread_id = G4Threading::G4GetThreadId(); |
23 | | - int eventID = event->GetEventID(); |
| 21 | + // Begin-of-event hook: logs event id and thread id for tracing. |
| 22 | + int thread_id = G4Threading::G4GetThreadId(); |
| 23 | + int eventID = event->GetEventID(); |
24 | 24 |
|
25 | | - log->debug(CONSTRUCTOR, FUNCTION_NAME, " event id ", eventID, " in thread ", thread_id); |
| 25 | + log->debug(CONSTRUCTOR, FUNCTION_NAME, " event id ", eventID, " in thread ", thread_id); |
26 | 26 | } |
27 | 27 |
|
28 | 28 | void GEventAction::EndOfEventAction([[maybe_unused]] const G4Event* event) { |
29 | | - // End-of-event hook: collect hit collections, digitize hits, and publish the event to streamers. |
30 | | - G4HCofThisEvent* HCsThisEvent = event->GetHCofThisEvent(); |
31 | | - 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 | | - } |
35 | | - |
36 | | - int thread_id = G4Threading::G4GetThreadId(); |
37 | | - int eventID = event->GetEventID(); |
38 | | - |
39 | | - // Create the event data container that will receive digitized data and truth information. |
40 | | - auto gevent_header = std::make_unique<GEventHeader>(goptions, eventID, thread_id); |
41 | | - auto eventDataCollection = std::make_shared<GEventDataCollection>(goptions, std::move(gevent_header)); |
42 | | - |
43 | | - // Loop over all hit collections produced by sensitive detectors in this event. |
44 | | - for (G4int hci = 0; hci < HCsThisEvent->GetNumberOfCollections(); hci++) { |
45 | | - auto thisGHC = (GHitsCollection*)HCsThisEvent->GetHC(hci); |
46 | | - |
47 | | - if (thisGHC) { |
48 | | - std::string hcSDName = thisGHC->GetSDname(); |
49 | | - 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 | | - } |
54 | | - |
55 | | - log->info(2, FUNCTION_NAME, " worker ", thread_id, |
56 | | - " for event number ", eventID, |
57 | | - " for collection number ", hci + 1, |
58 | | - " collection name: ", hcSDName); |
59 | | - |
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 | | - |
68 | | - 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 | | - } |
72 | | - |
73 | | - if (digitization_routine != nullptr) { |
74 | | - // Loop over hits in this collection and append produced data to the event container. |
75 | | - for (size_t hitIndex = 0; hitIndex < thisGHC->GetSize(); hitIndex++) { |
76 | | - auto thisHit = (GHit*)thisGHC->GetHit(hitIndex); |
77 | | - // PRAGMA TODO: switch these on/off with options |
78 | | - auto true_data = digitization_routine->collectTrueInformation(thisHit, hitIndex); |
79 | | - auto digi_data = digitization_routine->digitizeHit(thisHit, hitIndex); |
80 | | - eventDataCollection->addDetectorDigitizedData(hcSDName, std::move(digi_data)); |
81 | | - eventDataCollection->addDetectorTrueInfoData(hcSDName, std::move(true_data)); |
82 | | - } |
83 | | - |
84 | | - for (const auto& [name, gstreamer] : *gstreamers_map) { |
85 | | - // Publish the event to the gstreamer. |
86 | | - gstreamer->publishEventData(eventDataCollection); |
87 | | - } |
88 | | - } |
89 | | - } |
90 | | - } |
| 29 | + // End-of-event hook: collect hit collections, digitize hits, and publish the event to streamers. |
| 30 | + G4HCofThisEvent* HCsThisEvent = event->GetHCofThisEvent(); |
| 31 | + if (!HCsThisEvent) return; |
| 32 | + if (!run_action) { |
| 33 | + log->error(ERR_GRUNACTION_NOT_EXISTING, FUNCTION_NAME, |
| 34 | + " run_action is null - cannot access digitization routines or streamers."); |
| 35 | + } |
| 36 | + |
| 37 | + int thread_id = G4Threading::G4GetThreadId(); |
| 38 | + int eventID = event->GetEventID(); |
| 39 | + |
| 40 | + // Create the event data container that will receive digitized data and truth information. |
| 41 | + auto gevent_header = std::make_unique<GEventHeader>(goptions, eventID, thread_id); |
| 42 | + auto eventDataCollection = std::make_shared<GEventDataCollection>(goptions, std::move(gevent_header)); |
| 43 | + |
| 44 | + // Loop over all hit collections produced by sensitive detectors in this event. |
| 45 | + for (G4int hci = 0; hci < HCsThisEvent->GetNumberOfCollections(); hci++) { |
| 46 | + auto thisGHC = (GHitsCollection*)HCsThisEvent->GetHC(hci); |
| 47 | + |
| 48 | + if (thisGHC) { |
| 49 | + std::string hcSDName = thisGHC->GetSDname(); |
| 50 | + auto digi_map = run_action->get_digitization_routines_map(); |
| 51 | + if (!digi_map) { |
| 52 | + log->error(ERR_GDIGIMAP_NOT_EXISTING, FUNCTION_NAME, |
| 53 | + " no digitization routines map available for collection ", hcSDName, |
| 54 | + " in thread ", thread_id); |
| 55 | + } |
| 56 | + |
| 57 | + log->info(2, FUNCTION_NAME, " worker ", thread_id, |
| 58 | + " for event number ", eventID, |
| 59 | + " for collection number ", hci + 1, |
| 60 | + " collection name: ", hcSDName); |
| 61 | + |
| 62 | + // Select the digitization routine by hit collection name, then publish through all streamers. |
| 63 | + auto it = digi_map->find(hcSDName); |
| 64 | + if (it == digi_map->end()) { |
| 65 | + log->error(ERR_GDIGIMAP_NOT_EXISTING, FUNCTION_NAME, |
| 66 | + " no digitization routine registered for collection ", hcSDName, |
| 67 | + " in thread ", thread_id); |
| 68 | + } |
| 69 | + auto digitization_routine = it->second; |
| 70 | + |
| 71 | + auto gstreamers_map = run_action->get_streamer_map(); |
| 72 | + if (!gstreamers_map) { |
| 73 | + log->error(ERR_STREAMERMAP_NOT_EXISTING, FUNCTION_NAME, " no gstreamer map available in thread ", |
| 74 | + thread_id); |
| 75 | + } |
| 76 | + |
| 77 | + if (digitization_routine != nullptr) { |
| 78 | + // Loop over hits in this collection and append produced data to the event container. |
| 79 | + for (size_t hitIndex = 0; hitIndex < thisGHC->GetSize(); hitIndex++) { |
| 80 | + auto thisHit = (GHit*)thisGHC->GetHit(hitIndex); |
| 81 | + // PRAGMA TODO: switch these on/off with options |
| 82 | + auto true_data = digitization_routine->collectTrueInformation(thisHit, hitIndex); |
| 83 | + auto digi_data = digitization_routine->digitizeHit(thisHit, hitIndex); |
| 84 | + eventDataCollection->addDetectorDigitizedData(hcSDName, std::move(digi_data)); |
| 85 | + eventDataCollection->addDetectorTrueInfoData(hcSDName, std::move(true_data)); |
| 86 | + } |
| 87 | + |
| 88 | + for (const auto& [name, gstreamer] : *gstreamers_map) { |
| 89 | + // Publish the event to the gstreamer. |
| 90 | + gstreamer->publishEventData(eventDataCollection); |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + } |
91 | 95 | } |
0 commit comments