CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Static Private Member Functions
EcalWeightSetXMLTranslator Class Reference

#include <EcalWeightSetXMLTranslator.h>

Public Member Functions

 EcalWeightSetXMLTranslator ()
 

Static Public Member Functions

static int readXML (const std::string &filename, EcalCondHeader &header, EcalWeightSet &record)
 
static int writeXML (const std::string &filename, const EcalCondHeader &header, const EcalWeightSet &record)
 

Static Private Member Functions

static std::string dumpXML (const EcalCondHeader &header, const EcalWeightSet &record)
 
static void write10x10 (xercesc::DOMElement *node, const EcalWeightSet &record)
 
static void write3x10 (xercesc::DOMElement *node, const EcalWeightSet &record)
 

Detailed Description

Translates a EcalWeightSet record to XML and vice versa

Author
Stefano ARGIRO
Version
Id
EcalWeightSetXMLTranslator.h,v 1.1 2008/11/14 15:46:05 argiro Exp
Date
20 Jun 2008

Definition at line 18 of file EcalWeightSetXMLTranslator.h.

Constructor & Destructor Documentation

EcalWeightSetXMLTranslator::EcalWeightSetXMLTranslator ( )
inline

Member Function Documentation

std::string EcalWeightSetXMLTranslator::dumpXML ( const EcalCondHeader header,
const EcalWeightSet record 
)
staticprivate

Definition at line 304 of file EcalWeightSetXMLTranslator.cc.

References common_cff::doc, FrontierConditions_GlobalTag_cff::dump, xuti::EcalWeightSet_tag(), AlCaHLTBitMon_QueryRunRegistry::string, cms::xerces::toString(), cms::xerces::uStr(), xuti::wgtAfterSwitch_tag(), xuti::wgtBeforeSwitch_tag(), xuti::wgtChi2AfterSwitch_tag(), xuti::wgtChi2BeforeSwitch_tag(), xuti::writeHeader(), and cscNeutronWriter_cfi::writer.

Referenced by EcalWeightSetXMLTranslator().

305  {
306 
307  unique_ptr<DOMImplementation> impl( DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
308 
309  DOMLSSerializer* writer = impl->createLSSerializer();
310  if( writer->getDomConfig()->canSetParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true ))
311  writer->getDomConfig()->setParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true );
312 
313  DOMDocumentType* doctype = impl->createDocumentType( cms::xerces::uStr("XML").ptr(), nullptr, nullptr );
314  DOMDocument * doc =
315  impl->createDocument( nullptr,cms::xerces::uStr(EcalWeightSet_tag.c_str()).ptr(), doctype );
316 
317  DOMElement* root = doc->getDocumentElement();
318 
319  xuti::writeHeader(root, header);
320 
321  DOMElement* wgtBS = doc->createElement(cms::xerces::uStr(wgtBeforeSwitch_tag.c_str()).ptr());
322  root->appendChild(wgtBS);
323 
324  DOMElement* wgtAS = doc->createElement(cms::xerces::uStr(wgtAfterSwitch_tag.c_str()).ptr());
325  root->appendChild(wgtAS);
326 
327  DOMElement* wgtChi2BS = doc->createElement(cms::xerces::uStr(wgtChi2BeforeSwitch_tag.c_str()).ptr());
328  root->appendChild(wgtChi2BS);
329 
330  DOMElement* wgtChi2AS = doc->createElement(cms::xerces::uStr(wgtChi2AfterSwitch_tag.c_str()).ptr());
331  root->appendChild(wgtChi2AS);
332 
333  write3x10(wgtBS,record);
334  write3x10(wgtAS,record);
335 
336  write10x10(wgtChi2BS,record);
337  write10x10(wgtChi2AS,record);
338 
339  std::string dump = cms::xerces::toString(writer->writeToString( root ));
340  doc->release();
341  doctype->release();
342  writer->release();
343 
344  return dump;
345 }
const std::string EcalWeightSet_tag("EcalWeightSet")
const std::string wgtChi2AfterSwitch_tag("Chi2WeightAfterSwitch")
std::string toString(XMLCh const *toTranscode)
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
ZStr< XMLCh > uStr(char const *str)
const std::string wgtBeforeSwitch_tag("WeightBeforeSwitch")
Definition: dump.py:1
const std::string wgtChi2BeforeSwitch_tag("Chi2WeightBeforeSwitch")
const std::string wgtAfterSwitch_tag("WeightAfterSwitch")
static void write3x10(xercesc::DOMElement *node, const EcalWeightSet &record)
static void write10x10(xercesc::DOMElement *node, const EcalWeightSet &record)
int EcalWeightSetXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalWeightSet record 
)
static

Definition at line 21 of file EcalWeightSetXMLTranslator.cc.

References gather_cfg::cout, EcalWeightSet::getChi2WeightsAfterGainSwitch(), EcalWeightSet::getChi2WeightsBeforeGainSwitch(), xuti::getChildNode(), EcalWeightSet::getWeightsAfterGainSwitch(), EcalWeightSet::getWeightsBeforeGainSwitch(), mps_fire::i, xuti::id_tag(), createfilelist::parser, xuti::readHeader(), xuti::row_tag(), AlCaHLTBitMon_QueryRunRegistry::string, cms::xerces::toString(), cms::xerces::uStr(), xuti::wgtAfterSwitch_tag(), xuti::wgtBeforeSwitch_tag(), xuti::wgtChi2AfterSwitch_tag(), xuti::wgtChi2BeforeSwitch_tag(), cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

Referenced by EcalWeightSetXMLTranslator().

23  {
24 
26 
27  XercesDOMParser* parser = new XercesDOMParser;
28  parser->setValidationScheme( XercesDOMParser::Val_Never );
29  parser->setDoNamespaces( false );
30  parser->setDoSchema( false );
31 
32  parser->parse(filename.c_str());
33 
34  DOMDocument* xmlDoc = parser->getDocument();
35  if (!xmlDoc) {
36  std::cout << "EcalWeightSetXMLTranslator::Error parsing document" << std::endl;
37  return -1;
38  }
39 
40  DOMElement* elementRoot = xmlDoc->getDocumentElement();
41 
42  xuti::readHeader(elementRoot, header);
43  // get the first cell node
44  DOMNode * wgtBSnode=getChildNode(elementRoot,wgtBeforeSwitch_tag);
45  DOMNode * wgtASnode=getChildNode(elementRoot,wgtAfterSwitch_tag);
46  DOMNode * wgtChi2BSnode=getChildNode(elementRoot,wgtChi2BeforeSwitch_tag);
47  DOMNode * wgtChi2ASnode=getChildNode(elementRoot,wgtChi2AfterSwitch_tag);
48 
49  DOMNode* rownode = getChildNode(wgtBSnode,row_tag);
50 
51  DOMElement* rowelement;
52 
53  // loop on row nodes
54  while (rownode){
55 
56  rowelement = dynamic_cast< xercesc::DOMElement* >(rownode);
57 
58  std::string rowid_s = cms::xerces::toString(rowelement->getAttribute(cms::xerces::uStr(id_tag.c_str()).ptr()));
59 
60  std::stringstream rowid_ss(rowid_s);
61  int rowid = 0;
62  rowid_ss >> rowid;
63 
64  std::string weightrow = cms::xerces::toString(rownode->getTextContent());
65 
66  std::stringstream weightrow_s(weightrow);
67  double weight = 0;
68  int i = 0;
69  while(weightrow_s >> weight)
70  {
71  record.getWeightsBeforeGainSwitch()(i,rowid)= weight;
72  i++;
73  }
74 
75 
76  // get next cell
77  rownode = rownode->getNextSibling();
78 
79  while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
80  rownode = rownode->getNextSibling();
81  }
82 
83  rownode = getChildNode(wgtASnode,row_tag);
84 
85  // loop on row nodes
86  while (rownode){
87 
88  rowelement = dynamic_cast< xercesc::DOMElement* >(rownode);
89 
90  std::string rowid_s = cms::xerces::toString(rowelement->getAttribute(cms::xerces::uStr(id_tag.c_str()).ptr()));
91 
92  std::stringstream rowid_ss(rowid_s);
93  int rowid = 0;
94  rowid_ss >> rowid;
95 
96  std::string weightrow = cms::xerces::toString(rownode->getTextContent());
97 
98  std::stringstream weightrow_s(weightrow);
99  double weight = 0;
100  int i = 0;
101  while(weightrow_s >> weight)
102  {
103  record.getWeightsAfterGainSwitch()(i,rowid)= weight;
104  i++;
105  }
106 
107 
108  // get next cell
109  rownode = rownode->getNextSibling();
110 
111  while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
112  rownode = rownode->getNextSibling();
113 
114 
115  }
116 
117  rownode = getChildNode(wgtChi2BSnode,row_tag);
118 
119 
120  // loop on row nodes
121  while (rownode){
122 
123  rowelement = dynamic_cast< xercesc::DOMElement* >(rownode);
124  std::string rowid_s = cms::xerces::toString(rowelement->getAttribute(cms::xerces::uStr(id_tag.c_str()).ptr()));
125 
126  std::stringstream rowid_ss(rowid_s);
127  int rowid = 0;
128  rowid_ss >> rowid;
129 
130  std::string weightrow = cms::xerces::toString(rownode->getTextContent());
131 
132  std::stringstream weightrow_s(weightrow);
133  double weight = 0;
134  int i = 0;
135  while(weightrow_s >> weight)
136  {
137  record.getChi2WeightsBeforeGainSwitch()(i,rowid)= weight;
138  i++;
139  }
140 
141 
142  // get next cell
143  rownode = rownode->getNextSibling();
144 
145  while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
146  rownode = rownode->getNextSibling();
147 
148 
149  }
150 
151 
152  rownode = getChildNode(wgtChi2ASnode,row_tag);
153 
154 
155  // loop on row nodes
156  while (rownode){
157 
158  rowelement = dynamic_cast< xercesc::DOMElement* >(rownode);
159  std::string rowid_s = cms::xerces::toString(rowelement->getAttribute(cms::xerces::uStr(id_tag.c_str()).ptr()));
160 
161  std::stringstream rowid_ss(rowid_s);
162  int rowid = 0;
163  rowid_ss >> rowid;
164 
165  std::string weightrow = cms::xerces::toString(rownode->getTextContent());
166 
167  std::stringstream weightrow_s(weightrow);
168  double weight = 0;
169  int i = 0;
170  while(weightrow_s >> weight)
171  {
172  record.getChi2WeightsAfterGainSwitch()(i,rowid)= weight;
173  i++;
174  }
175 
176 
177  // get next cell
178  rownode = rownode->getNextSibling();
179 
180  while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
181  rownode = rownode->getNextSibling();
182 
183 
184  }
185 
186  delete parser;
188  return 0;
189 }
EcalChi2WeightMatrix & getChi2WeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:31
void xercesTerminate()
Definition: Xerces.cc:23
const std::string id_tag("id")
Definition: weight.py:1
const std::string row_tag("row")
void xercesInitialize()
Definition: Xerces.cc:18
const std::string wgtChi2AfterSwitch_tag("Chi2WeightAfterSwitch")
std::string toString(XMLCh const *toTranscode)
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
EcalChi2WeightMatrix & getChi2WeightsAfterGainSwitch()
Definition: EcalWeightSet.h:32
ZStr< XMLCh > uStr(char const *str)
const std::string wgtBeforeSwitch_tag("WeightBeforeSwitch")
EcalWeightMatrix & getWeightsAfterGainSwitch()
Definition: EcalWeightSet.h:30
EcalWeightMatrix & getWeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:29
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")
void EcalWeightSetXMLTranslator::write10x10 ( xercesc::DOMElement *  node,
const EcalWeightSet record 
)
staticprivate

Definition at line 205 of file EcalWeightSetXMLTranslator.cc.

References EcalWeightSet::getChi2WeightsAfterGainSwitch(), EcalWeightSet::getChi2WeightsBeforeGainSwitch(), mps_fire::i, xuti::id_tag(), gen::k, xuti::row_tag(), cms::xerces::toString(), cms::xerces::uStr(), xuti::wgtChi2AfterSwitch_tag(), and xuti::wgtChi2BeforeSwitch_tag().

Referenced by EcalWeightSetXMLTranslator().

206  {
207 
208  DOMElement* row[10];
209  DOMAttr* rowid[10];
210  DOMText* rowvalue[10];
212 
213 
214  if(cms::xerces::toString(node->getNodeName()) == wgtChi2BeforeSwitch_tag)
215  {
216  echi2wmatrix = record.getChi2WeightsBeforeGainSwitch();
217 
218  }
219  if(cms::xerces::toString(node->getNodeName()) == wgtChi2AfterSwitch_tag)
220  {
221  echi2wmatrix = record.getChi2WeightsAfterGainSwitch();
222 
223  }
224 
225  for(int i=0;i<10;++i)
226  {
227 
228 
229  row[i] = node->getOwnerDocument()->createElement(cms::xerces::uStr(row_tag.c_str()).ptr());
230  node->appendChild(row[i]);
231 
232  stringstream value_s;
233  value_s << i;
234 
235  rowid[i] = node->getOwnerDocument()->createAttribute(cms::xerces::uStr(id_tag.c_str()).ptr());
236  rowid[i]->setValue(cms::xerces::uStr(value_s.str().c_str()).ptr());
237  row[i]->setAttributeNode(rowid[i]);
238 
239  stringstream row_s;
240 
241  for(int k=0;k<10;++k)
242  {
243  row_s << " ";
244  row_s << echi2wmatrix(k,i);
245  row_s << " ";
246  }//for loop on element
247 
248 
249  rowvalue[i] = node->getOwnerDocument()->createTextNode(cms::xerces::uStr(row_s.str().c_str()).ptr());
250  row[i]->appendChild(rowvalue[i]);
251  }//for loop on row
252 }
EcalChi2WeightMatrix & getChi2WeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:31
const std::string id_tag("id")
const std::string row_tag("row")
const std::string wgtChi2AfterSwitch_tag("Chi2WeightAfterSwitch")
std::string toString(XMLCh const *toTranscode)
EcalChi2WeightMatrix & getChi2WeightsAfterGainSwitch()
Definition: EcalWeightSet.h:32
ZStr< XMLCh > uStr(char const *str)
int k[5][pyjets_maxn]
math::Matrix< 10, 10 >::type EcalChi2WeightMatrix
Definition: EcalWeightSet.h:23
const std::string wgtChi2BeforeSwitch_tag("Chi2WeightBeforeSwitch")
void EcalWeightSetXMLTranslator::write3x10 ( xercesc::DOMElement *  node,
const EcalWeightSet record 
)
staticprivate

Definition at line 256 of file EcalWeightSetXMLTranslator.cc.

References EcalWeightSet::getWeightsAfterGainSwitch(), EcalWeightSet::getWeightsBeforeGainSwitch(), mps_fire::i, xuti::id_tag(), gen::k, xuti::row_tag(), cms::xerces::toString(), cms::xerces::uStr(), xuti::wgtAfterSwitch_tag(), and xuti::wgtBeforeSwitch_tag().

Referenced by EcalWeightSetXMLTranslator().

257  {
258 
259  DOMElement* row[10];
260  DOMAttr* rowid[10];
261  DOMText* rowvalue[10];
263 
264 
265  if(cms::xerces::toString(node->getNodeName()) == wgtBeforeSwitch_tag)
266  ewmatrix = record.getWeightsBeforeGainSwitch();
267 
268  if(cms::xerces::toString(node->getNodeName()) == wgtAfterSwitch_tag)
269  ewmatrix = record.getWeightsAfterGainSwitch();
270 
271 
272  for(int i=0;i<10;++i)
273  {
274 
275  row[i] = node->getOwnerDocument()->createElement(cms::xerces::uStr(row_tag.c_str()).ptr());
276  node->appendChild(row[i]);
277 
278  stringstream value_s;
279  value_s << i;
280 
281  rowid[i] = node->getOwnerDocument()->createAttribute(cms::xerces::uStr(id_tag.c_str()).ptr());
282 
283  rowid[i]->setValue(cms::xerces::uStr(value_s.str().c_str()).ptr());
284 
285  row[i]->setAttributeNode(rowid[i]);
286 
287 
288  stringstream row_s;
289 
290  for(int k=0;k<3;++k)
291  {
292  row_s << " ";
293  row_s << ewmatrix(k,i);
294  row_s << " ";
295  }//for loop on element
296 
297 
298  rowvalue[i] = node->getOwnerDocument()->createTextNode(cms::xerces::uStr(row_s.str().c_str()).ptr());
299  row[i]->appendChild(rowvalue[i]);
300  }//for loop on row
301 }
const std::string id_tag("id")
const std::string row_tag("row")
std::string toString(XMLCh const *toTranscode)
ZStr< XMLCh > uStr(char const *str)
const std::string wgtBeforeSwitch_tag("WeightBeforeSwitch")
EcalWeightMatrix & getWeightsAfterGainSwitch()
Definition: EcalWeightSet.h:30
int k[5][pyjets_maxn]
EcalWeightMatrix & getWeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:29
const std::string wgtAfterSwitch_tag("WeightAfterSwitch")
math::Matrix< 3, 10 >::type EcalWeightMatrix
Definition: EcalWeightSet.h:22
int EcalWeightSetXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalWeightSet record 
)
static

Definition at line 191 of file EcalWeightSetXMLTranslator.cc.

References EcalCondTools::dumpXML(), MillePedeFileConverter_cfg::out, cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

Referenced by EcalWeightSetXMLTranslator().

193  {
194 
196 
197  std::fstream fs(filename.c_str(),ios::out);
198  fs<< dumpXML(header,record);
199 
201 
202  return 0;
203 }
void xercesTerminate()
Definition: Xerces.cc:23
void xercesInitialize()
Definition: Xerces.cc:18
static std::string dumpXML(const EcalCondHeader &header, const EcalWeightSet &record)