File indexing completed on 2025-02-22 09:37:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include <DDG4/Factories.h>
0017 #include <DDG4/Geant4Kernel.h>
0018 #include <DDG4/Python/DDPython.h>
0019 #include <DDG4/Python/Geant4PythonInitialization.h>
0020
0021 using namespace dd4hep::sim;
0022
0023 DECLARE_GEANT4ACTION(Geant4PythonInitialization)
0024
0025
0026 Geant4PythonInitialization::Geant4PythonInitialization(Geant4Context* ctxt, const std::string& nam)
0027 : Geant4UserInitialization(ctxt,nam), m_masterSetup(), m_workerSetup()
0028 {
0029 m_needsControl = true;
0030 }
0031
0032
0033 void Geant4PythonInitialization::setMasterSetup(PyObject* callable, PyObject* args) {
0034 m_masterSetup.set(callable, args);
0035 }
0036
0037
0038 void Geant4PythonInitialization::setWorkerSetup(PyObject* callable, PyObject* args) {
0039 m_workerSetup.set(callable, args);
0040 }
0041
0042
0043 void Geant4PythonInitialization::exec(const std::string& desc, const Geant4PythonCall& cmd) const {
0044 if ( cmd.isValid() ) {
0045 int ret = cmd.execute<int>();
0046 if ( ret != 1 ) {
0047 except("+++ %s returned %d, not SUCCESS (1). Terminating setup",desc.c_str(), ret);
0048 }
0049 }
0050 }
0051
0052
0053 void Geant4PythonInitialization::build() const {
0054 info("+++ Worker:%ld Build PYTHON Worker %s....",
0055 context()->kernel().id(), m_workerSetup.isValid() ? "[empty]" : "");
0056 exec("Worker setup command",m_workerSetup);
0057 }
0058
0059
0060 void Geant4PythonInitialization::buildMaster() const {
0061 DDPython::BlockThreads blocker(0);
0062 info("+++ Build PYTHON Master [id:%ld] %s ....",
0063 context()->kernel().id(), m_masterSetup.isValid() ? "[empty]" : "");
0064 exec("Master setup command",m_masterSetup);
0065 }