Go to the documentation of this file.00001
00002
00011 #include <xercesc/util/PlatformUtils.hpp>
00012
00013 #include <xercesc/dom/DOMDocument.hpp>
00014 #include <xercesc/dom/DOMNodeList.hpp>
00015
00016 #include <sstream>
00017 #include <stdexcept>
00018
00019 #include "DQM/EcalBarrelMonitorDbModule/interface/MonitorXMLParser.h"
00020
00021 MonitorXMLParser::MonitorXMLParser( const std::string& fromFile ) {
00022
00023 try{
00024
00025 xercesc::XMLPlatformUtils::Initialize();
00026
00027 }catch( xercesc::XMLException& e ){
00028
00029 char* message = xercesc::XMLString::transcode( e.getMessage() ) ;
00030
00031 std::cerr << "XML toolkit initialization error: " << message << std::endl;
00032
00033 xercesc::XMLString::release( &message );
00034
00035 exit( ERROR_XERCES_INIT );
00036
00037 }
00038
00039 xmlFile_ = fromFile;
00040 parser_ = new xercesc::XercesDOMParser();
00041 tags_ = new TagNames();
00042
00043 }
00044
00045
00046
00047 MonitorXMLParser::~MonitorXMLParser() throw() {
00048
00049 try{
00050 xercesc::XMLPlatformUtils::Terminate();
00051 } catch ( xercesc::XMLException& e ){
00052 char* message = xercesc::XMLString::transcode( e.getMessage() );
00053 std::cerr << "XML toolkit teardown error: " << message << std::endl;
00054 xercesc::XMLString::release( &message ) ;
00055 }
00056
00057 delete parser_;
00058 delete tags_;
00059
00060 }
00061
00062
00063
00064
00065
00066 void MonitorXMLParser::handleElement( xercesc::DOMElement* element ){
00067
00068 if( xercesc::XMLString::equals( tags_->TAG_ME, element->getTagName() ) ) {
00069
00070 char* c;
00071 std::stringstream s;
00072 DB_ME me;
00073 bool meok;
00074
00075 meok = false;
00076
00077 xercesc::DOMNodeList* d1Nodes = element->getElementsByTagName( tags_->TAG_1D );
00078 const XMLSize_t d1Count = d1Nodes->getLength();
00079
00080 for( XMLSize_t d1Index = 0; d1Index < d1Count; ++d1Index ){
00081
00082 xercesc::DOMNode* d1Node = d1Nodes->item( d1Index ) ;
00083
00084 xercesc::DOMElement* d1Element = dynamic_cast< xercesc::DOMElement* >( d1Node ) ;
00085
00086 const XMLCh* d1titleXMLCh = d1Element->getAttribute( tags_->ATTR_TITLE ) ;
00087 c = xercesc::XMLString::transcode( d1titleXMLCh );
00088 me.type = "th1d";
00089 me.title = c;
00090 meok = true;
00091 xercesc::XMLString::release( &c );
00092
00093 const XMLCh* d1xbinsXMLCh = d1Element->getAttribute( tags_->ATTR_XBINS ) ;
00094 c = xercesc::XMLString::transcode( d1xbinsXMLCh );
00095 s.clear(); s.str( c );
00096 s >> me.xbins;
00097 xercesc::XMLString::release( &c );
00098
00099 const XMLCh* d1xfromXMLCh = d1Element->getAttribute( tags_->ATTR_XFROM ) ;
00100 c = xercesc::XMLString::transcode( d1xfromXMLCh );
00101 s.clear(); s.str( c );
00102 s >> me.xfrom;
00103 xercesc::XMLString::release( &c );
00104
00105 const XMLCh* d1xtoXMLCh = d1Element->getAttribute( tags_->ATTR_XTO ) ;
00106 c = xercesc::XMLString::transcode( d1xtoXMLCh );
00107 s.clear(); s.str( c );
00108 s >> me.xto;
00109 xercesc::XMLString::release( &c );
00110
00111 const XMLCh* d1ncycleXMLCh = d1Element->getAttribute( tags_->ATTR_NCYCLE ) ;
00112 c = xercesc::XMLString::transcode( d1ncycleXMLCh );
00113 s.clear(); s.str( c );
00114 s >> me.ncycle;
00115 xercesc::XMLString::release( &c );
00116
00117 const XMLCh* d1loopXMLCh = d1Element->getAttribute( tags_->ATTR_LOOP ) ;
00118 c = xercesc::XMLString::transcode( d1loopXMLCh );
00119 s.clear(); s.str( c );
00120 s >> me.loop;
00121 xercesc::XMLString::release( &c );
00122
00123 me.ybins = 0;
00124 me.yfrom = 0.0;
00125 me.yto = 0.0;
00126 me.zbins = 0;
00127 me.zfrom = 0.0;
00128 me.zto = 0.0;
00129
00130 }
00131
00132 xercesc::DOMNodeList* d2Nodes = element->getElementsByTagName( tags_->TAG_2D );
00133 const XMLSize_t d2Count = d2Nodes->getLength();
00134
00135 for( XMLSize_t d2Index = 0; d2Index < d2Count; ++d2Index ){
00136
00137 xercesc::DOMNode* d2Node = d2Nodes->item( d2Index ) ;
00138
00139 xercesc::DOMElement* d2Element = dynamic_cast< xercesc::DOMElement* >( d2Node ) ;
00140
00141 const XMLCh* d2titleXMLCh = d2Element->getAttribute( tags_->ATTR_TITLE ) ;
00142 c = xercesc::XMLString::transcode( d2titleXMLCh );
00143 me.type = "th2d";
00144 me.title = c;
00145 meok = true;
00146 xercesc::XMLString::release( &c );
00147
00148 const XMLCh* d2xbinsXMLCh = d2Element->getAttribute( tags_->ATTR_XBINS ) ;
00149 c = xercesc::XMLString::transcode( d2xbinsXMLCh );
00150 s.clear(); s.str( c );
00151 s >> me.xbins;
00152 xercesc::XMLString::release( &c );
00153
00154 const XMLCh* d2xfromXMLCh = d2Element->getAttribute( tags_->ATTR_XFROM ) ;
00155 c = xercesc::XMLString::transcode( d2xfromXMLCh );
00156 s.clear(); s.str( c );
00157 s >> me.xfrom;
00158 xercesc::XMLString::release( &c );
00159
00160 const XMLCh* d2xtoXMLCh = d2Element->getAttribute( tags_->ATTR_XTO ) ;
00161 c = xercesc::XMLString::transcode( d2xtoXMLCh );
00162 s.clear(); s.str( c );
00163 s >> me.xto;
00164 xercesc::XMLString::release( &c );
00165
00166 const XMLCh* d2ybinsXMLCh = d2Element->getAttribute( tags_->ATTR_YBINS ) ;
00167 c = xercesc::XMLString::transcode( d2ybinsXMLCh );
00168 s.clear(); s.str( c );
00169 s >> me.ybins;
00170 xercesc::XMLString::release( &c );
00171
00172 const XMLCh* d2yfromXMLCh = d2Element->getAttribute( tags_->ATTR_YFROM ) ;
00173 c = xercesc::XMLString::transcode( d2yfromXMLCh );
00174 s.clear(); s.str( c );
00175 s >> me.yfrom;
00176 xercesc::XMLString::release( &c );
00177
00178 const XMLCh* d2ytoXMLCh = d2Element->getAttribute( tags_->ATTR_YTO ) ;
00179 c = xercesc::XMLString::transcode( d2ytoXMLCh );
00180 s.clear(); s.str( c );
00181 s >> me.yto;
00182 xercesc::XMLString::release( &c );
00183
00184 const XMLCh* d2ncycleXMLCh = d2Element->getAttribute( tags_->ATTR_NCYCLE ) ;
00185 c = xercesc::XMLString::transcode( d2ncycleXMLCh );
00186 s.clear(); s.str( c );
00187 s >> me.ncycle;
00188 xercesc::XMLString::release( &c );
00189
00190 const XMLCh* d2loopXMLCh = d2Element->getAttribute( tags_->ATTR_LOOP ) ;
00191 c = xercesc::XMLString::transcode( d2loopXMLCh );
00192 s.clear(); s.str( c );
00193 s >> me.loop;
00194 xercesc::XMLString::release( &c );
00195
00196 me.zbins = 0;
00197 me.zfrom = 0.0;
00198 me.zto = 0.0;
00199
00200 }
00201
00202 xercesc::DOMNodeList* tpNodes = element->getElementsByTagName( tags_->TAG_TPROFILE );
00203 const XMLSize_t tpCount = tpNodes->getLength();
00204
00205 for( XMLSize_t tpIndex = 0; tpIndex < tpCount; ++tpIndex ){
00206
00207 xercesc::DOMNode* tpNode = tpNodes->item( tpIndex ) ;
00208
00209 xercesc::DOMElement* tpElement = dynamic_cast< xercesc::DOMElement* >( tpNode ) ;
00210
00211 const XMLCh* tptitleXMLCh = tpElement->getAttribute( tags_->ATTR_TITLE ) ;
00212 c = xercesc::XMLString::transcode( tptitleXMLCh );
00213 me.type = "tprofile";
00214 me.title = c;
00215 meok = true;
00216 xercesc::XMLString::release( &c );
00217
00218 const XMLCh* tpxbinsXMLCh = tpElement->getAttribute( tags_->ATTR_XBINS ) ;
00219 c = xercesc::XMLString::transcode( tpxbinsXMLCh );
00220 s.clear(); s.str( c );
00221 s >> me.xbins;
00222 xercesc::XMLString::release( &c );
00223
00224 const XMLCh* tpxfromXMLCh = tpElement->getAttribute( tags_->ATTR_XFROM ) ;
00225 c = xercesc::XMLString::transcode( tpxfromXMLCh );
00226 s.clear(); s.str( c );
00227 s >> me.xfrom;
00228 xercesc::XMLString::release( &c );
00229
00230 const XMLCh* tpxtoXMLCh = tpElement->getAttribute( tags_->ATTR_XTO ) ;
00231 c = xercesc::XMLString::transcode( tpxtoXMLCh );
00232 s.clear(); s.str( c );
00233 s >> me.xto;
00234 xercesc::XMLString::release( &c );
00235
00236 const XMLCh* tpybinsXMLCh = tpElement->getAttribute( tags_->ATTR_YBINS ) ;
00237 c = xercesc::XMLString::transcode( tpybinsXMLCh );
00238 s.clear(); s.str( c );
00239 s >> me.ybins;
00240 xercesc::XMLString::release( &c );
00241
00242 const XMLCh* tpyfromXMLCh = tpElement->getAttribute( tags_->ATTR_YFROM ) ;
00243 c = xercesc::XMLString::transcode( tpyfromXMLCh );
00244 s.clear(); s.str( c );
00245 s >> me.yfrom;
00246 xercesc::XMLString::release( &c );
00247
00248 const XMLCh* tpytoXMLCh = tpElement->getAttribute( tags_->ATTR_YTO ) ;
00249 c = xercesc::XMLString::transcode( tpytoXMLCh );
00250 s.clear(); s.str( c );
00251 s >> me.yto;
00252 xercesc::XMLString::release( &c );
00253
00254 const XMLCh* tpncycleXMLCh = tpElement->getAttribute( tags_->ATTR_NCYCLE ) ;
00255 c = xercesc::XMLString::transcode( tpncycleXMLCh );
00256 s.clear(); s.str( c );
00257 s >> me.ncycle;
00258 xercesc::XMLString::release( &c );
00259
00260 const XMLCh* tploopXMLCh = tpElement->getAttribute( tags_->ATTR_LOOP ) ;
00261 c = xercesc::XMLString::transcode( tploopXMLCh );
00262 s.clear(); s.str( c );
00263 s >> me.loop;
00264 xercesc::XMLString::release( &c );
00265
00266 me.zbins = 0;
00267 me.zfrom = 0.0;
00268 me.zto = 0.0;
00269
00270 }
00271
00272 xercesc::DOMNodeList* tp2dNodes = element->getElementsByTagName( tags_->TAG_TPROFILE2D );
00273 const XMLSize_t tp2dCount = tp2dNodes->getLength();
00274
00275 for( XMLSize_t tp2dIndex = 0; tp2dIndex < tp2dCount; ++tp2dIndex ){
00276
00277 xercesc::DOMNode* tp2dNode = tp2dNodes->item( tp2dIndex ) ;
00278
00279 xercesc::DOMElement* tp2dElement = dynamic_cast< xercesc::DOMElement* >( tp2dNode ) ;
00280
00281 const XMLCh* tp2dtitleXMLCh = tp2dElement->getAttribute( tags_->ATTR_TITLE ) ;
00282 c = xercesc::XMLString::transcode( tp2dtitleXMLCh );
00283 me.type = "tprofile2d";
00284 me.title = c;
00285 meok = true;
00286 xercesc::XMLString::release( &c );
00287
00288 const XMLCh* tp2dxbinsXMLCh = tp2dElement->getAttribute( tags_->ATTR_XBINS ) ;
00289 c = xercesc::XMLString::transcode( tp2dxbinsXMLCh );
00290 s.clear(); s.str( c );
00291 s >> me.xbins;
00292 xercesc::XMLString::release( &c );
00293
00294 const XMLCh* tp2dxfromXMLCh = tp2dElement->getAttribute( tags_->ATTR_XFROM ) ;
00295 c = xercesc::XMLString::transcode( tp2dxfromXMLCh );
00296 s.clear(); s.str( c );
00297 s >> me.xfrom;
00298 xercesc::XMLString::release( &c );
00299
00300 const XMLCh* tp2dxtoXMLCh = tp2dElement->getAttribute( tags_->ATTR_XTO ) ;
00301 c = xercesc::XMLString::transcode( tp2dxtoXMLCh );
00302 s.clear(); s.str( c );
00303 s >> me.xto;
00304 xercesc::XMLString::release( &c );
00305
00306 const XMLCh* tp2dybinsXMLCh = tp2dElement->getAttribute( tags_->ATTR_YBINS ) ;
00307 c = xercesc::XMLString::transcode( tp2dybinsXMLCh );
00308 s.clear(); s.str( c );
00309 s >> me.ybins;
00310 xercesc::XMLString::release( &c );
00311
00312 const XMLCh* tp2dyfromXMLCh = tp2dElement->getAttribute( tags_->ATTR_YFROM ) ;
00313 c = xercesc::XMLString::transcode( tp2dyfromXMLCh );
00314 s.clear(); s.str( c );
00315 s >> me.yfrom;
00316 xercesc::XMLString::release( &c );
00317
00318 const XMLCh* tp2dytoXMLCh = tp2dElement->getAttribute( tags_->ATTR_YTO ) ;
00319 c = xercesc::XMLString::transcode( tp2dytoXMLCh );
00320 s.clear(); s.str( c );
00321 s >> me.yto;
00322 xercesc::XMLString::release( &c );
00323
00324 const XMLCh* tp2dzbinsXMLCh = tp2dElement->getAttribute( tags_->ATTR_ZBINS ) ;
00325 c = xercesc::XMLString::transcode( tp2dzbinsXMLCh );
00326 s.clear(); s.str( c );
00327 s >> me.zbins;
00328 xercesc::XMLString::release( &c );
00329
00330 const XMLCh* tp2dzfromXMLCh = tp2dElement->getAttribute( tags_->ATTR_ZFROM ) ;
00331 c = xercesc::XMLString::transcode( tp2dzfromXMLCh );
00332 s.clear(); s.str( c );
00333 s >> me.zfrom;
00334 xercesc::XMLString::release( &c );
00335
00336 const XMLCh* tp2dztoXMLCh = tp2dElement->getAttribute( tags_->ATTR_ZTO ) ;
00337 c = xercesc::XMLString::transcode( tp2dztoXMLCh );
00338 s.clear(); s.str( c );
00339 s >> me.zto;
00340 xercesc::XMLString::release( &c );
00341
00342 const XMLCh* tp2dncycleXMLCh = tp2dElement->getAttribute( tags_->ATTR_NCYCLE ) ;
00343 c = xercesc::XMLString::transcode( tp2dncycleXMLCh );
00344 s.clear(); s.str( c );
00345 s >> me.ncycle;
00346 xercesc::XMLString::release( &c );
00347
00348 const XMLCh* tp2dloopXMLCh = tp2dElement->getAttribute( tags_->ATTR_LOOP ) ;
00349 c = xercesc::XMLString::transcode( tp2dloopXMLCh );
00350 s.clear(); s.str( c );
00351 s >> me.loop;
00352 xercesc::XMLString::release( &c );
00353
00354 }
00355
00356
00357 xercesc::DOMNodeList* qNodes = element->getElementsByTagName( tags_->TAG_QUERY );
00358 const XMLSize_t qCount = qNodes->getLength();
00359
00360 for( XMLSize_t qIndex = 0; qIndex < qCount; ++qIndex ){
00361
00362 xercesc::DOMNode* qNode = qNodes->item( qIndex ) ;
00363
00364 xercesc::DOMElement* qElement = dynamic_cast< xercesc::DOMElement* >( qNode ) ;
00365
00366 const XMLCh* nameXMLCh = qElement->getAttribute( tags_->ATTR_NAME ) ;
00367 c = xercesc::XMLString::transcode( nameXMLCh );
00368
00369 const XMLCh* argXMLCh = qElement->getAttribute( tags_->ATTR_ARG ) ;
00370 char* d = xercesc::XMLString::transcode( argXMLCh );
00371
00372 const XMLCh* aliasXMLCh = qElement->getAttribute( tags_->ATTR_ALIAS ) ;
00373 char* e = xercesc::XMLString::transcode( aliasXMLCh );
00374
00375 DbQuery tmpQuery;
00376 tmpQuery.query = c;
00377 tmpQuery.arg = d;
00378 tmpQuery.alias = e;
00379
00380 me.queries.push_back( tmpQuery );
00381
00382 xercesc::XMLString::release( &c );
00383 xercesc::XMLString::release( &d );
00384 xercesc::XMLString::release( &e );
00385
00386
00387 }
00388
00389 if( meok ) DBMonitoringElements_.push_back( me );
00390
00391 }
00392 }
00393
00394
00395
00396
00397 void MonitorXMLParser::load() throw( std::runtime_error ) {
00398
00399 parser_->setValidationScheme( xercesc::XercesDOMParser::Val_Never );
00400 parser_->setDoNamespaces( false );
00401 parser_->setDoSchema( false );
00402 parser_->setLoadExternalDTD( false );
00403
00404 try{
00405
00406 parser_->parse( xmlFile_.c_str() );
00407
00408 xercesc::DOMDocument* xmlDoc = parser_->getDocument();
00409
00410 xercesc::DOMElement* dbe = xmlDoc->getDocumentElement();
00411
00412 if( NULL == dbe ){
00413 throw( std::runtime_error( "empty XML document" ) ) ;
00414 }
00415
00416 if( xercesc::XMLString::equals( tags_->TAG_DBE, dbe->getTagName() ) ) {
00417
00418 xercesc::DOMNodeList* children = dbe->getChildNodes();
00419 const XMLSize_t nodeCount = children->getLength();
00420
00421 for( XMLSize_t ix = 0 ; ix < nodeCount ; ++ix ){
00422 xercesc::DOMNode* currentNode = children->item( ix );
00423 if( NULL == currentNode ){
00424
00425 continue;
00426 }
00427
00428 if( xercesc::DOMNode::ELEMENT_NODE != currentNode->getNodeType() ){
00429 continue;
00430 }
00431
00432 xercesc::DOMElement* currentElement = dynamic_cast< xercesc::DOMElement* >( currentNode );
00433
00434 handleElement( currentElement );
00435
00436 }
00437 }
00438
00439 }catch( xercesc::XMLException& e ){
00440
00441 char* message = xercesc::XMLString::transcode( e.getMessage() );
00442
00443 std::ostringstream buf ;
00444 buf << "Error parsing file: " << message << std::endl;
00445
00446 xercesc::XMLString::release( &message );
00447
00448 throw( std::runtime_error( buf.str() ) );
00449
00450 }catch( const xercesc::DOMException& e ){
00451
00452 char* message = xercesc::XMLString::transcode( e.getMessage() );
00453
00454 std::ostringstream buf;
00455 buf << "Encountered DOM Exception: " << message << std::endl;
00456
00457 xercesc::XMLString::release( &message );
00458
00459 throw( std::runtime_error( buf.str() ) );
00460
00461 }
00462
00463 return;
00464
00465 }
00466