CMS 3D CMS Logo

PythonModule.cc
Go to the documentation of this file.
1 #ifndef FWCore_PythonFramework_PythonModule_h
2 #define FWCore_PythonFramework_PythonModule_h
3 
5 
8 
9 #include <pybind11/pybind11.h>
10 
11 // This is to give some special handling to cms::Exceptions thrown
12 // in C++ code called by python. Only at the very top level do
13 // we need the exception message returned by the function "what".
14 // We only need the central message here as this will get converted
15 // back into a cms::Exception again when control rises back into
16 // the C++ code. If necessary it would probably be possible to
17 // improve these messages even more by adding something in the python
18 // to add module type and label context to the messages being caught
19 // here. At this point we did not think it worth the time to implement.
20 
21 PYBIND11_MODULE(libFWCorePythonFramework, m) {
22  pybind11::register_exception_translator([](std::exception_ptr p) {
23  try {
24  if (p)
25  std::rethrow_exception(p);
26  } catch (const cms::Exception &e) {
27  PyErr_SetString(PyExc_RuntimeError, e.what());
28  }
29  });
30 
31  pybind11::class_<PythonEventProcessor>(m, "PythonEventProcessor")
32  .def(pybind11::init<PyBind11ProcessDesc const &>())
34  .def("totalEvents", &PythonEventProcessor::totalEvents)
35  .def("totalEventsPassed", &PythonEventProcessor::totalEventsPassed)
36  .def("totalEventsFailed", &PythonEventProcessor::totalEventsFailed);
37 }
38 #endif
int def(FILE *, FILE *, int)
PYBIND11_MODULE(libFWCorePythonFramework, m)
Definition: PythonModule.cc:21