DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4ActionPhase.h
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 #ifndef DD4HEP_DDG4_GEANT4ACTIONPHASE_H
15 #define DD4HEP_DDG4_GEANT4ACTIONPHASE_H
16 
17 // Framework include files
18 #include "DD4hep/Exceptions.h"
19 #include "DDG4/Geant4Action.h"
20 
21 // C/C++ include files
22 #include <vector>
23 
25 namespace DD4hep {
26 
28  namespace Simulation {
29 
31 
38  public:
40  Geant4PhaseAction(Geant4Context* context, const std::string& name);
42  virtual ~Geant4PhaseAction();
44  virtual void operator()();
46  virtual Callback callback();
47  };
48 
49  /*
50  Geant4Phase, G4EventGenerator --> G4VUserPrimaryGeneratorAction::GeneratePrimaries
51  Geant4Begin, G4Run --> G4UserRunAction::BeginOfRunAction
52  Geant4End, G4Run --> G4UserRunAction::EndOfRunAction
53  Geant4Begin, G4Event --> G4UserEventAction::BeginOfEventAction
54  Geant4End, G4Event --> G4UserEventAction::EndOfEventAction
55  Geant4Begin, G4Track --> G4UserTrackingAction::PreUserTrackingAction
56  Geant4End, G4Track --> G4UserTrackingAction::PostUserTrackingAction
57  Geant4Phase, G4Step --> G4UserSteppingAction::UserSteppingAction
58  Geant4Begin, G4TrackStack --> G4UserStackingAction::NewStage
59  Geant4End, G4TrackStack --> G4UserStackingAction::PrepareNewEvent
60 
61  */
62 
64 
70  public:
71  typedef std::vector<std::pair<Geant4Action*, Callback> > Members;
72  protected:
76  const std::type_info* m_argTypes[3];
77 
78  public:
80  Geant4ActionPhase(Geant4Context* context, const std::string& name, const std::type_info& arg_type0,
81  const std::type_info& arg_type1, const std::type_info& arg_type2);
83  virtual ~Geant4ActionPhase();
85  const Members& members() const {
86  return m_members;
87  }
89  const std::type_info* const * argTypes() const {
90  return m_argTypes;
91  }
93  void execute(void* argument);
95  virtual bool add(Geant4Action* action, Callback callback);
97  virtual bool remove(Geant4Action* action, Callback callback);
99  template <typename TYPE, typename IF_TYPE, typename A0, typename R>
100  bool add(TYPE* member, R (IF_TYPE::*callback)(A0 arg)) {
101  typeinfoCheck(typeid(A0), *m_argTypes[0], "Invalid ARG0 type. Failed to add phase callback.");
102  if (dynamic_cast<IF_TYPE*>(member)) {
103  return add(member,Callback(member).make(callback));
104  }
105  throw unrelated_type_error(typeid(TYPE), typeid(IF_TYPE), "Failed to add phase callback.");
106  }
108  template <typename TYPE, typename IF_TYPE, typename A0, typename A1, typename R>
109  bool add(TYPE* member, R (IF_TYPE::*callback)(A0 arg0, A1 arg1)) {
110  typeinfoCheck(typeid(A0), *m_argTypes[0], "Invalid ARG0 type. Failed to add phase callback.");
111  typeinfoCheck(typeid(A1), *m_argTypes[1], "Invalid ARG1 type. Failed to add phase callback.");
112  if (dynamic_cast<IF_TYPE*>(member)) {
113  return add(member,Callback(member).make(callback));
114  }
115  throw unrelated_type_error(typeid(TYPE), typeid(IF_TYPE), "Failed to add phase callback.");
116  }
118  template <typename TYPE, typename IF_TYPE, typename A0, typename A1, typename A2, typename R>
119  bool add(TYPE* member, R (IF_TYPE::*callback)(A0 arg0, A1 arg1)) {
120  typeinfoCheck(typeid(A0), *m_argTypes[0], "Invalid ARG0 type. Failed to add phase callback.");
121  typeinfoCheck(typeid(A1), *m_argTypes[1], "Invalid ARG1 type. Failed to add phase callback.");
122  typeinfoCheck(typeid(A2), *m_argTypes[2], "Invalid ARG2 type. Failed to add phase callback.");
123  if (dynamic_cast<IF_TYPE*>(member)) {
124  //member->addRef();
125  return add(member,Callback(member).make(callback));
126  }
127  throw unrelated_type_error(typeid(TYPE), typeid(IF_TYPE), "Failed to add phase callback.");
128  }
130  template <typename TYPE, typename PMF> bool remove(TYPE* member) {
131  return remove(member,Callback(member));
132  }
134  template <typename TYPE, typename PMF> bool remove(TYPE* member, PMF callback) {
135  Callback cb(member);
136  return remove(member,cb.make(callback));
137  }
139  void call();
140  template <typename A0> void call(A0 a0);
141  template <typename A0, typename A1> void call(A0 a0, A1 a1);
142  template <typename A0, typename A1, typename A2> void call(A0 a0, A1 a1, A2 a2);
143  };
144 
145  } // End namespace Simulation
146 } // End namespace DD4hep
147 
148 #endif // DD4HEP_DDG4_GEANT4ACTIONPHASE_H
const std::type_info * m_argTypes[3]
Type information of the argument type of the callback.
const std::type_info *const * argTypes() const
Type of the first phase callback-argument.
Geant4PhaseAction(Geant4Context *context, const std::string &name)
Standard constructor.
Generic action for Geant4 phases.
Members m_members
Phase members (actions) being called for a particular phase.
void execute(void *argument)
Execute all members in the phase context.
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:261
const std::string & name() const
Access name of the action.
Definition: Geant4Action.h:271
virtual Callback callback()
Create bound callback to operator()()
bool add(TYPE *member, R(IF_TYPE::*callback)(A0 arg0, A1 arg1))
Add a new member to the phase.
virtual ~Geant4ActionPhase()
Default destructor.
const Callback & make(R(T::*pmf)())
Callback setup function for Callbacks with member functions with explicit return type taking no argum...
Definition: Callback.h:121
Definition of the generic callback structure for member functions.
Definition: Callback.h:38
bool add(TYPE *member, R(IF_TYPE::*callback)(A0 arg))
Add a new member to the phase.
void call()
Create action to execute phase members.
const Members & members() const
Access phase members.
Exception class to signal operations on unrelated classes.
Definition: Exceptions.h:31
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.
virtual void operator()()
Callback to generate primary particles.
virtual ~Geant4PhaseAction()
Default destructor.
Generic context to extend user, run and event information.
Action phase definition. Client callback at various stage of the simulation processing.
bool add(TYPE *member, R(IF_TYPE::*callback)(A0 arg0, A1 arg1))
Add a new member to the phase.
void typeinfoCheck(const std::type_info &typ1, const std::type_info &typ2, const std::string &text="")
Check type infos for equivalence (dynamic casts) using ABI information.
Definition: Primitives.cpp:213
virtual bool add(Geant4Action *action, Callback callback)
Add a new member to the phase.
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:91
std::vector< std::pair< Geant4Action *, Callback > > Members