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::EcalWeightSetXMLTranslator ( )
inline

Definition at line 20 of file EcalWeightSetXMLTranslator.h.

20 {}

Member Function Documentation

◆ dumpXML()

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

Definition at line 255 of file EcalWeightSetXMLTranslator.cc.

References ALCARECOEcalPhiSym_cff::doc, GCP_Ntuples_cfg::dump, xuti::EcalWeightSet_tag(), RecoTauValidation_cfi::header, Hcal_FrontierConditions_cff::record, AlCaHLTBitMon_QueryRunRegistry::string, cms::xerces::toString(), cms::xerces::uStr(), xuti::wgtAfterSwitch_tag(), xuti::wgtBeforeSwitch_tag(), xuti::wgtChi2AfterSwitch_tag(), xuti::wgtChi2BeforeSwitch_tag(), xuti::writeHeader(), and convertToRaw::writer.

255  {
256  unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
257 
258  DOMLSSerializer* writer = impl->createLSSerializer();
259  if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
260  writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
261 
262  DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
263  DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(EcalWeightSet_tag.c_str()).ptr(), doctype);
264 
265  DOMElement* root = doc->getDocumentElement();
266 
268 
269  DOMElement* wgtBS = doc->createElement(cms::xerces::uStr(wgtBeforeSwitch_tag.c_str()).ptr());
270  root->appendChild(wgtBS);
271 
272  DOMElement* wgtAS = doc->createElement(cms::xerces::uStr(wgtAfterSwitch_tag.c_str()).ptr());
273  root->appendChild(wgtAS);
274 
275  DOMElement* wgtChi2BS = doc->createElement(cms::xerces::uStr(wgtChi2BeforeSwitch_tag.c_str()).ptr());
276  root->appendChild(wgtChi2BS);
277 
278  DOMElement* wgtChi2AS = doc->createElement(cms::xerces::uStr(wgtChi2AfterSwitch_tag.c_str()).ptr());
279  root->appendChild(wgtChi2AS);
280 
281  write3x10(wgtBS, record);
282  write3x10(wgtAS, record);
283 
284  write10x10(wgtChi2BS, record);
285  write10x10(wgtChi2AS, record);
286 
287  std::string dump = cms::xerces::toString(writer->writeToString(root));
288  doc->release();
289  doctype->release();
290  writer->release();
291 
292  return dump;
293 }
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")
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)

◆ readXML()

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

Definition at line 21 of file EcalWeightSetXMLTranslator.cc.

References gather_cfg::cout, corrVsCorr::filename, xuti::getChildNode(), RecoTauValidation_cfi::header, mps_fire::i, xuti::id_tag(), writedatasetfile::parser, xuti::readHeader(), Hcal_FrontierConditions_cff::record, 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().

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

◆ write10x10()

void EcalWeightSetXMLTranslator::write10x10 ( xercesc::DOMElement *  node,
const EcalWeightSet record 
)
staticprivate

Definition at line 180 of file EcalWeightSetXMLTranslator.cc.

References mps_fire::i, xuti::id_tag(), isotrackApplyRegressor::k, Hcal_FrontierConditions_cff::record, xuti::row_tag(), cms::xerces::toString(), cms::xerces::uStr(), xuti::wgtChi2AfterSwitch_tag(), and xuti::wgtChi2BeforeSwitch_tag().

180  {
181  DOMElement* row[10];
182  DOMAttr* rowid[10];
183  DOMText* rowvalue[10];
185 
186  if (cms::xerces::toString(node->getNodeName()) == wgtChi2BeforeSwitch_tag) {
187  echi2wmatrix = record.getChi2WeightsBeforeGainSwitch();
188  }
189  if (cms::xerces::toString(node->getNodeName()) == wgtChi2AfterSwitch_tag) {
190  echi2wmatrix = record.getChi2WeightsAfterGainSwitch();
191  }
192 
193  for (int i = 0; i < 10; ++i) {
194  row[i] = node->getOwnerDocument()->createElement(cms::xerces::uStr(row_tag.c_str()).ptr());
195  node->appendChild(row[i]);
196 
197  stringstream value_s;
198  value_s << i;
199 
200  rowid[i] = node->getOwnerDocument()->createAttribute(cms::xerces::uStr(id_tag.c_str()).ptr());
201  rowid[i]->setValue(cms::xerces::uStr(value_s.str().c_str()).ptr());
202  row[i]->setAttributeNode(rowid[i]);
203 
204  stringstream row_s;
205 
206  for (int k = 0; k < 10; ++k) {
207  row_s << " ";
208  row_s << echi2wmatrix(k, i);
209  row_s << " ";
210  } //for loop on element
211 
212  rowvalue[i] = node->getOwnerDocument()->createTextNode(cms::xerces::uStr(row_s.str().c_str()).ptr());
213  row[i]->appendChild(rowvalue[i]);
214  } //for loop on row
215 }
const std::string id_tag("id")
math::Matrix< 10, 10 >::type EcalChi2WeightMatrix
Definition: EcalWeightSet.h:20
const std::string row_tag("row")
const std::string wgtChi2AfterSwitch_tag("Chi2WeightAfterSwitch")
std::string toString(XMLCh const *toTranscode)
ZStr< XMLCh > uStr(char const *str)
const std::string wgtChi2BeforeSwitch_tag("Chi2WeightBeforeSwitch")

◆ write3x10()

void EcalWeightSetXMLTranslator::write3x10 ( xercesc::DOMElement *  node,
const EcalWeightSet record 
)
staticprivate

Definition at line 217 of file EcalWeightSetXMLTranslator.cc.

References mps_fire::i, xuti::id_tag(), isotrackApplyRegressor::k, Hcal_FrontierConditions_cff::record, xuti::row_tag(), cms::xerces::toString(), cms::xerces::uStr(), xuti::wgtAfterSwitch_tag(), and xuti::wgtBeforeSwitch_tag().

217  {
218  DOMElement* row[10];
219  DOMAttr* rowid[10];
220  DOMText* rowvalue[10];
222 
223  if (cms::xerces::toString(node->getNodeName()) == wgtBeforeSwitch_tag)
224  ewmatrix = record.getWeightsBeforeGainSwitch();
225 
226  if (cms::xerces::toString(node->getNodeName()) == wgtAfterSwitch_tag)
227  ewmatrix = record.getWeightsAfterGainSwitch();
228 
229  for (int i = 0; i < 10; ++i) {
230  row[i] = node->getOwnerDocument()->createElement(cms::xerces::uStr(row_tag.c_str()).ptr());
231  node->appendChild(row[i]);
232 
233  stringstream value_s;
234  value_s << i;
235 
236  rowid[i] = node->getOwnerDocument()->createAttribute(cms::xerces::uStr(id_tag.c_str()).ptr());
237 
238  rowid[i]->setValue(cms::xerces::uStr(value_s.str().c_str()).ptr());
239 
240  row[i]->setAttributeNode(rowid[i]);
241 
242  stringstream row_s;
243 
244  for (int k = 0; k < 3; ++k) {
245  row_s << " ";
246  row_s << ewmatrix(k, i);
247  row_s << " ";
248  } //for loop on element
249 
250  rowvalue[i] = node->getOwnerDocument()->createTextNode(cms::xerces::uStr(row_s.str().c_str()).ptr());
251  row[i]->appendChild(rowvalue[i]);
252  } //for loop on row
253 }
const std::string id_tag("id")
math::Matrix< 3, 10 >::type EcalWeightMatrix
Definition: EcalWeightSet.h:19
const std::string row_tag("row")
std::string toString(XMLCh const *toTranscode)
ZStr< XMLCh > uStr(char const *str)
const std::string wgtBeforeSwitch_tag("WeightBeforeSwitch")
const std::string wgtAfterSwitch_tag("WeightAfterSwitch")

◆ writeXML()

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