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 namespace { // Avoid cluttering the global namespace.
21 
22  template <typename PayloadType>
23  class Payload2xml {
24  public:
25  Payload2xml() {}
26  //
27  std::string write(const std::string &payloadData) {
28  // now to convert
29  std::unique_ptr<PayloadType> payload;
30  std::stringbuf sdataBuf;
31  sdataBuf.pubsetbuf(const_cast<char *>(payloadData.c_str()), payloadData.size());
32 
33  std::istream inBuffer(&sdataBuf);
35  payload.reset(new PayloadType);
36  ia >> (*payload);
37 
38  // now we have the object in memory, convert it to xml in a string and return it
39  std::ostringstream outBuffer;
40  {
41  boost::archive::xml_oarchive xmlResult(outBuffer);
42  xmlResult << boost::serialization::make_nvp("cmsCondPayload", *payload);
43  }
44  return outBuffer.str();
45  }
46  };
47 
48 } // end namespace
49 
50 #endif
jets_cff.payload
payload
Definition: jets_cff.py:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Archive.h
cond::serialization::InputArchive
eos::portable_iarchive InputArchive
Definition: Archive.h:17
writeEcalDQMStatus.write
write
Definition: writeEcalDQMStatus.py:48