Belle II Software  release-05-01-25
RegisterPythonModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Christian Pulvermacher *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <boost/python.hpp>
12 
13 #include <framework/utilities/RegisterPythonModule.h>
14 #include <framework/logging/Logger.h>
15 
16 #include <string>
17 
18 using namespace Belle2;
19 
20 BoostPythonModuleProxy::BoostPythonModuleProxy(const char* name, PyObject * (*initFunc)(), bool auto_import)
21 {
22  if (PyImport_AppendInittab(const_cast<char*>(name), initFunc) == -1) {
23  B2FATAL("REGISTER_PYTHON_MODULE(" << name << ") failed.");
24  }
25 
26  if (auto_import) {
27  if (!Py_IsInitialized()) {
28  B2FATAL("REGISTER_PYTHON_MODULE_AUTOIMPORT(" << name << "): Python is not initialized!");
29  }
30 
31  std::string importString = "import ";
32  importString += name;
33  if (PyRun_SimpleString(importString.c_str()) == -1) {
34  B2FATAL("'import " << name << "' failed.");
35  }
36  }
37 }
Belle2::BoostPythonModuleProxy::BoostPythonModuleProxy
BoostPythonModuleProxy(const char *name, PyObject *(*initFunc)(), bool auto_import=false)
Don't construct this object yourself, use the REGISTER_PYTHON_MODULE macro instead.
Definition: RegisterPythonModule.cc:20
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19