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> 27 XercesDOMParser*
parser =
new XercesDOMParser;
28 parser->setValidationScheme( XercesDOMParser::Val_Never );
29 parser->setDoNamespaces(
false );
30 parser->setDoSchema(
false );
32 parser->parse(filename.c_str());
34 DOMDocument* xmlDoc = parser->getDocument();
36 std::cout <<
"EcalWeightSetXMLTranslator::Error parsing document" << std::endl;
40 DOMElement* elementRoot = xmlDoc->getDocumentElement();
51 DOMElement* rowelement;
56 rowelement =
dynamic_cast< xercesc::DOMElement*
>(rownode);
60 std::stringstream rowid_ss(rowid_s);
66 std::stringstream weightrow_s(weightrow);
69 while(weightrow_s >> weight)
77 rownode = rownode->getNextSibling();
79 while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
80 rownode = rownode->getNextSibling();
88 rowelement =
dynamic_cast< xercesc::DOMElement*
>(rownode);
92 std::stringstream rowid_ss(rowid_s);
98 std::stringstream weightrow_s(weightrow);
101 while(weightrow_s >> weight)
109 rownode = rownode->getNextSibling();
111 while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
112 rownode = rownode->getNextSibling();
123 rowelement =
dynamic_cast< xercesc::DOMElement*
>(rownode);
126 std::stringstream rowid_ss(rowid_s);
132 std::stringstream weightrow_s(weightrow);
135 while(weightrow_s >> weight)
143 rownode = rownode->getNextSibling();
145 while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
146 rownode = rownode->getNextSibling();
158 rowelement =
dynamic_cast< xercesc::DOMElement*
>(rownode);
161 std::stringstream rowid_ss(rowid_s);
167 std::stringstream weightrow_s(weightrow);
170 while(weightrow_s >> weight)
178 rownode = rownode->getNextSibling();
180 while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
181 rownode = rownode->getNextSibling();
197 std::fstream fs(filename.c_str(),
ios::out);
210 DOMText* rowvalue[10];
225 for(
int i=0;
i<10;++
i)
230 node->appendChild(row[
i]);
232 stringstream value_s;
237 row[
i]->setAttributeNode(rowid[i]);
241 for(
int k=0;
k<10;++
k)
244 row_s << echi2wmatrix(
k,i);
249 rowvalue[
i] = node->getOwnerDocument()->createTextNode(
cms::xerces::uStr(row_s.str().c_str()).ptr());
250 row[
i]->appendChild(rowvalue[i]);
261 DOMText* rowvalue[10];
272 for(
int i=0;
i<10;++
i)
276 node->appendChild(row[
i]);
278 stringstream value_s;
285 row[
i]->setAttributeNode(rowid[i]);
293 row_s << ewmatrix(
k,i);
298 rowvalue[
i] = node->getOwnerDocument()->createTextNode(
cms::xerces::uStr(row_s.str().c_str()).ptr());
299 row[
i]->appendChild(rowvalue[i]);
307 unique_ptr<DOMImplementation>
impl( DOMImplementationRegistry::getDOMImplementation(
cms::xerces::uStr(
"LS").ptr()));
309 DOMLSSerializer*
writer = impl->createLSSerializer();
310 if( writer->getDomConfig()->canSetParameter( XMLUni::fgDOMWRTFormatPrettyPrint,
true ))
311 writer->getDomConfig()->setParameter( XMLUni::fgDOMWRTFormatPrettyPrint,
true );
313 DOMDocumentType* doctype = impl->createDocumentType(
cms::xerces::uStr(
"XML").ptr(),
nullptr,
nullptr );
317 DOMElement*
root = doc->getDocumentElement();
322 root->appendChild(wgtBS);
325 root->appendChild(wgtAS);
328 root->appendChild(wgtChi2BS);
331 root->appendChild(wgtChi2AS);
333 write3x10(wgtBS,record);
334 write3x10(wgtAS,record);
336 write10x10(wgtChi2BS,record);
337 write10x10(wgtChi2AS,record);
EcalChi2WeightMatrix & getChi2WeightsBeforeGainSwitch()
const std::string EcalWeightSet_tag("EcalWeightSet")
static int readXML(const std::string &filename, EcalCondHeader &header, EcalWeightSet &record)
const std::string id_tag("id")
const std::string row_tag("row")
const std::string wgtChi2AfterSwitch_tag("Chi2WeightAfterSwitch")
std::string toString(XMLCh const *toTranscode)
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
EcalChi2WeightMatrix & getChi2WeightsAfterGainSwitch()
ZStr< XMLCh > uStr(char const *str)
const std::string wgtBeforeSwitch_tag("WeightBeforeSwitch")
EcalWeightMatrix & getWeightsAfterGainSwitch()
math::Matrix< 10, 10 >::type EcalChi2WeightMatrix
EcalWeightMatrix & getWeightsBeforeGainSwitch()
const std::string wgtChi2BeforeSwitch_tag("Chi2WeightBeforeSwitch")
xercesc::DOMNode * getChildNode(xercesc::DOMNode *node, const std::string &nodename)
get the child of
const std::string wgtAfterSwitch_tag("WeightAfterSwitch")
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalWeightSet &record)
static std::string dumpXML(const EcalCondHeader &header, const EcalWeightSet &record)
math::Matrix< 3, 10 >::type EcalWeightMatrix
static void write3x10(xercesc::DOMElement *node, const EcalWeightSet &record)
static void write10x10(xercesc::DOMElement *node, const EcalWeightSet &record)