CMS 3D CMS Logo

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

#include <EcalTBWeightsXMLTranslator.h>

Static Public Member Functions

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

Static Private Member Functions

static std::string dumpXML (const EcalCondHeader &header, const EcalTBWeights &record)
 
static void readWeightSet (xercesc::DOMNode *parentNode, EcalWeightSet &ws)
 
static void writeChi2WeightMatrix (xercesc::DOMNode *node, const EcalWeightSet::EcalChi2WeightMatrix &matrix)
 
static void writeWeightMatrix (xercesc::DOMNode *node, const EcalWeightSet::EcalWeightMatrix &matrix)
 
static void writeWeightSet (xercesc::DOMNode *parentNode, const EcalWeightSet &ws)
 

Detailed Description

Translates a EcalTBWeights record to XML and vice versa

Author
Stefano ARGIRO
Version
Id
EcalTBWeightsXMLTranslator.h,v 1.1 2008/11/14 15:46:05 argiro Exp
Date
21 Aug 2008

Definition at line 19 of file EcalTBWeightsXMLTranslator.h.

Member Function Documentation

◆ dumpXML()

std::string EcalTBWeightsXMLTranslator::dumpXML ( const EcalCondHeader header,
const EcalTBWeights record 
)
staticprivate

Definition at line 298 of file EcalTBWeightsXMLTranslator.cc.

References boostedTaus_cff::doc, GCP_Ntuples_cfg::dump, xuti::EcalTBWeight_tag(), xuti::EcalTBWeights_tag(), xuti::EcalTDCId_tag(), xuti::EcalXtalGroupId_tag(), RecoTauValidation_cfi::header, AlCaHarvesting_cff::record, AlCaHLTBitMon_QueryRunRegistry::string, cms::xerces::toString(), cms::xerces::uStr(), xuti::writeHeader(), xuti::WriteNodeWithValue(), convertToRaw::writer, gpuVertexFinder::ws, and cms::concurrency::xercesInitialize().

298  {
300 
301  unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
302 
303  DOMLSSerializer* writer = impl->createLSSerializer();
304  if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
305  writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
306 
307  DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
308  DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(EcalTBWeights_tag.c_str()).ptr(), doctype);
309  DOMElement* root = doc->getDocumentElement();
310 
312 
313  const EcalTBWeights::EcalTBWeightMap& wmap = record.getMap();
314 
315  EcalTBWeights::EcalTBWeightMap::const_iterator it;
316  for (it = wmap.begin(); it != wmap.end(); ++it) {
317  DOMElement* tbweight = doc->createElement(cms::xerces::uStr(EcalTBWeight_tag.c_str()).ptr());
318  root->appendChild(tbweight);
319 
320  EcalXtalGroupId gid = it->first.first;
321  EcalTBWeights::EcalTDCId tid = it->first.second;
322  EcalWeightSet ws = it->second;
323 
324  WriteNodeWithValue(tbweight, EcalXtalGroupId_tag, gid);
325  WriteNodeWithValue(tbweight, EcalTDCId_tag, tid);
326  writeWeightSet(tbweight, ws);
327 
328  } //
329 
330  std::string dump = cms::xerces::toString(writer->writeToString(root));
331  doc->release();
332  doctype->release();
333  writer->release();
334 
335  return dump;
336 }
std::map< std::pair< EcalXtalGroupId, EcalTDCId >, EcalWeightSet > EcalTBWeightMap
Definition: EcalTBWeights.h:18
void xercesInitialize()
Definition: Xerces.cc:18
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
auto &__restrict__ ws
std::string toString(XMLCh const *toTranscode)
const std::string EcalTBWeights_tag("EcalTBWeights")
const std::string EcalTBWeight_tag("EcalTBWeight")
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
ZStr< XMLCh > uStr(char const *str)
static void writeWeightSet(xercesc::DOMNode *parentNode, const EcalWeightSet &ws)
const std::string EcalXtalGroupId_tag("EcalXtalGroupId")
const std::string EcalTDCId_tag("EcalTDCId")

◆ readWeightSet()

void EcalTBWeightsXMLTranslator::readWeightSet ( xercesc::DOMNode *  parentNode,
EcalWeightSet ws 
)
staticprivate

Definition at line 89 of file EcalTBWeightsXMLTranslator.cc.

References xuti::getChildNode(), mps_fire::i, xuti::id_tag(), xuti::row_tag(), AlCaHLTBitMon_QueryRunRegistry::string, cms::xerces::toString(), cms::xerces::uStr(), xuti::wgtAfterSwitch_tag(), xuti::wgtBeforeSwitch_tag(), xuti::wgtChi2AfterSwitch_tag(), xuti::wgtChi2BeforeSwitch_tag(), and gpuVertexFinder::ws.

89  {
90  // get the first cell node
91  DOMNode* wgtBSnode = getChildNode(parentNode, wgtBeforeSwitch_tag);
92  DOMNode* wgtASnode = getChildNode(parentNode, wgtAfterSwitch_tag);
93  DOMNode* wgtChi2BSnode = getChildNode(parentNode, wgtChi2BeforeSwitch_tag);
94  DOMNode* wgtChi2ASnode = getChildNode(parentNode, wgtChi2AfterSwitch_tag);
95 
96  DOMNode* rownode = getChildNode(wgtBSnode, row_tag);
97 
98  DOMElement* rowelement = nullptr;
99 
100  // loop on row nodes
101  while (rownode) {
102  rowelement = dynamic_cast<xercesc::DOMElement*>(rownode);
103 
104  std::string rowid_s = cms::xerces::toString(rowelement->getAttribute(cms::xerces::uStr(id_tag.c_str()).ptr()));
105 
106  std::stringstream rowid_ss(rowid_s);
107  int rowid = 0;
108  rowid_ss >> rowid;
109 
110  std::string weightrow = cms::xerces::toString(rownode->getTextContent());
111 
112  std::stringstream weightrow_s(weightrow);
113  double weight = 0;
114  int i = 0;
115  while (weightrow_s >> weight) {
116  ws.getWeightsBeforeGainSwitch()(rowid, i) = weight;
117  i++;
118  }
119 
120  // get next cell
121  rownode = rownode->getNextSibling();
122 
123  while (rownode && rownode->getNodeType() != DOMNode::ELEMENT_NODE)
124  rownode = rownode->getNextSibling();
125  }
126 
127  rownode = getChildNode(wgtASnode, row_tag);
128 
129  // loop on row nodes
130  while (rownode) {
131  rowelement = dynamic_cast<xercesc::DOMElement*>(rownode);
132 
133  std::string rowid_s = cms::xerces::toString(rowelement->getAttribute(cms::xerces::uStr(id_tag.c_str()).ptr()));
134 
135  std::stringstream rowid_ss(rowid_s);
136  int rowid = 0;
137  rowid_ss >> rowid;
138 
139  std::string weightrow = cms::xerces::toString(rownode->getTextContent());
140 
141  std::stringstream weightrow_s(weightrow);
142  double weight = 0;
143  int i = 0;
144  while (weightrow_s >> weight) {
145  ws.getWeightsAfterGainSwitch()(rowid, i) = weight;
146  i++;
147  }
148 
149  // get next cell
150  rownode = rownode->getNextSibling();
151 
152  while (rownode && rownode->getNodeType() != DOMNode::ELEMENT_NODE)
153  rownode = rownode->getNextSibling();
154  }
155 
156  rownode = getChildNode(wgtChi2BSnode, row_tag);
157 
158  // loop on row nodes
159  while (rownode) {
160  rowelement = dynamic_cast<xercesc::DOMElement*>(rownode);
161  std::string rowid_s = cms::xerces::toString(rowelement->getAttribute(cms::xerces::uStr(id_tag.c_str()).ptr()));
162 
163  std::stringstream rowid_ss(rowid_s);
164  int rowid = 0;
165  rowid_ss >> rowid;
166 
167  std::string weightrow = cms::xerces::toString(rownode->getTextContent());
168 
169  std::stringstream weightrow_s(weightrow);
170  double weight = 0;
171  int i = 0;
172  while (weightrow_s >> weight) {
173  ws.getChi2WeightsBeforeGainSwitch()(rowid, i) = weight;
174  i++;
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  rownode = getChildNode(wgtChi2ASnode, row_tag);
185 
186  // loop on row nodes
187  while (rownode) {
188  rowelement = dynamic_cast<xercesc::DOMElement*>(rownode);
189  std::string rowid_s = cms::xerces::toString(rowelement->getAttribute(cms::xerces::uStr(id_tag.c_str()).ptr()));
190 
191  std::stringstream rowid_ss(rowid_s);
192  int rowid = 0;
193  rowid_ss >> rowid;
194 
195  std::string weightrow = cms::xerces::toString(rownode->getTextContent());
196 
197  std::stringstream weightrow_s(weightrow);
198  double weight = 0;
199  int i = 0;
200  while (weightrow_s >> weight) {
201  ws.getChi2WeightsAfterGainSwitch()(rowid, i) = weight;
202  i++;
203  }
204 
205  // get next cell
206  rownode = rownode->getNextSibling();
207 
208  while (rownode && rownode->getNodeType() != DOMNode::ELEMENT_NODE)
209  rownode = rownode->getNextSibling();
210  }
211 }
const std::string id_tag("id")
Definition: weight.py:1
const std::string row_tag("row")
auto &__restrict__ ws
const std::string wgtChi2AfterSwitch_tag("Chi2WeightAfterSwitch")
std::string toString(XMLCh const *toTranscode)
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")

◆ readXML()

int EcalTBWeightsXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalTBWeights record 
)
static

Definition at line 28 of file EcalTBWeightsXMLTranslator.cc.

References gather_cfg::cout, xuti::EcalTBWeight_tag(), xuti::EcalTDCId_tag(), xuti::EcalWeightSet_tag(), xuti::EcalXtalGroupId_tag(), corrVsCorr::filename, xuti::getChildNode(), xuti::GetNodeData(), RecoTauValidation_cfi::header, writedatasetfile::parser, xuti::readHeader(), AlCaHarvesting_cff::record, gpuVertexFinder::ws, cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

28  {
30 
31  XercesDOMParser* parser = new XercesDOMParser;
32  parser->setValidationScheme(XercesDOMParser::Val_Never);
33  parser->setDoNamespaces(false);
34  parser->setDoSchema(false);
35 
36  parser->parse(filename.c_str());
37 
38  DOMDocument* xmlDoc = parser->getDocument();
39  if (!xmlDoc) {
40  std::cout << "EcalTBWeightsXMLTranslator::Error parsing document" << std::endl;
41  return -1;
42  }
43 
44  DOMElement* elementRoot = xmlDoc->getDocumentElement();
45  xuti::readHeader(elementRoot, header);
46 
47  DOMNode* wnode = getChildNode(elementRoot, EcalTBWeight_tag);
48 
49  while (wnode) {
50  DOMNode* gid_node = getChildNode(wnode, EcalXtalGroupId_tag);
51  DOMNode* tdc_node = getChildNode(wnode, EcalTDCId_tag);
52  DOMNode* ws_node = getChildNode(wnode, EcalWeightSet_tag);
53 
54  EcalXtalGroupId gid;
57 
58  GetNodeData(gid_node, gid);
59  GetNodeData(tdc_node, tid);
60 
61  readWeightSet(ws_node, ws);
62 
63  record.setValue(gid, tid, ws);
64 
65  wnode = wnode->getNextSibling();
66 
67  while (wnode && wnode->getNodeType() != DOMNode::ELEMENT_NODE)
68  wnode = wnode->getNextSibling();
69  }
70 
72 
73  return 0;
74 }
const std::string EcalWeightSet_tag("EcalWeightSet")
void xercesTerminate()
Definition: Xerces.cc:23
void xercesInitialize()
Definition: Xerces.cc:18
auto &__restrict__ ws
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
const std::string EcalTBWeight_tag("EcalTBWeight")
static void readWeightSet(xercesc::DOMNode *parentNode, EcalWeightSet &ws)
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 EcalXtalGroupId_tag("EcalXtalGroupId")
const std::string EcalTDCId_tag("EcalTDCId")

◆ writeChi2WeightMatrix()

void EcalTBWeightsXMLTranslator::writeChi2WeightMatrix ( xercesc::DOMNode *  node,
const EcalWeightSet::EcalChi2WeightMatrix matrix 
)
staticprivate

Definition at line 268 of file EcalTBWeightsXMLTranslator.cc.

References mps_fire::i, xuti::id_tag(), dqmdumpme::k, makeMuonMisalignmentScenario::matrix, hgcalPlots::ncols, xuti::row_tag(), and cms::xerces::uStr().

269  {
270  DOMElement* row = nullptr;
271  DOMAttr* rowid = nullptr;
272  DOMText* rowvalue = nullptr;
273 
274  const int ncols = 10;
275  const int nrows = 10;
276 
277  for (int i = 0; i < nrows; ++i) {
278  row = node->getOwnerDocument()->createElement(cms::xerces::uStr(row_tag.c_str()).ptr());
279  node->appendChild(row);
280 
281  stringstream value_s;
282  value_s << i;
283 
284  rowid = node->getOwnerDocument()->createAttribute(cms::xerces::uStr(id_tag.c_str()).ptr());
285  rowid->setValue(cms::xerces::uStr(value_s.str().c_str()).ptr());
286  row->setAttributeNode(rowid);
287 
288  stringstream row_s;
289 
290  for (int k = 0; k < ncols; ++k)
291  row_s << " " << matrix(i, k) << " ";
292 
293  rowvalue = node->getOwnerDocument()->createTextNode(cms::xerces::uStr(row_s.str().c_str()).ptr());
294  row->appendChild(rowvalue);
295  } //for loop on col
296 }
const std::string id_tag("id")
const std::string row_tag("row")
ZStr< XMLCh > uStr(char const *str)

◆ writeWeightMatrix()

void EcalTBWeightsXMLTranslator::writeWeightMatrix ( xercesc::DOMNode *  node,
const EcalWeightSet::EcalWeightMatrix matrix 
)
staticprivate

Definition at line 238 of file EcalTBWeightsXMLTranslator.cc.

References mps_fire::i, xuti::id_tag(), dqmdumpme::k, makeMuonMisalignmentScenario::matrix, hgcalPlots::ncols, xuti::row_tag(), and cms::xerces::uStr().

239  {
240  DOMElement* row = nullptr;
241  DOMAttr* rowid = nullptr;
242  DOMText* rowvalue = nullptr;
243 
244  const int ncols = 10;
245  const int nrows = 3;
246 
247  for (int i = 0; i < nrows; ++i) {
248  row = node->getOwnerDocument()->createElement(cms::xerces::uStr(row_tag.c_str()).ptr());
249  node->appendChild(row);
250 
251  stringstream value_s;
252  value_s << i;
253 
254  rowid = node->getOwnerDocument()->createAttribute(cms::xerces::uStr(id_tag.c_str()).ptr());
255  rowid->setValue(cms::xerces::uStr(value_s.str().c_str()).ptr());
256  row->setAttributeNode(rowid);
257 
258  stringstream row_s;
259 
260  for (int k = 0; k < ncols; ++k)
261  row_s << " " << matrix(i, k) << " ";
262 
263  rowvalue = node->getOwnerDocument()->createTextNode(cms::xerces::uStr(row_s.str().c_str()).ptr());
264  row->appendChild(rowvalue);
265  } //for loop on col
266 }
const std::string id_tag("id")
const std::string row_tag("row")
ZStr< XMLCh > uStr(char const *str)

◆ writeWeightSet()

void EcalTBWeightsXMLTranslator::writeWeightSet ( xercesc::DOMNode *  parentNode,
const EcalWeightSet ws 
)
staticprivate

Definition at line 213 of file EcalTBWeightsXMLTranslator.cc.

References boostedTaus_cff::doc, xuti::EcalWeightSet_tag(), cms::xerces::uStr(), xuti::wgtAfterSwitch_tag(), xuti::wgtBeforeSwitch_tag(), xuti::wgtChi2AfterSwitch_tag(), xuti::wgtChi2BeforeSwitch_tag(), and gpuVertexFinder::ws.

213  {
214  xercesc::DOMDocument* doc = parentNode->getOwnerDocument();
215 
216  DOMElement* weightsetel = doc->createElement(cms::xerces::uStr(EcalWeightSet_tag.c_str()).ptr());
217  parentNode->appendChild(weightsetel);
218 
219  DOMElement* wgtBS = doc->createElement(cms::xerces::uStr(wgtBeforeSwitch_tag.c_str()).ptr());
220  weightsetel->appendChild(wgtBS);
221 
222  DOMElement* wgtAS = doc->createElement(cms::xerces::uStr(wgtAfterSwitch_tag.c_str()).ptr());
223  weightsetel->appendChild(wgtAS);
224 
225  DOMElement* wgtChi2BS = doc->createElement(cms::xerces::uStr(wgtChi2BeforeSwitch_tag.c_str()).ptr());
226  weightsetel->appendChild(wgtChi2BS);
227 
228  DOMElement* wgtChi2AS = doc->createElement(cms::xerces::uStr(wgtChi2AfterSwitch_tag.c_str()).ptr());
229  weightsetel->appendChild(wgtChi2AS);
230 
231  writeWeightMatrix(wgtBS, ws.getWeightsBeforeGainSwitch());
232  writeWeightMatrix(wgtAS, ws.getWeightsAfterGainSwitch());
233 
234  writeChi2WeightMatrix(wgtChi2BS, ws.getChi2WeightsBeforeGainSwitch());
235  writeChi2WeightMatrix(wgtChi2AS, ws.getChi2WeightsBeforeGainSwitch());
236 }
const std::string EcalWeightSet_tag("EcalWeightSet")
static void writeWeightMatrix(xercesc::DOMNode *node, const EcalWeightSet::EcalWeightMatrix &matrix)
auto &__restrict__ ws
const std::string wgtChi2AfterSwitch_tag("Chi2WeightAfterSwitch")
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 writeChi2WeightMatrix(xercesc::DOMNode *node, const EcalWeightSet::EcalChi2WeightMatrix &matrix)

◆ writeXML()

int EcalTBWeightsXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalTBWeights record 
)
static