DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
dd4hep::DDPython Class Reference

Python interface class for callbacks and GIL. More...

#include <DDPython.h>

Classes

struct  AllowThreads
 
struct  BlockThreads
 
struct  GILState
 

Public Member Functions

 DDPython (const DDPython &)
 Copy constructor. More...
 
 ~DDPython ()
 Destructor. More...
 
int setArgs (int argc, char **argv) const
 
int runFile (const std::string &fname) const
 
int execute (const std::string &cmd) const
 
int evaluate (const std::string &cmd) const
 
PyObject * call (PyObject *method, PyObject *args)
 Call a python object with argument (typically a dictionary) More...
 
TPyReturn callC (PyObject *method, PyObject *args)
 Call a python object with argument (typically a dictionary). More...
 
void prompt () const
 Invoke command prompt. More...
 
void afterFork () const
 Callback after forking. More...
 

Static Public Member Functions

static void allowThreads ()
 Save thread state. More...
 
static void restoreThread ()
 
static DDPython instance ()
 Object instantiator. More...
 
static void shutdown ()
 
static void setMainThread ()
 
static void releaseObject (PyObject *&obj)
 Release python object. More...
 
static void assignObject (PyObject *&obj, PyObject *new_obj)
 Release python object. More...
 
static int run_interpreter (int argc, char **argv)
 Start the interpreter in normal mode without hacks like 'python.exe' does. More...
 

Protected Member Functions

 DDPython ()
 Standard constructor. More...
 

Static Protected Member Functions

static bool isMainThread ()
 

Protected Attributes

void * context
 

Detailed Description

Python interface class for callbacks and GIL.

Author
M.Frank
Version
1.0

Definition at line 34 of file DDPython.h.

Constructor & Destructor Documentation

◆ DDPython() [1/2]

dd4hep::DDPython::DDPython ( )
protected

Standard constructor.

Standard constructor, initializes variables.

Definition at line 137 of file DDPython.cpp.

◆ DDPython() [2/2]

dd4hep::DDPython::DDPython ( const DDPython )
inline

Copy constructor.

Definition at line 75 of file DDPython.h.

◆ ~DDPython()

dd4hep::DDPython::~DDPython ( )

Destructor.

Default Destructor.

Definition at line 173 of file DDPython.cpp.

Member Function Documentation

◆ afterFork()

void dd4hep::DDPython::afterFork ( ) const

Callback after forking.

Definition at line 309 of file DDPython.cpp.

◆ allowThreads()

void dd4hep::DDPython::allowThreads ( )
static

Save thread state.

Definition at line 196 of file DDPython.cpp.

◆ assignObject()

void dd4hep::DDPython::assignObject ( PyObject *&  obj,
PyObject *  new_obj 
)
static

Release python object.

Definition at line 296 of file DDPython.cpp.

◆ call()

PyObject * dd4hep::DDPython::call ( PyObject *  method,
PyObject *  args 
)

Call a python object with argument (typically a dictionary)

Note:

  • Typical call from python -> C -> python
  • Errors are printed and then cleared. A return code of NULL is passed to the caller in the event of an error condition
  • The returned object is NOT owned by the caller.
  • No GIL state handling by the caller necessary

Definition at line 261 of file DDPython.cpp.

◆ callC()

TPyReturn dd4hep::DDPython::callC ( PyObject *  method,
PyObject *  args 
)

Call a python object with argument (typically a dictionary).

Note:

  • Typical call from C -> python -> C
  • Errors are printed and then cleared. A return code of NULL is passed to the caller in the event of an error condition
  • The returned object TPyReturn must be destructed (ie. leave scope) BEFORE the GIL is released.
  • The caller MUST ensure the GIL state in case of multi-threading!

Definition at line 271 of file DDPython.cpp.

◆ evaluate()

int dd4hep::DDPython::evaluate ( const std::string &  cmd) const

Definition at line 253 of file DDPython.cpp.

◆ execute()

int dd4hep::DDPython::execute ( const std::string &  cmd) const

Definition at line 257 of file DDPython.cpp.

◆ instance()

dd4hep::DDPython dd4hep::DDPython::instance ( )
static

Object instantiator.

Definition at line 190 of file DDPython.cpp.

◆ isMainThread()

bool dd4hep::DDPython::isMainThread ( )
staticprotected

Definition at line 328 of file DDPython.cpp.

◆ prompt()

void dd4hep::DDPython::prompt ( ) const

Invoke command prompt.

Definition at line 304 of file DDPython.cpp.

◆ releaseObject()

void dd4hep::DDPython::releaseObject ( PyObject *&  obj)
static

Release python object.

Definition at line 288 of file DDPython.cpp.

◆ restoreThread()

void dd4hep::DDPython::restoreThread ( )
static

Definition at line 202 of file DDPython.cpp.

◆ run_interpreter()

int dd4hep::DDPython::run_interpreter ( int  argc,
char **  argv 
)
static

Start the interpreter in normal mode without hacks like 'python.exe' does.

Start the interpreter in normal mode without hacks like 'pythopn.exe' does.

Definition at line 333 of file DDPython.cpp.

◆ runFile()

int dd4hep::DDPython::runFile ( const std::string &  fname) const

Definition at line 248 of file DDPython.cpp.

◆ setArgs()

int dd4hep::DDPython::setArgs ( int  argc,
char **  argv 
) const

Definition at line 209 of file DDPython.cpp.

◆ setMainThread()

void dd4hep::DDPython::setMainThread ( )
static

Definition at line 324 of file DDPython.cpp.

◆ shutdown()

void dd4hep::DDPython::shutdown ( )
static

Definition at line 239 of file DDPython.cpp.

Member Data Documentation

◆ context

void* dd4hep::DDPython::context
protected

Definition at line 36 of file DDPython.h.


The documentation for this class was generated from the following files: