CMS 3D CMS Logo

PyBind11Module.h
Go to the documentation of this file.
1 #ifndef FWCore_PythonParameterSet_PyBind11Module_h
2 #define FWCore_PythonParameterSet_PyBind11Module_h
3 
6 
15 #include <pybind11/stl.h>
16 #include <string>
17 
18 // This is to give some special handling to cms::Exceptions thrown
19 // in C++ code called by python. Only at the very top level do
20 // we need the exception message returned by the function "what".
21 // We only need the central message here as this will get converted
22 // back into a cms::Exception again when control rises back into
23 // the C++ code. If necessary it would probably be possible to
24 // improve these messages even more by adding something in the python
25 // to add module type and label context to the messages being caught
26 // here. At this point we did not think it worth the time to implement.
27 //namespace {
28 // void translatorlibFWCorePythonParameterSet(cms::Exception const& ex) {
29 // PyErr_SetString(PyExc_RuntimeError, ex.message().c_str());
30 // }
31 //}
32 
33 #include <pybind11/pybind11.h>
34 
35 PYBIND11_MODULE(libFWCorePythonParameterSet, m) {
36  pybind11::register_exception_translator([](std::exception_ptr p) {
37  try {
38  if (p)
39  std::rethrow_exception(p);
40  } catch (const cms::Exception &e) {
41  PyErr_SetString(PyExc_RuntimeError, e.what());
42  }
43  });
44 
45  pybind11::class_<edm::InputTag>(m, "InputTag")
46  .def(pybind11::init<>())
47  .def(pybind11::init<const std::string &>())
48  .def(pybind11::init<const std::string &, const std::string &, const std::string &>())
49  .def(pybind11::init<const std::string &, const std::string &>())
53 
54  pybind11::class_<edm::ESInputTag>(m, "ESInputTag")
55  .def(pybind11::init<std::string>())
56  .def(pybind11::init<std::string, std::string>())
59 
60  pybind11::class_<edm::EventID>(m, "EventID")
61  .def(pybind11::init<edm::RunNumber_t, edm::LuminosityBlockNumber_t, edm::EventNumber_t>())
62  .def("run", &edm::EventID::run)
63  .def("luminosityBlock", &edm::EventID::luminosityBlock)
64  .def("event", &edm::EventID::event);
65 
66  pybind11::class_<edm::LuminosityBlockID>(m, "LuminosityBlockID")
67  .def(pybind11::init<unsigned int, unsigned int>())
69  .def("luminosityBlock", &edm::LuminosityBlockID::luminosityBlock);
70 
71  pybind11::class_<edm::FileInPath>(m, "FileInPath")
72  .def(pybind11::init<std::string>())
73  .def("fullPath", &edm::FileInPath::fullPath)
74  .def("relativePath", &edm::FileInPath::relativePath);
75 
76  pybind11::class_<edm::LuminosityBlockRange>(m, "LuminosityBlockRange")
77  .def(pybind11::init<unsigned int, unsigned int, unsigned int, unsigned int>())
79  .def("startSub", &edm::LuminosityBlockRange::startLumi)
81  .def("endSub", &edm::LuminosityBlockRange::endLumi);
82 
83  pybind11::class_<edm::EventRange>(m, "EventRange")
90  .def("start", &edm::EventRange::startRun)
91  .def("startLumi", &edm::EventRange::startLumi)
92  .def("startSub", &edm::EventRange::startEvent)
93  .def("end", &edm::EventRange::endRun)
94  .def("endLumi", &edm::EventRange::endLumi)
95  .def("endSub", &edm::EventRange::endEvent);
96 
97  pybind11::class_<Python11ParameterSet>(m, "ParameterSet")
98  .def(pybind11::init<>())
99  .def("addInt32", &Python11ParameterSet::addParameter<int>)
100  .def("getInt32", &Python11ParameterSet::getParameter<int>)
101  .def("addVInt32", &Python11ParameterSet::addParameters<int>)
102  .def("getVInt32", &Python11ParameterSet::getParameters<int>)
103  .def("addUInt32", &Python11ParameterSet::addParameter<unsigned int>)
104  .def("getUInt32", &Python11ParameterSet::getParameter<unsigned int>)
105  .def("addVUInt32", &Python11ParameterSet::addParameters<unsigned int>)
106  .def("getVUInt32", &Python11ParameterSet::getParameters<unsigned int>)
107  .def("addInt64", &Python11ParameterSet::addParameter<long long>)
108  .def("getInt64", &Python11ParameterSet::getParameter<long long>)
109  .def("addUInt64", &Python11ParameterSet::addParameter<unsigned long long>)
110  .def("getUInt64", &Python11ParameterSet::getParameter<unsigned long long>)
111  .def("addVInt64", &Python11ParameterSet::addParameters<long long>)
112  .def("getVInt64", &Python11ParameterSet::getParameters<long long>)
113  .def("addVUInt64", &Python11ParameterSet::addParameters<unsigned long long>)
114  .def("getVUInt64", &Python11ParameterSet::getParameters<unsigned long long>)
115  .def("addDouble", &Python11ParameterSet::addParameter<double>)
116  .def("getDouble", &Python11ParameterSet::getParameter<double>)
117  .def("addVDouble", &Python11ParameterSet::addParameters<double>)
118  .def("getVDouble", &Python11ParameterSet::getParameters<double>)
119  .def("addBool", &Python11ParameterSet::addParameter<bool>)
120  .def("getBool", &Python11ParameterSet::getParameter<bool>)
121  .def("addString", &Python11ParameterSet::addParameter<std::string>)
122  .def("getString", &Python11ParameterSet::getParameter<std::string>)
123  .def("addVString", &Python11ParameterSet::addParameters<std::string>)
124  .def("getVString", &Python11ParameterSet::getParameters<std::string>)
125  .def("addInputTag", &Python11ParameterSet::addParameter<edm::InputTag>)
126  .def("getInputTag", &Python11ParameterSet::getParameter<edm::InputTag>)
127  .def("addVInputTag", &Python11ParameterSet::addParameters<edm::InputTag>)
128  .def("getVInputTag", &Python11ParameterSet::getParameters<edm::InputTag>)
129  .def("addESInputTag", &Python11ParameterSet::addParameter<edm::ESInputTag>)
130  .def("getESInputTag", &Python11ParameterSet::getParameter<edm::ESInputTag>)
131  .def("addVESInputTag", &Python11ParameterSet::addParameters<edm::ESInputTag>)
132  .def("getVESInputTag", &Python11ParameterSet::getParameters<edm::ESInputTag>)
133  .def("addEventID", &Python11ParameterSet::addParameter<edm::EventID>)
134  .def("getEventID", &Python11ParameterSet::getParameter<edm::EventID>)
135  .def("addVEventID", &Python11ParameterSet::addParameters<edm::EventID>)
136  .def("getVEventID", &Python11ParameterSet::getParameters<edm::EventID>)
137  .def("addLuminosityBlockID", &Python11ParameterSet::addParameter<edm::LuminosityBlockID>)
138  .def("getLuminosityBlockID", &Python11ParameterSet::getParameter<edm::LuminosityBlockID>)
139  .def("addVLuminosityBlockID", &Python11ParameterSet::addParameters<edm::LuminosityBlockID>)
140  .def("getVLuminosityBlockID", &Python11ParameterSet::getParameters<edm::LuminosityBlockID>)
141  .def("addLuminosityBlockRange", &Python11ParameterSet::addParameter<edm::LuminosityBlockRange>)
142  .def("getLuminosityBlockRange", &Python11ParameterSet::getParameter<edm::LuminosityBlockRange>)
143  .def("addVLuminosityBlockRange", &Python11ParameterSet::addParameters<edm::LuminosityBlockRange>)
144  .def("getVLuminosityBlockRange", &Python11ParameterSet::getParameters<edm::LuminosityBlockRange>)
145  .def("addEventRange", &Python11ParameterSet::addParameter<edm::EventRange>)
146  .def("getEventRange", &Python11ParameterSet::getParameter<edm::EventRange>)
147  .def("addVEventRange", &Python11ParameterSet::addParameters<edm::EventRange>)
148  .def("getVEventRange", &Python11ParameterSet::getParameters<edm::EventRange>)
149  .def("addPSet", &Python11ParameterSet::addPSet)
150  .def("getPSet", &Python11ParameterSet::getPSet)
151  .def("addVPSet", &Python11ParameterSet::addVPSet)
152  .def("getVPSet", &Python11ParameterSet::getVPSet)
153  .def("addFileInPath", &Python11ParameterSet::addParameter<edm::FileInPath>)
154  .def("getFileInPath", &Python11ParameterSet::getParameter<edm::FileInPath>)
155  .def("newInputTag", &Python11ParameterSet::newInputTag)
156  .def("newESInputTag", &Python11ParameterSet::newESInputTag)
157  .def("newEventID", &Python11ParameterSet::newEventID)
158  .def("newLuminosityBlockID", &Python11ParameterSet::newLuminosityBlockID)
159  .def("newLuminosityBlockRange", &Python11ParameterSet::newLuminosityBlockRange)
160  .def("newEventRange", &Python11ParameterSet::newEventRange)
161  .def("addNewFileInPath", &Python11ParameterSet::addNewFileInPath)
162  .def("newPSet", &Python11ParameterSet::newPSet)
163  .def("dump", &Python11ParameterSet::dump);
164 
165  pybind11::class_<PyBind11ProcessDesc>(m, "ProcessDesc") //, pybind11::init<>())
166  .def(pybind11::init<>())
167  .def(pybind11::init<std::string, bool>())
168  .def("newPSet", &PyBind11ProcessDesc::newPSet)
170  .def("dump", &PyBind11ProcessDesc::dump);
171 }
172 
173 #endif
edm::LuminosityBlockID newLuminosityBlockID(unsigned int run, unsigned int lumi)
int def(FILE *, FILE *, int)
LuminosityBlockNumber_t luminosityBlock() const
LuminosityBlockNumber_t endLumi() const
edm::LuminosityBlockRange newLuminosityBlockRange(unsigned int start, unsigned int startSub, unsigned int end, unsigned int endSub)
void addNewFileInPath(bool tracked, std::string const &name, std::string const &value)
edm::ESInputTag newESInputTag(std::string const &module, std::string const &data)
std::string dump() const
EventNumber_t startEvent() const
Definition: EventRange.h:52
std::string const & instance() const
Definition: InputTag.h:37
std::string dump() const
int init
Definition: HydjetWrapper.h:66
unsigned long long EventNumber_t
PYBIND11_MODULE(libFWCorePythonParameterSet, m)
pybind11::list getVPSet(bool tracked, std::string const &name)
std::string const & label() const
Definition: InputTag.h:36
RunNumber_t startRun() const
Definition: EventRange.h:48
Python11ParameterSet getPSet(bool tracked, std::string const &name) const
unsigned int LuminosityBlockNumber_t
const std::string & data() const
Definition: ESInputTag.h:104
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:39
Python11ParameterSet newPSet() const
RunNumber_t startRun() const
void addPSet(bool tracked, std::string const &name, Python11ParameterSet const &ppset)
LuminosityBlockNumber_t endLumi() const
Definition: EventRange.h:51
RunNumber_t endRun() const
Definition: EventRange.h:49
Python11ParameterSet & pset()
const std::string & relativePath() const
Definition: FileInPath.cc:140
RunNumber_t run() const
RunNumber_t run() const
Definition: EventID.h:38
LuminosityBlockNumber_t startLumi() const
Definition: EventRange.h:50
edm::EventRange newEventRange(edm::RunNumber_t start, edm::LuminosityBlockNumber_t startLumi, edm::EventNumber_t startSub, edm::RunNumber_t end, edm::LuminosityBlockNumber_t endLumi, edm::EventNumber_t endSub)
edm::EventID newEventID(edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi, edm::EventNumber_t event)
EventNumber_t endEvent() const
Definition: EventRange.h:53
edm::InputTag newInputTag(std::string const &label, std::string const &instance, std::string const &process)
const std::string & fullPath() const
Definition: FileInPath.cc:144
Python11ParameterSet newPSet() const
unsigned int RunNumber_t
void addVPSet(bool tracked, std::string const &name, pybind11::list value)
const std::string & module() const
Definition: ESInputTag.h:99
std::string const & process() const
Definition: InputTag.h:40
LuminosityBlockNumber_t startLumi() const
EventNumber_t event() const
Definition: EventID.h:40