4 #include <xercesc/dom/DOMNode.hpp>
5 #include <xercesc/dom/DOM.hpp>
6 #include <xercesc/parsers/XercesDOMParser.hpp>
9 #include <xercesc/util/XMLString.hpp>
10 #include <xercesc/sax/SAXException.hpp>
11 #include <xercesc/framework/LocalFileFormatTarget.hpp>
24 XercesDOMParser*
parser =
new XercesDOMParser;
25 parser->setValidationScheme(XercesDOMParser::Val_Never);
26 parser->setDoNamespaces(
false);
27 parser->setDoSchema(
false);
31 DOMDocument* xmlDoc =
parser->getDocument();
33 std::cout <<
"EcalWeightSetXMLTranslator::Error parsing document" << std::endl;
37 DOMElement* elementRoot = xmlDoc->getDocumentElement();
48 DOMElement* rowelement;
52 rowelement = dynamic_cast<xercesc::DOMElement*>(rownode);
56 std::stringstream rowid_ss(rowid_s);
62 std::stringstream weightrow_s(weightrow);
65 while (weightrow_s >>
weight) {
71 rownode = rownode->getNextSibling();
73 while (rownode && rownode->getNodeType() != DOMNode::ELEMENT_NODE)
74 rownode = rownode->getNextSibling();
81 rowelement = dynamic_cast<xercesc::DOMElement*>(rownode);
85 std::stringstream rowid_ss(rowid_s);
91 std::stringstream weightrow_s(weightrow);
94 while (weightrow_s >>
weight) {
100 rownode = rownode->getNextSibling();
102 while (rownode && rownode->getNodeType() != DOMNode::ELEMENT_NODE)
103 rownode = rownode->getNextSibling();
110 rowelement = dynamic_cast<xercesc::DOMElement*>(rownode);
113 std::stringstream rowid_ss(rowid_s);
119 std::stringstream weightrow_s(weightrow);
122 while (weightrow_s >>
weight) {
128 rownode = rownode->getNextSibling();
130 while (rownode && rownode->getNodeType() != DOMNode::ELEMENT_NODE)
131 rownode = rownode->getNextSibling();
138 rowelement = dynamic_cast<xercesc::DOMElement*>(rownode);
141 std::stringstream rowid_ss(rowid_s);
147 std::stringstream weightrow_s(weightrow);
150 while (weightrow_s >>
weight) {
156 rownode = rownode->getNextSibling();
158 while (rownode && rownode->getNodeType() != DOMNode::ELEMENT_NODE)
159 rownode = rownode->getNextSibling();
183 DOMText* rowvalue[10];
187 echi2wmatrix =
record.getChi2WeightsBeforeGainSwitch();
190 echi2wmatrix =
record.getChi2WeightsAfterGainSwitch();
193 for (
int i = 0;
i < 10; ++
i) {
195 node->appendChild(row[
i]);
197 stringstream value_s;
202 row[
i]->setAttributeNode(rowid[
i]);
206 for (
int k = 0;
k < 10; ++
k) {
208 row_s << echi2wmatrix(
k,
i);
212 rowvalue[
i] = node->getOwnerDocument()->createTextNode(
cms::xerces::uStr(row_s.str().c_str()).ptr());
213 row[
i]->appendChild(rowvalue[
i]);
220 DOMText* rowvalue[10];
224 ewmatrix =
record.getWeightsBeforeGainSwitch();
227 ewmatrix =
record.getWeightsAfterGainSwitch();
229 for (
int i = 0;
i < 10; ++
i) {
231 node->appendChild(row[
i]);
233 stringstream value_s;
240 row[
i]->setAttributeNode(rowid[
i]);
244 for (
int k = 0;
k < 3; ++
k) {
246 row_s << ewmatrix(
k,
i);
250 rowvalue[
i] = node->getOwnerDocument()->createTextNode(
cms::xerces::uStr(row_s.str().c_str()).ptr());
251 row[
i]->appendChild(rowvalue[
i]);
256 unique_ptr<DOMImplementation>
impl(DOMImplementationRegistry::getDOMImplementation(
cms::xerces::uStr(
"LS").ptr()));
258 DOMLSSerializer*
writer =
impl->createLSSerializer();
259 if (
writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint,
true))
260 writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint,
true);
262 DOMDocumentType* doctype =
impl->createDocumentType(
cms::xerces::uStr(
"XML").ptr(),
nullptr,
nullptr);
265 DOMElement*
root =
doc->getDocumentElement();
270 root->appendChild(wgtBS);
273 root->appendChild(wgtAS);
276 root->appendChild(wgtChi2BS);
279 root->appendChild(wgtChi2AS);
284 write10x10(wgtChi2BS,
record);
285 write10x10(wgtChi2AS,
record);