Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:23

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
0015 #include <DD4hep/InstanceCount.h>
0016 #include <DDG4/Geant4ActionPhase.h>
0017 
0018 using namespace dd4hep::sim;
0019 
0020 /// Standard constructor
0021 Geant4PhaseAction::Geant4PhaseAction(Geant4Context* ctxt, const std::string& nam)
0022   : Geant4Action(ctxt,nam)
0023 {
0024 }
0025 
0026 /// Default destructor
0027 Geant4PhaseAction::~Geant4PhaseAction()   {
0028 }
0029 
0030 /// Callback to generate primary particles
0031 void Geant4PhaseAction::operator()() {
0032 }
0033 
0034 dd4hep::Callback Geant4PhaseAction::callback()    {
0035   return Callback(this).make(&Geant4PhaseAction::operator());
0036 }
0037 
0038 /// Standard constructor
0039 Geant4ActionPhase::Geant4ActionPhase(Geant4Context* ctxt, const std::string& nam, const std::type_info& arg_type0,
0040                                      const std::type_info& arg_type1, const std::type_info& arg_type2)
0041   : Geant4Action(ctxt, nam) {
0042   m_argTypes[0] = &arg_type0;
0043   m_argTypes[1] = &arg_type1;
0044   m_argTypes[2] = &arg_type2;
0045   InstanceCount::increment(this);
0046 }
0047 
0048 /// Default destructor
0049 Geant4ActionPhase::~Geant4ActionPhase() {
0050   for (Members::iterator i = m_members.begin(); i != m_members.end(); ++i)
0051     (*i).first->release();
0052   m_members.clear();
0053   InstanceCount::decrement(this);
0054 }
0055 
0056 /// Add a new member to the phase
0057 bool Geant4ActionPhase::add(Geant4Action* action, Callback callback) {
0058   action->addRef();
0059   m_members.emplace_back(action,callback);
0060   return true;
0061 }
0062 
0063 /// Remove an existing member from the phase. If not existing returns false
0064 bool Geant4ActionPhase::remove(Geant4Action* action, Callback callback) {
0065   if (action && callback.func.first) {
0066     Members::iterator i = find(m_members.begin(), m_members.end(), std::make_pair(action,callback));
0067     if (i != m_members.end()) {
0068       (*i).first->release();
0069       m_members.erase(i);
0070       return true;
0071     }
0072     return false;
0073   }
0074   size_t len = m_members.size();
0075   for (Members::iterator i = m_members.begin(); i != m_members.end(); ++i) {
0076     if ( (*i).first == action && (*i).second.par == callback.par) {
0077       (*i).first->release();
0078       m_members.erase(i);
0079       i = m_members.begin();
0080     }
0081   }
0082   return (len > m_members.size());
0083 }
0084 
0085 /// Execute all members in the phase context
0086 void Geant4ActionPhase::execute(void* argument) {
0087   for (Members::iterator i = m_members.begin(); i != m_members.end(); ++i) {
0088     (*i).second.execute((const void**) &argument);
0089   }
0090 }
0091 
0092 class G4HCofThisEvent;
0093 class G4TouchableHistory;
0094 #include <DDG4/Geant4RunAction.h>
0095 #include <DDG4/Geant4EventAction.h>
0096 #include <DDG4/Geant4TrackingAction.h>
0097 #include <DDG4/Geant4SteppingAction.h>
0098 #include <DDG4/Geant4StackingAction.h>
0099 #include <DDG4/Geant4GeneratorAction.h>
0100 namespace dd4hep {
0101   namespace sim {
0102     /// Callback in Begin stacking action
0103     void Geant4ActionPhase::call() {
0104       this->execute(0);
0105     }
0106     /// Callback in Begin stacking action
0107     template <> void Geant4ActionPhase::call(G4StackManager* stackManager) {
0108       this->execute((const void**) &stackManager);
0109     }
0110     /// Callback in BeginRun/EndRun
0111     template <> void Geant4ActionPhase::call<const G4Run*>(const G4Run* run) {
0112       this->execute((const void**) &run);
0113     }
0114     /// Callback in prepare primaries
0115     template <> void Geant4ActionPhase::call<G4Event*>(G4Event* event) {
0116       this->execute((const void**) &event);
0117     }
0118     /// Callback in BeginEvent/EndEvent
0119     template <> void Geant4ActionPhase::call<const G4Event*>(const G4Event* event) {
0120       this->execute((const void**) &event);
0121     }
0122     /// Callback in Begin/End tracking action
0123     template <> void Geant4ActionPhase::call<const G4Track*>(const G4Track* track) {
0124       this->execute((const void**) &track);
0125     }
0126     /// Callback in Begin/End stepping action
0127     template <> void Geant4ActionPhase::call<const G4Step*>(const G4Step* step) {
0128       this->execute((const void**) &step);
0129     }
0130     /// Callback for user stepping action
0131     template <> void Geant4ActionPhase::call<const G4Step*, G4SteppingManager*>(const G4Step* step, G4SteppingManager* mgr) {
0132       const void * args[] = { step, mgr };
0133       this->execute(args);
0134     }
0135     /// Callback for sensitives begin/end/clear
0136     template <> void Geant4ActionPhase::call<G4HCofThisEvent*>(G4HCofThisEvent* hce) {
0137       this->execute((const void**) &hce);
0138     }
0139     /// Callback for sensitives
0140     template <> void Geant4ActionPhase::call<G4Step*, G4TouchableHistory*>(G4Step* step, G4TouchableHistory* history) {
0141       const void * args[] = { step, history };
0142       this->execute(args);
0143     }
0144   }
0145 }