Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:35

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
0015 #include <DD4hep/InstanceCount.h>
0016 #include <DDG4/Geant4SteppingAction.h>
0017 
0018 // Geant4 headers
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 /// Standard constructor
0028 Geant4SteppingAction::Geant4SteppingAction(Geant4Context* ctxt, const std::string& nam)
0029 : Geant4Action(ctxt, nam) {
0030   InstanceCount::increment(this);
0031 }
0032 
0033 /// Default destructor
0034 Geant4SteppingAction::~Geant4SteppingAction() {
0035   InstanceCount::decrement(this);
0036 }
0037 
0038 /// User stepping callback
0039 void Geant4SteppingAction::operator()(const G4Step*, G4SteppingManager*) {
0040 }
0041 
0042 /// Standard constructor
0043 Geant4SharedSteppingAction::Geant4SharedSteppingAction(Geant4Context* ctxt, const std::string& nam)
0044   : Geant4SteppingAction(ctxt, nam), m_action(0)
0045 {
0046   InstanceCount::increment(this);
0047 }
0048 
0049 /// Default destructor
0050 Geant4SharedSteppingAction::~Geant4SharedSteppingAction()   {
0051   detail::releasePtr(m_action);
0052   InstanceCount::decrement(this);
0053 }
0054 
0055 /// Underlying object to be used during the execution of this thread
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 /// Set or update client for the use in a new thread fiber
0067 void Geant4SharedSteppingAction::configureFiber(Geant4Context* thread_context)   {
0068   m_action->configureFiber(thread_context);
0069 }
0070 
0071 /// User stepping callback
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 /// Standard constructor
0082 Geant4SteppingActionSequence::Geant4SteppingActionSequence(Geant4Context* ctxt, const std::string& nam)
0083 : Geant4Action(ctxt, nam) {
0084   m_needsControl = true;
0085   InstanceCount::increment(this);
0086 }
0087 
0088 /// Default destructor
0089 Geant4SteppingActionSequence::~Geant4SteppingActionSequence() {
0090   m_actors(&Geant4SteppingAction::release);
0091   m_actors.clear();
0092   m_calls.clear();
0093   InstanceCount::decrement(this);
0094 }
0095 
0096 /// Set or update client for the use in a new thread fiber
0097 void Geant4SteppingActionSequence::configureFiber(Geant4Context* thread_context)   {
0098   m_actors(&Geant4Action::configureFiber, thread_context);
0099 }
0100 
0101 /// Set or update client context
0102 void Geant4SteppingActionSequence::updateContext(Geant4Context* ctxt)    {
0103   m_context = ctxt;
0104   m_actors.updateContext(ctxt);
0105 }
0106 
0107 /// Get an action by name
0108 Geant4SteppingAction* Geant4SteppingActionSequence::get(const std::string& nam) const   {
0109   return m_actors.get(FindByName(TypeName::split(nam).second));
0110 }
0111 
0112 /// Pre-track action callback
0113 void Geant4SteppingActionSequence::operator()(const G4Step* step, G4SteppingManager* mgr) {
0114   m_actors(&Geant4SteppingAction::operator(), step, mgr);
0115   m_calls(step, mgr);
0116 }
0117 
0118 /// Add an actor responding to all callbacks. Sequence takes ownership.
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 }