test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
MonitorXMLParser Class Reference

#include <MonitorXMLParser.h>

Public Member Functions

const std::vector< DB_ME > & getDB_ME (void) const
 
void load () throw ( std::runtime_error )
 
 MonitorXMLParser (const std::string &fromFile)
 
 ~MonitorXMLParser () throw ()
 

Private Member Functions

void handleElement (xercesc::DOMElement *element)
 

Private Attributes

std::vector< DB_MEDBMonitoringElements_
 
xercesc::XercesDOMParser * parser_
 
TagNamestags_
 
std::string xmlFile_
 

Detailed Description

Definition at line 159 of file MonitorXMLParser.h.

Constructor & Destructor Documentation

MonitorXMLParser::MonitorXMLParser ( const std::string &  fromFile)

Definition at line 18 of file MonitorXMLParser.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, alignCSCRings::e, ERROR_XERCES_INIT, cmsRelvalreport::exit, python.rootplot.argparse::message, parser_, fetchall_from_DQM_v2::release, tags_, XERCES_CPP_NAMESPACE_USE::transcode(), cms::concurrency::xercesInitialize(), and xmlFile_.

18  {
19 
20  try{
21 
23 
24  }catch( xercesc::XMLException& e ){
25 
26  char* message = xercesc::XMLString::transcode( e.getMessage() ) ;
27 
28  std::cerr << "XML toolkit initialization error: " << message << std::endl;
29 
30  xercesc::XMLString::release( &message );
31 
33 
34  }
35 
36  xmlFile_ = fromFile;
37  parser_ = new xercesc::XercesDOMParser();
38  tags_ = new TagNames();
39 
40 }
std::string xmlFile_
void xercesInitialize()
Definition: Xerces.cc:17
XMLCh * transcode(const T &fInput)
xercesc::XercesDOMParser * parser_
MonitorXMLParser::~MonitorXMLParser ( )
throw (
)

Definition at line 44 of file MonitorXMLParser.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, alignCSCRings::e, python.rootplot.argparse::message, parser_, fetchall_from_DQM_v2::release, tags_, XERCES_CPP_NAMESPACE_USE::transcode(), and cms::concurrency::xercesTerminate().

44  {
45 
46  try{
48  } catch ( xercesc::XMLException& e ){
49  char* message = xercesc::XMLString::transcode( e.getMessage() );
50  std::cerr << "XML toolkit teardown error: " << message << std::endl;
51  xercesc::XMLString::release( &message ) ;
52  }
53 
54  delete parser_;
55  delete tags_;
56 
57 }
void xercesTerminate()
Definition: Xerces.cc:22
XMLCh * transcode(const T &fInput)
xercesc::XercesDOMParser * parser_

Member Function Documentation

const std::vector< DB_ME >& MonitorXMLParser::getDB_ME ( void  ) const
inline

Definition at line 175 of file MonitorXMLParser.h.

References DBMonitoringElements_.

Referenced by MonitorElementsDb::MonitorElementsDb().

175 { return (DBMonitoringElements_ ); }
std::vector< DB_ME > DBMonitoringElements_
void MonitorXMLParser::handleElement ( xercesc::DOMElement *  element)
private

Definition at line 63 of file MonitorXMLParser.cc.

References DbQuery::alias, DbQuery::arg, TagNames::ATTR_ALIAS, TagNames::ATTR_ARG, TagNames::ATTR_LOOP, TagNames::ATTR_NAME, TagNames::ATTR_NCYCLE, TagNames::ATTR_TITLE, TagNames::ATTR_XBINS, TagNames::ATTR_XFROM, TagNames::ATTR_XTO, TagNames::ATTR_YBINS, TagNames::ATTR_YFROM, TagNames::ATTR_YTO, TagNames::ATTR_ZBINS, TagNames::ATTR_ZFROM, TagNames::ATTR_ZTO, EnergyCorrector::c, ztail::d, DBMonitoringElements_, alignCSCRings::e, DB_ME::loop, DB_ME::ncycle, DB_ME::queries, DbQuery::query, fetchall_from_DQM_v2::release, alignCSCRings::s, TagNames::TAG_1D, TagNames::TAG_2D, TagNames::TAG_ME, TagNames::TAG_QUERY, TagNames::TAG_TPROFILE, TagNames::TAG_TPROFILE2D, tags_, DB_ME::title, XERCES_CPP_NAMESPACE_USE::transcode(), DB_ME::type, DB_ME::xbins, DB_ME::xfrom, DB_ME::xto, DB_ME::ybins, DB_ME::yfrom, DB_ME::yto, DB_ME::zbins, DB_ME::zfrom, and DB_ME::zto.

Referenced by load().

63  {
64 
65  if( xercesc::XMLString::equals( tags_->TAG_ME, element->getTagName() ) ) {
66 
67  char* c;
68  std::stringstream s;
69  DB_ME me;
70  bool meok;
71 
72  meok = false;
73 
74  xercesc::DOMNodeList* d1Nodes = element->getElementsByTagName( tags_->TAG_1D );
75  const XMLSize_t d1Count = d1Nodes->getLength();
76 
77  for( XMLSize_t d1Index = 0; d1Index < d1Count; ++d1Index ){
78 
79  xercesc::DOMNode* d1Node = d1Nodes->item( d1Index ) ;
80 
81  xercesc::DOMElement* d1Element = dynamic_cast< xercesc::DOMElement* >( d1Node ) ;
82 
83  const XMLCh* d1titleXMLCh = d1Element->getAttribute( tags_->ATTR_TITLE ) ;
84  c = xercesc::XMLString::transcode( d1titleXMLCh );
85  me.type = "th1d";
86  me.title = c;
87  meok = true;
89 
90  const XMLCh* d1xbinsXMLCh = d1Element->getAttribute( tags_->ATTR_XBINS ) ;
91  c = xercesc::XMLString::transcode( d1xbinsXMLCh );
92  s.clear(); s.str( c );
93  s >> me.xbins;
95 
96  const XMLCh* d1xfromXMLCh = d1Element->getAttribute( tags_->ATTR_XFROM ) ;
97  c = xercesc::XMLString::transcode( d1xfromXMLCh );
98  s.clear(); s.str( c );
99  s >> me.xfrom;
101 
102  const XMLCh* d1xtoXMLCh = d1Element->getAttribute( tags_->ATTR_XTO ) ;
103  c = xercesc::XMLString::transcode( d1xtoXMLCh );
104  s.clear(); s.str( c );
105  s >> me.xto;
107 
108  const XMLCh* d1ncycleXMLCh = d1Element->getAttribute( tags_->ATTR_NCYCLE ) ;
109  c = xercesc::XMLString::transcode( d1ncycleXMLCh );
110  s.clear(); s.str( c );
111  s >> me.ncycle;
113 
114  const XMLCh* d1loopXMLCh = d1Element->getAttribute( tags_->ATTR_LOOP ) ;
115  c = xercesc::XMLString::transcode( d1loopXMLCh );
116  s.clear(); s.str( c );
117  s >> me.loop;
119 
120  me.ybins = 0;
121  me.yfrom = 0.0;
122  me.yto = 0.0;
123  me.zbins = 0;
124  me.zfrom = 0.0;
125  me.zto = 0.0;
126 
127  }
128 
129  xercesc::DOMNodeList* d2Nodes = element->getElementsByTagName( tags_->TAG_2D );
130  const XMLSize_t d2Count = d2Nodes->getLength();
131 
132  for( XMLSize_t d2Index = 0; d2Index < d2Count; ++d2Index ){
133 
134  xercesc::DOMNode* d2Node = d2Nodes->item( d2Index ) ;
135 
136  xercesc::DOMElement* d2Element = dynamic_cast< xercesc::DOMElement* >( d2Node ) ;
137 
138  const XMLCh* d2titleXMLCh = d2Element->getAttribute( tags_->ATTR_TITLE ) ;
139  c = xercesc::XMLString::transcode( d2titleXMLCh );
140  me.type = "th2d";
141  me.title = c;
142  meok = true;
144 
145  const XMLCh* d2xbinsXMLCh = d2Element->getAttribute( tags_->ATTR_XBINS ) ;
146  c = xercesc::XMLString::transcode( d2xbinsXMLCh );
147  s.clear(); s.str( c );
148  s >> me.xbins;
150 
151  const XMLCh* d2xfromXMLCh = d2Element->getAttribute( tags_->ATTR_XFROM ) ;
152  c = xercesc::XMLString::transcode( d2xfromXMLCh );
153  s.clear(); s.str( c );
154  s >> me.xfrom;
156 
157  const XMLCh* d2xtoXMLCh = d2Element->getAttribute( tags_->ATTR_XTO ) ;
158  c = xercesc::XMLString::transcode( d2xtoXMLCh );
159  s.clear(); s.str( c );
160  s >> me.xto;
162 
163  const XMLCh* d2ybinsXMLCh = d2Element->getAttribute( tags_->ATTR_YBINS ) ;
164  c = xercesc::XMLString::transcode( d2ybinsXMLCh );
165  s.clear(); s.str( c );
166  s >> me.ybins;
168 
169  const XMLCh* d2yfromXMLCh = d2Element->getAttribute( tags_->ATTR_YFROM ) ;
170  c = xercesc::XMLString::transcode( d2yfromXMLCh );
171  s.clear(); s.str( c );
172  s >> me.yfrom;
174 
175  const XMLCh* d2ytoXMLCh = d2Element->getAttribute( tags_->ATTR_YTO ) ;
176  c = xercesc::XMLString::transcode( d2ytoXMLCh );
177  s.clear(); s.str( c );
178  s >> me.yto;
180 
181  const XMLCh* d2ncycleXMLCh = d2Element->getAttribute( tags_->ATTR_NCYCLE ) ;
182  c = xercesc::XMLString::transcode( d2ncycleXMLCh );
183  s.clear(); s.str( c );
184  s >> me.ncycle;
186 
187  const XMLCh* d2loopXMLCh = d2Element->getAttribute( tags_->ATTR_LOOP ) ;
188  c = xercesc::XMLString::transcode( d2loopXMLCh );
189  s.clear(); s.str( c );
190  s >> me.loop;
192 
193  me.zbins = 0;
194  me.zfrom = 0.0;
195  me.zto = 0.0;
196 
197  }
198 
199  xercesc::DOMNodeList* tpNodes = element->getElementsByTagName( tags_->TAG_TPROFILE );
200  const XMLSize_t tpCount = tpNodes->getLength();
201 
202  for( XMLSize_t tpIndex = 0; tpIndex < tpCount; ++tpIndex ){
203 
204  xercesc::DOMNode* tpNode = tpNodes->item( tpIndex ) ;
205 
206  xercesc::DOMElement* tpElement = dynamic_cast< xercesc::DOMElement* >( tpNode ) ;
207 
208  const XMLCh* tptitleXMLCh = tpElement->getAttribute( tags_->ATTR_TITLE ) ;
209  c = xercesc::XMLString::transcode( tptitleXMLCh );
210  me.type = "tprofile";
211  me.title = c;
212  meok = true;
214 
215  const XMLCh* tpxbinsXMLCh = tpElement->getAttribute( tags_->ATTR_XBINS ) ;
216  c = xercesc::XMLString::transcode( tpxbinsXMLCh );
217  s.clear(); s.str( c );
218  s >> me.xbins;
220 
221  const XMLCh* tpxfromXMLCh = tpElement->getAttribute( tags_->ATTR_XFROM ) ;
222  c = xercesc::XMLString::transcode( tpxfromXMLCh );
223  s.clear(); s.str( c );
224  s >> me.xfrom;
226 
227  const XMLCh* tpxtoXMLCh = tpElement->getAttribute( tags_->ATTR_XTO ) ;
228  c = xercesc::XMLString::transcode( tpxtoXMLCh );
229  s.clear(); 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(); s.str( c );
236  s >> me.ybins;
238 
239  const XMLCh* tpyfromXMLCh = tpElement->getAttribute( tags_->ATTR_YFROM ) ;
240  c = xercesc::XMLString::transcode( tpyfromXMLCh );
241  s.clear(); s.str( c );
242  s >> me.yfrom;
244 
245  const XMLCh* tpytoXMLCh = tpElement->getAttribute( tags_->ATTR_YTO ) ;
246  c = xercesc::XMLString::transcode( tpytoXMLCh );
247  s.clear(); s.str( c );
248  s >> me.yto;
250 
251  const XMLCh* tpncycleXMLCh = tpElement->getAttribute( tags_->ATTR_NCYCLE ) ;
252  c = xercesc::XMLString::transcode( tpncycleXMLCh );
253  s.clear(); s.str( c );
254  s >> me.ncycle;
256 
257  const XMLCh* tploopXMLCh = tpElement->getAttribute( tags_->ATTR_LOOP ) ;
258  c = xercesc::XMLString::transcode( tploopXMLCh );
259  s.clear(); s.str( c );
260  s >> me.loop;
262 
263  me.zbins = 0;
264  me.zfrom = 0.0;
265  me.zto = 0.0;
266 
267  }
268 
269  xercesc::DOMNodeList* tp2dNodes = element->getElementsByTagName( tags_->TAG_TPROFILE2D );
270  const XMLSize_t tp2dCount = tp2dNodes->getLength();
271 
272  for( XMLSize_t tp2dIndex = 0; tp2dIndex < tp2dCount; ++tp2dIndex ){
273 
274  xercesc::DOMNode* tp2dNode = tp2dNodes->item( tp2dIndex ) ;
275 
276  xercesc::DOMElement* tp2dElement = dynamic_cast< xercesc::DOMElement* >( tp2dNode ) ;
277 
278  const XMLCh* tp2dtitleXMLCh = tp2dElement->getAttribute( tags_->ATTR_TITLE ) ;
279  c = xercesc::XMLString::transcode( tp2dtitleXMLCh );
280  me.type = "tprofile2d";
281  me.title = c;
282  meok = true;
284 
285  const XMLCh* tp2dxbinsXMLCh = tp2dElement->getAttribute( tags_->ATTR_XBINS ) ;
286  c = xercesc::XMLString::transcode( tp2dxbinsXMLCh );
287  s.clear(); s.str( c );
288  s >> me.xbins;
290 
291  const XMLCh* tp2dxfromXMLCh = tp2dElement->getAttribute( tags_->ATTR_XFROM ) ;
292  c = xercesc::XMLString::transcode( tp2dxfromXMLCh );
293  s.clear(); s.str( c );
294  s >> me.xfrom;
296 
297  const XMLCh* tp2dxtoXMLCh = tp2dElement->getAttribute( tags_->ATTR_XTO ) ;
298  c = xercesc::XMLString::transcode( tp2dxtoXMLCh );
299  s.clear(); s.str( c );
300  s >> me.xto;
302 
303  const XMLCh* tp2dybinsXMLCh = tp2dElement->getAttribute( tags_->ATTR_YBINS ) ;
304  c = xercesc::XMLString::transcode( tp2dybinsXMLCh );
305  s.clear(); s.str( c );
306  s >> me.ybins;
308 
309  const XMLCh* tp2dyfromXMLCh = tp2dElement->getAttribute( tags_->ATTR_YFROM ) ;
310  c = xercesc::XMLString::transcode( tp2dyfromXMLCh );
311  s.clear(); s.str( c );
312  s >> me.yfrom;
314 
315  const XMLCh* tp2dytoXMLCh = tp2dElement->getAttribute( tags_->ATTR_YTO ) ;
316  c = xercesc::XMLString::transcode( tp2dytoXMLCh );
317  s.clear(); s.str( c );
318  s >> me.yto;
320 
321  const XMLCh* tp2dzbinsXMLCh = tp2dElement->getAttribute( tags_->ATTR_ZBINS ) ;
322  c = xercesc::XMLString::transcode( tp2dzbinsXMLCh );
323  s.clear(); s.str( c );
324  s >> me.zbins;
326 
327  const XMLCh* tp2dzfromXMLCh = tp2dElement->getAttribute( tags_->ATTR_ZFROM ) ;
328  c = xercesc::XMLString::transcode( tp2dzfromXMLCh );
329  s.clear(); s.str( c );
330  s >> me.zfrom;
332 
333  const XMLCh* tp2dztoXMLCh = tp2dElement->getAttribute( tags_->ATTR_ZTO ) ;
334  c = xercesc::XMLString::transcode( tp2dztoXMLCh );
335  s.clear(); s.str( c );
336  s >> me.zto;
338 
339  const XMLCh* tp2dncycleXMLCh = tp2dElement->getAttribute( tags_->ATTR_NCYCLE ) ;
340  c = xercesc::XMLString::transcode( tp2dncycleXMLCh );
341  s.clear(); s.str( c );
342  s >> me.ncycle;
344 
345  const XMLCh* tp2dloopXMLCh = tp2dElement->getAttribute( tags_->ATTR_LOOP ) ;
346  c = xercesc::XMLString::transcode( tp2dloopXMLCh );
347  s.clear(); s.str( c );
348  s >> me.loop;
350 
351  }
352 
353 
354  xercesc::DOMNodeList* qNodes = element->getElementsByTagName( tags_->TAG_QUERY );
355  const XMLSize_t qCount = qNodes->getLength();
356 
357  for( XMLSize_t qIndex = 0; qIndex < qCount; ++qIndex ){
358 
359  xercesc::DOMNode* qNode = qNodes->item( qIndex ) ;
360 
361  xercesc::DOMElement* qElement = dynamic_cast< xercesc::DOMElement* >( qNode ) ;
362 
363  const XMLCh* nameXMLCh = qElement->getAttribute( tags_->ATTR_NAME ) ;
364  c = xercesc::XMLString::transcode( nameXMLCh );
365 
366  const XMLCh* argXMLCh = qElement->getAttribute( tags_->ATTR_ARG ) ;
367  char* d = xercesc::XMLString::transcode( argXMLCh );
368 
369  const XMLCh* aliasXMLCh = qElement->getAttribute( tags_->ATTR_ALIAS ) ;
370  char* e = xercesc::XMLString::transcode( aliasXMLCh );
371 
372  DbQuery tmpQuery;
373  tmpQuery.query = c;
374  tmpQuery.arg = d;
375  tmpQuery.alias = e;
376 
377  me.queries.push_back( tmpQuery );
378 
382 
383 
384  }
385 
386  if( meok ) DBMonitoringElements_.push_back( me );
387 
388  }
389 } // handleElement()
XMLCh * TAG_ME
std::string type
XMLCh * TAG_QUERY
XMLCh * ATTR_YTO
XMLCh * ATTR_ZBINS
XMLCh * ATTR_XBINS
XMLCh * ATTR_ARG
std::string alias
XMLCh * TAG_2D
double xto
unsigned int ncycle
double yfrom
XMLCh * ATTR_YFROM
tuple d
Definition: ztail.py:151
double yto
std::vector< DbQuery > queries
XMLCh * transcode(const T &fInput)
std::vector< DB_ME > DBMonitoringElements_
XMLCh * ATTR_ZTO
XMLCh * TAG_1D
XMLCh * ATTR_YBINS
double zfrom
XMLCh * ATTR_NAME
std::string title
XMLCh * ATTR_XTO
unsigned int loop
XMLCh * TAG_TPROFILE2D
XMLCh * ATTR_ALIAS
std::string arg
XMLCh * ATTR_NCYCLE
double zto
XMLCh * ATTR_TITLE
XMLCh * ATTR_LOOP
std::string query
XMLCh * ATTR_XFROM
XMLCh * TAG_TPROFILE
double xfrom
XMLCh * ATTR_ZFROM
void MonitorXMLParser::load ( )
throw (std::runtime_error
)

Definition at line 394 of file MonitorXMLParser.cc.

References alignCSCRings::e, handleElement(), python.rootplot.argparse::message, NULL, parser_, fetchall_from_DQM_v2::release, TagNames::TAG_DBE, tags_, XERCES_CPP_NAMESPACE_USE::transcode(), and xmlFile_.

Referenced by MonitorElementsDb::MonitorElementsDb().

394  {
395 
396  parser_->setValidationScheme( xercesc::XercesDOMParser::Val_Never );
397  parser_->setDoNamespaces( false );
398  parser_->setDoSchema( false );
399  parser_->setLoadExternalDTD( false );
400 
401  try{
402 
403  parser_->parse( xmlFile_.c_str() );
404 
405  xercesc::DOMDocument* xmlDoc = parser_->getDocument();
406 
407  xercesc::DOMElement* dbe = xmlDoc->getDocumentElement();
408 
409  if( NULL == dbe ){
410  throw( std::runtime_error( "empty XML document" ) ) ;
411  }
412 
413  if( xercesc::XMLString::equals( tags_->TAG_DBE, dbe->getTagName() ) ) {
414 
415  xercesc::DOMNodeList* children = dbe->getChildNodes();
416  const XMLSize_t nodeCount = children->getLength();
417 
418  for( XMLSize_t ix = 0 ; ix < nodeCount ; ++ix ){
419  xercesc::DOMNode* currentNode = children->item( ix );
420  if( NULL == currentNode ){
421  // null node...
422  continue;
423  }
424 
425  if( xercesc::DOMNode::ELEMENT_NODE != currentNode->getNodeType() ){
426  continue;
427  }
428 
429  xercesc::DOMElement* currentElement = dynamic_cast< xercesc::DOMElement* >( currentNode );
430 
431  handleElement( currentElement );
432 
433  }
434  }
435 
436  }catch( xercesc::XMLException& e ){
437 
438  char* message = xercesc::XMLString::transcode( e.getMessage() );
439 
440  std::ostringstream buf ;
441  buf << "Error parsing file: " << message << std::endl;
442 
443  xercesc::XMLString::release( &message );
444 
445  throw( std::runtime_error( buf.str() ) );
446 
447  }catch( const xercesc::DOMException& e ){
448 
449  char* message = xercesc::XMLString::transcode( e.getMessage() );
450 
451  std::ostringstream buf;
452  buf << "Encountered DOM Exception: " << message << std::endl;
453 
454  xercesc::XMLString::release( &message );
455 
456  throw( std::runtime_error( buf.str() ) );
457 
458  }
459 
460  return;
461 
462 } // load()
std::string xmlFile_
#define NULL
Definition: scimark2.h:8
XMLCh * transcode(const T &fInput)
void handleElement(xercesc::DOMElement *element)
xercesc::XercesDOMParser * parser_
XMLCh * TAG_DBE

Member Data Documentation

std::vector< DB_ME > MonitorXMLParser::DBMonitoringElements_
private

Definition at line 163 of file MonitorXMLParser.h.

Referenced by getDB_ME(), and handleElement().

xercesc::XercesDOMParser* MonitorXMLParser::parser_
private

Definition at line 165 of file MonitorXMLParser.h.

Referenced by load(), MonitorXMLParser(), and ~MonitorXMLParser().

TagNames* MonitorXMLParser::tags_
private

Definition at line 166 of file MonitorXMLParser.h.

Referenced by handleElement(), load(), MonitorXMLParser(), and ~MonitorXMLParser().

std::string MonitorXMLParser::xmlFile_
private

Definition at line 164 of file MonitorXMLParser.h.

Referenced by load(), and MonitorXMLParser().