Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:54:30

0001 
0002 /*!
0003   \file MonitorXMLParser.h
0004   \brief monitor db xml elements parsing tool
0005   \author B. Gobbo
0006 */
0007 
0008 #ifndef MonitorXMLParser_h
0009 #define MonitorXMLParser_h
0010 
0011 #include <iostream>
0012 #include <map>
0013 #include <sstream>
0014 #include <string>
0015 #include <vector>
0016 
0017 #include <xercesc/dom/DOM.hpp>
0018 #include <xercesc/dom/DOMElement.hpp>
0019 #include <xercesc/parsers/XercesDOMParser.hpp>
0020 
0021 // - - - - - - - - - - - - - - - - - - - -
0022 
0023 enum { ERROR_ARGS = 1, ERROR_XERCES_INIT, ERROR_PARSE, ERROR_EMPTY_DOCUMENT };
0024 
0025 // - - - - - - - - - - - - - - - - - - - -
0026 
0027 struct DbQuery {
0028   std::string query;
0029   std::string arg;
0030   std::string alias;
0031 };
0032 
0033 struct DB_ME {
0034   std::string type;
0035   std::string title;
0036   int xbins;
0037   double xfrom;
0038   double xto;
0039   int ybins;
0040   double yfrom;
0041   double yto;
0042   int zbins;
0043   double zfrom;
0044   double zto;
0045   unsigned int ncycle;
0046   unsigned int loop;
0047   std::vector<DbQuery> queries;
0048 };
0049 
0050 // - - - - - - - - - - - - - - - - - - - -
0051 
0052 class TagNames {
0053 public:
0054   XMLCh *TAG_DBE;
0055   XMLCh *TAG_ME;
0056   XMLCh *TAG_1D;
0057   XMLCh *TAG_2D;
0058   XMLCh *TAG_TPROFILE;
0059   XMLCh *TAG_TPROFILE2D;
0060   XMLCh *TAG_QUERY;
0061 
0062   XMLCh *ATTR_TITLE;
0063   XMLCh *ATTR_XBINS;
0064   XMLCh *ATTR_XFROM;
0065   XMLCh *ATTR_XTO;
0066   XMLCh *ATTR_YBINS;
0067   XMLCh *ATTR_YFROM;
0068   XMLCh *ATTR_YTO;
0069   XMLCh *ATTR_ZBINS;
0070   XMLCh *ATTR_ZFROM;
0071   XMLCh *ATTR_ZTO;
0072   XMLCh *ATTR_NCYCLE;
0073   XMLCh *ATTR_LOOP;
0074   XMLCh *ATTR_NAME;
0075   XMLCh *ATTR_ARG;
0076   XMLCh *ATTR_ALIAS;
0077 
0078   TagNames()
0079       : TAG_DBE(xercesc::XMLString::transcode("dbelements")),
0080         TAG_ME(xercesc::XMLString::transcode("me")),
0081         TAG_1D(xercesc::XMLString::transcode("th1d")),
0082         TAG_2D(xercesc::XMLString::transcode("th2d")),
0083         TAG_TPROFILE(xercesc::XMLString::transcode("tprofile")),
0084         TAG_TPROFILE2D(xercesc::XMLString::transcode("tprofile2d")),
0085         TAG_QUERY(xercesc::XMLString::transcode("query")),
0086 
0087         ATTR_TITLE(xercesc::XMLString::transcode("title")),
0088         ATTR_XBINS(xercesc::XMLString::transcode("xbins")),
0089         ATTR_XFROM(xercesc::XMLString::transcode("xfrom")),
0090         ATTR_XTO(xercesc::XMLString::transcode("xto")),
0091         ATTR_YBINS(xercesc::XMLString::transcode("ybins")),
0092         ATTR_YFROM(xercesc::XMLString::transcode("yfrom")),
0093         ATTR_YTO(xercesc::XMLString::transcode("yto")),
0094         ATTR_ZBINS(xercesc::XMLString::transcode("ybins")),
0095         ATTR_ZFROM(xercesc::XMLString::transcode("yfrom")),
0096         ATTR_ZTO(xercesc::XMLString::transcode("yto")),
0097         ATTR_NCYCLE(xercesc::XMLString::transcode("ncycle")),
0098         ATTR_LOOP(xercesc::XMLString::transcode("loop")),
0099         ATTR_NAME(xercesc::XMLString::transcode("name")),
0100         ATTR_ARG(xercesc::XMLString::transcode("arg")),
0101         ATTR_ALIAS(xercesc::XMLString::transcode("alias")) {
0102     return;
0103   }
0104 
0105   ~TagNames() noexcept(false) {
0106     try {
0107       xercesc::XMLString::release(&TAG_DBE);
0108       xercesc::XMLString::release(&TAG_ME);
0109       xercesc::XMLString::release(&TAG_1D);
0110       xercesc::XMLString::release(&TAG_2D);
0111       xercesc::XMLString::release(&TAG_TPROFILE);
0112       xercesc::XMLString::release(&TAG_TPROFILE2D);
0113       xercesc::XMLString::release(&TAG_QUERY);
0114 
0115       xercesc::XMLString::release(&ATTR_TITLE);
0116       xercesc::XMLString::release(&ATTR_XFROM);
0117       xercesc::XMLString::release(&ATTR_XTO);
0118       xercesc::XMLString::release(&ATTR_XBINS);
0119       xercesc::XMLString::release(&ATTR_YFROM);
0120       xercesc::XMLString::release(&ATTR_YTO);
0121       xercesc::XMLString::release(&ATTR_YBINS);
0122       xercesc::XMLString::release(&ATTR_NCYCLE);
0123       xercesc::XMLString::release(&ATTR_LOOP);
0124       xercesc::XMLString::release(&ATTR_NAME);
0125       xercesc::XMLString::release(&ATTR_ARG);
0126       xercesc::XMLString::release(&ATTR_ALIAS);
0127 
0128     } catch (xercesc::XMLException &e) {
0129       char *message = xercesc::XMLString::transcode(e.getMessage());
0130 
0131       std::ostringstream buf;
0132       buf << "Error parsing file: " << message << std::flush;
0133 
0134       xercesc::XMLString::release(&message);
0135 
0136       throw(std::runtime_error(buf.str()));
0137 
0138     } catch (const xercesc::DOMException &e) {
0139       char *message = xercesc::XMLString::transcode(e.getMessage());
0140 
0141       std::ostringstream buf;
0142       buf << "Encountered DOM Exception: " << message << std::flush;
0143 
0144       xercesc::XMLString::release(&message);
0145 
0146       throw(std::runtime_error(buf.str()));
0147     }
0148   }
0149 
0150 };  // class TagNames
0151 
0152 // - - - - - - - - - - - - - - - - - - - -
0153 
0154 class MonitorXMLParser {
0155 private:
0156   std::vector<DB_ME> DBMonitoringElements_;
0157   std::string xmlFile_;
0158   xercesc::XercesDOMParser *parser_;
0159   TagNames *tags_;
0160   void handleElement(xercesc::DOMElement *element);
0161 
0162 public:
0163   MonitorXMLParser(const std::string &fromFile);
0164 
0165   ~MonitorXMLParser() throw();
0166 
0167   const std::vector<DB_ME> &getDB_ME(void) const { return (DBMonitoringElements_); }
0168 
0169   void load() noexcept(false);
0170 
0171 };  // class MonitorXMLParser
0172 
0173 #endif  // MonitorXMLParser_h