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.

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 }

References common_cff::doc, FrontierConditions_GlobalTag_cff::dump, xuti::EcalTBWeight_tag(), xuti::EcalTBWeights_tag(), xuti::EcalTDCId_tag(), xuti::EcalXtalGroupId_tag(), RecoTauValidation_cfi::header, GlobalPosition_Frontier_DevDB_cff::record, AlCaHLTBitMon_QueryRunRegistry::string, cms::xerces::toString(), cms::xerces::uStr(), xuti::writeHeader(), xuti::WriteNodeWithValue(), cscNeutronWriter_cfi::writer, and cms::concurrency::xercesInitialize().

◆ readWeightSet()

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

Definition at line 89 of file EcalTBWeightsXMLTranslator.cc.

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 }

References EcalWeightSet::getChi2WeightsAfterGainSwitch(), EcalWeightSet::getChi2WeightsBeforeGainSwitch(), xuti::getChildNode(), EcalWeightSet::getWeightsAfterGainSwitch(), EcalWeightSet::getWeightsBeforeGainSwitch(), 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(), and xuti::wgtChi2BeforeSwitch_tag().

◆ readXML()

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

Definition at line 28 of file EcalTBWeightsXMLTranslator.cc.

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;
56  EcalWeightSet ws;
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 }

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(), GlobalPosition_Frontier_DevDB_cff::record, cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

◆ writeChi2WeightMatrix()

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

Definition at line 268 of file EcalTBWeightsXMLTranslator.cc.

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 }

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

◆ writeWeightMatrix()

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

Definition at line 238 of file EcalTBWeightsXMLTranslator.cc.

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 }

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

◆ writeWeightSet()

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

Definition at line 213 of file EcalTBWeightsXMLTranslator.cc.

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 
233 
236 }

References common_cff::doc, xuti::EcalWeightSet_tag(), EcalWeightSet::getChi2WeightsBeforeGainSwitch(), EcalWeightSet::getWeightsAfterGainSwitch(), EcalWeightSet::getWeightsBeforeGainSwitch(), cms::xerces::uStr(), xuti::wgtAfterSwitch_tag(), xuti::wgtBeforeSwitch_tag(), xuti::wgtChi2AfterSwitch_tag(), and xuti::wgtChi2BeforeSwitch_tag().

◆ writeXML()

int EcalTBWeightsXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalTBWeights record 
)
static
xuti::getChildNode
xercesc::DOMNode * getChildNode(xercesc::DOMNode *node, const std::string &nodename)
get the child of
xuti::EcalTBWeights_tag
const std::string EcalTBWeights_tag("EcalTBWeights")
hgcalPlots.ncols
ncols
Definition: hgcalPlots.py:105
common_cff.doc
doc
Definition: common_cff.py:54
mps_fire.i
i
Definition: mps_fire.py:355
EcalTBWeightsXMLTranslator::writeWeightSet
static void writeWeightSet(xercesc::DOMNode *parentNode, const EcalWeightSet &ws)
Definition: EcalTBWeightsXMLTranslator.cc:213
xuti::writeHeader
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
Definition: DOMHelperFunctions.cc:151
makeMuonMisalignmentScenario.matrix
list matrix
Definition: makeMuonMisalignmentScenario.py:141
xuti::EcalXtalGroupId_tag
const std::string EcalXtalGroupId_tag("EcalXtalGroupId")
xuti::wgtChi2BeforeSwitch_tag
const std::string wgtChi2BeforeSwitch_tag("Chi2WeightBeforeSwitch")
gather_cfg.cout
cout
Definition: gather_cfg.py:144
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
writedatasetfile.parser
parser
Definition: writedatasetfile.py:7
cscNeutronWriter_cfi.writer
writer
Definition: cscNeutronWriter_cfi.py:6
EcalXtalGroupId
Definition: EcalXtalGroupId.h:11
xuti::wgtAfterSwitch_tag
const std::string wgtAfterSwitch_tag("WeightAfterSwitch")
cms::xerces::toString
std::string toString(XMLCh const *toTranscode)
Definition: XercesStrUtils.h:34
xuti::EcalTDCId_tag
const std::string EcalTDCId_tag("EcalTDCId")
xuti::id_tag
const std::string id_tag("id")
xuti::wgtBeforeSwitch_tag
const std::string wgtBeforeSwitch_tag("WeightBeforeSwitch")
xuti::WriteNodeWithValue
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
Definition: DOMHelperFunctions.h:46
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
dqmdumpme.k
k
Definition: dqmdumpme.py:60
EcalWeightSet::getWeightsAfterGainSwitch
EcalWeightMatrix & getWeightsAfterGainSwitch()
Definition: EcalWeightSet.h:27
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalWeightSet::getWeightsBeforeGainSwitch
EcalWeightMatrix & getWeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:26
EcalTBWeights::EcalTDCId
int EcalTDCId
Definition: EcalTBWeights.h:17
EcalWeightSet::getChi2WeightsAfterGainSwitch
EcalChi2WeightMatrix & getChi2WeightsAfterGainSwitch()
Definition: EcalWeightSet.h:29
FrontierConditions_GlobalTag_cff.dump
dump
Definition: FrontierConditions_GlobalTag_cff.py:12
cms::concurrency::xercesTerminate
void xercesTerminate()
Definition: Xerces.cc:23
root
Definition: RooFitFunction.h:10
xuti::EcalWeightSet_tag
const std::string EcalWeightSet_tag("EcalWeightSet")
cms::xerces::uStr
ZStr< XMLCh > uStr(char const *str)
Definition: XercesStrUtils.h:30
EcalTBWeightsXMLTranslator::writeChi2WeightMatrix
static void writeChi2WeightMatrix(xercesc::DOMNode *node, const EcalWeightSet::EcalChi2WeightMatrix &matrix)
Definition: EcalTBWeightsXMLTranslator.cc:268
EcalTBWeights::EcalTBWeightMap
std::map< std::pair< EcalXtalGroupId, EcalTDCId >, EcalWeightSet > EcalTBWeightMap
Definition: EcalTBWeights.h:18
EcalTBWeightsXMLTranslator::writeWeightMatrix
static void writeWeightMatrix(xercesc::DOMNode *node, const EcalWeightSet::EcalWeightMatrix &matrix)
Definition: EcalTBWeightsXMLTranslator.cc:238
EcalWeightSet
Definition: EcalWeightSet.h:17
impl
Definition: trackAlgoPriorityOrder.h:18
EcalTBWeightsXMLTranslator::readWeightSet
static void readWeightSet(xercesc::DOMNode *parentNode, EcalWeightSet &ws)
Definition: EcalTBWeightsXMLTranslator.cc:89
EcalTBWeightsXMLTranslator::dumpXML
static std::string dumpXML(const EcalCondHeader &header, const EcalTBWeights &record)
Definition: EcalTBWeightsXMLTranslator.cc:298
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
EcalWeightSet::getChi2WeightsBeforeGainSwitch
EcalChi2WeightMatrix & getChi2WeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:28
xuti::EcalTBWeight_tag
const std::string EcalTBWeight_tag("EcalTBWeight")
cms::concurrency::xercesInitialize
void xercesInitialize()
Definition: Xerces.cc:18
xuti::readHeader
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
Definition: DOMHelperFunctions.cc:164
xuti::wgtChi2AfterSwitch_tag
const std::string wgtChi2AfterSwitch_tag("Chi2WeightAfterSwitch")
weight
Definition: weight.py:1
xuti::row_tag
const std::string row_tag("row")
xuti::GetNodeData
void GetNodeData(xercesc::DOMNode *node, T &value)
get the node data
Definition: DOMHelperFunctions.h:38