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 
6 
9 
10 // This is to give some special handling to cms::Exceptions thrown
11 // in C++ code called by python. Only at the very top level do
12 // we need the exception message returned by the function "what".
13 // We only need the central message here as this will get converted
14 // back into a cms::Exception again when control rises back into
15 // the C++ code. If necessary it would probably be possible to
16 // improve these messages even more by adding something in the python
17 // to add module type and label context to the messages being caught
18 // here. At this point we did not think it worth the time to implement.
19 namespace {
20  void translator(cms::Exception const& ex) {
21  PyErr_SetString(PyExc_RuntimeError, ex.message().c_str());
22  }
23 }
24 
25 BOOST_PYTHON_MODULE(libFWCorePythonFramework)
26 {
27  boost::python::register_exception_translator<cms::Exception>(translator);
28 
29  boost::python::class_<PythonEventProcessor, boost::noncopyable>("PythonEventProcessor", boost::python::init<PythonProcessDesc const&>())
30  .def("run", &PythonEventProcessor::run)
31  .def("totalEvents", &PythonEventProcessor::totalEvents)
32  .def("totalEventsPassed", &PythonEventProcessor::totalEventsPassed)
33  .def("totalEventsFailed", &PythonEventProcessor::totalEventsFailed)
34  ;
35 }
36 #endif
BOOST_PYTHON_MODULE(libFWCorePythonFramework)
Definition: PythonModule.cc:25
std::string message() const
Definition: Exception.cc:187