DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4PythonInitialization.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 
15 // Framework include files
16 #include <DDG4/Factories.h>
17 #include <DDG4/Geant4Kernel.h>
18 #include <DDG4/Python/DDPython.h>
20 
21 using namespace dd4hep::sim;
22 
24 
27 : Geant4UserInitialization(ctxt,nam), m_masterSetup(), m_workerSetup()
28 {
29  m_needsControl = true;
30 }
31 
33 void Geant4PythonInitialization::setMasterSetup(PyObject* callable, PyObject* args) {
34  m_masterSetup.set(callable, args);
35 }
36 
38 void Geant4PythonInitialization::setWorkerSetup(PyObject* callable, PyObject* args) {
39  m_workerSetup.set(callable, args);
40 }
41 
43 void Geant4PythonInitialization::exec(const std::string& desc, const Geant4PythonCall& cmd) const {
44  if ( cmd.isValid() ) {
45  int ret = cmd.execute<int>();
46  if ( ret != 1 ) {
47  except("+++ %s returned %d, not SUCCESS (1). Terminating setup",desc.c_str(), ret);
48  }
49  }
50 }
51 
54  info("+++ Worker:%ld Build PYTHON Worker %s....",
55  context()->kernel().id(), m_workerSetup.isValid() ? "[empty]" : "");
56  exec("Worker setup command",m_workerSetup);
57 }
58 
61  DDPython::BlockThreads blocker(0);
62  info("+++ Build PYTHON Master [id:%ld] %s ....",
63  context()->kernel().id(), m_masterSetup.isValid() ? "[empty]" : "");
64  exec("Master setup command",m_masterSetup);
65 }
dd4hep::sim::Geant4Action::m_needsControl
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:123
DECLARE_GEANT4ACTION
#define DECLARE_GEANT4ACTION(name)
Plugin defintion to create Geant4Action objects.
Definition: Factories.h:210
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::Geant4PythonCall
Base class to initialize a multi-threaded or single threaded Geant4 application.
Definition: Geant4PythonCall.h:32
dd4hep::sim::Geant4PythonCall::set
void set(PyObject *callable, PyObject *args)
Set the callback structures for callbacks with arguments.
Definition: Geant4PythonCall.cpp:36
dd4hep::sim::Geant4PythonInitialization
Base class to initialize a multi-threaded or single threaded Geant4 application.
Definition: Geant4PythonInitialization.h:59
dd4hep::sim::Geant4UserInitialization
Base class to initialize a multi-threaded or single threaded Geant4 application.
Definition: Geant4UserInitialization.h:33
dd4hep::sim::Geant4PythonInitialization::setMasterSetup
void setMasterSetup(PyObject *callable, PyObject *args)
Set the Detector initialization command.
Definition: Geant4PythonInitialization.cpp:33
Geant4PythonInitialization.h
dd4hep::sim::Geant4PythonCall::execute
RETURN execute() const
Execute command in the python interpreter.
Definition: Geant4PythonCall.cpp:52
DDPython.h
dd4hep::sim::Geant4PythonInitialization::m_masterSetup
Geant4PythonCall m_masterSetup
Master initialization command. Default: empty.
Definition: Geant4PythonInitialization.h:62
dd4hep::sim::Geant4PythonInitialization::Geant4PythonInitialization
Geant4PythonInitialization(Geant4Context *c, const std::string &nam)
Standard constructor.
Definition: Geant4PythonInitialization.cpp:26
Factories.h
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: EDM4hepFileReader.cpp:41
dd4hep::sim::Geant4PythonInitialization::exec
void exec(const std::string &desc, const Geant4PythonCall &cmd) const
Execute command in the python interpreter.
Definition: Geant4PythonInitialization.cpp:43
dd4hep::sim::Geant4PythonInitialization::build
virtual void build() const
Callback function to build setup for the MT worker thread.
Definition: Geant4PythonInitialization.cpp:53
Geant4Kernel.h
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4PythonInitialization::buildMaster
virtual void buildMaster() const
Callback function to build setup for the MT master thread.
Definition: Geant4PythonInitialization.cpp:60
dd4hep::sim::Geant4PythonInitialization::setWorkerSetup
void setWorkerSetup(PyObject *callable, PyObject *args)
Set the field initialization command.
Definition: Geant4PythonInitialization.cpp:38
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270
dd4hep::sim::Geant4PythonInitialization::m_workerSetup
Geant4PythonCall m_workerSetup
Worker initialization command. Default: empty.
Definition: Geant4PythonInitialization.h:64