4 #include <xercesc/dom/DOMNode.hpp>
5 #include <xercesc/dom/DOM.hpp>
6 #include <xercesc/parsers/XercesDOMParser.hpp>
8 #include <xercesc/util/XMLString.hpp>
9 #include <xercesc/sax/SAXException.hpp>
10 #include <xercesc/framework/LocalFileFormatTarget.hpp>
19 using namespace XERCES_CPP_NAMESPACE;
31 XercesDOMParser*
parser =
new XercesDOMParser;
32 parser->setValidationScheme( XercesDOMParser::Val_Never );
33 parser->setDoNamespaces(
false );
34 parser->setDoSchema(
false );
36 parser->parse(filename.c_str());
38 DOMDocument* xmlDoc = parser->getDocument();
40 std::cout <<
"EcalWeightSetXMLTranslator::Error parsing document" << std::endl;
44 DOMElement* elementRoot = xmlDoc->getDocumentElement();
56 DOMElement* rowelement;
61 rowelement =
dynamic_cast< xercesc::DOMElement*
>(rownode);
65 std::stringstream rowid_ss(rowid_s);
71 std::stringstream weightrow_s(weightrow);
74 while(weightrow_s >> weight)
82 rownode = rownode->getNextSibling();
84 while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
85 rownode = rownode->getNextSibling();
95 rowelement =
dynamic_cast< xercesc::DOMElement*
>(rownode);
99 std::stringstream rowid_ss(rowid_s);
105 std::stringstream weightrow_s(weightrow);
108 while(weightrow_s >> weight)
116 rownode = rownode->getNextSibling();
118 while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
119 rownode = rownode->getNextSibling();
130 rowelement =
dynamic_cast< xercesc::DOMElement*
>(rownode);
133 std::stringstream rowid_ss(rowid_s);
139 std::stringstream weightrow_s(weightrow);
142 while(weightrow_s >> weight)
150 rownode = rownode->getNextSibling();
152 while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
153 rownode = rownode->getNextSibling();
165 rowelement =
dynamic_cast< xercesc::DOMElement*
>(rownode);
168 std::stringstream rowid_ss(rowid_s);
174 std::stringstream weightrow_s(weightrow);
177 while(weightrow_s >> weight)
185 rownode = rownode->getNextSibling();
187 while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
188 rownode = rownode->getNextSibling();
207 std::fstream fs(filename.c_str(),
ios::out);
221 DOMText* rowvalue[10];
236 for(
int i=0;
i<10;++
i)
241 node->appendChild(row[
i]);
243 stringstream value_s;
246 rowid[
i] = node->getOwnerDocument()->createAttribute(
fromNative(
id_tag).c_str());
247 rowid[
i]->setValue(
fromNative(value_s.str()).c_str());
248 row[
i]->setAttributeNode(rowid[i]);
252 for(
int k=0;
k<10;++
k)
255 row_s << echi2wmatrix(
k,i);
260 rowvalue[
i] = node->getOwnerDocument()->createTextNode(
fromNative(row_s.str()).c_str());
261 row[
i]->appendChild(rowvalue[i]);
272 DOMText* rowvalue[10];
283 for(
int i=0;
i<10;++
i)
287 node->appendChild(row[
i]);
289 stringstream value_s;
292 rowid[
i] = node->getOwnerDocument()->createAttribute(
fromNative(
id_tag).c_str());
294 rowid[
i]->setValue(
fromNative(value_s.str()).c_str());
296 row[
i]->setAttributeNode(rowid[i]);
304 row_s << ewmatrix(
k,i);
309 rowvalue[
i] = node->getOwnerDocument()->createTextNode(
fromNative(row_s.str()).c_str());
310 row[
i]->appendChild(rowvalue[i]);
321 DOMImplementation* impl =
322 DOMImplementationRegistry::getDOMImplementation(
fromNative(
"LS").c_str());
324 DOMWriter* writer =
static_cast<DOMImplementationLS*
>(impl)->createDOMWriter( );
325 writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
true);
327 DOMDocumentType* doctype = impl->createDocumentType(
fromNative(
"XML").c_str(), 0, 0 );
332 doc->setEncoding(
fromNative(
"UTF-8").c_str() );
333 doc->setStandalone(
true);
336 DOMElement*
root = doc->getDocumentElement();
341 root->appendChild(wgtBS);
344 root->appendChild(wgtAS);
347 root->appendChild(wgtChi2BS);
350 root->appendChild(wgtChi2AS);
352 write3x10(wgtBS,record);
353 write3x10(wgtAS,record);
355 write10x10(wgtChi2BS,record);
356 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")
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
EcalChi2WeightMatrix & getChi2WeightsAfterGainSwitch()
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)
XercesString fromNative(const char *str)
math::Matrix< 3, 10 >::type EcalWeightMatrix
static void write3x10(xercesc::DOMElement *node, const EcalWeightSet &record)
static void write10x10(xercesc::DOMElement *node, const EcalWeightSet &record)
std::string toNative(const XMLCh *str)
string root
initialization