DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4PythonDetectorConstruction.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // \author Markus Frank
11 // \date 2015-11-03
12 //
13 //==========================================================================
14 // Framework include files
15 #include <DDG4/Geant4Context.h>
16 #include <DDG4/Geant4Kernel.h>
17 
18 #include <DDG4/Python/DDPython.h>
21 
22 using namespace dd4hep::sim;
23 
24 #include <DDG4/Factories.h>
26 
29 : Geant4DetectorConstruction(ctxt,nam),
30  m_constructSD(), m_constructFLD(), m_constructGEO()
31 {
32  m_needsControl = true;
33 }
34 
36 void Geant4PythonDetectorConstruction::setConstructGeo(PyObject* callable, PyObject* args) {
37  m_constructGEO.set(callable, args);
38 }
39 
41 void Geant4PythonDetectorConstruction::setConstructField(PyObject* callable, PyObject* args) {
42  m_constructFLD.set(callable, args);
43 }
44 
46 void Geant4PythonDetectorConstruction::setConstructSensitives(PyObject* callable, PyObject* args) {
47  m_constructSD.set(callable, args);
48 }
49 
51 void Geant4PythonDetectorConstruction::exec(const std::string& desc, const Geant4PythonCall& cmd) const {
52  if ( cmd.isValid() ) {
53  int ret = cmd.execute<int>();
54  if ( ret != 1 ) {
55  except("+++ %s returned %d, not SUCCESS (1). Terminating setup",desc.c_str(), ret);
56  }
57  }
58 }
59 
62  info("+++ Worker:%ld Execute PYTHON constructGeo %s....",
63  context()->kernel().id(), m_constructGEO.isValid() ? "" : "[empty]");
64  DDPython::BlockThreads blocker(0);
65  exec("constructGeo", m_constructGEO);
66 }
67 
70  info("+++ Worker:%ld Execute PYTHON constructField %s....",
71  context()->kernel().id(), m_constructFLD.isValid() ? "" : "[empty]");
72  exec("constructField", m_constructFLD);
73 }
74 
77  info("+++ Worker:%ld Execute PYTHON constructSensitives %s....",
78  context()->kernel().id(), m_constructSD.isValid() ? "" : "[empty]");
79  exec("constructSensitives", m_constructSD);
80 }
dd4hep::sim::Geant4PythonDetectorConstruction
Base class to initialize a multi-threaded or single threaded Geant4 application.
Definition: Geant4PythonDetectorConstruction.h:63
dd4hep::sim::Geant4PythonDetectorConstruction::exec
void exec(const std::string &desc, const Geant4PythonCall &cmd) const
Execute command in the python interpreter.
Definition: Geant4PythonDetectorConstruction.cpp:51
dd4hep::sim::Geant4PythonDetectorConstruction::m_constructSD
Geant4PythonCall m_constructSD
Sensitive detector initialization command. Default: empty.
Definition: Geant4PythonDetectorConstruction.h:66
dd4hep::sim::Geant4PythonDetectorConstruction::constructField
virtual void constructField(Geant4DetectorConstructionContext *ctxt) override
Electromagnetic field construction callback. Called at "ConstructSDandField()".
Definition: Geant4PythonDetectorConstruction.cpp:69
dd4hep::sim::Geant4PythonDetectorConstruction::setConstructSensitives
void setConstructSensitives(PyObject *callable, PyObject *args)
Set the sensitive detector initialization command.
Definition: Geant4PythonDetectorConstruction.cpp:46
Geant4PythonDetectorConstruction.h
dd4hep::sim::Geant4PythonDetectorConstruction::m_constructFLD
Geant4PythonCall m_constructFLD
Field initialization command. Default: empty.
Definition: Geant4PythonDetectorConstruction.h:68
dd4hep::sim::Geant4PythonDetectorConstruction::setConstructGeo
void setConstructGeo(PyObject *callable, PyObject *args)
Set the Detector initialization command.
Definition: Geant4PythonDetectorConstruction.cpp:36
DECLARE_GEANT4ACTION
#define DECLARE_GEANT4ACTION(name)
Plugin defintion to create Geant4Action objects.
Definition: Factories.h:210
dd4hep::sim::Geant4PythonDetectorConstruction::setConstructField
void setConstructField(PyObject *callable, PyObject *args)
Set the field initialization command.
Definition: Geant4PythonDetectorConstruction.cpp:41
Geant4PythonAction.h
dd4hep::sim::Geant4PythonCall::isValid
bool isValid() const
Check if call is set.
Definition: Geant4PythonCall.h:45
dd4hep::sim::Geant4Action::info
void info(const char *fmt,...) const
Support of info messages.
Definition: Geant4Action.cpp:215
dd4hep::DDPython::BlockThreads
Definition: DDPython.h:47
dd4hep::sim::Geant4Action::except
void except(const char *fmt,...) const
Support of exceptions: Print fatal message and throw runtime_error.
Definition: Geant4Action.cpp:256
dd4hep::sim::Geant4DetectorConstructionContext
Geant4 detector construction context definition.
Definition: Geant4DetectorConstruction.h:61
dd4hep::sim::Geant4PythonCall
Base class to initialize a multi-threaded or single threaded Geant4 application.
Definition: Geant4PythonCall.h:32
dd4hep::sim::Geant4PythonDetectorConstruction::m_constructGEO
Geant4PythonCall m_constructGEO
Geometry initialization command. Default: empty.
Definition: Geant4PythonDetectorConstruction.h:70
dd4hep::sim::Geant4PythonCall::set
void set(PyObject *callable, PyObject *args)
Set the callback structures for callbacks with arguments.
Definition: Geant4PythonCall.cpp:36
dd4hep::sim::Geant4PythonDetectorConstruction::constructSensitives
virtual void constructSensitives(Geant4DetectorConstructionContext *ctxt) override
Sensitive detector construction callback. Called at "ConstructSDandField()".
Definition: Geant4PythonDetectorConstruction.cpp:76
dd4hep::sim::Geant4PythonCall::execute
RETURN execute() const
Execute command in the python interpreter.
Definition: Geant4PythonCall.cpp:52
DDPython.h
Factories.h
dd4hep::sim::Geant4PythonDetectorConstruction::constructGeo
virtual void constructGeo(Geant4DetectorConstructionContext *ctxt) override
Geometry construction callback. Called at "Construct()".
Definition: Geant4PythonDetectorConstruction.cpp:61
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4PythonDetectorConstruction::Geant4PythonDetectorConstruction
Geant4PythonDetectorConstruction(Geant4Context *c, const std::string &nam)
Standard constructor.
Definition: Geant4PythonDetectorConstruction.cpp:28
Geant4Kernel.h
dd4hep::sim::Geant4DetectorConstruction
Basic implementation of the Geant4 detector construction action.
Definition: Geant4DetectorConstruction.h:102
Geant4Context.h
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270