CMS 3D CMS Logo

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 <boost/python.hpp>
8 #include "boost/archive/xml_oarchive.hpp"
9 
11 
12 #define XML_CONVERTER_NAME(CLASS_NAME) (std::string(#CLASS_NAME) + "2xml").c_str()
13 
14 #define PAYLOAD_2XML_MODULE(MODULE_NAME) BOOST_PYTHON_MODULE(MODULE_NAME)
15 
16 #define PAYLOAD_2XML_CLASS(CLASS_NAME) \
17  boost::python::class_<Payload2xml<CLASS_NAME> >(XML_CONVERTER_NAME(CLASS_NAME), boost::python::init<>()) \
18  .def("write", &Payload2xml<CLASS_NAME>::write);
19 
20 #include <boost/version.hpp>
21 namespace cond {
22  struct BoostVersion {
24  std::stringstream ss;
25  ss << BOOST_VERSION / 100000 << ".";
26  ss << BOOST_VERSION / 100 % 1000 << ".";
27  ss << BOOST_VERSION % 100;
28  return ss.str();
29  }
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);
47  eos::portable_iarchive ia(inBuffer);
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
Definition: plugin.cc:24
def write(self, setup)