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> 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);
const std::string EcalWeightSet_tag("EcalWeightSet")
static std::string dumpXML(const EcalCondHeader &header, const EcalTBWeights &record)
std::istream & operator>>(std::istream &stream_, EcalXtalGroupId &id_)
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalTBWeights &record)
std::map< std::pair< EcalXtalGroupId, EcalTDCId >, EcalWeightSet > EcalTBWeightMap
std::ostream & operator<<(std::ostream &stream_, const EcalXtalGroupId &id_)
static void writeWeightMatrix(xercesc::DOMNode *node, const EcalWeightSet::EcalWeightMatrix &matrix)
const std::string id_tag("id")
math::Matrix< 10, 10 >::type EcalChi2WeightMatrix
math::Matrix< 3, 10 >::type EcalWeightMatrix
const std::string row_tag("row")
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
const std::string wgtChi2AfterSwitch_tag("Chi2WeightAfterSwitch")
std::string toString(XMLCh const *toTranscode)
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
const std::string EcalTBWeights_tag("EcalTBWeights")
const std::string EcalTBWeight_tag("EcalTBWeight")
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
ZStr< XMLCh > uStr(char const *str)
const std::string wgtBeforeSwitch_tag("WeightBeforeSwitch")
static void writeWeightSet(xercesc::DOMNode *parentNode, const EcalWeightSet &ws)
static void readWeightSet(xercesc::DOMNode *parentNode, EcalWeightSet &ws)
const std::string wgtChi2BeforeSwitch_tag("Chi2WeightBeforeSwitch")
void GetNodeData(xercesc::DOMNode *node, T &value)
get the node data
xercesc::DOMNode * getChildNode(xercesc::DOMNode *node, const std::string &nodename)
get the child of
const std::string wgtAfterSwitch_tag("WeightAfterSwitch")
static int readXML(const std::string &filename, EcalCondHeader &header, EcalTBWeights &record)
const std::string EcalXtalGroupId_tag("EcalXtalGroupId")
static void writeChi2WeightMatrix(xercesc::DOMNode *node, const EcalWeightSet::EcalChi2WeightMatrix &matrix)
const std::string EcalTDCId_tag("EcalTDCId")