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

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

Definition at line 358 of file EcalTBWeightsXMLTranslator.cc.

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

359  {
360 
361 
363 
364  unique_ptr<DOMImplementation> impl( DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
365 
366  DOMLSSerializer* writer = impl->createLSSerializer();
367  if( writer->getDomConfig()->canSetParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true ))
368  writer->getDomConfig()->setParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true );
369 
370  DOMDocumentType* doctype = impl->createDocumentType( cms::xerces::uStr("XML").ptr(), nullptr, nullptr );
371  DOMDocument* doc =
372  impl->createDocument( nullptr, cms::xerces::uStr(EcalTBWeights_tag.c_str()).ptr(), doctype );
373  DOMElement* root = doc->getDocumentElement();
374 
375  xuti::writeHeader(root, header);
376 
377  const EcalTBWeights::EcalTBWeightMap& wmap= record.getMap();
378 
379  EcalTBWeights::EcalTBWeightMap::const_iterator it ;
380  for (it =wmap.begin(); it!=wmap.end(); ++it){
381 
382  DOMElement * tbweight= doc->createElement(cms::xerces::uStr(EcalTBWeight_tag.c_str()).ptr());
383  root->appendChild(tbweight);
384 
385  EcalXtalGroupId gid = it->first.first;
386  EcalTBWeights::EcalTDCId tid = it->first.second;
387  EcalWeightSet ws = it->second;
388 
390  WriteNodeWithValue(tbweight,EcalTDCId_tag, tid);
391  writeWeightSet(tbweight,ws);
392 
393 
394  } //
395 
396  std::string dump = cms::xerces::toString( writer->writeToString( root ));
397  doc->release();
398  doctype->release();
399  writer->release();
400 
401  return dump;
402 }
std::map< std::pair< EcalXtalGroupId, EcalTDCId >, EcalWeightSet > EcalTBWeightMap
Definition: EcalTBWeights.h:21
void xercesInitialize()
Definition: Xerces.cc:18
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
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 EcalTBWeightMap & getMap() const
Definition: EcalTBWeights.h:31
const std::string EcalTDCId_tag("EcalTDCId")
void EcalTBWeightsXMLTranslator::readWeightSet ( xercesc::DOMNode *  parentNode,
EcalWeightSet ws 
)
staticprivate

Definition at line 100 of file EcalTBWeightsXMLTranslator.cc.

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().

101  {
102 
103 
104 
105  // get the first cell node
106  DOMNode * wgtBSnode=getChildNode(parentNode,wgtBeforeSwitch_tag);
107  DOMNode * wgtASnode=getChildNode(parentNode,wgtAfterSwitch_tag);
108  DOMNode * wgtChi2BSnode=getChildNode(parentNode,wgtChi2BeforeSwitch_tag);
109  DOMNode * wgtChi2ASnode=getChildNode(parentNode,wgtChi2AfterSwitch_tag);
110 
111 
112  DOMNode* rownode = getChildNode(wgtBSnode,row_tag);
113 
114  DOMElement* rowelement=nullptr;
115 
116  // loop on row nodes
117  while (rownode){
118 
119  rowelement = dynamic_cast< xercesc::DOMElement* >(rownode);
120 
121  std::string rowid_s = cms::xerces::toString(rowelement->getAttribute(cms::xerces::uStr(id_tag.c_str()).ptr()));
122 
123  std::stringstream rowid_ss(rowid_s);
124  int rowid = 0;
125  rowid_ss >> rowid;
126 
127  std::string weightrow = cms::xerces::toString(rownode->getTextContent());
128 
129  std::stringstream weightrow_s(weightrow);
130  double weight = 0;
131  int i = 0;
132  while(weightrow_s >> weight){
133  ws.getWeightsBeforeGainSwitch()(rowid,i)= weight;
134  i++;
135 
136  }
137 
138 
139  // get next cell
140  rownode = rownode->getNextSibling();
141 
142  while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
143  rownode = rownode->getNextSibling();
144 
145 
146  }
147 
148  rownode = getChildNode(wgtASnode,row_tag);
149 
150  // loop on row nodes
151  while (rownode){
152 
153  rowelement = dynamic_cast< xercesc::DOMElement* >(rownode);
154 
155  std::string rowid_s = cms::xerces::toString(rowelement->getAttribute( cms::xerces::uStr(id_tag.c_str()).ptr()));
156 
157  std::stringstream rowid_ss(rowid_s);
158  int rowid = 0;
159  rowid_ss >> rowid;
160 
161  std::string weightrow = cms::xerces::toString(rownode->getTextContent());
162 
163  std::stringstream weightrow_s(weightrow);
164  double weight = 0;
165  int i = 0;
166  while(weightrow_s >> weight){
167  ws.getWeightsAfterGainSwitch()(rowid,i)= weight;
168  i++;
169  }
170 
171 
172  // get next cell
173  rownode = rownode->getNextSibling();
174 
175  while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
176  rownode = rownode->getNextSibling();
177 
178 
179  }
180 
181  rownode = getChildNode(wgtChi2BSnode,row_tag);
182 
183 
184  // loop on row nodes
185  while (rownode){
186 
187  rowelement = dynamic_cast< xercesc::DOMElement* >(rownode);
188  std::string rowid_s = cms::xerces::toString(rowelement->getAttribute(cms::xerces::uStr(id_tag.c_str()).ptr()));
189 
190  std::stringstream rowid_ss(rowid_s);
191  int rowid = 0;
192  rowid_ss >> rowid;
193 
194  std::string weightrow = cms::xerces::toString(rownode->getTextContent());
195 
196  std::stringstream weightrow_s(weightrow);
197  double weight = 0;
198  int i = 0;
199  while(weightrow_s >> weight)
200  {
201  ws.getChi2WeightsBeforeGainSwitch()(rowid,i)= weight;
202  i++;
203  }
204 
205 
206  // get next cell
207  rownode = rownode->getNextSibling();
208 
209  while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
210  rownode = rownode->getNextSibling();
211 
212 
213  }
214 
215 
216  rownode = getChildNode(wgtChi2ASnode,row_tag);
217 
218 
219  // loop on row nodes
220  while (rownode){
221 
222  rowelement = dynamic_cast< xercesc::DOMElement* >(rownode);
223  std::string rowid_s = cms::xerces::toString(rowelement->getAttribute(cms::xerces::uStr(id_tag.c_str()).ptr()));
224 
225  std::stringstream rowid_ss(rowid_s);
226  int rowid = 0;
227  rowid_ss >> rowid;
228 
229  std::string weightrow = cms::xerces::toString(rownode->getTextContent());
230 
231  std::stringstream weightrow_s(weightrow);
232  double weight = 0;
233  int i = 0;
234  while(weightrow_s >> weight){
235  ws.getChi2WeightsAfterGainSwitch()(rowid,i)= weight;
236  i++;
237  }
238 
239 
240  // get next cell
241  rownode = rownode->getNextSibling();
242 
243  while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
244  rownode = rownode->getNextSibling();
245 
246 
247  }
248 
249 
250 }
EcalChi2WeightMatrix & getChi2WeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:31
const std::string id_tag("id")
Definition: weight.py:1
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)
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")
int EcalTBWeightsXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalTBWeights record 
)
static

Definition at line 33 of file EcalTBWeightsXMLTranslator.cc.

References gather_cfg::cout, xuti::EcalTBWeight_tag(), xuti::EcalTDCId_tag(), xuti::EcalWeightSet_tag(), xuti::EcalXtalGroupId_tag(), xuti::getChildNode(), xuti::GetNodeData(), createfilelist::parser, xuti::readHeader(), EcalTBWeights::setValue(), cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

35  {
36 
38 
39  XercesDOMParser* parser = new XercesDOMParser;
40  parser->setValidationScheme( XercesDOMParser::Val_Never );
41  parser->setDoNamespaces( false );
42  parser->setDoSchema( false );
43 
44  parser->parse(filename.c_str());
45 
46  DOMDocument* xmlDoc = parser->getDocument();
47  if (!xmlDoc) {
48  std::cout << "EcalTBWeightsXMLTranslator::Error parsing document" << std::endl;
49  return -1;
50  }
51 
52  DOMElement* elementRoot = xmlDoc->getDocumentElement();
53  xuti::readHeader(elementRoot, header);
54 
55  DOMNode * wnode=getChildNode(elementRoot,EcalTBWeight_tag);
56 
57  while (wnode){
58 
59  DOMNode * gid_node = getChildNode(wnode,EcalXtalGroupId_tag);
60  DOMNode * tdc_node = getChildNode(wnode,EcalTDCId_tag);
61  DOMNode * ws_node = getChildNode(wnode,EcalWeightSet_tag);
62 
63  EcalXtalGroupId gid;
65  EcalWeightSet ws;
66 
67  GetNodeData(gid_node,gid);
68  GetNodeData(tdc_node,tid);
69 
70  readWeightSet(ws_node,ws);
71 
72  record.setValue(gid,tid,ws);
73 
74  wnode= wnode->getNextSibling();
75 
76  while (wnode&& wnode->getNodeType( ) != DOMNode::ELEMENT_NODE)
77  wnode= wnode->getNextSibling();
78  }
79 
81 
82  return 0;
83 }
const std::string EcalWeightSet_tag("EcalWeightSet")
void xercesTerminate()
Definition: Xerces.cc:23
void setValue(const EcalXtalGroupId &groupId, const EcalTDCId &tdcId, const EcalWeightSet &weight)
void xercesInitialize()
Definition: Xerces.cc:18
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")
void EcalTBWeightsXMLTranslator::writeChi2WeightMatrix ( xercesc::DOMNode *  node,
const EcalWeightSet::EcalChi2WeightMatrix matrix 
)
staticprivate

Definition at line 321 of file EcalTBWeightsXMLTranslator.cc.

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

322  {
323 
324  DOMElement* row=nullptr;
325  DOMAttr* rowid=nullptr;
326  DOMText* rowvalue=nullptr;
327 
328  const int ncols =10;
329  const int nrows =10;
330 
331  for(int i=0;i<nrows;++i)
332  {
333 
334 
335  row= node->getOwnerDocument()->createElement( cms::xerces::uStr(row_tag.c_str()).ptr());
336  node->appendChild(row);
337 
338  stringstream value_s;
339  value_s << i;
340 
341  rowid = node->getOwnerDocument()->createAttribute(cms::xerces::uStr(id_tag.c_str()).ptr());
342  rowid ->setValue(cms::xerces::uStr(value_s.str().c_str()).ptr());
343  row ->setAttributeNode(rowid);
344 
345  stringstream row_s;
346 
347  for(int k=0;k<ncols;++k) row_s << " "<< matrix(i,k)<<" ";
348 
349  rowvalue =
350  node->getOwnerDocument()->createTextNode(cms::xerces::uStr(row_s.str().c_str()).ptr());
351  row->appendChild(rowvalue);
352  }//for loop on col
353 
354 
355 }
const std::string id_tag("id")
const std::string row_tag("row")
ZStr< XMLCh > uStr(char const *str)
int k[5][pyjets_maxn]
void EcalTBWeightsXMLTranslator::writeWeightMatrix ( xercesc::DOMNode *  node,
const EcalWeightSet::EcalWeightMatrix matrix 
)
staticprivate

Definition at line 283 of file EcalTBWeightsXMLTranslator.cc.

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

284  {
285 
286  DOMElement* row=nullptr;
287  DOMAttr* rowid=nullptr;
288  DOMText* rowvalue=nullptr;
289 
290  const int ncols =10;
291  const int nrows =3;
292 
293  for(int i=0;i<nrows;++i)
294  {
295 
296 
297  row= node->getOwnerDocument()->createElement( cms::xerces::uStr(row_tag.c_str()).ptr());
298  node->appendChild(row);
299 
300  stringstream value_s;
301  value_s << i;
302 
303  rowid = node->getOwnerDocument()->createAttribute(cms::xerces::uStr(id_tag.c_str()).ptr());
304  rowid ->setValue(cms::xerces::uStr(value_s.str().c_str()).ptr());
305  row ->setAttributeNode(rowid);
306 
307  stringstream row_s;
308 
309  for(int k=0;k<ncols;++k) row_s <<" " << matrix(i,k)<<" " ;
310 
311  rowvalue =
312  node->getOwnerDocument()->createTextNode(cms::xerces::uStr(row_s.str().c_str()).ptr());
313  row->appendChild(rowvalue);
314  }//for loop on col
315 
316 
317 }
const std::string id_tag("id")
const std::string row_tag("row")
ZStr< XMLCh > uStr(char const *str)
int k[5][pyjets_maxn]
void EcalTBWeightsXMLTranslator::writeWeightSet ( xercesc::DOMNode *  parentNode,
const EcalWeightSet ws 
)
staticprivate

Definition at line 253 of file EcalTBWeightsXMLTranslator.cc.

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().

254  {
255 
256 
257  xercesc::DOMDocument* doc = parentNode->getOwnerDocument();
258 
259  DOMElement * weightsetel= doc->createElement( cms::xerces::uStr(EcalWeightSet_tag.c_str()).ptr());
260  parentNode-> appendChild(weightsetel);
261 
262  DOMElement* wgtBS = doc->createElement( cms::xerces::uStr(wgtBeforeSwitch_tag.c_str()).ptr());
263  weightsetel->appendChild(wgtBS);
264 
265  DOMElement* wgtAS = doc->createElement(cms::xerces::uStr(wgtAfterSwitch_tag.c_str()).ptr());
266  weightsetel->appendChild(wgtAS);
267 
268  DOMElement* wgtChi2BS = doc->createElement( cms::xerces::uStr(wgtChi2BeforeSwitch_tag.c_str()).ptr());
269  weightsetel->appendChild(wgtChi2BS);
270 
271  DOMElement* wgtChi2AS = doc->createElement(cms::xerces::uStr(wgtChi2AfterSwitch_tag.c_str()).ptr());
272  weightsetel->appendChild(wgtChi2AS);
273 
276 
279 
280 }
EcalChi2WeightMatrix & getChi2WeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:31
const std::string EcalWeightSet_tag("EcalWeightSet")
static void writeWeightMatrix(xercesc::DOMNode *node, const EcalWeightSet::EcalWeightMatrix &matrix)
const std::string wgtChi2AfterSwitch_tag("Chi2WeightAfterSwitch")
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")
const std::string wgtAfterSwitch_tag("WeightAfterSwitch")
static void writeChi2WeightMatrix(xercesc::DOMNode *node, const EcalWeightSet::EcalChi2WeightMatrix &matrix)
int EcalTBWeightsXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalTBWeights record 
)
static

Definition at line 85 of file EcalTBWeightsXMLTranslator.cc.

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

87  {
89 
90  std::fstream fs(filename.c_str(),ios::out);
91  fs<< dumpXML(header,record);
92 
94 
95  return 0;
96 }
static std::string dumpXML(const EcalCondHeader &header, const EcalTBWeights &record)
void xercesTerminate()
Definition: Xerces.cc:23
void xercesInitialize()
Definition: Xerces.cc:18