Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// $Id: Geant4ActionPhase.cpp 603 2013-06-13 21:15:14Z markus.frank $
//====================================================================
// AIDA Detector description implementation for LCD
//--------------------------------------------------------------------
//
// Author : M.Frank
//
//====================================================================
// Framework include files
#include "DD4hep/InstanceCount.h"
#include "DDG4/Geant4ActionPhase.h"
using namespace std;
using namespace DD4hep::Simulation;
/// Standard constructor
Geant4ActionPhase::Geant4ActionPhase(Geant4Context* context, const string& nam, const type_info& arg_type0,
const type_info& arg_type1, const type_info& arg_type2)
: Geant4Action(context,nam)
{
m_argTypes[0] = &arg_type0;
m_argTypes[1] = &arg_type1;
m_argTypes[2] = &arg_type2;
InstanceCount::increment(this);
}
/// Default destructor
Geant4ActionPhase::~Geant4ActionPhase() {
m_members.clear();
InstanceCount::decrement(this);
}
/// Add a new member to the phase
bool Geant4ActionPhase::add(Callback callback) {
m_members.push_back(callback);
return true;
}
/// Remove an existing member from the phase. If not existing returns false
bool Geant4ActionPhase::remove(Callback callback) {
if ( callback.func.first ) {
Members::iterator i = find(m_members.begin(),m_members.end(),callback);
if ( i != m_members.end() ) {
m_members.erase(i);
return true;
}
return false;
}
size_t len = m_members.size();
for(Members::iterator i = m_members.begin(); i != m_members.end(); ++i) {
if ( (*i).par == callback.par ) {
m_members.erase(i);
i = m_members.begin();
}
}
return (len > m_members.size());
}
/// Execute all members in the phase context
void Geant4ActionPhase::execute(void* argument) {
for(Members::iterator i=m_members.begin(); i!=m_members.end(); ++i) {
(*i).execute((const void**)&argument);
}
}
class G4HCofThisEvent;
class G4TouchableHistory;
#include "DDG4/Geant4RunAction.h"
#include "DDG4/Geant4EventAction.h"
#include "DDG4/Geant4TrackingAction.h"
#include "DDG4/Geant4SteppingAction.h"
#include "DDG4/Geant4GeneratorAction.h"
namespace DD4hep { namespace Simulation {
/// Callback in Begin stacking action
void Geant4ActionPhase::call() {
this->execute(0);
}
/// Callback in BeginRun/EndRun
template <> void Geant4ActionPhase::call<const G4Run*>(const G4Run* run) {
this->execute((const void**)&run);
}
/// Callback in prepare primaries
template <> void Geant4ActionPhase::call<G4Event*>(G4Event* event) {
this->execute((const void**)&event);
}
/// Callback in BeginEvent/EndEvent
template <> void Geant4ActionPhase::call<const G4Event*>(const G4Event* event) {
this->execute((const void**)&event);
}
/// Callback in Begin/End tracking action
template <> void Geant4ActionPhase::call<const G4Track*>(const G4Track* track) {
this->execute((const void**)&track);
}
/// Callback in Begin/End stepping action
template <> void Geant4ActionPhase::call<const G4Step*>(const G4Step* step) {
this->execute((const void**)&step);
}
/// Callback for user stepping action
template <> void Geant4ActionPhase::call<const G4Step*,G4SteppingManager*>(const G4Step* step,G4SteppingManager* mgr) {
const void * args[] = {step,mgr};
this->execute(args);
}
/// Callback for sensitives begin/end/clear
template <> void Geant4ActionPhase::call<G4HCofThisEvent*>(G4HCofThisEvent* hce) {
this->execute((const void**)&hce);
}
/// Callback for sensitives
template <> void Geant4ActionPhase::call<G4Step*,G4TouchableHistory*>(G4Step* step,G4TouchableHistory* history) {
const void * args[] = {step,history};
this->execute(args);
}
}
}