Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:22

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_GEANT4ACTIONPHASE_H
0014 #define DDG4_GEANT4ACTIONPHASE_H
0015 
0016 // Framework include files
0017 #include <DD4hep/Exceptions.h>
0018 #include <DDG4/Geant4Action.h>
0019 
0020 // C/C++ include files
0021 #include <vector>
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     /// Generic action for Geant4 phases
0030     /**
0031      *
0032      *  \author  M.Frank
0033      *  \version 1.0
0034      *  \ingroup DD4HEP_SIMULATION
0035      */
0036     class Geant4PhaseAction : public Geant4Action {
0037     public:
0038       /// Standard constructor
0039       Geant4PhaseAction(Geant4Context* context, const std::string& name);
0040       /// Default destructor
0041       virtual ~Geant4PhaseAction();
0042       /// Callback to generate primary particles
0043       virtual void operator()();
0044       /// Create bound callback to operator()()
0045       virtual Callback callback();
0046     };
0047 
0048     /*
0049       Geant4Phase,  G4EventGenerator    --> G4VUserPrimaryGeneratorAction::GeneratePrimaries
0050       Geant4Begin,  G4Run               --> G4UserRunAction::BeginOfRunAction
0051       Geant4End,    G4Run               --> G4UserRunAction::EndOfRunAction
0052       Geant4Begin,  G4Event             --> G4UserEventAction::BeginOfEventAction
0053       Geant4End,    G4Event             --> G4UserEventAction::EndOfEventAction
0054       Geant4Begin,  G4Track             --> G4UserTrackingAction::PreUserTrackingAction
0055       Geant4End,    G4Track             --> G4UserTrackingAction::PostUserTrackingAction
0056       Geant4Phase,  G4Step              --> G4UserSteppingAction::UserSteppingAction
0057       Geant4Begin,  G4TrackStack        --> G4UserStackingAction::NewStage
0058       Geant4End,    G4TrackStack        --> G4UserStackingAction::PrepareNewEvent
0059 
0060     */
0061 
0062     /// Action phase definition. Client callback at various stage of the simulation processing
0063     /**
0064      *  \author  M.Frank
0065      *  \version 1.0
0066      *  \ingroup DD4HEP_SIMULATION
0067      */
0068     class Geant4ActionPhase : public Geant4Action {
0069     public:
0070       typedef std::vector<std::pair<Geant4Action*, Callback> > Members;
0071     protected:
0072       /// Phase members (actions) being called for a particular phase
0073       Members m_members  { };
0074       /// Type information of the argument type of the callback
0075       const std::type_info* m_argTypes[3] = { nullptr, nullptr, nullptr };
0076 
0077     public:
0078       /// Standard constructor
0079       Geant4ActionPhase(Geant4Context* context, const std::string& name, const std::type_info& arg_type0,
0080                         const std::type_info& arg_type1, const std::type_info& arg_type2);
0081       /// Default destructor
0082       virtual ~Geant4ActionPhase();
0083       /// Access phase members
0084       const Members& members() const {
0085         return m_members;
0086       }
0087       /// Type of the first phase callback-argument
0088       const std::type_info* const * argTypes() const {
0089         return m_argTypes;
0090       }
0091       /// Execute all members in the phase context
0092       void execute(void* argument);
0093       /// Add a new member to the phase
0094       virtual bool add(Geant4Action* action, Callback callback);
0095       /// Remove an existing member from the phase. If not existing returns false
0096       virtual bool remove(Geant4Action* action, Callback callback);
0097       /// Add a new member to the phase
0098       template <typename TYPE, typename IF_TYPE, typename A0, typename R>
0099       bool add(TYPE* member, R (IF_TYPE::*callback)(A0 arg)) {
0100         typeinfoCheck(typeid(A0), *m_argTypes[0], "Invalid ARG0 type. Failed to add phase callback.");
0101         if (dynamic_cast<IF_TYPE*>(member)) {
0102           return add(member,Callback(member).make(callback));
0103         }
0104         throw unrelated_type_error(typeid(TYPE), typeid(IF_TYPE), "Failed to add phase callback.");
0105       }
0106       /// Add a new member to the phase
0107       template <typename TYPE, typename IF_TYPE, typename A0, typename A1, typename R>
0108       bool add(TYPE* member, R (IF_TYPE::*callback)(A0 arg0, A1 arg1)) {
0109         typeinfoCheck(typeid(A0), *m_argTypes[0], "Invalid ARG0 type. Failed to add phase callback.");
0110         typeinfoCheck(typeid(A1), *m_argTypes[1], "Invalid ARG1 type. Failed to add phase callback.");
0111         if (dynamic_cast<IF_TYPE*>(member)) {
0112           return add(member,Callback(member).make(callback));
0113         }
0114         throw unrelated_type_error(typeid(TYPE), typeid(IF_TYPE), "Failed to add phase callback.");
0115       }
0116       /// Add a new member to the phase
0117       template <typename TYPE, typename IF_TYPE, typename A0, typename A1, typename A2, typename R>
0118       bool add(TYPE* member, R (IF_TYPE::*callback)(A0 arg0, A1 arg1)) {
0119         typeinfoCheck(typeid(A0), *m_argTypes[0], "Invalid ARG0 type. Failed to add phase callback.");
0120         typeinfoCheck(typeid(A1), *m_argTypes[1], "Invalid ARG1 type. Failed to add phase callback.");
0121         typeinfoCheck(typeid(A2), *m_argTypes[2], "Invalid ARG2 type. Failed to add phase callback.");
0122         if (dynamic_cast<IF_TYPE*>(member)) {
0123           //member->addRef();
0124           return add(member,Callback(member).make(callback));
0125         }
0126         throw unrelated_type_error(typeid(TYPE), typeid(IF_TYPE), "Failed to add phase callback.");
0127       }
0128       /// Remove all member callbacks from the phase. If not existing returns false
0129       template <typename TYPE, typename PMF> bool remove(TYPE* member) {
0130         return remove(member,Callback(member));
0131       }
0132       /// Remove an existing member callback from the phase. If not existing returns false
0133       template <typename TYPE, typename PMF> bool remove(TYPE* member, PMF callback) {
0134         Callback cb(member);
0135         return remove(member,cb.make(callback));
0136       }
0137       /// Create action to execute phase members
0138       void call();
0139       template <typename A0> void call(A0 a0);
0140       template <typename A0, typename A1> void call(A0 a0, A1 a1);
0141       template <typename A0, typename A1, typename A2> void call(A0 a0, A1 a1, A2 a2);
0142     };
0143 
0144   }    // End namespace sim
0145 }      // End namespace dd4hep
0146 
0147 #endif // DDG4_GEANT4ACTIONPHASE_H