|
||||
File indexing completed on 2024-11-15 09:35: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 #ifndef DDG4_GEANT4GENERATORACTION_H 0014 #define DDG4_GEANT4GENERATORACTION_H 0015 0016 // Framework include files 0017 #include <DDG4/Geant4Action.h> 0018 0019 // Forward declaration 0020 class G4Event; 0021 0022 /// Namespace for the AIDA detector description toolkit 0023 namespace dd4hep { 0024 0025 /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit 0026 namespace sim { 0027 0028 // Forward declarations 0029 class Geant4GeneratorAction; 0030 class Geant4SharedGeneratorAction; 0031 class Geant4GeneratorActionSequence; 0032 0033 /// Concrete implementation of the Geant4 generator action base class 0034 /** 0035 * The Geant4GeneratorAction is called for every event. 0036 * During the callback all particles are created which form the 0037 * microscopic kinematic action of the particle collision. 0038 * This input may either origin directly from an event generator program 0039 * or come from file. 0040 * 0041 * The callback signature is: void operator()(G4Event* event) 0042 * 0043 * \author M.Frank 0044 * \version 1.0 0045 * \ingroup DD4HEP_SIMULATION 0046 */ 0047 class Geant4GeneratorAction : public Geant4Action { 0048 public: 0049 typedef Geant4SharedGeneratorAction shared_type; 0050 protected: 0051 Callback m_calls; 0052 0053 /// Define standard assignments and constructors 0054 DDG4_DEFINE_ACTION_CONSTRUCTORS(Geant4GeneratorAction); 0055 public: 0056 /// Standard constructor 0057 Geant4GeneratorAction(Geant4Context* context, const std::string& name); 0058 /// Default destructor 0059 virtual ~Geant4GeneratorAction(); 0060 /// Callback to generate primary particles 0061 virtual void operator()(G4Event*) { 0062 } 0063 }; 0064 0065 /// Implementation of the Geant4 shared generator action 0066 /** 0067 * Wrapper to share single instances of generator actions for 0068 * multi-threaded purposes. The wrapper ensures the locking 0069 * of the basic actions to avoid race conditions. 0070 * 0071 * Shared action should be 'fast'. The global lock otherwise 0072 * inhibits the efficient use of the multiple threads. 0073 * 0074 * \author M.Frank 0075 * \version 1.0 0076 * \ingroup DD4HEP_SIMULATION 0077 */ 0078 class Geant4SharedGeneratorAction : public Geant4GeneratorAction { 0079 protected: 0080 /// Reference to the shared action 0081 Geant4GeneratorAction* m_action = 0; 0082 0083 /// Define standard assignments and constructors 0084 DDG4_DEFINE_ACTION_CONSTRUCTORS(Geant4SharedGeneratorAction); 0085 public: 0086 /// Standard constructor 0087 Geant4SharedGeneratorAction(Geant4Context* context, const std::string& nam); 0088 /// Default destructor 0089 virtual ~Geant4SharedGeneratorAction(); 0090 /// Set or update client for the use in a new thread fiber 0091 virtual void configureFiber(Geant4Context* thread_context) override; 0092 /// Underlying object to be used during the execution of this thread 0093 virtual void use(Geant4GeneratorAction* action); 0094 /// User generator callback 0095 virtual void operator()(G4Event* event) override; 0096 }; 0097 0098 /// Concrete implementation of the Geant4 generator action sequence 0099 /** 0100 * The sequence dispatches the callbacks at the beginning 0101 * of an event to all registered Geant4GeneratorAction members and all 0102 * registered callbacks. 0103 * 0104 * The callback signature is: void operator()(G4Event* event) 0105 * 0106 * Note Multi-Threading issue: 0107 * Neither callbacks not the action list is protected against multiple 0108 * threads calling the Geant4 callbacks! 0109 * These must be protected in the user actions themselves. 0110 * 0111 * \author M.Frank 0112 * \version 1.0 0113 * \ingroup DD4HEP_SIMULATION 0114 */ 0115 class Geant4GeneratorActionSequence : public Geant4Action { 0116 protected: 0117 /// Callback sequence to generate primary particles 0118 CallbackSequence m_calls; 0119 /// The list of action objects to be called 0120 Actors<Geant4GeneratorAction> m_actors; 0121 0122 /// Define standard assignments and constructors 0123 DDG4_DEFINE_ACTION_CONSTRUCTORS(Geant4GeneratorActionSequence); 0124 public: 0125 /// Standard constructor 0126 Geant4GeneratorActionSequence(Geant4Context* context, const std::string& name); 0127 /// Default destructor 0128 virtual ~Geant4GeneratorActionSequence(); 0129 /// Set or update client context 0130 virtual void updateContext(Geant4Context* ctxt) override; 0131 /// Set or update client for the use in a new thread fiber 0132 virtual void configureFiber(Geant4Context* thread_context) override; 0133 /// Get an action by name 0134 Geant4GeneratorAction* get(const std::string& name) const; 0135 /// Register primary particle generation callback. Types Q and T must be polymorph! 0136 template <typename Q, typename T> 0137 void call(Q* p, void (T::*f)(G4Event*)) { 0138 m_calls.add(p, f); 0139 } 0140 /// Add an actor responding to all callbacks. Sequence takes ownership. 0141 void adopt(Geant4GeneratorAction* action); 0142 /// Callback to generate primary particles 0143 virtual void operator()(G4Event* event); 0144 }; 0145 0146 } // End namespace sim 0147 } // End namespace dd4hep 0148 0149 #endif // DDG4_GEANT4GENERATORACTION_H
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |