CMS 3D CMS Logo

MonitorXMLParser.cc
Go to the documentation of this file.
1 
9 
10 #include <xercesc/dom/DOMDocument.hpp>
11 #include <xercesc/dom/DOMNodeList.hpp>
12 
13 #include <sstream>
14 #include <stdexcept>
15 
17 
19  try {
21 
22  } catch (xercesc::XMLException &e) {
23  char *message = xercesc::XMLString::transcode(e.getMessage());
24 
25  std::cerr << "XML toolkit initialization error: " << message << std::endl;
26 
28 
30  }
31 
32  xmlFile_ = fromFile;
33  parser_ = new xercesc::XercesDOMParser();
34  tags_ = new TagNames();
35 }
36 
37 // - - - - - - - - - - - - - - - - -
38 
40  try {
42  } catch (xercesc::XMLException &e) {
43  char *message = xercesc::XMLString::transcode(e.getMessage());
44  std::cerr << "XML toolkit teardown error: " << message << std::endl;
46  }
47 
48  delete parser_;
49  delete tags_;
50 }
51 
52 // - - - - - - - - - - - - - - - - -
53 
54 void MonitorXMLParser::handleElement(xercesc::DOMElement *element) {
55  if (xercesc::XMLString::equals(tags_->TAG_ME, element->getTagName())) {
56  char *c;
57  std::stringstream s;
58  DB_ME me;
59  bool meok;
60 
61  meok = false;
62 
63  xercesc::DOMNodeList *d1Nodes = element->getElementsByTagName(tags_->TAG_1D);
64  const XMLSize_t d1Count = d1Nodes->getLength();
65 
66  for (XMLSize_t d1Index = 0; d1Index < d1Count; ++d1Index) {
67  xercesc::DOMNode *d1Node = d1Nodes->item(d1Index);
68 
69  xercesc::DOMElement *d1Element = dynamic_cast<xercesc::DOMElement *>(d1Node);
70 
71  const XMLCh *d1titleXMLCh = d1Element->getAttribute(tags_->ATTR_TITLE);
72  c = xercesc::XMLString::transcode(d1titleXMLCh);
73  me.type = "th1d";
74  me.title = c;
75  meok = true;
77 
78  const XMLCh *d1xbinsXMLCh = d1Element->getAttribute(tags_->ATTR_XBINS);
79  c = xercesc::XMLString::transcode(d1xbinsXMLCh);
80  s.clear();
81  s.str(c);
82  s >> me.xbins;
84 
85  const XMLCh *d1xfromXMLCh = d1Element->getAttribute(tags_->ATTR_XFROM);
86  c = xercesc::XMLString::transcode(d1xfromXMLCh);
87  s.clear();
88  s.str(c);
89  s >> me.xfrom;
91 
92  const XMLCh *d1xtoXMLCh = d1Element->getAttribute(tags_->ATTR_XTO);
93  c = xercesc::XMLString::transcode(d1xtoXMLCh);
94  s.clear();
95  s.str(c);
96  s >> me.xto;
98 
99  const XMLCh *d1ncycleXMLCh = d1Element->getAttribute(tags_->ATTR_NCYCLE);
100  c = xercesc::XMLString::transcode(d1ncycleXMLCh);
101  s.clear();
102  s.str(c);
103  s >> me.ncycle;
105 
106  const XMLCh *d1loopXMLCh = d1Element->getAttribute(tags_->ATTR_LOOP);
107  c = xercesc::XMLString::transcode(d1loopXMLCh);
108  s.clear();
109  s.str(c);
110  s >> me.loop;
112 
113  me.ybins = 0;
114  me.yfrom = 0.0;
115  me.yto = 0.0;
116  me.zbins = 0;
117  me.zfrom = 0.0;
118  me.zto = 0.0;
119  }
120 
121  xercesc::DOMNodeList *d2Nodes = element->getElementsByTagName(tags_->TAG_2D);
122  const XMLSize_t d2Count = d2Nodes->getLength();
123 
124  for (XMLSize_t d2Index = 0; d2Index < d2Count; ++d2Index) {
125  xercesc::DOMNode *d2Node = d2Nodes->item(d2Index);
126 
127  xercesc::DOMElement *d2Element = dynamic_cast<xercesc::DOMElement *>(d2Node);
128 
129  const XMLCh *d2titleXMLCh = d2Element->getAttribute(tags_->ATTR_TITLE);
130  c = xercesc::XMLString::transcode(d2titleXMLCh);
131  me.type = "th2d";
132  me.title = c;
133  meok = true;
135 
136  const XMLCh *d2xbinsXMLCh = d2Element->getAttribute(tags_->ATTR_XBINS);
137  c = xercesc::XMLString::transcode(d2xbinsXMLCh);
138  s.clear();
139  s.str(c);
140  s >> me.xbins;
142 
143  const XMLCh *d2xfromXMLCh = d2Element->getAttribute(tags_->ATTR_XFROM);
144  c = xercesc::XMLString::transcode(d2xfromXMLCh);
145  s.clear();
146  s.str(c);
147  s >> me.xfrom;
149 
150  const XMLCh *d2xtoXMLCh = d2Element->getAttribute(tags_->ATTR_XTO);
151  c = xercesc::XMLString::transcode(d2xtoXMLCh);
152  s.clear();
153  s.str(c);
154  s >> me.xto;
156 
157  const XMLCh *d2ybinsXMLCh = d2Element->getAttribute(tags_->ATTR_YBINS);
158  c = xercesc::XMLString::transcode(d2ybinsXMLCh);
159  s.clear();
160  s.str(c);
161  s >> me.ybins;
163 
164  const XMLCh *d2yfromXMLCh = d2Element->getAttribute(tags_->ATTR_YFROM);
165  c = xercesc::XMLString::transcode(d2yfromXMLCh);
166  s.clear();
167  s.str(c);
168  s >> me.yfrom;
170 
171  const XMLCh *d2ytoXMLCh = d2Element->getAttribute(tags_->ATTR_YTO);
172  c = xercesc::XMLString::transcode(d2ytoXMLCh);
173  s.clear();
174  s.str(c);
175  s >> me.yto;
177 
178  const XMLCh *d2ncycleXMLCh = d2Element->getAttribute(tags_->ATTR_NCYCLE);
179  c = xercesc::XMLString::transcode(d2ncycleXMLCh);
180  s.clear();
181  s.str(c);
182  s >> me.ncycle;
184 
185  const XMLCh *d2loopXMLCh = d2Element->getAttribute(tags_->ATTR_LOOP);
186  c = xercesc::XMLString::transcode(d2loopXMLCh);
187  s.clear();
188  s.str(c);
189  s >> me.loop;
191 
192  me.zbins = 0;
193  me.zfrom = 0.0;
194  me.zto = 0.0;
195  }
196 
197  xercesc::DOMNodeList *tpNodes = element->getElementsByTagName(tags_->TAG_TPROFILE);
198  const XMLSize_t tpCount = tpNodes->getLength();
199 
200  for (XMLSize_t tpIndex = 0; tpIndex < tpCount; ++tpIndex) {
201  xercesc::DOMNode *tpNode = tpNodes->item(tpIndex);
202 
203  xercesc::DOMElement *tpElement = dynamic_cast<xercesc::DOMElement *>(tpNode);
204 
205  const XMLCh *tptitleXMLCh = tpElement->getAttribute(tags_->ATTR_TITLE);
206  c = xercesc::XMLString::transcode(tptitleXMLCh);
207  me.type = "tprofile";
208  me.title = c;
209  meok = true;
211 
212  const XMLCh *tpxbinsXMLCh = tpElement->getAttribute(tags_->ATTR_XBINS);
213  c = xercesc::XMLString::transcode(tpxbinsXMLCh);
214  s.clear();
215  s.str(c);
216  s >> me.xbins;
218 
219  const XMLCh *tpxfromXMLCh = tpElement->getAttribute(tags_->ATTR_XFROM);
220  c = xercesc::XMLString::transcode(tpxfromXMLCh);
221  s.clear();
222  s.str(c);
223  s >> me.xfrom;
225 
226  const XMLCh *tpxtoXMLCh = tpElement->getAttribute(tags_->ATTR_XTO);
227  c = xercesc::XMLString::transcode(tpxtoXMLCh);
228  s.clear();
229  s.str(c);
230  s >> me.xto;
232 
233  const XMLCh *tpybinsXMLCh = tpElement->getAttribute(tags_->ATTR_YBINS);
234  c = xercesc::XMLString::transcode(tpybinsXMLCh);
235  s.clear();
236  s.str(c);
237  s >> me.ybins;
239 
240  const XMLCh *tpyfromXMLCh = tpElement->getAttribute(tags_->ATTR_YFROM);
241  c = xercesc::XMLString::transcode(tpyfromXMLCh);
242  s.clear();
243  s.str(c);
244  s >> me.yfrom;
246 
247  const XMLCh *tpytoXMLCh = tpElement->getAttribute(tags_->ATTR_YTO);
248  c = xercesc::XMLString::transcode(tpytoXMLCh);
249  s.clear();
250  s.str(c);
251  s >> me.yto;
253 
254  const XMLCh *tpncycleXMLCh = tpElement->getAttribute(tags_->ATTR_NCYCLE);
255  c = xercesc::XMLString::transcode(tpncycleXMLCh);
256  s.clear();
257  s.str(c);
258  s >> me.ncycle;
260 
261  const XMLCh *tploopXMLCh = tpElement->getAttribute(tags_->ATTR_LOOP);
262  c = xercesc::XMLString::transcode(tploopXMLCh);
263  s.clear();
264  s.str(c);
265  s >> me.loop;
267 
268  me.zbins = 0;
269  me.zfrom = 0.0;
270  me.zto = 0.0;
271  }
272 
273  xercesc::DOMNodeList *tp2dNodes = element->getElementsByTagName(tags_->TAG_TPROFILE2D);
274  const XMLSize_t tp2dCount = tp2dNodes->getLength();
275 
276  for (XMLSize_t tp2dIndex = 0; tp2dIndex < tp2dCount; ++tp2dIndex) {
277  xercesc::DOMNode *tp2dNode = tp2dNodes->item(tp2dIndex);
278 
279  xercesc::DOMElement *tp2dElement = dynamic_cast<xercesc::DOMElement *>(tp2dNode);
280 
281  const XMLCh *tp2dtitleXMLCh = tp2dElement->getAttribute(tags_->ATTR_TITLE);
282  c = xercesc::XMLString::transcode(tp2dtitleXMLCh);
283  me.type = "tprofile2d";
284  me.title = c;
285  meok = true;
287 
288  const XMLCh *tp2dxbinsXMLCh = tp2dElement->getAttribute(tags_->ATTR_XBINS);
289  c = xercesc::XMLString::transcode(tp2dxbinsXMLCh);
290  s.clear();
291  s.str(c);
292  s >> me.xbins;
294 
295  const XMLCh *tp2dxfromXMLCh = tp2dElement->getAttribute(tags_->ATTR_XFROM);
296  c = xercesc::XMLString::transcode(tp2dxfromXMLCh);
297  s.clear();
298  s.str(c);
299  s >> me.xfrom;
301 
302  const XMLCh *tp2dxtoXMLCh = tp2dElement->getAttribute(tags_->ATTR_XTO);
303  c = xercesc::XMLString::transcode(tp2dxtoXMLCh);
304  s.clear();
305  s.str(c);
306  s >> me.xto;
308 
309  const XMLCh *tp2dybinsXMLCh = tp2dElement->getAttribute(tags_->ATTR_YBINS);
310  c = xercesc::XMLString::transcode(tp2dybinsXMLCh);
311  s.clear();
312  s.str(c);
313  s >> me.ybins;
315 
316  const XMLCh *tp2dyfromXMLCh = tp2dElement->getAttribute(tags_->ATTR_YFROM);
317  c = xercesc::XMLString::transcode(tp2dyfromXMLCh);
318  s.clear();
319  s.str(c);
320  s >> me.yfrom;
322 
323  const XMLCh *tp2dytoXMLCh = tp2dElement->getAttribute(tags_->ATTR_YTO);
324  c = xercesc::XMLString::transcode(tp2dytoXMLCh);
325  s.clear();
326  s.str(c);
327  s >> me.yto;
329 
330  const XMLCh *tp2dzbinsXMLCh = tp2dElement->getAttribute(tags_->ATTR_ZBINS);
331  c = xercesc::XMLString::transcode(tp2dzbinsXMLCh);
332  s.clear();
333  s.str(c);
334  s >> me.zbins;
336 
337  const XMLCh *tp2dzfromXMLCh = tp2dElement->getAttribute(tags_->ATTR_ZFROM);
338  c = xercesc::XMLString::transcode(tp2dzfromXMLCh);
339  s.clear();
340  s.str(c);
341  s >> me.zfrom;
343 
344  const XMLCh *tp2dztoXMLCh = tp2dElement->getAttribute(tags_->ATTR_ZTO);
345  c = xercesc::XMLString::transcode(tp2dztoXMLCh);
346  s.clear();
347  s.str(c);
348  s >> me.zto;
350 
351  const XMLCh *tp2dncycleXMLCh = tp2dElement->getAttribute(tags_->ATTR_NCYCLE);
352  c = xercesc::XMLString::transcode(tp2dncycleXMLCh);
353  s.clear();
354  s.str(c);
355  s >> me.ncycle;
357 
358  const XMLCh *tp2dloopXMLCh = tp2dElement->getAttribute(tags_->ATTR_LOOP);
359  c = xercesc::XMLString::transcode(tp2dloopXMLCh);
360  s.clear();
361  s.str(c);
362  s >> me.loop;
364  }
365 
366  xercesc::DOMNodeList *qNodes = element->getElementsByTagName(tags_->TAG_QUERY);
367  const XMLSize_t qCount = qNodes->getLength();
368 
369  for (XMLSize_t qIndex = 0; qIndex < qCount; ++qIndex) {
370  xercesc::DOMNode *qNode = qNodes->item(qIndex);
371 
372  xercesc::DOMElement *qElement = dynamic_cast<xercesc::DOMElement *>(qNode);
373 
374  const XMLCh *nameXMLCh = qElement->getAttribute(tags_->ATTR_NAME);
375  c = xercesc::XMLString::transcode(nameXMLCh);
376 
377  const XMLCh *argXMLCh = qElement->getAttribute(tags_->ATTR_ARG);
378  char *d = xercesc::XMLString::transcode(argXMLCh);
379 
380  const XMLCh *aliasXMLCh = qElement->getAttribute(tags_->ATTR_ALIAS);
381  char *e = xercesc::XMLString::transcode(aliasXMLCh);
382 
383  DbQuery tmpQuery;
384  tmpQuery.query = c;
385  tmpQuery.arg = d;
386  tmpQuery.alias = e;
387 
388  me.queries.push_back(tmpQuery);
389 
393  }
394 
395  if (meok)
396  DBMonitoringElements_.push_back(me);
397  }
398 } // handleElement()
399 
400 // - - - - - - - - - - - - - - - - - - -
401 
402 void MonitorXMLParser::load() noexcept(false) {
403  parser_->setValidationScheme(xercesc::XercesDOMParser::Val_Never);
404  parser_->setDoNamespaces(false);
405  parser_->setDoSchema(false);
406  parser_->setLoadExternalDTD(false);
407 
408  try {
409  parser_->parse(xmlFile_.c_str());
410 
411  xercesc::DOMDocument *xmlDoc = parser_->getDocument();
412 
413  xercesc::DOMElement *dbe = xmlDoc->getDocumentElement();
414 
415  if (nullptr == dbe) {
416  throw(std::runtime_error("empty XML document"));
417  }
418 
419  if (xercesc::XMLString::equals(tags_->TAG_DBE, dbe->getTagName())) {
420  xercesc::DOMNodeList *children = dbe->getChildNodes();
421  const XMLSize_t nodeCount = children->getLength();
422 
423  for (XMLSize_t ix = 0; ix < nodeCount; ++ix) {
424  xercesc::DOMNode *currentNode = children->item(ix);
425  if (nullptr == currentNode) {
426  // null node...
427  continue;
428  }
429 
430  if (xercesc::DOMNode::ELEMENT_NODE != currentNode->getNodeType()) {
431  continue;
432  }
433 
434  xercesc::DOMElement *currentElement = dynamic_cast<xercesc::DOMElement *>(currentNode);
435 
436  handleElement(currentElement);
437  }
438  }
439 
440  } catch (xercesc::XMLException &e) {
441  char *message = xercesc::XMLString::transcode(e.getMessage());
442 
443  std::ostringstream buf;
444  buf << "Error parsing file: " << message << std::endl;
445 
446  xercesc::XMLString::release(&message);
447 
448  throw(std::runtime_error(buf.str()));
449 
450  } catch (const xercesc::DOMException &e) {
451  char *message = xercesc::XMLString::transcode(e.getMessage());
452 
453  std::ostringstream buf;
454  buf << "Encountered DOM Exception: " << message << std::endl;
455 
456  xercesc::XMLString::release(&message);
457 
458  throw(std::runtime_error(buf.str()));
459  }
460 
461  return;
462 
463 } // load()
MonitorXMLParser::MonitorXMLParser
MonitorXMLParser(const std::string &fromFile)
Definition: MonitorXMLParser.cc:18
TagNames::TAG_DBE
XMLCh * TAG_DBE
Definition: MonitorXMLParser.h:54
TagNames::TAG_ME
XMLCh * TAG_ME
Definition: MonitorXMLParser.h:55
funct::false
false
Definition: Factorize.h:29
ERROR_XERCES_INIT
Definition: MonitorXMLParser.h:23
class-composition.children
children
Definition: class-composition.py:88
TagNames::TAG_2D
XMLCh * TAG_2D
Definition: MonitorXMLParser.h:57
MonitorXMLParser.h
monitor db xml elements parsing tool
TagNames::TAG_TPROFILE
XMLCh * TAG_TPROFILE
Definition: MonitorXMLParser.h:58
DbQuery::alias
std::string alias
Definition: MonitorXMLParser.h:30
MonitorXMLParser::load
void load() noexcept(false)
Definition: MonitorXMLParser.cc:402
alignCSCRings.s
s
Definition: alignCSCRings.py:92
TagNames::ATTR_XBINS
XMLCh * ATTR_XBINS
Definition: MonitorXMLParser.h:63
MonitorXMLParser::DBMonitoringElements_
std::vector< DB_ME > DBMonitoringElements_
Definition: MonitorXMLParser.h:156
TagNames::ATTR_NCYCLE
XMLCh * ATTR_NCYCLE
Definition: MonitorXMLParser.h:72
MonitorXMLParser::parser_
xercesc::XercesDOMParser * parser_
Definition: MonitorXMLParser.h:158
equals
bool equals(const edm::RefToBase< Jet > &j1, const edm::RefToBase< Jet > &j2)
Definition: DeepCMVATagInfoProducer.cc:56
TagNames::ATTR_ZTO
XMLCh * ATTR_ZTO
Definition: MonitorXMLParser.h:71
TagNames::ATTR_ZBINS
XMLCh * ATTR_ZBINS
Definition: MonitorXMLParser.h:69
TagNames::ATTR_YFROM
XMLCh * ATTR_YFROM
Definition: MonitorXMLParser.h:67
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TagNames::ATTR_NAME
XMLCh * ATTR_NAME
Definition: MonitorXMLParser.h:74
TagNames::ATTR_XTO
XMLCh * ATTR_XTO
Definition: MonitorXMLParser.h:65
fetchall_from_DQM_v2.release
release
Definition: fetchall_from_DQM_v2.py:92
DB_ME
Definition: MonitorXMLParser.h:33
TagNames::ATTR_ALIAS
XMLCh * ATTR_ALIAS
Definition: MonitorXMLParser.h:76
MonitorXMLParser::xmlFile_
std::string xmlFile_
Definition: MonitorXMLParser.h:157
Xerces.h
cms::concurrency::xercesTerminate
void xercesTerminate()
Definition: Xerces.cc:23
TagNames::ATTR_LOOP
XMLCh * ATTR_LOOP
Definition: MonitorXMLParser.h:73
DbQuery
Definition: MonitorXMLParser.h:27
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
TagNames::ATTR_XFROM
XMLCh * ATTR_XFROM
Definition: MonitorXMLParser.h:64
TagNames::TAG_1D
XMLCh * TAG_1D
Definition: MonitorXMLParser.h:56
DbQuery::arg
std::string arg
Definition: MonitorXMLParser.h:29
TagNames::ATTR_YBINS
XMLCh * ATTR_YBINS
Definition: MonitorXMLParser.h:66
MonitorXMLParser::tags_
TagNames * tags_
Definition: MonitorXMLParser.h:159
TagNames::TAG_QUERY
XMLCh * TAG_QUERY
Definition: MonitorXMLParser.h:60
DbQuery::query
std::string query
Definition: MonitorXMLParser.h:28
TagNames::TAG_TPROFILE2D
XMLCh * TAG_TPROFILE2D
Definition: MonitorXMLParser.h:59
MonitorXMLParser::~MonitorXMLParser
~MonitorXMLParser()
Definition: MonitorXMLParser.cc:39
ALCARECOPromptCalibProdSiPixelAli0T_cff.throw
throw
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:9
TagNames::ATTR_ARG
XMLCh * ATTR_ARG
Definition: MonitorXMLParser.h:75
ztail.d
d
Definition: ztail.py:151
TagNames
Definition: MonitorXMLParser.h:52
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
hlt_dqm_clientPB-live_cfg.me
me
Definition: hlt_dqm_clientPB-live_cfg.py:61
TagNames::ATTR_YTO
XMLCh * ATTR_YTO
Definition: MonitorXMLParser.h:68
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
TagNames::ATTR_ZFROM
XMLCh * ATTR_ZFROM
Definition: MonitorXMLParser.h:70
cms::concurrency::xercesInitialize
void xercesInitialize()
Definition: Xerces.cc:18
TagNames::ATTR_TITLE
XMLCh * ATTR_TITLE
Definition: MonitorXMLParser.h:62
MonitorXMLParser::handleElement
void handleElement(xercesc::DOMElement *element)
Definition: MonitorXMLParser.cc:54
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37