Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-13 08:20:13

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/Geant4EventAction.h>
0017 
0018 // Geant4 headers
0019 #include <G4Threading.hh>
0020 #include <G4AutoLock.hh>
0021 
0022 using namespace dd4hep::sim;
0023 
0024 namespace {
0025   G4Mutex event_action_mutex=G4MUTEX_INITIALIZER;
0026 }
0027 
0028 /// Standard constructor
0029 Geant4EventAction::Geant4EventAction(Geant4Context* ctxt, const std::string& nam)
0030   : Geant4Action(ctxt, nam) 
0031 {
0032   InstanceCount::increment(this);
0033 }
0034 
0035 /// Default destructor
0036 Geant4EventAction::~Geant4EventAction() {
0037   InstanceCount::decrement(this);
0038 }
0039 
0040 /// begin-of-event callback
0041 void Geant4EventAction::begin(const G4Event* ) {
0042 }
0043 
0044 /// End-of-event callback
0045 void Geant4EventAction::end(const G4Event* ) {
0046 }
0047 
0048 /// Standard constructor
0049 Geant4SharedEventAction::Geant4SharedEventAction(Geant4Context* ctxt, const std::string& nam)
0050   : Geant4EventAction(ctxt, nam)
0051 {
0052   InstanceCount::increment(this);
0053 }
0054 
0055 /// Default destructor
0056 Geant4SharedEventAction::~Geant4SharedEventAction()   {
0057   detail::releasePtr(m_action);
0058   InstanceCount::decrement(this);
0059 }
0060 
0061 /// Set or update client for the use in a new thread fiber
0062 void Geant4SharedEventAction::configureFiber(Geant4Context* thread_context)   {
0063   m_action->configureFiber(thread_context);
0064 }
0065 
0066 /// Underlying object to be used during the execution of this thread
0067 void Geant4SharedEventAction::use(Geant4EventAction* action)   {
0068   if (action) {
0069     action->addRef();
0070     m_properties.adopt(action->properties());
0071     m_action = action;
0072     return;
0073   }
0074   except("Geant4SharedEventAction: Attempt to use invalid actor!");
0075 }
0076 
0077 /// Begin-of-event callback
0078 void Geant4SharedEventAction::begin(const G4Event* event)   {
0079   if ( m_action )  {
0080     G4AutoLock protection_lock(&event_action_mutex);    {
0081       ContextSwap swap(m_action,context());
0082       m_action->begin(event);
0083     }
0084   }
0085 }
0086 
0087 /// End-of-event callback
0088 void Geant4SharedEventAction::end(const G4Event* event)   {
0089   if ( m_action )  {
0090     G4AutoLock protection_lock(&event_action_mutex);  {
0091       ContextSwap swap(m_action,context());
0092       m_action->end(event);
0093     }
0094   }
0095 }
0096 
0097 /// Standard constructor
0098 Geant4EventActionSequence::Geant4EventActionSequence(Geant4Context* ctxt, const std::string& nam)
0099   : Geant4Action(ctxt, nam) {
0100   m_needsControl = true;
0101   InstanceCount::increment(this);
0102 }
0103 
0104 /// Default destructor
0105 Geant4EventActionSequence::~Geant4EventActionSequence() {
0106   m_actors(&Geant4Action::release);
0107   m_actors.clear();
0108   m_begin.clear();
0109   m_end.clear();
0110   m_final.clear();
0111   InstanceCount::decrement(this);
0112 }
0113 
0114 /// Set or update client context
0115 void Geant4EventActionSequence::updateContext(Geant4Context* ctxt)    {
0116   m_context = ctxt;
0117   m_actors.updateContext(ctxt);
0118 }
0119 
0120 /// Set or update client for the use in a new thread fiber
0121 void Geant4EventActionSequence::configureFiber(Geant4Context* thread_context)   {
0122   m_actors(&Geant4Action::configureFiber, thread_context);
0123 }
0124 
0125 /// Get an action by name
0126 Geant4EventAction* Geant4EventActionSequence::get(const std::string& nam) const   {
0127   return m_actors.get(FindByName(TypeName::split(nam).second));
0128 }
0129 
0130 /// Add an actor responding to all callbacks. Sequence takes ownership.
0131 void Geant4EventActionSequence::adopt(Geant4EventAction* action) {
0132   if (action) {
0133     G4AutoLock protection_lock(&event_action_mutex);
0134     action->addRef();
0135     m_actors.add(action);
0136     return;
0137   }
0138   except("Geant4EventActionSequence: Attempt to add invalid actor!");
0139 }
0140 
0141 /// Pre-track action callback
0142 void Geant4EventActionSequence::begin(const G4Event* event)   {
0143   m_actors(&Geant4EventAction::begin, event);
0144   m_begin(event);
0145 }
0146 
0147 /// Post-track action callback
0148 void Geant4EventActionSequence::end(const G4Event* event)   {
0149   m_end(event);
0150   m_actors(&Geant4EventAction::end, event);
0151   m_final(event);
0152 }