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.cpp
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 
15 // Framework include files
16 #include "DD4hep/InstanceCount.h"
17 #include "DDG4/Geant4ActionPhase.h"
18 
19 using namespace std;
20 using namespace DD4hep::Simulation;
21 
23 Geant4PhaseAction::Geant4PhaseAction(Geant4Context* ctxt, const std::string& nam)
24  : Geant4Action(ctxt,nam)
25 {
26 }
27 
30 }
31 
34 }
35 
37  return Callback(this).make(&Geant4PhaseAction::operator());
38 }
39 
41 Geant4ActionPhase::Geant4ActionPhase(Geant4Context* ctxt, const string& nam, const type_info& arg_type0,
42  const type_info& arg_type1, const type_info& arg_type2)
43  : Geant4Action(ctxt, nam) {
44  m_argTypes[0] = &arg_type0;
45  m_argTypes[1] = &arg_type1;
46  m_argTypes[2] = &arg_type2;
48 }
49 
52  for (Members::iterator i = m_members.begin(); i != m_members.end(); ++i)
53  (*i).first->release();
54  m_members.clear();
56 }
57 
59 bool Geant4ActionPhase::add(Geant4Action* action, Callback callback) {
60  action->addRef();
61  m_members.push_back(make_pair(action,callback));
62  return true;
63 }
64 
67  if (action && callback.func.first) {
68  Members::iterator i = find(m_members.begin(), m_members.end(), make_pair(action,callback));
69  if (i != m_members.end()) {
70  (*i).first->release();
71  m_members.erase(i);
72  return true;
73  }
74  return false;
75  }
76  size_t len = m_members.size();
77  for (Members::iterator i = m_members.begin(); i != m_members.end(); ++i) {
78  if ( (*i).first == action && (*i).second.par == callback.par) {
79  (*i).first->release();
80  m_members.erase(i);
81  i = m_members.begin();
82  }
83  }
84  return (len > m_members.size());
85 }
86 
88 void Geant4ActionPhase::execute(void* argument) {
89  for (Members::iterator i = m_members.begin(); i != m_members.end(); ++i) {
90  (*i).second.execute((const void**) &argument);
91  }
92 }
93 
94 class G4HCofThisEvent;
95 class G4TouchableHistory;
96 #include "DDG4/Geant4RunAction.h"
97 #include "DDG4/Geant4EventAction.h"
101 namespace DD4hep {
102  namespace Simulation {
105  this->execute(0);
106  }
108  template <> void Geant4ActionPhase::call<const G4Run*>(const G4Run* run) {
109  this->execute((const void**) &run);
110  }
112  template <> void Geant4ActionPhase::call<G4Event*>(G4Event* event) {
113  this->execute((const void**) &event);
114  }
116  template <> void Geant4ActionPhase::call<const G4Event*>(const G4Event* event) {
117  this->execute((const void**) &event);
118  }
120  template <> void Geant4ActionPhase::call<const G4Track*>(const G4Track* track) {
121  this->execute((const void**) &track);
122  }
124  template <> void Geant4ActionPhase::call<const G4Step*>(const G4Step* step) {
125  this->execute((const void**) &step);
126  }
128  template <> void Geant4ActionPhase::call<const G4Step*, G4SteppingManager*>(const G4Step* step, G4SteppingManager* mgr) {
129  const void * args[] = { step, mgr };
130  this->execute(args);
131  }
133  template <> void Geant4ActionPhase::call<G4HCofThisEvent*>(G4HCofThisEvent* hce) {
134  this->execute((const void**) &hce);
135  }
137  template <> void Geant4ActionPhase::call<G4Step*, G4TouchableHistory*>(G4Step* step, G4TouchableHistory* history) {
138  const void * args[] = { step, history };
139  this->execute(args);
140  }
141  }
142 }
const std::type_info * m_argTypes[3]
Type information of the argument type of the callback.
mfunc_t func
Definition: Callback.h:49
static void decrement(T *)
Decrement count according to type information.
Members m_members
Phase members (actions) being called for a particular phase.
void execute(void *argument)
Execute all members in the phase context.
virtual Callback callback()
Create bound callback to operator()()
virtual ~Geant4ActionPhase()
Default destructor.
long addRef()
Increase reference count.
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
static T::const_iterator find(const T &c, const string &s)
Definition: View.cpp:34
void call()
Create action to execute phase members.
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 bool remove(Geant4Action *action, Callback callback)
Remove an existing member from the phase. If not existing returns false.
virtual ~Geant4PhaseAction()
Default destructor.
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
Generic context to extend user, run and event information.
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