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