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);
36 parser->parse(filename.c_str());
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();
81 std::fstream fs(filename.c_str(),
ios::out);
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) {
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) {
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) {
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) {
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);
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);
EcalChi2WeightMatrix & getChi2WeightsBeforeGainSwitch()
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 setValue(const EcalXtalGroupId &groupId, const EcalTDCId &tdcId, const EcalWeightSet &weight)
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
const unsigned int id() const
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
EcalChi2WeightMatrix & getChi2WeightsAfterGainSwitch()
ZStr< XMLCh > uStr(char const *str)
const std::string wgtBeforeSwitch_tag("WeightBeforeSwitch")
static void writeWeightSet(xercesc::DOMNode *parentNode, const EcalWeightSet &ws)
EcalWeightMatrix & getWeightsAfterGainSwitch()
static void readWeightSet(xercesc::DOMNode *parentNode, EcalWeightSet &ws)
EcalWeightMatrix & getWeightsBeforeGainSwitch()
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 EcalTBWeightMap & getMap() const
const std::string EcalTDCId_tag("EcalTDCId")