Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:23

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/Printout.h>
0016 #include <DD4hep/Primitives.h>
0017 #include <DD4hep/InstanceCount.h>
0018 
0019 #include <DDG4/Geant4ActionContainer.h>
0020 #include <DDG4/Geant4RunAction.h>
0021 #include <DDG4/Geant4PhysicsList.h>
0022 #include <DDG4/Geant4EventAction.h>
0023 #include <DDG4/Geant4SteppingAction.h>
0024 #include <DDG4/Geant4TrackingAction.h>
0025 #include <DDG4/Geant4StackingAction.h>
0026 #include <DDG4/Geant4GeneratorAction.h>
0027 #include <DDG4/Geant4DetectorConstruction.h>
0028 #include <DDG4/Geant4UserInitialization.h>
0029 #include <DDG4/Geant4SensDetAction.h>
0030 
0031 // C/C++ include files
0032 #include <stdexcept>
0033 #include <algorithm>
0034 
0035 using namespace dd4hep::sim;
0036 
0037 /// Standard constructor
0038 Geant4ActionContainer::Geant4ActionContainer(Geant4Context* ctxt) : m_context(ctxt)
0039 {
0040   m_sensDetActions = new Geant4SensDetSequences();
0041   InstanceCount::increment(this);
0042 }
0043 
0044 /// Default destructor
0045 Geant4ActionContainer::~Geant4ActionContainer() {
0046   this->Geant4ActionContainer::terminate();
0047   InstanceCount::decrement(this);
0048 }
0049 
0050 /// Terminate all associated action instances
0051 int Geant4ActionContainer::terminate() {
0052   detail::releasePtr (m_physicsList);
0053   detail::releasePtr (m_constructionAction);
0054   detail::releasePtr (m_stackingAction);
0055   detail::releasePtr (m_steppingAction);
0056   detail::releasePtr (m_trackingAction);
0057   detail::releasePtr (m_eventAction);
0058   detail::releasePtr (m_generatorAction);
0059   detail::releasePtr (m_runAction);
0060   detail::deletePtr  (m_sensDetActions);
0061   detail::deletePtr  (m_context);
0062   return 1;
0063 }
0064 
0065 Geant4Context* Geant4ActionContainer::workerContext()   {
0066   if ( m_context ) return m_context;
0067   throw std::runtime_error(format("Geant4Kernel", "DDG4: Master kernel object has no thread context! [Invalid Handle]"));
0068 }
0069 
0070 /// Set the thread's context
0071 void Geant4ActionContainer::setContext(Geant4Context* ctxt)    {
0072   m_context = ctxt;
0073 }
0074 
0075 template <class C> bool Geant4ActionContainer::registerSequence(C*& seq, const std::string& name) {
0076   if (!name.empty()) {
0077     seq = new C(m_context, name);
0078     seq->installMessengers();
0079     return true;
0080   }
0081   throw std::runtime_error(format("Geant4ActionContainer", "DDG4: The action '%s' not found. [Action-NotFound]", name.c_str()));
0082 }
0083 
0084 /// Access generator action sequence
0085 Geant4GeneratorActionSequence* Geant4ActionContainer::generatorAction(bool create) {
0086   if (!m_generatorAction && create)
0087     registerSequence(m_generatorAction, "GeneratorAction");
0088   return m_generatorAction;
0089 }
0090 
0091 /// Access run action sequence
0092 Geant4RunActionSequence* Geant4ActionContainer::runAction(bool create) {
0093   if (!m_runAction && create)
0094     registerSequence(m_runAction, "RunAction");
0095   return m_runAction;
0096 }
0097 
0098 /// Access event action sequence
0099 Geant4EventActionSequence* Geant4ActionContainer::eventAction(bool create) {
0100   if (!m_eventAction && create)
0101     registerSequence(m_eventAction, "EventAction");
0102   return m_eventAction;
0103 }
0104 
0105 /// Access stepping action sequence
0106 Geant4SteppingActionSequence* Geant4ActionContainer::steppingAction(bool create) {
0107   if (!m_steppingAction && create)
0108     registerSequence(m_steppingAction, "SteppingAction");
0109   return m_steppingAction;
0110 }
0111 
0112 /// Access tracking action sequence
0113 Geant4TrackingActionSequence* Geant4ActionContainer::trackingAction(bool create) {
0114   if (!m_trackingAction && create)
0115     registerSequence(m_trackingAction, "TrackingAction");
0116   return m_trackingAction;
0117 }
0118 
0119 /// Access stacking action sequence
0120 Geant4StackingActionSequence* Geant4ActionContainer::stackingAction(bool create) {
0121   if (!m_stackingAction && create)
0122     registerSequence(m_stackingAction, "StackingAction");
0123   return m_stackingAction;
0124 }
0125 
0126 /// Access detector construcion action sequence (geometry+sensitives+field)
0127 Geant4DetectorConstructionSequence* Geant4ActionContainer::detectorConstruction(bool create)  {
0128   if (!m_constructionAction && create)
0129     registerSequence(m_constructionAction, "DetectorConstructionAction");
0130   return m_constructionAction;
0131 }
0132 
0133 /// Access to the sensitive detector sequences from the kernel object
0134 Geant4SensDetSequences& Geant4ActionContainer::sensitiveActions() const {
0135   return *m_sensDetActions;
0136 }
0137 
0138 /// Access to the sensitive detector action from the kernel object
0139 Geant4SensDetActionSequence* Geant4ActionContainer::sensitiveAction(const std::string& nam) {
0140   Geant4SensDetActionSequence* ptr = m_sensDetActions->find(nam);
0141   if (ptr)   {
0142     return ptr;
0143   }
0144   ptr = new Geant4SensDetActionSequence(workerContext(), nam);
0145   m_sensDetActions->insert(nam, ptr);
0146   return ptr;
0147 }
0148 
0149 /// Access to the physics list
0150 Geant4PhysicsListActionSequence* Geant4ActionContainer::physicsList(bool create) {
0151   if (!m_physicsList && create)
0152     registerSequence(m_physicsList, "PhysicsList");
0153   return m_physicsList;
0154 }
0155 
0156 /// Access to the physics list
0157 Geant4UserInitializationSequence* Geant4ActionContainer::userInitialization(bool create) {
0158   if (!m_userInit && create)   {
0159     registerSequence(m_userInit, "UserInitialization");
0160   }
0161   return m_userInit;
0162 }