CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PyModule.cc
Go to the documentation of this file.
1 /*
2  * PyModule.cc
3  * CMSSW
4  *
5  * Created by Chris Jones on 3/22/06.
6  *
7  */
8 #include <boost/python/module.hpp>
9 #include <boost/python/class.hpp>
10 #include <boost/python/exception_translator.hpp>
11 
13 
15 
17 
18 #include "Rtypes.h"
19 #include "TClass.h"
20 
21 class TClass;
22 namespace PyROOT {
23  PyObject* BindRootObject( void* object, TClass* klass, Bool_t isRef = kFALSE );
24 }
25 
26 namespace {
27  void (edm::python::ConstEventWrapper::*getByLabel1)(std::string const& , edm::GenericHandle& ) const = &edm::python::ConstEventWrapper::getByLabel;
28  void (edm::python::ConstEventWrapper::*getByLabel2)(std::string const& , std::string const&, edm::GenericHandle& ) const = &edm::python::ConstEventWrapper::getByLabel;
29 
30  PyObject* getFromHandle(const edm::GenericHandle& iHandle)
31  {
32  if(0 == iHandle.product() ) {
34  return null.ptr();
35  }
36  return PyROOT::BindRootObject( iHandle.product()->Address(), TClass::GetClass(iHandle.type().TypeInfo()));
37  }
38 }
39 
40 //this function is used to translate C++ exceptions to python exceptions
41 static
42 void
44  PyErr_SetString(PyExc_RuntimeError, iException.what());
45 }
46 
47 
48 using namespace boost::python;
49 BOOST_PYTHON_MODULE(libFWCorePython)
50 {
51  register_exception_translator< cms::Exception >(exceptionTranslation);
52 
53  class_<edm::python::ConstEventWrapper>("ConstEvent",no_init)
54  .def("getByLabel",getByLabel1)
55  .def("getByLabel",getByLabel2);
56 
57  class_<edm::GenericHandle>("Handle",init<std::string>())
58  .def("get",getFromHandle);
59 }
virtual char const * what() const
Definition: Exception.cc:141
void getByLabel(std::string const &, edm::GenericHandle &) const
Definition: EventWrapper.cc:61
BOOST_PYTHON_MODULE(pluginBeamSpotObjectsPyInterface)
Reflex::Object const * product() const
PyObject * BindRootObject(void *object, TClass *klass, Bool_t isRef=kFALSE)
Reflex::Type const & type() const
list object
Definition: dbtoconf.py:77
static void exceptionTranslation(cms::Exception const &iException)
Definition: PyModule.cc:43
JetCorrectorParameters::Definitions def
Definition: classes.h:10