Back to home page

EIC code displayed by LXR

 
 

    


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 #ifndef DDG4_GEANT4STEPPINGACTION_H
0014 #define DDG4_GEANT4STEPPINGACTION_H
0015 
0016 // Framework include files
0017 #include <DDG4/Geant4Action.h>
0018 
0019 // Forward declarations
0020 class G4SteppingManager;
0021 class G4Step;
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 Geant4SteppingAction;
0031     class Geant4SharedSteppingAction;
0032     class Geant4SteppingActionSequence;
0033 
0034     /// Concrete implementation of the Geant4 stepping action sequence
0035     /**
0036      *  \author  M.Frank
0037      *  \version 1.0
0038      *  \ingroup DD4HEP_SIMULATION
0039      */
0040     class Geant4SteppingAction: public Geant4Action {
0041     public:
0042       typedef Geant4SharedSteppingAction shared_type;
0043       /// Define standard assignments and constructors
0044       DDG4_DEFINE_ACTION_CONSTRUCTORS(Geant4SteppingAction);
0045 
0046     public:
0047       /// Standard constructor
0048       Geant4SteppingAction(Geant4Context* context, const std::string& name);
0049       /// Default destructor
0050       virtual ~Geant4SteppingAction();
0051       /// User stepping callback
0052       virtual void operator()(const G4Step* step, G4SteppingManager* mgr);
0053     };
0054 
0055     /// Implementation of the Geant4 shared stepping action
0056     /**
0057      * Wrapper to share single instances of stepping actions for
0058      * multi-threaded purposes. The wrapper ensures the locking
0059      * of the basic actions to avoid race conditions.
0060      *
0061      * Shared action should be 'fast'. The global lock otherwise
0062      * inhibits the efficient use of the multiple threads.
0063      *
0064      *  \author  M.Frank
0065      *  \version 1.0
0066      *  \ingroup DD4HEP_SIMULATION
0067      */
0068     class Geant4SharedSteppingAction : public Geant4SteppingAction {
0069     protected:
0070       /// Reference to the shared action
0071       Geant4SteppingAction* m_action = 0;
0072 
0073       /// Define standard assignments and constructors
0074       DDG4_DEFINE_ACTION_CONSTRUCTORS(Geant4SharedSteppingAction);
0075 
0076     public:
0077       /// Standard constructor
0078       Geant4SharedSteppingAction(Geant4Context* context, const std::string& nam);
0079       /// Default destructor
0080       virtual ~Geant4SharedSteppingAction();
0081       /// Set or update client for the use in a new thread fiber
0082       virtual void configureFiber(Geant4Context* thread_context)  override;
0083       /// Underlying object to be used during the execution of this thread
0084       virtual void use(Geant4SteppingAction* action);
0085       /// User stepping callback
0086       virtual void operator()(const G4Step* step, G4SteppingManager* mgr)  override;
0087     };
0088 
0089     /// Concrete implementation of the Geant4 stepping action sequence
0090     /**
0091      * The sequence dispatches the callbacks for each stepping action
0092      * to all registered Geant4SteppingAction members and all
0093      * registered callbacks.
0094      *
0095      * Note Multi-Threading issue:
0096      * Neither callbacks not the action list is protected against multiple 
0097      * threads calling the Geant4 callbacks!
0098      * These must be protected in the user actions themselves.
0099      *
0100      *  \author  M.Frank
0101      *  \version 1.0
0102      *  \ingroup DD4HEP_SIMULATION
0103      */
0104     class Geant4SteppingActionSequence: public Geant4Action {
0105     protected:
0106       /// Callback sequence for user stepping action calls
0107       CallbackSequence m_calls;
0108       /// The list of action objects to be called
0109       Actors<Geant4SteppingAction> m_actors;
0110 
0111       /// Define standard assignments and constructors
0112       DDG4_DEFINE_ACTION_CONSTRUCTORS(Geant4SteppingActionSequence);
0113 
0114     public:
0115       /// Standard constructor
0116       Geant4SteppingActionSequence(Geant4Context* context, const std::string& name);
0117       /// Default destructor
0118       virtual ~Geant4SteppingActionSequence();
0119       /// Set or update client context
0120       virtual void updateContext(Geant4Context* ctxt)  override;
0121       /// Set or update client for the use in a new thread fiber
0122       virtual void configureFiber(Geant4Context* thread_context)  override;
0123       /// Get an action by name
0124       Geant4SteppingAction* get(const std::string& name) const;
0125       /// Register stepping action callback. Types Q and T must be polymorph!
0126       template <typename Q, typename T>
0127       void call(Q* p, void (T::*f)(const G4Step*, G4SteppingManager*)) {
0128         m_calls.add(p, f);
0129       }
0130       /// Add an actor responding to all callbacks. Sequence takes ownership.
0131       void adopt(Geant4SteppingAction* action);
0132       /// User stepping callback
0133       virtual void operator()(const G4Step* step, G4SteppingManager* mgr);
0134     };
0135 
0136   }    // End namespace sim
0137 }      // End namespace dd4hep
0138 
0139 #endif // DDG4_GEANT4STEPPINGACTION_H