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