DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
DDPython.h
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-07
12 //
13 //==========================================================================
14 #ifndef DDG4_PYTHON_DDPYTHON_H
15 #define DDG4_PYTHON_DDPYTHON_H 1
16 
17 // C/C++ include files
18 #include <string>
19 
20 // ROOT include file(s)
21 #include <TPyReturn.h>
22 
24 namespace dd4hep {
25 
26  struct DDPythonGlobalState;
27 
29 
34  class DDPython {
35  protected:
36  void* context;
38  DDPython( );
39  protected:
40  static bool isMainThread();
41  public:
42  struct GILState {
43  int state;
44  explicit GILState(int);
45  ~GILState();
46  };
47  struct BlockThreads {
48  explicit BlockThreads(int);
49  ~BlockThreads();
50  };
51  struct AllowThreads {
52  explicit AllowThreads(int);
53  ~AllowThreads();
54  };
55 
57  static void allowThreads();
58  static void restoreThread();
59 
61  static DDPython instance();
62  static void shutdown();
63  static void setMainThread();
64 
66  static void releaseObject(PyObject*& obj);
67 
69  static void assignObject(PyObject*& obj, PyObject* new_obj);
70 
72  static int run_interpreter(int argc, char** argv);
73 
75  DDPython(const DDPython& ) {}
76 
78  ~DDPython( );
79 
80  int setArgs(int argc, char** argv) const;
81  int runFile(const std::string& fname) const;
82  int execute(const std::string& cmd) const;
83  int evaluate(const std::string& cmd) const;
84 
86 
93  PyObject* call(PyObject* method, PyObject* args);
94 
96 
104  TPyReturn callC(PyObject* method, PyObject* args);
105 
107  void prompt() const;
108 
110  void afterFork() const;
111 
112  private:
113 
114  };
115 }
116 
117 #endif // DDG4_PYTHON_DDPYTHON_H
dd4hep::DDPython::DDPython
DDPython()
Standard constructor.
Definition: DDPython.cpp:137
dd4hep::DDPython::AllowThreads::~AllowThreads
~AllowThreads()
Definition: DDPython.cpp:132
dd4hep::DDPython::isMainThread
static bool isMainThread()
Definition: DDPython.cpp:328
dd4hep::DDPython::callC
TPyReturn callC(PyObject *method, PyObject *args)
Call a python object with argument (typically a dictionary).
Definition: DDPython.cpp:271
dd4hep::DDPython::setMainThread
static void setMainThread()
Definition: DDPython.cpp:324
dd4hep::DDPython::GILState::state
int state
Definition: DDPython.h:43
dd4hep::DDPython::GILState::GILState
GILState(int)
Definition: DDPython.cpp:100
dd4hep::DDPython::shutdown
static void shutdown()
Definition: DDPython.cpp:239
dd4hep::DDPython
Python interface class for callbacks and GIL.
Definition: DDPython.h:34
dd4hep::DDPython::evaluate
int evaluate(const std::string &cmd) const
Definition: DDPython.cpp:253
dd4hep::DDPython::allowThreads
static void allowThreads()
Save thread state.
Definition: DDPython.cpp:196
dd4hep::DDPython::run_interpreter
static int run_interpreter(int argc, char **argv)
Start the interpreter in normal mode without hacks like 'python.exe' does.
Definition: DDPython.cpp:333
dd4hep::DDPython::afterFork
void afterFork() const
Callback after forking.
Definition: DDPython.cpp:309
dd4hep::DDPython::BlockThreads::BlockThreads
BlockThreads(int)
Definition: DDPython.cpp:114
dd4hep::DDPython::BlockThreads
Definition: DDPython.h:47
dd4hep::DDPython::BlockThreads::~BlockThreads
~BlockThreads()
Definition: DDPython.cpp:121
dd4hep::DDPython::assignObject
static void assignObject(PyObject *&obj, PyObject *new_obj)
Release python object.
Definition: DDPython.cpp:296
dd4hep::DDPython::AllowThreads::AllowThreads
AllowThreads(int)
Definition: DDPython.cpp:128
dd4hep::DDPython::releaseObject
static void releaseObject(PyObject *&obj)
Release python object.
Definition: DDPython.cpp:288
dd4hep::DDPython::setArgs
int setArgs(int argc, char **argv) const
Definition: DDPython.cpp:209
dd4hep::DDPython::restoreThread
static void restoreThread()
Definition: DDPython.cpp:202
dd4hep::DDPython::execute
int execute(const std::string &cmd) const
Definition: DDPython.cpp:257
dd4hep::DDPython::context
void * context
Definition: DDPython.h:36
dd4hep::DDPython::GILState
Definition: DDPython.h:42
dd4hep::DDPython::instance
static DDPython instance()
Object instantiator.
Definition: DDPython.cpp:190
dd4hep::DDPython::GILState::~GILState
~GILState()
Definition: DDPython.cpp:107
dd4hep::DDPython::runFile
int runFile(const std::string &fname) const
Definition: DDPython.cpp:248
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::DDPython::DDPython
DDPython(const DDPython &)
Copy constructor.
Definition: DDPython.h:75
dd4hep::DDPython::~DDPython
~DDPython()
Destructor.
Definition: DDPython.cpp:173
dd4hep::DDPython::prompt
void prompt() const
Invoke command prompt.
Definition: DDPython.cpp:304
dd4hep::DDPython::call
PyObject * call(PyObject *method, PyObject *args)
Call a python object with argument (typically a dictionary)
Definition: DDPython.cpp:261
dd4hep::DDPython::AllowThreads
Definition: DDPython.h:51