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> 21 return stream_ << id_.
id();
39 XercesDOMParser*
parser =
new XercesDOMParser;
40 parser->setValidationScheme( XercesDOMParser::Val_Never );
41 parser->setDoNamespaces(
false );
42 parser->setDoSchema(
false );
44 parser->parse(filename.c_str());
46 DOMDocument* xmlDoc = parser->getDocument();
48 std::cout <<
"EcalTBWeightsXMLTranslator::Error parsing document" << std::endl;
52 DOMElement* elementRoot = xmlDoc->getDocumentElement();
70 readWeightSet(ws_node,ws);
74 wnode= wnode->getNextSibling();
76 while (wnode&& wnode->getNodeType( ) != DOMNode::ELEMENT_NODE)
77 wnode= wnode->getNextSibling();
90 std::fstream fs(filename.c_str(),
ios::out);
114 DOMElement* rowelement=
nullptr;
119 rowelement =
dynamic_cast< xercesc::DOMElement*
>(rownode);
123 std::stringstream rowid_ss(rowid_s);
129 std::stringstream weightrow_s(weightrow);
132 while(weightrow_s >> weight){
140 rownode = rownode->getNextSibling();
142 while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
143 rownode = rownode->getNextSibling();
153 rowelement =
dynamic_cast< xercesc::DOMElement*
>(rownode);
157 std::stringstream rowid_ss(rowid_s);
163 std::stringstream weightrow_s(weightrow);
166 while(weightrow_s >> weight){
173 rownode = rownode->getNextSibling();
175 while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
176 rownode = rownode->getNextSibling();
187 rowelement =
dynamic_cast< xercesc::DOMElement*
>(rownode);
190 std::stringstream rowid_ss(rowid_s);
196 std::stringstream weightrow_s(weightrow);
199 while(weightrow_s >> weight)
207 rownode = rownode->getNextSibling();
209 while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
210 rownode = rownode->getNextSibling();
222 rowelement =
dynamic_cast< xercesc::DOMElement*
>(rownode);
225 std::stringstream rowid_ss(rowid_s);
231 std::stringstream weightrow_s(weightrow);
234 while(weightrow_s >> weight){
241 rownode = rownode->getNextSibling();
243 while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
244 rownode = rownode->getNextSibling();
257 xercesc::DOMDocument*
doc = parentNode->getOwnerDocument();
260 parentNode-> appendChild(weightsetel);
263 weightsetel->appendChild(wgtBS);
266 weightsetel->appendChild(wgtAS);
269 weightsetel->appendChild(wgtChi2BS);
272 weightsetel->appendChild(wgtChi2AS);
286 DOMElement* row=
nullptr;
287 DOMAttr* rowid=
nullptr;
288 DOMText* rowvalue=
nullptr;
293 for(
int i=0;
i<nrows;++
i)
298 node->appendChild(row);
300 stringstream value_s;
305 row ->setAttributeNode(rowid);
312 node->getOwnerDocument()->createTextNode(
cms::xerces::uStr(row_s.str().c_str()).ptr());
313 row->appendChild(rowvalue);
324 DOMElement* row=
nullptr;
325 DOMAttr* rowid=
nullptr;
326 DOMText* rowvalue=
nullptr;
331 for(
int i=0;
i<nrows;++
i)
336 node->appendChild(row);
338 stringstream value_s;
343 row ->setAttributeNode(rowid);
350 node->getOwnerDocument()->createTextNode(
cms::xerces::uStr(row_s.str().c_str()).ptr());
351 row->appendChild(rowvalue);
364 unique_ptr<DOMImplementation>
impl( DOMImplementationRegistry::getDOMImplementation(
cms::xerces::uStr(
"LS").ptr()));
366 DOMLSSerializer*
writer = impl->createLSSerializer();
367 if( writer->getDomConfig()->canSetParameter( XMLUni::fgDOMWRTFormatPrettyPrint,
true ))
368 writer->getDomConfig()->setParameter( XMLUni::fgDOMWRTFormatPrettyPrint,
true );
370 DOMDocumentType* doctype = impl->createDocumentType(
cms::xerces::uStr(
"XML").ptr(),
nullptr,
nullptr );
373 DOMElement*
root = doc->getDocumentElement();
379 EcalTBWeights::EcalTBWeightMap::const_iterator it ;
380 for (it =wmap.begin(); it!=wmap.end(); ++it){
383 root->appendChild(tbweight);
391 writeWeightSet(tbweight,ws);
EcalChi2WeightMatrix & getChi2WeightsBeforeGainSwitch()
std::map< std::pair< EcalXtalGroupId, EcalTDCId >, EcalWeightSet > EcalTBWeightMap
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::ostream & operator<<(std::ostream &stream_, const EcalXtalGroupId &id_)
static void writeWeightMatrix(xercesc::DOMNode *node, const EcalWeightSet::EcalWeightMatrix &matrix)
const std::string id_tag("id")
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)
math::Matrix< 10, 10 >::type EcalChi2WeightMatrix
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
math::Matrix< 3, 10 >::type EcalWeightMatrix
const std::string EcalTDCId_tag("EcalTDCId")