2 #include <xercesc/dom/DOM.hpp>
3 #include <xercesc/parsers/XercesDOMParser.hpp>
6 #include <xercesc/util/XMLString.hpp>
7 #include <xercesc/sax/SAXException.hpp>
8 #include <xercesc/framework/LocalFileFormatTarget.hpp>
13 using namespace xercesc;
31 XercesDOMParser*
parser =
new XercesDOMParser;
32 parser->setValidationScheme(XercesDOMParser::Val_Never);
33 parser->setDoNamespaces(
false);
34 parser->setDoSchema(
false);
38 DOMDocument* xmlDoc =
parser->getDocument();
40 std::cout <<
"EcalTBWeightsXMLTranslator::Error parsing document" << std::endl;
44 DOMElement* elementRoot = xmlDoc->getDocumentElement();
61 readWeightSet(ws_node,
ws);
65 wnode = wnode->getNextSibling();
67 while (wnode && wnode->getNodeType() != DOMNode::ELEMENT_NODE)
68 wnode = wnode->getNextSibling();
98 DOMElement* rowelement =
nullptr;
102 rowelement = dynamic_cast<xercesc::DOMElement*>(rownode);
106 std::stringstream rowid_ss(rowid_s);
112 std::stringstream weightrow_s(weightrow);
115 while (weightrow_s >>
weight) {
116 ws.getWeightsBeforeGainSwitch()(rowid,
i) =
weight;
121 rownode = rownode->getNextSibling();
123 while (rownode && rownode->getNodeType() != DOMNode::ELEMENT_NODE)
124 rownode = rownode->getNextSibling();
131 rowelement = dynamic_cast<xercesc::DOMElement*>(rownode);
135 std::stringstream rowid_ss(rowid_s);
141 std::stringstream weightrow_s(weightrow);
144 while (weightrow_s >>
weight) {
145 ws.getWeightsAfterGainSwitch()(rowid,
i) =
weight;
150 rownode = rownode->getNextSibling();
152 while (rownode && rownode->getNodeType() != DOMNode::ELEMENT_NODE)
153 rownode = rownode->getNextSibling();
160 rowelement = dynamic_cast<xercesc::DOMElement*>(rownode);
163 std::stringstream rowid_ss(rowid_s);
169 std::stringstream weightrow_s(weightrow);
172 while (weightrow_s >>
weight) {
173 ws.getChi2WeightsBeforeGainSwitch()(rowid,
i) =
weight;
178 rownode = rownode->getNextSibling();
180 while (rownode && rownode->getNodeType() != DOMNode::ELEMENT_NODE)
181 rownode = rownode->getNextSibling();
188 rowelement = dynamic_cast<xercesc::DOMElement*>(rownode);
191 std::stringstream rowid_ss(rowid_s);
197 std::stringstream weightrow_s(weightrow);
200 while (weightrow_s >>
weight) {
201 ws.getChi2WeightsAfterGainSwitch()(rowid,
i) =
weight;
206 rownode = rownode->getNextSibling();
208 while (rownode && rownode->getNodeType() != DOMNode::ELEMENT_NODE)
209 rownode = rownode->getNextSibling();
214 xercesc::DOMDocument*
doc = parentNode->getOwnerDocument();
217 parentNode->appendChild(weightsetel);
220 weightsetel->appendChild(wgtBS);
223 weightsetel->appendChild(wgtAS);
226 weightsetel->appendChild(wgtChi2BS);
229 weightsetel->appendChild(wgtChi2AS);
231 writeWeightMatrix(wgtBS,
ws.getWeightsBeforeGainSwitch());
232 writeWeightMatrix(wgtAS,
ws.getWeightsAfterGainSwitch());
234 writeChi2WeightMatrix(wgtChi2BS,
ws.getChi2WeightsBeforeGainSwitch());
235 writeChi2WeightMatrix(wgtChi2AS,
ws.getChi2WeightsBeforeGainSwitch());
240 DOMElement* row =
nullptr;
241 DOMAttr* rowid =
nullptr;
242 DOMText* rowvalue =
nullptr;
244 const int ncols = 10;
247 for (
int i = 0;
i < nrows; ++
i) {
249 node->appendChild(row);
251 stringstream value_s;
256 row->setAttributeNode(rowid);
261 row_s <<
" " <<
matrix(
i,
k) <<
" ";
263 rowvalue = node->getOwnerDocument()->createTextNode(
cms::xerces::uStr(row_s.str().c_str()).ptr());
264 row->appendChild(rowvalue);
270 DOMElement* row =
nullptr;
271 DOMAttr* rowid =
nullptr;
272 DOMText* rowvalue =
nullptr;
274 const int ncols = 10;
275 const int nrows = 10;
277 for (
int i = 0;
i < nrows; ++
i) {
279 node->appendChild(row);
281 stringstream value_s;
286 row->setAttributeNode(rowid);
291 row_s <<
" " <<
matrix(
i,
k) <<
" ";
293 rowvalue = node->getOwnerDocument()->createTextNode(
cms::xerces::uStr(row_s.str().c_str()).ptr());
294 row->appendChild(rowvalue);
301 unique_ptr<DOMImplementation>
impl(DOMImplementationRegistry::getDOMImplementation(
cms::xerces::uStr(
"LS").ptr()));
303 DOMLSSerializer*
writer =
impl->createLSSerializer();
304 if (
writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint,
true))
305 writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint,
true);
307 DOMDocumentType* doctype =
impl->createDocumentType(
cms::xerces::uStr(
"XML").ptr(),
nullptr,
nullptr);
309 DOMElement*
root =
doc->getDocumentElement();
315 EcalTBWeights::EcalTBWeightMap::const_iterator it;
316 for (it = wmap.begin(); it != wmap.end(); ++it) {
318 root->appendChild(tbweight);
326 writeWeightSet(tbweight,
ws);