CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 std::string dumpXML (const EcalCondHeader &header, const EcalWeightSet &record)
 
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 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 22 of file EcalWeightSetXMLTranslator.h.

Constructor & Destructor Documentation

EcalWeightSetXMLTranslator::EcalWeightSetXMLTranslator ( )
inline

Definition at line 26 of file EcalWeightSetXMLTranslator.h.

26 {};

Member Function Documentation

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

Definition at line 315 of file EcalWeightSetXMLTranslator.cc.

References hcal_timing_source_file_cfg::dump, xuti::EcalWeightSet_tag(), xuti::fromNative(), pyrootRender::root, AlCaHLTBitMon_QueryRunRegistry::string, xuti::toNative(), xuti::wgtAfterSwitch_tag(), xuti::wgtBeforeSwitch_tag(), xuti::wgtChi2AfterSwitch_tag(), xuti::wgtChi2BeforeSwitch_tag(), xuti::writeHeader(), and cms::concurrency::xercesInitialize().

316  {
317 
318 
320 
321  DOMImplementation* impl =
322  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
323 
324  DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
325  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
326 
327  DOMDocumentType* doctype = impl->createDocumentType( fromNative("XML").c_str(), 0, 0 );
328  DOMDocument * doc =
329  impl->createDocument( 0,fromNative(EcalWeightSet_tag).c_str(), doctype );
330 
331 
332  doc->setEncoding(fromNative("UTF-8").c_str() );
333  doc->setStandalone(true);
334  doc->setVersion(fromNative("1.0").c_str() );
335 
336  DOMElement* root = doc->getDocumentElement();
337 
338  xuti::writeHeader(root, header);
339 
340  DOMElement* wgtBS = doc->createElement(fromNative(wgtBeforeSwitch_tag).c_str());
341  root->appendChild(wgtBS);
342 
343  DOMElement* wgtAS = doc->createElement(fromNative(wgtAfterSwitch_tag).c_str());
344  root->appendChild(wgtAS);
345 
346  DOMElement* wgtChi2BS = doc->createElement(fromNative(wgtChi2BeforeSwitch_tag).c_str());
347  root->appendChild(wgtChi2BS);
348 
349  DOMElement* wgtChi2AS = doc->createElement(fromNative(wgtChi2AfterSwitch_tag).c_str());
350  root->appendChild(wgtChi2AS);
351 
352  write3x10(wgtBS,record);
353  write3x10(wgtAS,record);
354 
355  write10x10(wgtChi2BS,record);
356  write10x10(wgtChi2AS,record);
357 
358  std::string dump= toNative(writer->writeToString(*root));
359  doc->release();
360 
361  return dump;
362 
363 
364 }
const std::string EcalWeightSet_tag("EcalWeightSet")
void xercesInitialize()
Definition: Xerces.cc:17
const std::string wgtChi2AfterSwitch_tag("Chi2WeightAfterSwitch")
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
const std::string wgtBeforeSwitch_tag("WeightBeforeSwitch")
const std::string wgtChi2BeforeSwitch_tag("Chi2WeightBeforeSwitch")
const std::string wgtAfterSwitch_tag("WeightAfterSwitch")
XercesString fromNative(const char *str)
Definition: XercesString.h:31
static void write3x10(xercesc::DOMElement *node, const EcalWeightSet &record)
static void write10x10(xercesc::DOMElement *node, const EcalWeightSet &record)
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
int EcalWeightSetXMLTranslator::readXML ( const std::string &  filename,
EcalCondHeader header,
EcalWeightSet record 
)
static

Definition at line 25 of file EcalWeightSetXMLTranslator.cc.

References gather_cfg::cout, xuti::fromNative(), EcalWeightSet::getChi2WeightsAfterGainSwitch(), EcalWeightSet::getChi2WeightsBeforeGainSwitch(), xuti::getChildNode(), EcalWeightSet::getWeightsAfterGainSwitch(), EcalWeightSet::getWeightsBeforeGainSwitch(), i, xuti::id_tag(), mps_alisetup::parser, xuti::readHeader(), xuti::row_tag(), AlCaHLTBitMon_QueryRunRegistry::string, xuti::toNative(), puppiForMET_cff::weight, xuti::wgtAfterSwitch_tag(), xuti::wgtBeforeSwitch_tag(), xuti::wgtChi2AfterSwitch_tag(), xuti::wgtChi2BeforeSwitch_tag(), cms::concurrency::xercesInitialize(), and cms::concurrency::xercesTerminate().

27  {
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 << "EcalWeightSetXMLTranslator::Error parsing document" << std::endl;
41  return -1;
42  }
43 
44  DOMElement* elementRoot = xmlDoc->getDocumentElement();
45 
46  xuti::readHeader(elementRoot, header);
47  // get the first cell node
48  DOMNode * wgtBSnode=getChildNode(elementRoot,wgtBeforeSwitch_tag);
49  DOMNode * wgtASnode=getChildNode(elementRoot,wgtAfterSwitch_tag);
50  DOMNode * wgtChi2BSnode=getChildNode(elementRoot,wgtChi2BeforeSwitch_tag);
51  DOMNode * wgtChi2ASnode=getChildNode(elementRoot,wgtChi2AfterSwitch_tag);
52 
53 
54  DOMNode* rownode = getChildNode(wgtBSnode,row_tag);
55 
56  DOMElement* rowelement;
57 
58  // loop on row nodes
59  while (rownode){
60 
61  rowelement = dynamic_cast< xercesc::DOMElement* >(rownode);
62 
63  std::string rowid_s = toNative(rowelement->getAttribute(fromNative(id_tag).c_str()));
64 
65  std::stringstream rowid_ss(rowid_s);
66  int rowid = 0;
67  rowid_ss >> rowid;
68 
69  std::string weightrow = toNative(rownode->getTextContent());
70 
71  std::stringstream weightrow_s(weightrow);
72  double weight = 0;
73  int i = 0;
74  while(weightrow_s >> weight)
75  {
76  record.getWeightsBeforeGainSwitch()(i,rowid)= weight;
77  i++;
78  }
79 
80 
81  // get next cell
82  rownode = rownode->getNextSibling();
83 
84  while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
85  rownode = rownode->getNextSibling();
86 
87 
88  }
89 
90  rownode = getChildNode(wgtASnode,row_tag);
91 
92  // loop on row nodes
93  while (rownode){
94 
95  rowelement = dynamic_cast< xercesc::DOMElement* >(rownode);
96 
97  std::string rowid_s = toNative(rowelement->getAttribute(fromNative(id_tag).c_str()));
98 
99  std::stringstream rowid_ss(rowid_s);
100  int rowid = 0;
101  rowid_ss >> rowid;
102 
103  std::string weightrow = toNative(rownode->getTextContent());
104 
105  std::stringstream weightrow_s(weightrow);
106  double weight = 0;
107  int i = 0;
108  while(weightrow_s >> weight)
109  {
110  record.getWeightsAfterGainSwitch()(i,rowid)= weight;
111  i++;
112  }
113 
114 
115  // get next cell
116  rownode = rownode->getNextSibling();
117 
118  while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
119  rownode = rownode->getNextSibling();
120 
121 
122  }
123 
124  rownode = getChildNode(wgtChi2BSnode,row_tag);
125 
126 
127  // loop on row nodes
128  while (rownode){
129 
130  rowelement = dynamic_cast< xercesc::DOMElement* >(rownode);
131  std::string rowid_s = toNative(rowelement->getAttribute(fromNative(id_tag).c_str()));
132 
133  std::stringstream rowid_ss(rowid_s);
134  int rowid = 0;
135  rowid_ss >> rowid;
136 
137  std::string weightrow = toNative(rownode->getTextContent());
138 
139  std::stringstream weightrow_s(weightrow);
140  double weight = 0;
141  int i = 0;
142  while(weightrow_s >> weight)
143  {
144  record.getChi2WeightsBeforeGainSwitch()(i,rowid)= weight;
145  i++;
146  }
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  }
157 
158 
159  rownode = getChildNode(wgtChi2ASnode,row_tag);
160 
161 
162  // loop on row nodes
163  while (rownode){
164 
165  rowelement = dynamic_cast< xercesc::DOMElement* >(rownode);
166  std::string rowid_s = toNative(rowelement->getAttribute(fromNative(id_tag).c_str()));
167 
168  std::stringstream rowid_ss(rowid_s);
169  int rowid = 0;
170  rowid_ss >> rowid;
171 
172  std::string weightrow = toNative(rownode->getTextContent());
173 
174  std::stringstream weightrow_s(weightrow);
175  double weight = 0;
176  int i = 0;
177  while(weightrow_s >> weight)
178  {
179  record.getChi2WeightsAfterGainSwitch()(i,rowid)= weight;
180  i++;
181  }
182 
183 
184  // get next cell
185  rownode = rownode->getNextSibling();
186 
187  while (rownode && rownode->getNodeType( ) != DOMNode::ELEMENT_NODE)
188  rownode = rownode->getNextSibling();
189 
190 
191  }
192 
193  delete parser;
195  return 0;
196 
197 }
EcalChi2WeightMatrix & getChi2WeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:31
int i
Definition: DBlmapReader.cc:9
void xercesTerminate()
Definition: Xerces.cc:22
const std::string id_tag("id")
const std::string row_tag("row")
void xercesInitialize()
Definition: Xerces.cc:17
const std::string wgtChi2AfterSwitch_tag("Chi2WeightAfterSwitch")
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
EcalChi2WeightMatrix & getChi2WeightsAfterGainSwitch()
Definition: EcalWeightSet.h:32
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")
tuple filename
Definition: lut2db_cfg.py:20
XercesString fromNative(const char *str)
Definition: XercesString.h:31
tuple cout
Definition: gather_cfg.py:145
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
void EcalWeightSetXMLTranslator::write10x10 ( xercesc::DOMElement *  node,
const EcalWeightSet record 
)
staticprivate

Definition at line 216 of file EcalWeightSetXMLTranslator.cc.

References xuti::fromNative(), EcalWeightSet::getChi2WeightsAfterGainSwitch(), EcalWeightSet::getChi2WeightsBeforeGainSwitch(), i, xuti::id_tag(), relval_2017::k, xuti::row_tag(), xuti::toNative(), xuti::wgtChi2AfterSwitch_tag(), and xuti::wgtChi2BeforeSwitch_tag().

217  {
218 
219  DOMElement* row[10];
220  DOMAttr* rowid[10];
221  DOMText* rowvalue[10];
223 
224 
225  if(toNative(node->getNodeName()) == wgtChi2BeforeSwitch_tag)
226  {
227  echi2wmatrix = record.getChi2WeightsBeforeGainSwitch();
228 
229  }
230  if(toNative(node->getNodeName()) == wgtChi2AfterSwitch_tag)
231  {
232  echi2wmatrix = record.getChi2WeightsAfterGainSwitch();
233 
234  }
235 
236  for(int i=0;i<10;++i)
237  {
238 
239 
240  row[i] = node->getOwnerDocument()->createElement(fromNative(row_tag).c_str());
241  node->appendChild(row[i]);
242 
243  stringstream value_s;
244  value_s << i;
245 
246  rowid[i] = node->getOwnerDocument()->createAttribute(fromNative(id_tag).c_str());
247  rowid[i]->setValue(fromNative(value_s.str()).c_str());
248  row[i]->setAttributeNode(rowid[i]);
249 
250  stringstream row_s;
251 
252  for(int k=0;k<10;++k)
253  {
254  row_s << " ";
255  row_s << echi2wmatrix(k,i);
256  row_s << " ";
257  }//for loop on element
258 
259 
260  rowvalue[i] = node->getOwnerDocument()->createTextNode(fromNative(row_s.str()).c_str());
261  row[i]->appendChild(rowvalue[i]);
262  }//for loop on row
263 }
EcalChi2WeightMatrix & getChi2WeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:31
int i
Definition: DBlmapReader.cc:9
const std::string id_tag("id")
const std::string row_tag("row")
const std::string wgtChi2AfterSwitch_tag("Chi2WeightAfterSwitch")
EcalChi2WeightMatrix & getChi2WeightsAfterGainSwitch()
Definition: EcalWeightSet.h:32
math::Matrix< 10, 10 >::type EcalChi2WeightMatrix
Definition: EcalWeightSet.h:23
const std::string wgtChi2BeforeSwitch_tag("Chi2WeightBeforeSwitch")
XercesString fromNative(const char *str)
Definition: XercesString.h:31
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
void EcalWeightSetXMLTranslator::write3x10 ( xercesc::DOMElement *  node,
const EcalWeightSet record 
)
staticprivate

Definition at line 267 of file EcalWeightSetXMLTranslator.cc.

References xuti::fromNative(), EcalWeightSet::getWeightsAfterGainSwitch(), EcalWeightSet::getWeightsBeforeGainSwitch(), i, xuti::id_tag(), relval_2017::k, xuti::row_tag(), xuti::toNative(), xuti::wgtAfterSwitch_tag(), and xuti::wgtBeforeSwitch_tag().

268  {
269 
270  DOMElement* row[10];
271  DOMAttr* rowid[10];
272  DOMText* rowvalue[10];
274 
275 
276  if(toNative(node->getNodeName()) == wgtBeforeSwitch_tag)
277  ewmatrix = record.getWeightsBeforeGainSwitch();
278 
279  if(toNative(node->getNodeName()) == wgtAfterSwitch_tag)
280  ewmatrix = record.getWeightsAfterGainSwitch();
281 
282 
283  for(int i=0;i<10;++i)
284  {
285 
286  row[i] = node->getOwnerDocument()->createElement(fromNative(row_tag).c_str());
287  node->appendChild(row[i]);
288 
289  stringstream value_s;
290  value_s << i;
291 
292  rowid[i] = node->getOwnerDocument()->createAttribute(fromNative(id_tag).c_str());
293 
294  rowid[i]->setValue(fromNative(value_s.str()).c_str());
295 
296  row[i]->setAttributeNode(rowid[i]);
297 
298 
299  stringstream row_s;
300 
301  for(int k=0;k<3;++k)
302  {
303  row_s << " ";
304  row_s << ewmatrix(k,i);
305  row_s << " ";
306  }//for loop on element
307 
308 
309  rowvalue[i] = node->getOwnerDocument()->createTextNode(fromNative(row_s.str()).c_str());
310  row[i]->appendChild(rowvalue[i]);
311  }//for loop on row
312 }
int i
Definition: DBlmapReader.cc:9
const std::string id_tag("id")
const std::string row_tag("row")
const std::string wgtBeforeSwitch_tag("WeightBeforeSwitch")
EcalWeightMatrix & getWeightsAfterGainSwitch()
Definition: EcalWeightSet.h:30
EcalWeightMatrix & getWeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:29
const std::string wgtAfterSwitch_tag("WeightAfterSwitch")
XercesString fromNative(const char *str)
Definition: XercesString.h:31
math::Matrix< 3, 10 >::type EcalWeightMatrix
Definition: EcalWeightSet.h:22
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
int EcalWeightSetXMLTranslator::writeXML ( const std::string &  filename,
const EcalCondHeader header,
const EcalWeightSet record 
)
static

Definition at line 203 of file EcalWeightSetXMLTranslator.cc.

References EcalCondTools::dumpXML(), and GenerateHcalLaserBadRunList::out.

205  {
206 
207  std::fstream fs(filename.c_str(),ios::out);
208  fs<< dumpXML(header,record);
209  return 0;
210 
211 }
static std::string dumpXML(const EcalCondHeader &header, const EcalWeightSet &record)
tuple filename
Definition: lut2db_cfg.py:20