Newer
Older
Markus Frank
committed
//==========================================================================
// AIDA Detector description implementation for LCD
Markus Frank
committed
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
Markus Frank
committed
// All rights reserved.
Markus Frank
committed
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
Markus Frank
committed
// Author : M.Frank
//
//==========================================================================
// Framework include files
#include "DD4hep/InstanceCount.h"
#include "DDG4/Geant4StackingAction.h"
Markus Frank
committed
// Geant4 headers
#include "G4Threading.hh"
#include "G4AutoLock.hh"
// C/C++ include files
#include <stdexcept>
Markus Frank
committed
using namespace std;
Markus Frank
committed
namespace {
G4Mutex action_mutex=G4MUTEX_INITIALIZER;
}
Markus Frank
committed
Geant4StackingAction::Geant4StackingAction(Geant4Context* ctxt, const string& nam)
Markus Frank
committed
: Geant4Action(ctxt, nam) {
InstanceCount::increment(this);
}
/// Default destructor
Geant4StackingAction::~Geant4StackingAction() {
Markus Frank
committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
Geant4SharedStackingAction::Geant4SharedStackingAction(Geant4Context* ctxt, const string& nam)
: Geant4StackingAction(ctxt, nam)
{
InstanceCount::increment(this);
}
/// Default destructor
Geant4SharedStackingAction::~Geant4SharedStackingAction() {
releasePtr(m_action);
InstanceCount::decrement(this);
}
/// Set or update client for the use in a new thread fiber
void Geant4SharedStackingAction::configureFiber(Geant4Context* thread_context) {
m_action->configureFiber(thread_context);
}
/// Underlying object to be used during the execution of this thread
void Geant4SharedStackingAction::use(Geant4StackingAction* action) {
if (action) {
action->addRef();
m_action = action;
return;
}
throw runtime_error("Geant4SharedStackingAction: Attempt to use invalid actor!");
}
/// Begin-of-stacking callback
void Geant4SharedStackingAction::newStage() {
if ( m_action ) {
G4AutoLock protection_lock(&action_mutex); {
ContextSwap swap(m_action,context());
m_action->newStage();
}
}
}
/// End-of-stacking callback
void Geant4SharedStackingAction::prepare() {
if ( m_action ) {
G4AutoLock protection_lock(&action_mutex); {
ContextSwap swap(m_action,context());
m_action->prepare();
}
}
}
/// Standard constructor
Geant4StackingActionSequence::Geant4StackingActionSequence(Geant4Context* ctxt, const string& nam)
Markus Frank
committed
: Geant4Action(ctxt, nam) {
InstanceCount::increment(this);
}
/// Default destructor
Geant4StackingActionSequence::~Geant4StackingActionSequence() {
m_actors(&Geant4StackingAction::release);
m_actors.clear();
m_newStage.clear();
m_prepare.clear();
InstanceCount::decrement(this);
}
/// Add an actor responding to all callbacks. Sequence takes ownership.
void Geant4StackingActionSequence::adopt(Geant4StackingAction* action) {
if (action) {
action->addRef();
m_actors.add(action);
return;
}
Markus Frank
committed
throw runtime_error("Geant4StackingActionSequence: Attempt to add invalid actor!");
}
/// Set or update client context
void Geant4StackingActionSequence::updateContext(Geant4Context* ctxt) {
m_context = ctxt;
m_actors.updateContext(ctxt);
}
/// Set or update client for the use in a new thread fiber
void Geant4StackingActionSequence::configureFiber(Geant4Context* thread_context) {
m_actors(&Geant4Action::configureFiber, thread_context);
}
/// Get an action by name
Geant4StackingAction* Geant4StackingActionSequence::get(const string& nam) const {
return m_actors.get(FindByName(TypeName::split(nam).second));
void Geant4StackingActionSequence::newStage() {
m_actors(&Geant4StackingAction::newStage);
m_newStage();
}
/// Post-track action callback
void Geant4StackingActionSequence::prepare() {
m_actors(&Geant4StackingAction::prepare);
m_prepare();
}