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 #include <DDG4/Geant4Context.h>
0016 #include <DDG4/Geant4Kernel.h>
0017
0018 #include <DDG4/Python/DDPython.h>
0019 #include <DDG4/Python/Geant4PythonAction.h>
0020 #include <DDG4/Python/Geant4PythonDetectorConstruction.h>
0021
0022 using namespace dd4hep::sim;
0023
0024 #include <DDG4/Factories.h>
0025 DECLARE_GEANT4ACTION(Geant4PythonDetectorConstruction)
0026
0027
0028 Geant4PythonDetectorConstruction::Geant4PythonDetectorConstruction(Geant4Context* ctxt, const std::string& nam)
0029 : Geant4DetectorConstruction(ctxt,nam),
0030 m_constructSD(), m_constructFLD(), m_constructGEO()
0031 {
0032 m_needsControl = true;
0033 }
0034
0035
0036 void Geant4PythonDetectorConstruction::setConstructGeo(PyObject* callable, PyObject* args) {
0037 m_constructGEO.set(callable, args);
0038 }
0039
0040
0041 void Geant4PythonDetectorConstruction::setConstructField(PyObject* callable, PyObject* args) {
0042 m_constructFLD.set(callable, args);
0043 }
0044
0045
0046 void Geant4PythonDetectorConstruction::setConstructSensitives(PyObject* callable, PyObject* args) {
0047 m_constructSD.set(callable, args);
0048 }
0049
0050
0051 void Geant4PythonDetectorConstruction::exec(const std::string& desc, const Geant4PythonCall& cmd) const {
0052 if ( cmd.isValid() ) {
0053 int ret = cmd.execute<int>();
0054 if ( ret != 1 ) {
0055 except("+++ %s returned %d, not SUCCESS (1). Terminating setup",desc.c_str(), ret);
0056 }
0057 }
0058 }
0059
0060
0061 void Geant4PythonDetectorConstruction::constructGeo(Geant4DetectorConstructionContext* ) {
0062 info("+++ Worker:%ld Execute PYTHON constructGeo %s....",
0063 context()->kernel().id(), m_constructGEO.isValid() ? "" : "[empty]");
0064 DDPython::BlockThreads blocker(0);
0065 exec("constructGeo", m_constructGEO);
0066 }
0067
0068
0069 void Geant4PythonDetectorConstruction::constructField(Geant4DetectorConstructionContext* ) {
0070 info("+++ Worker:%ld Execute PYTHON constructField %s....",
0071 context()->kernel().id(), m_constructFLD.isValid() ? "" : "[empty]");
0072 exec("constructField", m_constructFLD);
0073 }
0074
0075
0076 void Geant4PythonDetectorConstruction::constructSensitives(Geant4DetectorConstructionContext* ) {
0077 info("+++ Worker:%ld Execute PYTHON constructSensitives %s....",
0078 context()->kernel().id(), m_constructSD.isValid() ? "" : "[empty]");
0079 exec("constructSensitives", m_constructSD);
0080 }