File indexing completed on 2024-04-06 12:01:52
0001 #ifndef CondCore_Utilities_Payload2XMLModule_h
0002 #define CondCore_Utilities_Payload2XMLModule_h
0003
0004 #include <string>
0005 #include <memory>
0006
0007 #include <pybind11/pybind11.h>
0008
0009 namespace py = pybind11;
0010
0011 #include "CondFormats/Serialization/interface/Archive.h"
0012
0013 #define XML_CONVERTER_NAME(CLASS_NAME) (std::string(#CLASS_NAME) + "2xml").c_str()
0014
0015 #define PAYLOAD_2XML_MODULE(MODULE_NAME) PYBIND11_MODULE(MODULE_NAME, m)
0016
0017 #define PAYLOAD_2XML_CLASS(CLASS_NAME) \
0018 py::class_<Payload2xml<CLASS_NAME> >(m, XML_CONVERTER_NAME(CLASS_NAME)) \
0019 .def(py::init<>()) \
0020 .def("write", &Payload2xml<CLASS_NAME>::write);
0021
0022 #include <boost/version.hpp>
0023 namespace cond {
0024 inline std::string boost_version_label() {
0025 std::stringstream ss;
0026 ss << BOOST_VERSION / 100000 << ".";
0027 ss << BOOST_VERSION / 100 % 1000 << ".";
0028 ss << BOOST_VERSION % 100;
0029 return ss.str();
0030 }
0031 }
0032
0033 namespace {
0034
0035 template <typename PayloadType>
0036 class Payload2xml {
0037 public:
0038 Payload2xml() {}
0039
0040 std::string write(const std::string &payloadData) {
0041
0042 std::unique_ptr<PayloadType> payload;
0043 std::stringbuf sdataBuf;
0044 sdataBuf.pubsetbuf(const_cast<char *>(payloadData.c_str()), payloadData.size());
0045
0046 std::istream inBuffer(&sdataBuf);
0047 cond::serialization::InputArchive ia(inBuffer);
0048 payload.reset(new PayloadType);
0049 ia >> (*payload);
0050
0051
0052 std::ostringstream outBuffer;
0053 {
0054 boost::archive::xml_oarchive xmlResult(outBuffer);
0055 xmlResult << boost::serialization::make_nvp("cmsCondPayload", *payload);
0056 }
0057 return outBuffer.str();
0058 }
0059 };
0060
0061 }
0062
0063 #endif