File indexing completed on 2025-01-18 09:55:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DDG4_GEANT4ACTIONPHASE_H
0014 #define DDG4_GEANT4ACTIONPHASE_H
0015
0016
0017 #include <DD4hep/Exceptions.h>
0018 #include <DDG4/Geant4Action.h>
0019
0020
0021 #include <vector>
0022
0023
0024 namespace dd4hep {
0025
0026
0027 namespace sim {
0028
0029
0030
0031
0032
0033
0034
0035
0036 class Geant4PhaseAction : public Geant4Action {
0037 public:
0038
0039 Geant4PhaseAction(Geant4Context* context, const std::string& name);
0040
0041 virtual ~Geant4PhaseAction();
0042
0043 virtual void operator()();
0044
0045 virtual Callback callback();
0046 };
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068 class Geant4ActionPhase : public Geant4Action {
0069 public:
0070 typedef std::vector<std::pair<Geant4Action*, Callback> > Members;
0071 protected:
0072
0073 Members m_members { };
0074
0075 const std::type_info* m_argTypes[3] = { nullptr, nullptr, nullptr };
0076
0077 public:
0078
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
0082 virtual ~Geant4ActionPhase();
0083
0084 const Members& members() const {
0085 return m_members;
0086 }
0087
0088 const std::type_info* const * argTypes() const {
0089 return m_argTypes;
0090 }
0091
0092 void execute(void* argument);
0093
0094 virtual bool add(Geant4Action* action, Callback callback);
0095
0096 virtual bool remove(Geant4Action* action, Callback callback);
0097
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
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
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
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
0129 template <typename TYPE, typename PMF> bool remove(TYPE* member) {
0130 return remove(member,Callback(member));
0131 }
0132
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
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 }
0145 }
0146
0147 #endif