DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4ActionPhase.cpp
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 
14 // Framework include files
15 #include <DD4hep/InstanceCount.h>
16 #include <DDG4/Geant4ActionPhase.h>
17 
18 using namespace dd4hep::sim;
19 
22  : Geant4Action(ctxt,nam)
23 {
24 }
25 
28 }
29 
32 }
33 
35  return Callback(this).make(&Geant4PhaseAction::operator());
36 }
37 
39 Geant4ActionPhase::Geant4ActionPhase(Geant4Context* ctxt, const std::string& nam, const std::type_info& arg_type0,
40  const std::type_info& arg_type1, const std::type_info& arg_type2)
41  : Geant4Action(ctxt, nam) {
42  m_argTypes[0] = &arg_type0;
43  m_argTypes[1] = &arg_type1;
44  m_argTypes[2] = &arg_type2;
46 }
47 
50  for (Members::iterator i = m_members.begin(); i != m_members.end(); ++i)
51  (*i).first->release();
52  m_members.clear();
54 }
55 
57 bool Geant4ActionPhase::add(Geant4Action* action, Callback callback) {
58  action->addRef();
59  m_members.emplace_back(action,callback);
60  return true;
61 }
62 
65  if (action && callback.func.first) {
66  Members::iterator i = find(m_members.begin(), m_members.end(), std::make_pair(action,callback));
67  if (i != m_members.end()) {
68  (*i).first->release();
69  m_members.erase(i);
70  return true;
71  }
72  return false;
73  }
74  size_t len = m_members.size();
75  for (Members::iterator i = m_members.begin(); i != m_members.end(); ++i) {
76  if ( (*i).first == action && (*i).second.par == callback.par) {
77  (*i).first->release();
78  m_members.erase(i);
79  i = m_members.begin();
80  }
81  }
82  return (len > m_members.size());
83 }
84 
86 void Geant4ActionPhase::execute(void* argument) {
87  for (Members::iterator i = m_members.begin(); i != m_members.end(); ++i) {
88  (*i).second.execute((const void**) &argument);
89  }
90 }
91 
92 class G4HCofThisEvent;
93 class G4TouchableHistory;
94 #include <DDG4/Geant4RunAction.h>
95 #include <DDG4/Geant4EventAction.h>
100 namespace dd4hep {
101  namespace sim {
104  this->execute(0);
105  }
107  template <> void Geant4ActionPhase::call(G4StackManager* stackManager) {
108  this->execute((const void**) &stackManager);
109  }
111  template <> void Geant4ActionPhase::call<const G4Run*>(const G4Run* run) {
112  this->execute((const void**) &run);
113  }
115  template <> void Geant4ActionPhase::call<G4Event*>(G4Event* event) {
116  this->execute((const void**) &event);
117  }
119  template <> void Geant4ActionPhase::call<const G4Event*>(const G4Event* event) {
120  this->execute((const void**) &event);
121  }
123  template <> void Geant4ActionPhase::call<const G4Track*>(const G4Track* track) {
124  this->execute((const void**) &track);
125  }
127  template <> void Geant4ActionPhase::call<const G4Step*>(const G4Step* step) {
128  this->execute((const void**) &step);
129  }
131  template <> void Geant4ActionPhase::call<const G4Step*, G4SteppingManager*>(const G4Step* step, G4SteppingManager* mgr) {
132  const void * args[] = { step, mgr };
133  this->execute(args);
134  }
136  template <> void Geant4ActionPhase::call<G4HCofThisEvent*>(G4HCofThisEvent* hce) {
137  this->execute((const void**) &hce);
138  }
140  template <> void Geant4ActionPhase::call<G4Step*, G4TouchableHistory*>(G4Step* step, G4TouchableHistory* history) {
141  const void * args[] = { step, history };
142  this->execute(args);
143  }
144  }
145 }
Geant4TrackingAction.h
Geant4RunAction.h
Geant4EventAction.h
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Geant4PhaseAction::Geant4PhaseAction
Geant4PhaseAction(Geant4Context *context, const std::string &name)
Standard constructor.
Definition: Geant4ActionPhase.cpp:21
Geant4SteppingAction.h
dd4hep::Callback::func
mfunc_t func
Definition: Callback.h:49
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
Geant4GeneratorAction.h
Geant4StackingAction.h
dd4hep::Callback
Definition of the generic callback structure for member functions.
Definition: Callback.h:38
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
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::Callback::par
void * par
Definition: Callback.h:47
dd4hep::sim::Geant4ActionPhase::call
void call()
Create action to execute phase members.
Definition: Geant4ActionPhase.cpp:103
dd4hep::sim::Geant4Action::addRef
long addRef()
Increase reference count.
Definition: Geant4Action.cpp:71
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4ActionPhase::execute
void execute(void *argument)
Execute all members in the phase context.
Definition: Geant4ActionPhase.cpp:86
dd4hep::Callback::mfunc_t::first
void * first
Definition: Callback.h:43
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
InstanceCount.h
Geant4ActionPhase.h
dd4hep::sim::Geant4ActionPhase::~Geant4ActionPhase
virtual ~Geant4ActionPhase()
Default destructor.
Definition: Geant4ActionPhase.cpp:49
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201