File indexing completed on 2025-03-13 08:20:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/InstanceCount.h>
0016 #include <DDG4/Geant4EventAction.h>
0017
0018
0019 #include <G4Threading.hh>
0020 #include <G4AutoLock.hh>
0021
0022 using namespace dd4hep::sim;
0023
0024 namespace {
0025 G4Mutex event_action_mutex=G4MUTEX_INITIALIZER;
0026 }
0027
0028
0029 Geant4EventAction::Geant4EventAction(Geant4Context* ctxt, const std::string& nam)
0030 : Geant4Action(ctxt, nam)
0031 {
0032 InstanceCount::increment(this);
0033 }
0034
0035
0036 Geant4EventAction::~Geant4EventAction() {
0037 InstanceCount::decrement(this);
0038 }
0039
0040
0041 void Geant4EventAction::begin(const G4Event* ) {
0042 }
0043
0044
0045 void Geant4EventAction::end(const G4Event* ) {
0046 }
0047
0048
0049 Geant4SharedEventAction::Geant4SharedEventAction(Geant4Context* ctxt, const std::string& nam)
0050 : Geant4EventAction(ctxt, nam)
0051 {
0052 InstanceCount::increment(this);
0053 }
0054
0055
0056 Geant4SharedEventAction::~Geant4SharedEventAction() {
0057 detail::releasePtr(m_action);
0058 InstanceCount::decrement(this);
0059 }
0060
0061
0062 void Geant4SharedEventAction::configureFiber(Geant4Context* thread_context) {
0063 m_action->configureFiber(thread_context);
0064 }
0065
0066
0067 void Geant4SharedEventAction::use(Geant4EventAction* action) {
0068 if (action) {
0069 action->addRef();
0070 m_properties.adopt(action->properties());
0071 m_action = action;
0072 return;
0073 }
0074 except("Geant4SharedEventAction: Attempt to use invalid actor!");
0075 }
0076
0077
0078 void Geant4SharedEventAction::begin(const G4Event* event) {
0079 if ( m_action ) {
0080 G4AutoLock protection_lock(&event_action_mutex); {
0081 ContextSwap swap(m_action,context());
0082 m_action->begin(event);
0083 }
0084 }
0085 }
0086
0087
0088 void Geant4SharedEventAction::end(const G4Event* event) {
0089 if ( m_action ) {
0090 G4AutoLock protection_lock(&event_action_mutex); {
0091 ContextSwap swap(m_action,context());
0092 m_action->end(event);
0093 }
0094 }
0095 }
0096
0097
0098 Geant4EventActionSequence::Geant4EventActionSequence(Geant4Context* ctxt, const std::string& nam)
0099 : Geant4Action(ctxt, nam) {
0100 m_needsControl = true;
0101 InstanceCount::increment(this);
0102 }
0103
0104
0105 Geant4EventActionSequence::~Geant4EventActionSequence() {
0106 m_actors(&Geant4Action::release);
0107 m_actors.clear();
0108 m_begin.clear();
0109 m_end.clear();
0110 m_final.clear();
0111 InstanceCount::decrement(this);
0112 }
0113
0114
0115 void Geant4EventActionSequence::updateContext(Geant4Context* ctxt) {
0116 m_context = ctxt;
0117 m_actors.updateContext(ctxt);
0118 }
0119
0120
0121 void Geant4EventActionSequence::configureFiber(Geant4Context* thread_context) {
0122 m_actors(&Geant4Action::configureFiber, thread_context);
0123 }
0124
0125
0126 Geant4EventAction* Geant4EventActionSequence::get(const std::string& nam) const {
0127 return m_actors.get(FindByName(TypeName::split(nam).second));
0128 }
0129
0130
0131 void Geant4EventActionSequence::adopt(Geant4EventAction* action) {
0132 if (action) {
0133 G4AutoLock protection_lock(&event_action_mutex);
0134 action->addRef();
0135 m_actors.add(action);
0136 return;
0137 }
0138 except("Geant4EventActionSequence: Attempt to add invalid actor!");
0139 }
0140
0141
0142 void Geant4EventActionSequence::begin(const G4Event* event) {
0143 m_actors(&Geant4EventAction::begin, event);
0144 m_begin(event);
0145 }
0146
0147
0148 void Geant4EventActionSequence::end(const G4Event* event) {
0149 m_end(event);
0150 m_actors(&Geant4EventAction::end, event);
0151 m_final(event);
0152 }