From 982395bebba06e408d77d66e8d5c0f76d107de4a Mon Sep 17 00:00:00 2001 From: Markus Frank <markus.frank@cern.ch> Date: Wed, 25 Nov 2015 21:19:19 +0000 Subject: [PATCH] Fix to export properties of shared actions and remove dead-lock in run-action --- DDG4/examples/SiDSim_MT.py | 9 ++++----- DDG4/src/Geant4Kernel.cpp | 3 +++ DDG4/src/Geant4RunAction.cpp | 6 ++++-- DDG4/src/Geant4StackingAction.cpp | 1 + DDG4/src/Geant4SteppingAction.cpp | 1 + DDG4/src/Geant4TrackingAction.cpp | 1 + 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/DDG4/examples/SiDSim_MT.py b/DDG4/examples/SiDSim_MT.py index b0d514656..289e7f79f 100644 --- a/DDG4/examples/SiDSim_MT.py +++ b/DDG4/examples/SiDSim_MT.py @@ -21,13 +21,12 @@ def setupWorker(geant4): kernel = geant4.kernel() print '#PYTHON: +++ Creating Geant4 worker thread ....' print "#PYTHON: Configure Run actions" - run1 = DDG4.RunAction(kernel,'Geant4TestRunAction/RunInit') - run1.Property_int = 12345 + run1 = DDG4.RunAction(kernel,'Geant4TestRunAction/RunInit',shared=True) + run1.Property_int = int(12345) run1.Property_double = -5e15*keV run1.Property_string = 'Startrun: Hello_2' print run1.Property_string, run1.Property_double, run1.Property_int run1.enableUI() - kernel.registerGlobalAction(run1) kernel.runAction().adopt(run1) print "#PYTHON: Configure Event actions" @@ -52,7 +51,7 @@ def setupWorker(geant4): gen = DDG4.GeneratorAction(kernel,"Geant4IsotropeGenerator/IsotropPi+"); gen.Mask = 1 gen.Particle = 'pi+' - gen.Energy = 100 * GeV + gen.Energy = 20 * GeV gen.Multiplicity = 2 kernel.generatorAction().adopt(gen) print "#PYTHON: Install vertex smearing for this interaction" @@ -66,7 +65,7 @@ def setupWorker(geant4): gen = DDG4.GeneratorAction(kernel,"Geant4IsotropeGenerator/IsotropE-"); gen.Mask = 2 gen.Particle = 'e-' - gen.Energy = 25 * GeV + gen.Energy = 15 * GeV gen.Multiplicity = 3 kernel.generatorAction().adopt(gen) print "#PYTHON: Install vertex smearing for this interaction" diff --git a/DDG4/src/Geant4Kernel.cpp b/DDG4/src/Geant4Kernel.cpp index daed8a26e..228a507d7 100644 --- a/DDG4/src/Geant4Kernel.cpp +++ b/DDG4/src/Geant4Kernel.cpp @@ -162,6 +162,9 @@ Geant4Kernel& Geant4Kernel::worker(unsigned long identifier, bool create_if) if ( i != m_workers.end() ) { return *((*i).second); } + else if ( identifier == m_id ) { + return *this; + } else if ( !isMultiThreaded() ) { unsigned long self = thread_self(); if ( identifier == self ) { diff --git a/DDG4/src/Geant4RunAction.cpp b/DDG4/src/Geant4RunAction.cpp index 58b049a6c..f764c925e 100644 --- a/DDG4/src/Geant4RunAction.cpp +++ b/DDG4/src/Geant4RunAction.cpp @@ -26,6 +26,7 @@ using namespace DD4hep::Simulation; namespace { G4Mutex action_mutex=G4MUTEX_INITIALIZER; + G4Mutex sequence_mutex=G4MUTEX_INITIALIZER; } /// Standard constructor @@ -69,6 +70,7 @@ void Geant4SharedRunAction::configureFiber(Geant4Context* thread_context) { void Geant4SharedRunAction::use(Geant4RunAction* action) { if (action) { action->addRef(); + m_properties.adopt(action->properties()); m_action = action; return; } @@ -140,14 +142,14 @@ void Geant4RunActionSequence::adopt(Geant4RunAction* action) { /// Pre-track action callback void Geant4RunActionSequence::begin(const G4Run* run) { - G4AutoLock protection_lock(&action_mutex); + G4AutoLock protection_lock(&sequence_mutex); m_actors(&Geant4RunAction::begin, run); m_begin(run); } /// Post-track action callback void Geant4RunActionSequence::end(const G4Run* run) { - G4AutoLock protection_lock(&action_mutex); + G4AutoLock protection_lock(&sequence_mutex); m_end(run); m_actors(&Geant4RunAction::end, run); } diff --git a/DDG4/src/Geant4StackingAction.cpp b/DDG4/src/Geant4StackingAction.cpp index bd675c2bd..acffe5b88 100644 --- a/DDG4/src/Geant4StackingAction.cpp +++ b/DDG4/src/Geant4StackingAction.cpp @@ -61,6 +61,7 @@ void Geant4SharedStackingAction::configureFiber(Geant4Context* thread_context) void Geant4SharedStackingAction::use(Geant4StackingAction* action) { if (action) { action->addRef(); + m_properties.adopt(action->properties()); m_action = action; return; } diff --git a/DDG4/src/Geant4SteppingAction.cpp b/DDG4/src/Geant4SteppingAction.cpp index bbd90a6cd..461c830a2 100644 --- a/DDG4/src/Geant4SteppingAction.cpp +++ b/DDG4/src/Geant4SteppingAction.cpp @@ -59,6 +59,7 @@ Geant4SharedSteppingAction::~Geant4SharedSteppingAction() { void Geant4SharedSteppingAction::use(Geant4SteppingAction* action) { if (action) { action->addRef(); + m_properties.adopt(action->properties()); m_action = action; return; } diff --git a/DDG4/src/Geant4TrackingAction.cpp b/DDG4/src/Geant4TrackingAction.cpp index 2eeded641..2571a059d 100644 --- a/DDG4/src/Geant4TrackingAction.cpp +++ b/DDG4/src/Geant4TrackingAction.cpp @@ -143,6 +143,7 @@ void Geant4SharedTrackingAction::configureFiber(Geant4Context* thread_context) void Geant4SharedTrackingAction::use(Geant4TrackingAction* action) { if (action) { action->addRef(); + m_properties.adopt(action->properties()); m_action = action; return; } -- GitLab