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