CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/DQM/EcalBarrelMonitorDbModule/interface/MonitorXMLParser.h

Go to the documentation of this file.
00001 // $Id: MonitorXMLParser.h,v 1.7 2008/04/03 05:51:36 dellaric Exp $
00002 
00011 #ifndef MonitorXMLParser_h
00012 #define MonitorXMLParser_h
00013 
00014 #include <string>
00015 #include <vector>
00016 #include <map>
00017 #include <iostream>
00018 
00019 #include <xercesc/dom/DOM.hpp>
00020 #include <xercesc/dom/DOMElement.hpp>
00021 #include <xercesc/parsers/XercesDOMParser.hpp>
00022 
00023 // - - - - - - - - - - - - - - - - - - - -
00024 
00025 enum { ERROR_ARGS = 1 ,
00026        ERROR_XERCES_INIT ,
00027        ERROR_PARSE ,
00028        ERROR_EMPTY_DOCUMENT
00029 };
00030 
00031 // - - - - - - - - - - - - - - - - - - - -
00032 
00033 struct DbQuery { std::string query;
00034                  std::string arg;
00035                  std::string alias; };
00036 
00037 struct DB_ME { std::string type;
00038                std::string title;
00039                int xbins; double xfrom; double xto; 
00040                int ybins; double yfrom; double yto;
00041                int zbins; double zfrom; double zto;
00042                unsigned int ncycle;
00043                unsigned int loop;
00044                std::vector< DbQuery > queries; };
00045 
00046 // - - - - - - - - - - - - - - - - - - - -
00047 
00048 class TagNames {
00049 
00050 public:
00051   XMLCh* TAG_DBE;
00052   XMLCh* TAG_ME;
00053   XMLCh* TAG_1D;
00054   XMLCh* TAG_2D;
00055   XMLCh* TAG_TPROFILE;
00056   XMLCh* TAG_TPROFILE2D;
00057   XMLCh* TAG_QUERY;
00058 
00059   XMLCh* ATTR_TITLE;
00060   XMLCh* ATTR_XBINS;
00061   XMLCh* ATTR_XFROM;
00062   XMLCh* ATTR_XTO;
00063   XMLCh* ATTR_YBINS;
00064   XMLCh* ATTR_YFROM;
00065   XMLCh* ATTR_YTO;
00066   XMLCh* ATTR_ZBINS;
00067   XMLCh* ATTR_ZFROM;
00068   XMLCh* ATTR_ZTO;
00069   XMLCh* ATTR_NCYCLE;
00070   XMLCh* ATTR_LOOP;
00071   XMLCh* ATTR_NAME;
00072   XMLCh* ATTR_ARG;
00073   XMLCh* ATTR_ALIAS;  
00074 
00075   TagNames() :
00076     TAG_DBE( xercesc::XMLString::transcode( "dbelements" ) ),
00077     TAG_ME( xercesc::XMLString::transcode( "me" ) ),
00078     TAG_1D( xercesc::XMLString::transcode( "th1d" ) ),
00079     TAG_2D( xercesc::XMLString::transcode( "th2d" ) ),
00080     TAG_TPROFILE( xercesc::XMLString::transcode( "tprofile" ) ),
00081     TAG_TPROFILE2D( xercesc::XMLString::transcode( "tprofile2d" ) ),
00082     TAG_QUERY( xercesc::XMLString::transcode( "query" ) ),
00083 
00084     ATTR_TITLE( xercesc::XMLString::transcode( "title" ) ),
00085     ATTR_XBINS( xercesc::XMLString::transcode( "xbins" ) ),   
00086     ATTR_XFROM( xercesc::XMLString::transcode( "xfrom" ) ),
00087     ATTR_XTO( xercesc::XMLString::transcode( "xto" ) ),
00088     ATTR_YBINS( xercesc::XMLString::transcode( "ybins" ) ),
00089     ATTR_YFROM( xercesc::XMLString::transcode( "yfrom" ) ),
00090     ATTR_YTO( xercesc::XMLString::transcode( "yto" ) ),
00091     ATTR_ZBINS( xercesc::XMLString::transcode( "ybins" ) ),
00092     ATTR_ZFROM( xercesc::XMLString::transcode( "yfrom" ) ),
00093     ATTR_ZTO( xercesc::XMLString::transcode( "yto" ) ),
00094     ATTR_NCYCLE( xercesc::XMLString::transcode( "ncycle" ) ),
00095     ATTR_LOOP( xercesc::XMLString::transcode( "loop" ) ),
00096     ATTR_NAME( xercesc::XMLString::transcode( "name" ) ),
00097     ATTR_ARG( xercesc::XMLString::transcode( "arg" ) ),
00098     ATTR_ALIAS( xercesc::XMLString::transcode( "alias" ) )  { 
00099 
00100     return ;
00101 
00102   }
00103 
00104 
00105   ~TagNames() throw(){
00106     
00107     try{
00108 
00109       xercesc::XMLString::release( &TAG_DBE ) ;
00110       xercesc::XMLString::release( &TAG_ME ) ;
00111       xercesc::XMLString::release( &TAG_1D ) ;
00112       xercesc::XMLString::release( &TAG_2D ) ;
00113       xercesc::XMLString::release( &TAG_TPROFILE ) ;
00114       xercesc::XMLString::release( &TAG_TPROFILE2D ) ;
00115       xercesc::XMLString::release( &TAG_QUERY ) ;
00116       
00117       xercesc::XMLString::release( &ATTR_TITLE ) ;
00118       xercesc::XMLString::release( &ATTR_XFROM ) ;
00119       xercesc::XMLString::release( &ATTR_XTO ) ;
00120       xercesc::XMLString::release( &ATTR_XBINS ) ;
00121       xercesc::XMLString::release( &ATTR_YFROM ) ;
00122       xercesc::XMLString::release( &ATTR_YTO ) ;
00123       xercesc::XMLString::release( &ATTR_YBINS ) ;
00124       xercesc::XMLString::release( &ATTR_NCYCLE ) ;
00125       xercesc::XMLString::release( &ATTR_LOOP ) ;
00126       xercesc::XMLString::release( &ATTR_NAME ) ;
00127       xercesc::XMLString::release( &ATTR_ARG ) ;
00128       xercesc::XMLString::release( &ATTR_ALIAS ) ;
00129 
00130     }catch( xercesc::XMLException& e ){
00131    
00132       char* message = xercesc::XMLString::transcode( e.getMessage() );
00133    
00134       std::ostringstream buf ;
00135       buf << "Error parsing file: " << message << std::flush;
00136    
00137       xercesc::XMLString::release( &message );
00138    
00139       throw( std::runtime_error( buf.str() ) );
00140    
00141     }catch( const xercesc::DOMException& e ){
00142    
00143       char* message = xercesc::XMLString::transcode( e.getMessage() );
00144    
00145       std::ostringstream buf;
00146       buf << "Encountered DOM Exception: " << message << std::flush;
00147    
00148       xercesc::XMLString::release( &message );
00149    
00150       throw( std::runtime_error( buf.str() ) );
00151    
00152     }
00153 
00154   } 
00155 
00156 }; // class TagNames
00157 
00158 
00159 // - - - - - - - - - - - - - - - - - - - -
00160 
00161 
00162 class MonitorXMLParser {
00163 
00164 private:
00165   
00166   std::vector< DB_ME >      DBMonitoringElements_;
00167   std::string               xmlFile_;
00168   xercesc::XercesDOMParser* parser_;
00169   TagNames*                 tags_;
00170   void handleElement( xercesc::DOMElement* element );
00171 
00172 public:
00173 
00174   MonitorXMLParser( const std::string& fromFile );
00175 
00176   ~MonitorXMLParser() throw();
00177 
00178   const std::vector< DB_ME > & getDB_ME( void ) const { return (DBMonitoringElements_ ); }
00179 
00180   void load() throw( std::runtime_error ); 
00181 
00182 }; // class MonitorXMLParser
00183 
00184 #endif // MonitorXMLParser_h