From e442b5862fbe7617d9fcf4184afdc00bbf597b10 Mon Sep 17 00:00:00 2001 From: Giacomo Govi Date: Wed, 28 Jul 2021 11:20:41 +0200 Subject: [PATCH 1/3] PayloadInspector moved to pybind11 --- CondCore/Utilities/BuildFile.xml | 1 - .../Utilities/interface/PayloadInspector.h | 39 ++++++++++--------- .../interface/PayloadInspectorModule.h | 23 ++++++----- .../plugins/BasicP_PayloadInspector.cc | 6 +-- CondCore/Utilities/plugins/BuildFile.xml | 3 +- .../plugins/Module_PayloadInspector.cc | 12 +++--- CondCore/Utilities/src/PayloadInspector.cc | 32 +++++++-------- 7 files changed, 61 insertions(+), 55 deletions(-) diff --git a/CondCore/Utilities/BuildFile.xml b/CondCore/Utilities/BuildFile.xml index eca5755e41a15..c107dfe203abb 100644 --- a/CondCore/Utilities/BuildFile.xml +++ b/CondCore/Utilities/BuildFile.xml @@ -2,7 +2,6 @@ - diff --git a/CondCore/Utilities/interface/PayloadInspector.h b/CondCore/Utilities/interface/PayloadInspector.h index 11d873675082d..a682206067076 100644 --- a/CondCore/Utilities/interface/PayloadInspector.h +++ b/CondCore/Utilities/interface/PayloadInspector.h @@ -14,25 +14,27 @@ #include "FWCore/Utilities/interface/GlobalIdentifier.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" -#include -#include -#include +#include +#include +namespace py = pybind11; namespace PI { - inline boost::python::list mk_input(const std::string& tagName, cond::Time_t start, cond::Time_t end) { - boost::python::list ret; - ret.append(boost::python::make_tuple(tagName, std::to_string(start), std::to_string(end))); + __attribute__((visibility("default"))) inline py::list mk_input(const std::string& tagName, + cond::Time_t start, + cond::Time_t end) { + py::list ret; + ret.append(py::make_tuple(tagName, std::to_string(start), std::to_string(end))); return ret; } - inline boost::python::list mk_input(const std::string& tagName0, - cond::Time_t start0, - cond::Time_t end0, - const std::string& tagName1, - cond::Time_t start1, - cond::Time_t end1) { - boost::python::list ret; - ret.append(boost::python::make_tuple(tagName0, std::to_string(start0), std::to_string(end0))); - ret.append(boost::python::make_tuple(tagName1, std::to_string(start1), std::to_string(end1))); + __attribute__((visibility("default"))) inline py::list mk_input(const std::string& tagName0, + cond::Time_t start0, + cond::Time_t end0, + const std::string& tagName1, + cond::Time_t start1, + cond::Time_t end1) { + py::list ret; + ret.append(py::make_tuple(tagName0, std::to_string(start0), std::to_string(end0))); + ret.append(py::make_tuple(tagName1, std::to_string(start1), std::to_string(end1))); return ret; } } // namespace PI @@ -228,16 +230,17 @@ namespace cond { bool isSingleIov() const; // required in the browser - boost::python::list inputParams() const; + __attribute__((visibility("default"))) py::list inputParams() const; // required in the browser - void setInputParamValues(const boost::python::dict& values); + __attribute__((visibility("default"))) void setInputParamValues(const py::dict& values); // returns the json file with the plot data std::string data() const; // triggers the processing producing the plot - bool process(const std::string& connectionString, const boost::python::list& tagsWithTimeBoundaries); + __attribute__((visibility("default"))) bool process(const std::string& connectionString, + const py::list& tagsWithTimeBoundaries); // called by the above method - to be used in C++ unit tests... bool exec_process(const std::string& connectionString, diff --git a/CondCore/Utilities/interface/PayloadInspectorModule.h b/CondCore/Utilities/interface/PayloadInspectorModule.h index 2dfa41c534671..a2f71dfbfa3f6 100644 --- a/CondCore/Utilities/interface/PayloadInspectorModule.h +++ b/CondCore/Utilities/interface/PayloadInspectorModule.h @@ -1,18 +1,21 @@ -#include +#include +namespace py = pybind11; #define PPCAT_NX(A, B) A##B #define PPCAT(A, B) PPCAT_NX(A, B) #define STRINGIZE_NX(A) #A #define STRINGIZE(A) STRINGIZE_NX(A) -#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME) BOOST_PYTHON_MODULE(plugin##PAYLOAD_TYPENAME##_PayloadInspector) +#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME) PYBIND11_MODULE(plugin##PAYLOAD_TYPENAME##_PayloadInspector, m) -#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME) \ - boost::python::class_ >( \ - STRINGIZE(PPCAT(plot_, CLASS_NAME)), boost::python::init<>()) \ - .def("process", &cond::payloadInspector::PlotBase::process) \ - .def("payloadType", &cond::payloadInspector::PlotBase::payloadType) \ - .def("title", &cond::payloadInspector::PlotBase::title) \ - .def("isSingleIov", &cond::payloadInspector::PlotBase::isSingleIov) \ - .def("isTwoTags", &cond::payloadInspector::PlotBase::isTwoTags) \ +#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME) \ + py::class_( \ + m, \ + STRINGIZE(PPCAT(plot_, CLASS_NAME))) \ + .def(py::init<>()) \ + .def("process", &cond::payloadInspector::PlotBase::process) \ + .def("payloadType", &cond::payloadInspector::PlotBase::payloadType) \ + .def("title", &cond::payloadInspector::PlotBase::title) \ + .def("isSingleIov", &cond::payloadInspector::PlotBase::isSingleIov) \ + .def("isTwoTags", &cond::payloadInspector::PlotBase::isTwoTags) \ .def("data", &cond::payloadInspector::PlotBase::data); diff --git a/CondCore/Utilities/plugins/BasicP_PayloadInspector.cc b/CondCore/Utilities/plugins/BasicP_PayloadInspector.cc index 35a4a52429b79..fbcd8389f8b9d 100644 --- a/CondCore/Utilities/plugins/BasicP_PayloadInspector.cc +++ b/CondCore/Utilities/plugins/BasicP_PayloadInspector.cc @@ -34,15 +34,15 @@ namespace { auto paramValues = cond::payloadInspector::PlotBase::inputParamValues(); auto ip = paramValues.find("Factor"); if (ip != paramValues.end()) { - v = v * boost::lexical_cast(ip->second); + v = v * std::stof(ip->second); } ip = paramValues.find("Offset"); if (ip != paramValues.end()) { - v = v + boost::lexical_cast(ip->second); + v = v + std::stof(ip->second); } ip = paramValues.find("Scale"); if (ip != paramValues.end()) { - v = v * boost::lexical_cast(ip->second); + v = v * std::stof(ip->second); } return v; } diff --git a/CondCore/Utilities/plugins/BuildFile.xml b/CondCore/Utilities/plugins/BuildFile.xml index a102433193fa1..122db196be4f8 100644 --- a/CondCore/Utilities/plugins/BuildFile.xml +++ b/CondCore/Utilities/plugins/BuildFile.xml @@ -12,12 +12,13 @@ - + + diff --git a/CondCore/Utilities/plugins/Module_PayloadInspector.cc b/CondCore/Utilities/plugins/Module_PayloadInspector.cc index 7b7817534709b..6d8d82f732f46 100644 --- a/CondCore/Utilities/plugins/Module_PayloadInspector.cc +++ b/CondCore/Utilities/plugins/Module_PayloadInspector.cc @@ -1,11 +1,11 @@ #include "CondCore/Utilities/interface/PayloadInspector.h" -#include -#include +#include +namespace py = pybind11; -BOOST_PYTHON_MODULE(pluginModule_PayloadInspector) { - boost::python::class_("ModuleVersion") - .def_readonly("label", &cond::payloadInspector::ModuleVersion::label); - boost::python::class_("PlotBase") +PYBIND11_MODULE(pluginModule_PayloadInspector, m) { + py::class_(m, "ModuleVersion") + .def_readonly_static("label", &cond::payloadInspector::ModuleVersion::label); + py::class_(m, "PlotBase") .def("process", &cond::payloadInspector::PlotBase::process) .def("payloadType", &cond::payloadInspector::PlotBase::payloadType) .def("type", &cond::payloadInspector::PlotBase::type) diff --git a/CondCore/Utilities/src/PayloadInspector.cc b/CondCore/Utilities/src/PayloadInspector.cc index 15a0f80b4b6f3..82116f7501f79 100644 --- a/CondCore/Utilities/src/PayloadInspector.cc +++ b/CondCore/Utilities/src/PayloadInspector.cc @@ -5,7 +5,6 @@ #include #include -#include namespace cond { @@ -49,38 +48,39 @@ namespace cond { bool PlotBase::isTwoTags() const { return m_plotAnnotations.ntags == 2; } - boost::python::list PlotBase::inputParams() const { - boost::python::list tmp; + py::list PlotBase::inputParams() const { + py::list tmp; for (const auto& ip : m_inputParams) { tmp.append(ip); } return tmp; } - void PlotBase::setInputParamValues(const boost::python::dict& values) { - for (const auto& ip : m_inputParams) { - if (values.has_key(ip)) { - std::string val = boost::python::extract(values.get(ip)); - m_inputParamValues.insert(std::make_pair(ip, val)); + void PlotBase::setInputParamValues(const py::dict& values) { + for (auto item : values) { + std::string k = item.first.cast(); + std::string v = item.second.cast(); + if (m_inputParams.find(k) != m_inputParams.end()) { + m_inputParamValues.insert(std::make_pair(k, v)); } } } std::string PlotBase::data() const { return m_data; } - bool PlotBase::process(const std::string& connectionString, const boost::python::list& tagsWithTimeBoundaries) { - size_t nt = boost::python::len(tagsWithTimeBoundaries); + bool PlotBase::process(const std::string& connectionString, const py::list& tagsWithTimeBoundaries) { + size_t nt = py::len(tagsWithTimeBoundaries); bool ret = false; if (nt) { std::vector > tags; tags.resize(nt); for (size_t i = 0; i < nt; i++) { - boost::python::tuple entry = boost::python::extract(tagsWithTimeBoundaries[i]); - std::string tagName = boost::python::extract(entry[0]); - std::string time0s = boost::python::extract(entry[1]); - std::string time1s = boost::python::extract(entry[2]); - cond::Time_t time0 = boost::lexical_cast(time0s); - cond::Time_t time1 = boost::lexical_cast(time1s); + py::tuple entry = tagsWithTimeBoundaries[i].cast(); + std::string tagName = entry[0].cast(); + std::string time0s = entry[1].cast(); + std::string time1s = entry[2].cast(); + cond::Time_t time0 = std::stoull(time0s); + cond::Time_t time1 = std::stoull(time1s); tags[i] = std::make_tuple(tagName, time0, time1); } ret = exec_process(connectionString, tags); From 8a52739c0deb2e1461f89a8a539c709cfdf9687f Mon Sep 17 00:00:00 2001 From: Giacomo Govi Date: Wed, 28 Jul 2021 11:21:25 +0200 Subject: [PATCH 2/3] Fixed dependencies --- CondCore/EcalPlugins/plugins/EcalPyUtils.cc | 27 ++++++++++--------- .../test/testSiPixelPayloadInspector.cpp | 2 +- .../test/testSiStripPayloadInspector.cpp | 5 ++-- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/CondCore/EcalPlugins/plugins/EcalPyUtils.cc b/CondCore/EcalPlugins/plugins/EcalPyUtils.cc index 27b0513b3ecd6..0922829b8164f 100644 --- a/CondCore/EcalPlugins/plugins/EcalPyUtils.cc +++ b/CondCore/EcalPlugins/plugins/EcalPyUtils.cc @@ -8,10 +8,13 @@ #include "DataFormats/EcalDetId/interface/EBDetId.h" #include "DataFormats/EcalDetId/interface/EEDetId.h" #include "CondTools/Ecal/interface/EcalFloatCondObjectContainerXMLTranslator.h" -#include -#include +#include +namespace py = pybind11; -using namespace boost::python; +//#include +//#include + +//using namespace boost::python; namespace ecalpyutils { @@ -59,7 +62,7 @@ namespace ecalpyutils { } } // namespace ecalpyutils -BOOST_PYTHON_MODULE(pluginEcalPyUtils) { +PYBIND11_MODULE(pluginEcalPyUtils, m) { // looks like these are already defined somewhere // python access to stl integer vectors @@ -71,12 +74,12 @@ BOOST_PYTHON_MODULE(pluginEcalPyUtils) { // .def(vector_indexing_suite >()) // ; - def("hashedIndexToEtaPhi", &ecalpyutils::hashedIndexToEtaPhi); - def("hashedIndexToXY", &ecalpyutils::hashedIndexToXY); - def("hashedIndex", &ecalpyutils::hashedIndex); - def("hashedIndexEE", &ecalpyutils::hashedIndexEE); - def("ism", &ecalpyutils::ism); - def("barrelfromXML", &EcalFloatCondObjectContainerXMLTranslator::barrelfromXML); - def("endcapfromXML", &EcalFloatCondObjectContainerXMLTranslator::endcapfromXML); - def("arraystoXML", &ecalpyutils::arraystoXML); + m.def("hashedIndexToEtaPhi", &ecalpyutils::hashedIndexToEtaPhi); + m.def("hashedIndexToXY", &ecalpyutils::hashedIndexToXY); + m.def("hashedIndex", &ecalpyutils::hashedIndex); + m.def("hashedIndexEE", &ecalpyutils::hashedIndexEE); + m.def("ism", &ecalpyutils::ism); + m.def("barrelfromXML", &EcalFloatCondObjectContainerXMLTranslator::barrelfromXML); + m.def("endcapfromXML", &EcalFloatCondObjectContainerXMLTranslator::endcapfromXML); + m.def("arraystoXML", &ecalpyutils::arraystoXML); } diff --git a/CondCore/SiPixelPlugins/test/testSiPixelPayloadInspector.cpp b/CondCore/SiPixelPlugins/test/testSiPixelPayloadInspector.cpp index 34b6ad1d50ed0..8a79edc14d72a 100644 --- a/CondCore/SiPixelPlugins/test/testSiPixelPayloadInspector.cpp +++ b/CondCore/SiPixelPlugins/test/testSiPixelPayloadInspector.cpp @@ -132,7 +132,7 @@ int main(int argc, char** argv) { histo16.process(connectionString, PI::mk_input(tag, end, end)); edm::LogPrint("testSiPixelPayloadInspector") << histo16.data() << std::endl; - boost::python::dict inputs; + py::dict inputs; inputs["SetLog"] = "True"; // sets to true, 1,True,Yes will work SiPixelGainCalibrationOfflineGainsValuesBarrel histo17; diff --git a/CondCore/SiStripPlugins/test/testSiStripPayloadInspector.cpp b/CondCore/SiStripPlugins/test/testSiStripPayloadInspector.cpp index 285202ed5293c..ec3e2f0715e65 100644 --- a/CondCore/SiStripPlugins/test/testSiStripPayloadInspector.cpp +++ b/CondCore/SiStripPlugins/test/testSiStripPayloadInspector.cpp @@ -33,7 +33,7 @@ int main(int argc, char** argv) { std::string tag = "SiStripApvGain_FromParticles_GR10_v11_offline"; cond::Time_t start = boost::lexical_cast(132440); cond::Time_t end = boost::lexical_cast(285368); - boost::python::dict inputs; + py::dict inputs; edm::LogPrint("testSiStripPayloadInspector") << "## Exercising Gains plots " << std::endl; @@ -112,7 +112,8 @@ int main(int argc, char** argv) { edm::LogPrint("testSiStripPayloadInspector") << histo11.data() << std::endl; SiStripPedestalPerDetId histoPedestalForDetId; - inputs["DetIds"] += ",470065830,369121594,369124670,470177668"; // add a bunch of other DetIds + inputs["DetIds"] = py::cast(inputs["DetIds"]) + + ",470065830,369121594,369124670,470177668"; // add a bunch of other DetIds histoPedestalForDetId.setInputParamValues(inputs); histoPedestalForDetId.process(connectionString, PI::mk_input(tag, start, start)); edm::LogPrint("testSiStripPayloadInspector") << histoPedestalForDetId.data() << std::endl; From 6b59c291d8259cce0de906688ad20497eadab201 Mon Sep 17 00:00:00 2001 From: Giacomo Govi Date: Wed, 28 Jul 2021 15:57:51 +0200 Subject: [PATCH 3/3] Removed obsolete commented code --- CondCore/EcalPlugins/plugins/EcalPyUtils.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CondCore/EcalPlugins/plugins/EcalPyUtils.cc b/CondCore/EcalPlugins/plugins/EcalPyUtils.cc index 0922829b8164f..a4e7a12f024fb 100644 --- a/CondCore/EcalPlugins/plugins/EcalPyUtils.cc +++ b/CondCore/EcalPlugins/plugins/EcalPyUtils.cc @@ -11,11 +11,6 @@ #include namespace py = pybind11; -//#include -//#include - -//using namespace boost::python; - namespace ecalpyutils { std::vector hashedIndexToEtaPhi(int hashedindex) {