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>
17 using namespace XERCES_CPP_NAMESPACE;
24 XercesDOMParser*
parser =
new XercesDOMParser;
25 parser->setValidationScheme(XercesDOMParser::Val_Never);
26 parser->setDoNamespaces(
false);
27 parser->setDoSchema(
false);
29 parser->parse(filename.c_str());
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();
172 std::fstream fs(filename.c_str(),
ios::out);
183 DOMText* rowvalue[10];
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];
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);
281 write3x10(wgtBS, record);
282 write3x10(wgtAS, record);
284 write10x10(wgtChi2BS, record);
285 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")
math::Matrix< 10, 10 >::type EcalChi2WeightMatrix
math::Matrix< 3, 10 >::type EcalWeightMatrix
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()
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)
static void write3x10(xercesc::DOMElement *node, const EcalWeightSet &record)
static void write10x10(xercesc::DOMElement *node, const EcalWeightSet &record)
tuple dump
OutputFilePath = cms.string('/tmp/zhokin/'), OutputFileExt = cms.string(''),.