CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Payload2XMLModule.h
Go to the documentation of this file.
1 #ifndef CondCore_Utilities_Payload2XMLModule_h
2 #define CondCore_Utilities_Payload2XMLModule_h
3 
4 #include <string>
5 #include <memory>
6 
7 #include <pybind11/pybind11.h>
8 
9 namespace py = pybind11;
10 
12 
13 #define XML_CONVERTER_NAME(CLASS_NAME) (std::string(#CLASS_NAME) + "2xml").c_str()
14 
15 #define PAYLOAD_2XML_MODULE(MODULE_NAME) PYBIND11_MODULE(MODULE_NAME, m)
16 
17 #define PAYLOAD_2XML_CLASS(CLASS_NAME) \
18  py::class_<Payload2xml<CLASS_NAME> >(m, XML_CONVERTER_NAME(CLASS_NAME)) \
19  .def(py::init<>()) \
20  .def("write", &Payload2xml<CLASS_NAME>::write);
21 
22 #include <boost/version.hpp>
23 namespace cond {
25  std::stringstream ss;
26  ss << BOOST_VERSION / 100000 << ".";
27  ss << BOOST_VERSION / 100 % 1000 << ".";
28  ss << BOOST_VERSION % 100;
29  return ss.str();
30  }
31 } // namespace cond
32 
33 namespace { // Avoid cluttering the global namespace.
34 
35  template <typename PayloadType>
36  class Payload2xml {
37  public:
38  Payload2xml() {}
39  //
40  std::string write(const std::string &payloadData) {
41  // now to convert
42  std::unique_ptr<PayloadType> payload;
43  std::stringbuf sdataBuf;
44  sdataBuf.pubsetbuf(const_cast<char *>(payloadData.c_str()), payloadData.size());
45 
46  std::istream inBuffer(&sdataBuf);
48  payload.reset(new PayloadType);
49  ia >> (*payload);
50 
51  // now we have the object in memory, convert it to xml in a string and return it
52  std::ostringstream outBuffer;
53  {
54  boost::archive::xml_oarchive xmlResult(outBuffer);
55  xmlResult << boost::serialization::make_nvp("cmsCondPayload", *payload);
56  }
57  return outBuffer.str();
58  }
59  };
60 
61 } // end namespace
62 
63 #endif
eos::portable_iarchive InputArchive
Definition: Archive.h:17
std::string boost_version_label()