|
||||
File indexing completed on 2025-01-18 09:55:24
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 #ifndef DDG4_GEANT4RUNACTION_H 0015 #define DDG4_GEANT4RUNACTION_H 0016 0017 // Framework include files 0018 #include <DDG4/Geant4Action.h> 0019 0020 // Forward declaration 0021 class G4Run; 0022 0023 /// Namespace for the AIDA detector description toolkit 0024 namespace dd4hep { 0025 0026 /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit 0027 namespace sim { 0028 0029 // Forward declarations 0030 class Geant4RunAction; 0031 class Geant4SharedRunAction; 0032 class Geant4RunActionSequence; 0033 0034 /// Concrete basic implementation of the Geant4 run action base class. 0035 /** 0036 * The Run Action is called once per start and end of a run. 0037 * i.e. a series of generated events. These two callbacks 0038 * allow clients to define run-dependent actions such as statistics 0039 * summaries etc. 0040 * 0041 * \author M.Frank 0042 * \version 1.0 0043 * \ingroup DD4HEP_SIMULATION 0044 */ 0045 class Geant4RunAction: public Geant4Action { 0046 public: 0047 typedef Geant4SharedRunAction shared_type; 0048 0049 protected: 0050 /// Define standard assignments and constructors 0051 DDG4_DEFINE_ACTION_CONSTRUCTORS(Geant4RunAction); 0052 0053 public: 0054 /// Standard constructor 0055 Geant4RunAction(Geant4Context* context, const std::string& nam); 0056 /// Default destructor 0057 virtual ~Geant4RunAction(); 0058 /// Begin-of-run callback 0059 virtual void begin(const G4Run* run); 0060 /// End-of-run callback 0061 virtual void end(const G4Run* run); 0062 }; 0063 0064 /// Implementation of the Geant4 shared run action 0065 /** 0066 * Wrapper to share single instances of run actions for 0067 * multi-threaded purposes. The wrapper ensures the locking 0068 * of the basic actions to avoid race conditions. 0069 * 0070 * Shared action should be 'fast'. The global lock otherwise 0071 * inhibits the efficient use of the multiple threads. 0072 * 0073 * \author M.Frank 0074 * \version 1.0 0075 * \ingroup DD4HEP_SIMULATION 0076 */ 0077 class Geant4SharedRunAction : public Geant4RunAction { 0078 protected: 0079 /// Reference to the shared action 0080 Geant4RunAction* m_action = 0; 0081 0082 protected: 0083 /// Define standard assignments and constructors 0084 DDG4_DEFINE_ACTION_CONSTRUCTORS(Geant4SharedRunAction); 0085 0086 public: 0087 /// Inhibit default constructor 0088 /// Standard constructor 0089 Geant4SharedRunAction(Geant4Context* context, const std::string& nam); 0090 /// Default destructor 0091 virtual ~Geant4SharedRunAction(); 0092 /// Set or update client for the use in a new thread fiber 0093 virtual void configureFiber(Geant4Context* thread_context); 0094 /// Underlying object to be used during the execution of this thread 0095 virtual void use(Geant4RunAction* action); 0096 /// Begin-of-run callback 0097 virtual void begin(const G4Run* run); 0098 /// End-of-run callback 0099 virtual void end(const G4Run* run); 0100 }; 0101 0102 /// Concrete basic implementation of the Geant4 run action sequencer. 0103 /** 0104 * Concrete implementation of the Geant4 run action sequence. 0105 * The sequence dispatches the callbacks at the beginning and the and 0106 * of a run to all registered Geant4RunAction members and all 0107 * registered callbacks. 0108 * 0109 * Note Multi-Threading issue: 0110 * Callbacks and the action list is protected against multiple 0111 * threads calling the Geant4 callbacks! 0112 * 0113 * \author M.Frank 0114 * \version 1.0 0115 * \ingroup DD4HEP_SIMULATION 0116 */ 0117 class Geant4RunActionSequence: public Geant4Action { 0118 0119 protected: 0120 /// Callback sequence for begin-run action 0121 CallbackSequence m_begin; 0122 /// Callback sequence for end-run action 0123 CallbackSequence m_end; 0124 /// The list of action objects to be called 0125 Actors<Geant4RunAction> m_actors; 0126 0127 protected: 0128 /// Define standard assignments and constructors 0129 DDG4_DEFINE_ACTION_CONSTRUCTORS(Geant4RunActionSequence); 0130 0131 public: 0132 /// Standard constructor 0133 Geant4RunActionSequence(Geant4Context* context, const std::string& nam); 0134 /// Default destructor 0135 virtual ~Geant4RunActionSequence(); 0136 /// Set or update client context 0137 virtual void updateContext(Geant4Context* ctxt); 0138 /// Set or update client for the use in a new thread fiber 0139 virtual void configureFiber(Geant4Context* thread_context); 0140 /// Get an action by name 0141 Geant4RunAction* get(const std::string& name) const; 0142 /// Register begin-of-run callback. Types Q and T must be polymorph! 0143 template <typename Q, typename T> 0144 void callAtBegin(Q* p, void (T::*f)(const G4Run*)) { 0145 m_begin.add(p, f); 0146 } 0147 /// Register end-of-run callback. Types Q and T must be polymorph! 0148 template <typename Q, typename T> 0149 void callAtEnd(Q* p, void (T::*f)(const G4Run*)) { 0150 m_end.add(p, f); 0151 } 0152 /// Add an actor responding to all callbacks. Sequence takes ownership. 0153 void adopt(Geant4RunAction* action); 0154 /// Begin-of-run callback 0155 virtual void begin(const G4Run* run); 0156 /// End-of-run callback 0157 virtual void end(const G4Run* run); 0158 }; 0159 0160 } // End namespace sim 0161 } // End namespace dd4hep 0162 0163 #endif // DDG4_GEANT4RUNACTION_H
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |