DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4ActionPhase.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #ifndef DDG4_GEANT4ACTIONPHASE_H
14 #define DDG4_GEANT4ACTIONPHASE_H
15 
16 // Framework include files
17 #include <DD4hep/Exceptions.h>
18 #include <DDG4/Geant4Action.h>
19 
20 // C/C++ include files
21 #include <vector>
22 
24 namespace dd4hep {
25 
27  namespace sim {
28 
30 
37  public:
39  Geant4PhaseAction(Geant4Context* context, const std::string& name);
41  virtual ~Geant4PhaseAction();
43  virtual void operator()();
45  virtual Callback callback();
46  };
47 
48  /*
49  Geant4Phase, G4EventGenerator --> G4VUserPrimaryGeneratorAction::GeneratePrimaries
50  Geant4Begin, G4Run --> G4UserRunAction::BeginOfRunAction
51  Geant4End, G4Run --> G4UserRunAction::EndOfRunAction
52  Geant4Begin, G4Event --> G4UserEventAction::BeginOfEventAction
53  Geant4End, G4Event --> G4UserEventAction::EndOfEventAction
54  Geant4Begin, G4Track --> G4UserTrackingAction::PreUserTrackingAction
55  Geant4End, G4Track --> G4UserTrackingAction::PostUserTrackingAction
56  Geant4Phase, G4Step --> G4UserSteppingAction::UserSteppingAction
57  Geant4Begin, G4TrackStack --> G4UserStackingAction::NewStage
58  Geant4End, G4TrackStack --> G4UserStackingAction::PrepareNewEvent
59 
60  */
61 
63 
69  public:
70  typedef std::vector<std::pair<Geant4Action*, Callback> > Members;
71  protected:
75  const std::type_info* m_argTypes[3] = { nullptr, nullptr, nullptr };
76 
77  public:
79  Geant4ActionPhase(Geant4Context* context, const std::string& name, const std::type_info& arg_type0,
80  const std::type_info& arg_type1, const std::type_info& arg_type2);
82  virtual ~Geant4ActionPhase();
84  const Members& members() const {
85  return m_members;
86  }
88  const std::type_info* const * argTypes() const {
89  return m_argTypes;
90  }
92  void execute(void* argument);
94  virtual bool add(Geant4Action* action, Callback callback);
96  virtual bool remove(Geant4Action* action, Callback callback);
98  template <typename TYPE, typename IF_TYPE, typename A0, typename R>
99  bool add(TYPE* member, R (IF_TYPE::*callback)(A0 arg)) {
100  typeinfoCheck(typeid(A0), *m_argTypes[0], "Invalid ARG0 type. Failed to add phase callback.");
101  if (dynamic_cast<IF_TYPE*>(member)) {
102  return add(member,Callback(member).make(callback));
103  }
104  throw unrelated_type_error(typeid(TYPE), typeid(IF_TYPE), "Failed to add phase callback.");
105  }
107  template <typename TYPE, typename IF_TYPE, typename A0, typename A1, typename R>
108  bool add(TYPE* member, R (IF_TYPE::*callback)(A0 arg0, A1 arg1)) {
109  typeinfoCheck(typeid(A0), *m_argTypes[0], "Invalid ARG0 type. Failed to add phase callback.");
110  typeinfoCheck(typeid(A1), *m_argTypes[1], "Invalid ARG1 type. Failed to add phase callback.");
111  if (dynamic_cast<IF_TYPE*>(member)) {
112  return add(member,Callback(member).make(callback));
113  }
114  throw unrelated_type_error(typeid(TYPE), typeid(IF_TYPE), "Failed to add phase callback.");
115  }
117  template <typename TYPE, typename IF_TYPE, typename A0, typename A1, typename A2, typename R>
118  bool add(TYPE* member, R (IF_TYPE::*callback)(A0 arg0, A1 arg1)) {
119  typeinfoCheck(typeid(A0), *m_argTypes[0], "Invalid ARG0 type. Failed to add phase callback.");
120  typeinfoCheck(typeid(A1), *m_argTypes[1], "Invalid ARG1 type. Failed to add phase callback.");
121  typeinfoCheck(typeid(A2), *m_argTypes[2], "Invalid ARG2 type. Failed to add phase callback.");
122  if (dynamic_cast<IF_TYPE*>(member)) {
123  //member->addRef();
124  return add(member,Callback(member).make(callback));
125  }
126  throw unrelated_type_error(typeid(TYPE), typeid(IF_TYPE), "Failed to add phase callback.");
127  }
129  template <typename TYPE, typename PMF> bool remove(TYPE* member) {
130  return remove(member,Callback(member));
131  }
133  template <typename TYPE, typename PMF> bool remove(TYPE* member, PMF callback) {
134  Callback cb(member);
135  return remove(member,cb.make(callback));
136  }
138  void call();
139  template <typename A0> void call(A0 a0);
140  template <typename A0, typename A1> void call(A0 a0, A1 a1);
141  template <typename A0, typename A1, typename A2> void call(A0 a0, A1 a1, A2 a2);
142  };
143 
144  } // End namespace sim
145 } // End namespace dd4hep
146 
147 #endif // DDG4_GEANT4ACTIONPHASE_H
dd4hep::sim::Geant4ActionPhase::add
bool add(TYPE *member, R(IF_TYPE::*callback)(A0 arg))
Add a new member to the phase.
Definition: Geant4ActionPhase.h:99
dd4hep::sim::Geant4ActionPhase::add
bool add(TYPE *member, R(IF_TYPE::*callback)(A0 arg0, A1 arg1))
Add a new member to the phase.
Definition: Geant4ActionPhase.h:108
dd4hep::sim::Geant4ActionPhase::remove
bool remove(TYPE *member, PMF callback)
Remove an existing member callback from the phase. If not existing returns false.
Definition: Geant4ActionPhase.h:133
dd4hep::sim::Geant4ActionPhase::Members
std::vector< std::pair< Geant4Action *, Callback > > Members
Definition: Geant4ActionPhase.h:70
dd4hep::sim::Geant4ActionPhase::call
void call(A0 a0, A1 a1, A2 a2)
dd4hep::sim::Geant4ActionPhase::argTypes
const std::type_info *const * argTypes() const
Type of the first phase callback-argument.
Definition: Geant4ActionPhase.h:88
dd4hep::sim::Geant4ActionPhase
Action phase definition. Client callback at various stage of the simulation processing.
Definition: Geant4ActionPhase.h:68
dd4hep::sim::Geant4PhaseAction::Geant4PhaseAction
Geant4PhaseAction(Geant4Context *context, const std::string &name)
Standard constructor.
Definition: Geant4ActionPhase.cpp:21
dd4hep::sim::Geant4ActionPhase::remove
bool remove(TYPE *member)
Remove all member callbacks from the phase. If not existing returns false.
Definition: Geant4ActionPhase.h:129
dd4hep::sim::Geant4ActionPhase::m_members
Members m_members
Phase members (actions) being called for a particular phase.
Definition: Geant4ActionPhase.h:73
dd4hep::Callback::make
const Callback & make(R(T::*pmf)())
Callback setup function for Callbacks with member functions with explicit return type taking no argum...
Definition: Callback.h:126
dd4hep::sim::Geant4ActionPhase::add
virtual bool add(Geant4Action *action, Callback callback)
Add a new member to the phase.
Definition: Geant4ActionPhase.cpp:57
dd4hep::sim::Geant4PhaseAction::operator()
virtual void operator()()
Callback to generate primary particles.
Definition: Geant4ActionPhase.cpp:31
dd4hep::sim::Geant4ActionPhase::add
bool add(TYPE *member, R(IF_TYPE::*callback)(A0 arg0, A1 arg1))
Add a new member to the phase.
Definition: Geant4ActionPhase.h:118
dd4hep::Callback
Definition of the generic callback structure for member functions.
Definition: Callback.h:38
dd4hep::sim::Geant4ActionPhase::call
void call(A0 a0)
dd4hep::sim::Geant4PhaseAction::callback
virtual Callback callback()
Create bound callback to operator()()
Definition: Geant4ActionPhase.cpp:34
dd4hep::sim::Geant4Action
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:113
dd4hep::sim::Geant4Action::name
const std::string & name() const
Access name of the action.
Definition: Geant4Action.h:280
dd4hep::sim::Geant4ActionPhase::members
const Members & members() const
Access phase members.
Definition: Geant4ActionPhase.h:84
dd4hep::sim::Geant4PhaseAction
Generic action for Geant4 phases.
Definition: Geant4ActionPhase.h:36
dd4hep::sim::Geant4ActionPhase::call
void call()
Create action to execute phase members.
Definition: Geant4ActionPhase.cpp:103
dd4hep::sim::Geant4ActionPhase::execute
void execute(void *argument)
Execute all members in the phase context.
Definition: Geant4ActionPhase.cpp:86
dd4hep::sim::Geant4ActionPhase::call
void call(A0 a0, A1 a1)
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::Geant4ActionPhase::remove
virtual bool remove(Geant4Action *action, Callback callback)
Remove an existing member from the phase. If not existing returns false.
Definition: Geant4ActionPhase.cpp:64
dd4hep::sim::Geant4ActionPhase::Geant4ActionPhase
Geant4ActionPhase(Geant4Context *context, const std::string &name, const std::type_info &arg_type0, const std::type_info &arg_type1, const std::type_info &arg_type2)
Standard constructor.
Definition: Geant4ActionPhase.cpp:39
dd4hep::sim::Geant4ActionPhase::m_argTypes
const std::type_info * m_argTypes[3]
Type information of the argument type of the callback.
Definition: Geant4ActionPhase.h:75
dd4hep::sim::Geant4PhaseAction::~Geant4PhaseAction
virtual ~Geant4PhaseAction()
Default destructor.
Definition: Geant4ActionPhase.cpp:27
dd4hep::sim::Geant4ActionPhase::~Geant4ActionPhase
virtual ~Geant4ActionPhase()
Default destructor.
Definition: Geant4ActionPhase.cpp:49
Geant4Action.h
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
Exceptions.h
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270