Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:04

0001 #ifndef FWCore_PythonParameterSet_PyBind11Module_h
0002 #define FWCore_PythonParameterSet_PyBind11Module_h
0003 
0004 #include "FWCore/PythonParameterSet/interface/Python11ParameterSet.h"
0005 #include "FWCore/PythonParameterSet/interface/PyBind11ProcessDesc.h"
0006 
0007 #include "DataFormats/Provenance/interface/EventRange.h"
0008 #include "DataFormats/Provenance/interface/LuminosityBlockID.h"
0009 #include "DataFormats/Provenance/interface/LuminosityBlockRange.h"
0010 #include "DataFormats/Provenance/interface/EventID.h"
0011 #include "DataFormats/Provenance/interface/RunLumiEventNumber.h"
0012 #include "FWCore/Utilities/interface/ESInputTag.h"
0013 #include "FWCore/Utilities/interface/Exception.h"
0014 #include "FWCore/Utilities/interface/InputTag.h"
0015 #include <pybind11/stl.h>
0016 #include <string>
0017 
0018 // This is to give some special handling to cms::Exceptions thrown
0019 // in C++ code called by python. Only at the very top level do
0020 // we need the exception message returned by the function "what".
0021 // We only need the central message here as this will get converted
0022 // back into a cms::Exception again when control rises back into
0023 // the C++ code.  If necessary it would probably be possible to
0024 // improve these messages even more by adding something in the python
0025 // to add module type and label context to the messages being caught
0026 // here. At this point we did not think it worth the time to implement.
0027 //namespace {
0028 //  void translatorlibFWCorePythonParameterSet(cms::Exception const& ex) {
0029 //    PyErr_SetString(PyExc_RuntimeError, ex.message().c_str());
0030 //  }
0031 //}
0032 
0033 #include <pybind11/pybind11.h>
0034 
0035 PYBIND11_MODULE(libFWCorePythonParameterSet, m) {
0036   pybind11::register_exception_translator([](std::exception_ptr p) {
0037     try {
0038       if (p)
0039         std::rethrow_exception(p);
0040     } catch (const cms::Exception &e) {
0041       PyErr_SetString(PyExc_RuntimeError, e.what());
0042     }
0043   });
0044 
0045   pybind11::class_<edm::InputTag>(m, "InputTag")
0046       .def(pybind11::init<>())
0047       .def(pybind11::init<const std::string &>())
0048       .def(pybind11::init<const std::string &, const std::string &, const std::string &>())
0049       .def(pybind11::init<const std::string &, const std::string &>())
0050       .def("label", &edm::InputTag::label, pybind11::return_value_policy::copy)
0051       .def("instance", &edm::InputTag::instance, pybind11::return_value_policy::copy)
0052       .def("process", &edm::InputTag::process, pybind11::return_value_policy::copy);
0053 
0054   pybind11::class_<edm::ESInputTag>(m, "ESInputTag")
0055       .def(pybind11::init<std::string>())
0056       .def(pybind11::init<std::string, std::string>())
0057       .def("module", &edm::ESInputTag::module, pybind11::return_value_policy::copy)
0058       .def("data", &edm::ESInputTag::data, pybind11::return_value_policy::copy);
0059 
0060   pybind11::class_<edm::EventID>(m, "EventID")
0061       .def(pybind11::init<edm::RunNumber_t, edm::LuminosityBlockNumber_t, edm::EventNumber_t>())
0062       .def("run", &edm::EventID::run)
0063       .def("luminosityBlock", &edm::EventID::luminosityBlock)
0064       .def("event", &edm::EventID::event);
0065 
0066   pybind11::class_<edm::LuminosityBlockID>(m, "LuminosityBlockID")
0067       .def(pybind11::init<unsigned int, unsigned int>())
0068       .def("run", &edm::LuminosityBlockID::run)
0069       .def("luminosityBlock", &edm::LuminosityBlockID::luminosityBlock);
0070 
0071   pybind11::class_<edm::FileInPath>(m, "FileInPath")
0072       .def(pybind11::init<std::string>())
0073       .def("fullPath", &edm::FileInPath::fullPath)
0074       .def("relativePath", &edm::FileInPath::relativePath);
0075 
0076   pybind11::class_<edm::LuminosityBlockRange>(m, "LuminosityBlockRange")
0077       .def(pybind11::init<unsigned int, unsigned int, unsigned int, unsigned int>())
0078       .def("start", &edm::LuminosityBlockRange::startRun)
0079       .def("startSub", &edm::LuminosityBlockRange::startLumi)
0080       .def("end", &edm::LuminosityBlockRange::endRun)
0081       .def("endSub", &edm::LuminosityBlockRange::endLumi);
0082 
0083   pybind11::class_<edm::EventRange>(m, "EventRange")
0084       .def(pybind11::init<edm::RunNumber_t,
0085                           edm::LuminosityBlockNumber_t,
0086                           edm::EventNumber_t,
0087                           edm::RunNumber_t,
0088                           edm::LuminosityBlockNumber_t,
0089                           edm::EventNumber_t>())
0090       .def("start", &edm::EventRange::startRun)
0091       .def("startLumi", &edm::EventRange::startLumi)
0092       .def("startSub", &edm::EventRange::startEvent)
0093       .def("end", &edm::EventRange::endRun)
0094       .def("endLumi", &edm::EventRange::endLumi)
0095       .def("endSub", &edm::EventRange::endEvent);
0096 
0097   pybind11::class_<Python11ParameterSet>(m, "ParameterSet")
0098       .def(pybind11::init<>())
0099       .def("addInt32", &Python11ParameterSet::addParameter<int>)
0100       .def("getInt32", &Python11ParameterSet::getParameter<int>)
0101       .def("addVInt32", &Python11ParameterSet::addParameters<int>)
0102       .def("getVInt32", &Python11ParameterSet::getParameters<int>)
0103       .def("addUInt32", &Python11ParameterSet::addParameter<unsigned int>)
0104       .def("getUInt32", &Python11ParameterSet::getParameter<unsigned int>)
0105       .def("addVUInt32", &Python11ParameterSet::addParameters<unsigned int>)
0106       .def("getVUInt32", &Python11ParameterSet::getParameters<unsigned int>)
0107       .def("addInt64", &Python11ParameterSet::addParameter<long long>)
0108       .def("getInt64", &Python11ParameterSet::getParameter<long long>)
0109       .def("addUInt64", &Python11ParameterSet::addParameter<unsigned long long>)
0110       .def("getUInt64", &Python11ParameterSet::getParameter<unsigned long long>)
0111       .def("addVInt64", &Python11ParameterSet::addParameters<long long>)
0112       .def("getVInt64", &Python11ParameterSet::getParameters<long long>)
0113       .def("addVUInt64", &Python11ParameterSet::addParameters<unsigned long long>)
0114       .def("getVUInt64", &Python11ParameterSet::getParameters<unsigned long long>)
0115       .def("addDouble", &Python11ParameterSet::addParameter<double>)
0116       .def("getDouble", &Python11ParameterSet::getParameter<double>)
0117       .def("addVDouble", &Python11ParameterSet::addParameters<double>)
0118       .def("getVDouble", &Python11ParameterSet::getParameters<double>)
0119       .def("addBool", &Python11ParameterSet::addParameter<bool>)
0120       .def("getBool", &Python11ParameterSet::getParameter<bool>)
0121       .def("addString", &Python11ParameterSet::addParameter<std::string>)
0122       .def("getString", &Python11ParameterSet::getParameter<std::string>)
0123       .def("addVString", &Python11ParameterSet::addParameters<std::string>)
0124       .def("getVString", &Python11ParameterSet::getParameters<std::string>)
0125       .def("addInputTag", &Python11ParameterSet::addParameter<edm::InputTag>)
0126       .def("getInputTag", &Python11ParameterSet::getParameter<edm::InputTag>)
0127       .def("addVInputTag", &Python11ParameterSet::addParameters<edm::InputTag>)
0128       .def("getVInputTag", &Python11ParameterSet::getParameters<edm::InputTag>)
0129       .def("addESInputTag", &Python11ParameterSet::addParameter<edm::ESInputTag>)
0130       .def("getESInputTag", &Python11ParameterSet::getParameter<edm::ESInputTag>)
0131       .def("addVESInputTag", &Python11ParameterSet::addParameters<edm::ESInputTag>)
0132       .def("getVESInputTag", &Python11ParameterSet::getParameters<edm::ESInputTag>)
0133       .def("addEventID", &Python11ParameterSet::addParameter<edm::EventID>)
0134       .def("getEventID", &Python11ParameterSet::getParameter<edm::EventID>)
0135       .def("addVEventID", &Python11ParameterSet::addParameters<edm::EventID>)
0136       .def("getVEventID", &Python11ParameterSet::getParameters<edm::EventID>)
0137       .def("addLuminosityBlockID", &Python11ParameterSet::addParameter<edm::LuminosityBlockID>)
0138       .def("getLuminosityBlockID", &Python11ParameterSet::getParameter<edm::LuminosityBlockID>)
0139       .def("addVLuminosityBlockID", &Python11ParameterSet::addParameters<edm::LuminosityBlockID>)
0140       .def("getVLuminosityBlockID", &Python11ParameterSet::getParameters<edm::LuminosityBlockID>)
0141       .def("addLuminosityBlockRange", &Python11ParameterSet::addParameter<edm::LuminosityBlockRange>)
0142       .def("getLuminosityBlockRange", &Python11ParameterSet::getParameter<edm::LuminosityBlockRange>)
0143       .def("addVLuminosityBlockRange", &Python11ParameterSet::addParameters<edm::LuminosityBlockRange>)
0144       .def("getVLuminosityBlockRange", &Python11ParameterSet::getParameters<edm::LuminosityBlockRange>)
0145       .def("addEventRange", &Python11ParameterSet::addParameter<edm::EventRange>)
0146       .def("getEventRange", &Python11ParameterSet::getParameter<edm::EventRange>)
0147       .def("addVEventRange", &Python11ParameterSet::addParameters<edm::EventRange>)
0148       .def("getVEventRange", &Python11ParameterSet::getParameters<edm::EventRange>)
0149       .def("addPSet", &Python11ParameterSet::addPSet)
0150       .def("getPSet", &Python11ParameterSet::getPSet)
0151       .def("addVPSet", &Python11ParameterSet::addVPSet)
0152       .def("getVPSet", &Python11ParameterSet::getVPSet)
0153       .def("addFileInPath", &Python11ParameterSet::addParameter<edm::FileInPath>)
0154       .def("getFileInPath", &Python11ParameterSet::getParameter<edm::FileInPath>)
0155       .def("newInputTag", &Python11ParameterSet::newInputTag)
0156       .def("newESInputTag", &Python11ParameterSet::newESInputTag)
0157       .def("newEventID", &Python11ParameterSet::newEventID)
0158       .def("newLuminosityBlockID", &Python11ParameterSet::newLuminosityBlockID)
0159       .def("newLuminosityBlockRange", &Python11ParameterSet::newLuminosityBlockRange)
0160       .def("newEventRange", &Python11ParameterSet::newEventRange)
0161       .def("addNewFileInPath", &Python11ParameterSet::addNewFileInPath)
0162       .def("newPSet", &Python11ParameterSet::newPSet)
0163       .def("dump", &Python11ParameterSet::dump);
0164 
0165   pybind11::class_<PyBind11ProcessDesc>(m, "ProcessDesc")  //, pybind11::init<>())
0166       .def(pybind11::init<>())
0167       .def(pybind11::init<std::string>())
0168       .def("newPSet", &PyBind11ProcessDesc::newPSet)
0169       .def("pset", &PyBind11ProcessDesc::pset, pybind11::return_value_policy::reference)
0170       .def("dump", &PyBind11ProcessDesc::dump);
0171 }
0172 
0173 #endif