2 #include <xercesc/dom/DOM.hpp>
3 #include <xercesc/parsers/XercesDOMParser.hpp>
5 #include <xercesc/util/XMLString.hpp>
6 #include <xercesc/sax/SAXException.hpp>
7 #include <xercesc/framework/LocalFileFormatTarget.hpp>
12 using namespace xercesc;
20 return stream_ << id_.
id();
41 XercesDOMParser*
parser =
new XercesDOMParser;
42 parser->setValidationScheme( XercesDOMParser::Val_Never );
43 parser->setDoNamespaces(
false );
44 parser->setDoSchema(
false );
46 parser->parse(filename.c_str());
48 DOMDocument* xmlDoc = parser->getDocument();
50 std::cout <<
"EcalTBWeightsXMLTranslator::Error parsing document" << std::endl;
54 DOMElement* elementRoot = xmlDoc->getDocumentElement();
72 readWeightSet(ws_node,ws);
76 wnode= wnode->getNextSibling();
78 while (wnode&& wnode->getNodeType( ) != DOMNode::ELEMENT_NODE)
79 wnode= wnode->getNextSibling();
88 std::fstream fs(filename.c_str(),
ios::out);
109 DOMElement* rowelement=0;
114 rowelement =
dynamic_cast< xercesc::DOMElement*
>(rownode);
118 std::stringstream rowid_ss(rowid_s);
124 std::stringstream weightrow_s(weightrow);
127 while(weightrow_s >> weight){
135 rownode = rownode->getNextSibling();
137 while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
138 rownode = rownode->getNextSibling();
148 rowelement =
dynamic_cast< xercesc::DOMElement*
>(rownode);
152 std::stringstream rowid_ss(rowid_s);
158 std::stringstream weightrow_s(weightrow);
161 while(weightrow_s >> weight){
168 rownode = rownode->getNextSibling();
170 while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
171 rownode = rownode->getNextSibling();
182 rowelement =
dynamic_cast< xercesc::DOMElement*
>(rownode);
185 std::stringstream rowid_ss(rowid_s);
191 std::stringstream weightrow_s(weightrow);
194 while(weightrow_s >> weight)
202 rownode = rownode->getNextSibling();
204 while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
205 rownode = rownode->getNextSibling();
217 rowelement =
dynamic_cast< xercesc::DOMElement*
>(rownode);
220 std::stringstream rowid_ss(rowid_s);
226 std::stringstream weightrow_s(weightrow);
229 while(weightrow_s >> weight){
236 rownode = rownode->getNextSibling();
238 while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
239 rownode = rownode->getNextSibling();
252 xercesc::DOMDocument*
doc = parentNode->getOwnerDocument();
255 parentNode-> appendChild(weightsetel);
258 weightsetel->appendChild(wgtBS);
261 weightsetel->appendChild(wgtAS);
264 weightsetel->appendChild(wgtChi2BS);
267 weightsetel->appendChild(wgtChi2AS);
288 for(
int i=0;
i<nrows;++
i)
293 node->appendChild(row);
295 stringstream value_s;
298 rowid = node->getOwnerDocument()->createAttribute(
fromNative(
id_tag).c_str());
299 rowid ->setValue(
fromNative(value_s.str()).c_str());
300 row ->setAttributeNode(rowid);
304 for(
int k=0;
k<ncols;++
k) row_s <<
" " <<
matrix(i,
k)<<
" " ;
307 node->getOwnerDocument()->createTextNode(
fromNative(row_s.str()).c_str());
308 row->appendChild(rowvalue);
326 for(
int i=0;
i<nrows;++
i)
331 node->appendChild(row);
333 stringstream value_s;
336 rowid = node->getOwnerDocument()->createAttribute(
fromNative(
id_tag).c_str());
337 rowid ->setValue(
fromNative(value_s.str()).c_str());
338 row ->setAttributeNode(rowid);
342 for(
int k=0;
k<ncols;++
k) row_s <<
" "<<
matrix(i,
k)<<
" ";
345 node->getOwnerDocument()->createTextNode(
fromNative(row_s.str()).c_str());
346 row->appendChild(rowvalue);
359 DOMImplementation* impl =
360 DOMImplementationRegistry::getDOMImplementation(
fromNative(
"LS").c_str());
362 DOMWriter* writer =
static_cast<DOMImplementationLS*
>(impl)->createDOMWriter( );
363 writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
true);
365 DOMDocumentType* doctype = impl->createDocumentType(
fromNative(
"XML").c_str(), 0, 0 );
370 doc->setEncoding(
fromNative(
"UTF-8").c_str() );
371 doc->setStandalone(
true);
375 DOMElement*
root = doc->getDocumentElement();
381 EcalTBWeights::EcalTBWeightMap::const_iterator it ;
382 for (it =wmap.begin(); it!=wmap.end(); ++it){
385 root->appendChild(tbweight);
393 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)
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalTBWeights &record)
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)
std::ostream & operator<<(std::ostream &out, const ALILine &li)
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")
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()
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")
std::istream & operator>>(std::istream &input, CLHEP::HepGenMatrix &matrix)
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
XercesString fromNative(const char *str)
math::Matrix< 3, 10 >::type EcalWeightMatrix
std::string toNative(const XMLCh *str)
const std::string EcalTDCId_tag("EcalTDCId")
string root
initialization