Go to the documentation of this file.00001 #include "DQMServices/ClientConfig/interface/QTestConfigurationParser.h"
00002 #include "DQMServices/ClientConfig/interface/QTestParameterNames.h"
00003 #include "DQMServices/ClientConfig/interface/ParserFunctions.h"
00004 #include <cstring>
00005 #include <stdexcept>
00014 using namespace xercesc;
00015
00016 int QTestConfigurationParser::s_numberOfInstances = 0;
00017
00018
00019 QTestConfigurationParser::QTestConfigurationParser(){
00020
00021 qtestParamNames=new QTestParameterNames();
00022
00023 try {
00024 if (s_numberOfInstances==0)
00025 XMLPlatformUtils::Initialize();
00026 }
00027 catch (const XMLException& e) {
00028 throw(std::runtime_error("Standard pool exception : Fatal Error on pool::TrivialFileCatalog"));
00029 }
00030
00031 ++s_numberOfInstances;
00032 }
00033
00034 QTestConfigurationParser::~QTestConfigurationParser(){
00035 delete qtestParamNames;
00036 qtestParamNames = 0;
00037 }
00038
00039 bool QTestConfigurationParser::parseQTestsConfiguration(){
00040 testsToDisable.clear();
00041 testsRequested.clear();
00042 mapMonitorElementTests.clear();
00043 bool qtErrors= this->qtestsConfig();
00044 bool meErrors= this->monitorElementTestsMap();
00045 return (qtErrors||meErrors);
00046
00047 }
00048
00049 bool QTestConfigurationParser::qtestsConfig(){
00050
00051 std::string testActivationOFF="false";
00052
00053 unsigned int qtestTagsNum =
00054 doc()->getElementsByTagName(qtxml::_toDOMS("QTEST"))->getLength();
00055
00056 for (unsigned int i=0; i<qtestTagsNum; ++i){
00058 DOMNode* qtestNode =
00059 doc()->getElementsByTagName(qtxml::_toDOMS("QTEST"))->item(i);
00060
00061
00063 if (! qtestNode){
00064 return true;
00065 }
00066 DOMElement* qtestElement = static_cast<DOMElement *>(qtestNode);
00067 if (! qtestElement){
00068 return true;
00069 }
00070 std::string qtestName = qtxml::_toString (qtestElement->getAttribute (qtxml::_toDOMS ("name")));
00071 std::string activate = qtxml::_toString (qtestElement->getAttribute (qtxml::_toDOMS ("activate")));
00072 if(!std::strcmp(activate.c_str(),testActivationOFF.c_str())) {
00073 testsToDisable.push_back(qtestName);
00074 }else{
00075
00077 DOMNodeList *typeNodePrefix
00078 = qtestElement->getElementsByTagName (qtxml::_toDOMS ("TYPE"));
00079
00080 if (typeNodePrefix->getLength () != 1)return true;
00081
00082
00083 DOMElement *prefixNode = dynamic_cast <DOMElement *> (typeNodePrefix->item (0));
00084 if (!prefixNode)return true;
00085
00086 DOMText *prefixText = dynamic_cast <DOMText *> (prefixNode->getFirstChild());
00087 if (!prefixText)return true;
00088
00089 std::string qtestType = qtxml::_toString (prefixText->getData ());
00090
00091 testsRequested[qtestName]= this->getParams(qtestElement, qtestType);
00092
00093 if( this->checkParameters(qtestName, qtestType)) return true;
00094 }
00095
00096 }
00097
00098 return false;
00099
00100 }
00101
00102 std::map<std::string, std::string> QTestConfigurationParser::getParams(DOMElement* qtestElement, std::string qtestType){
00103
00104 std::map<std::string, std::string> paramNamesValues;
00105 paramNamesValues["type"]=qtestType;
00106
00107 DOMNodeList *arguments = qtestElement->getElementsByTagName (qtxml::_toDOMS ("PARAM"));
00108
00109 for (unsigned int i=0; i<arguments->getLength(); ++i){
00110 DOMElement *argNode = dynamic_cast <DOMElement *> ( arguments ->item(i));
00111 std::string regExp = qtxml::_toString (argNode->getAttribute (qtxml::_toDOMS ("name")));
00112 DOMText *argText = dynamic_cast <DOMText *> (argNode->getFirstChild());
00113 if (!argText){
00114 break;
00115 }
00116
00117 std::string regExpValue = qtxml::_toString (argText->getData());
00118 paramNamesValues[regExp]=regExpValue;
00119 }
00120
00121 return paramNamesValues;
00122
00123 }
00124
00125 bool QTestConfigurationParser::checkParameters(std::string qtestName, std::string qtestType){
00126
00127 std::vector<std::string> paramNames=qtestParamNames->getTestParamNames(qtestType);
00128
00129
00130
00131
00132
00133
00134 paramNames.push_back("error");
00135 paramNames.push_back("warning");
00136
00137 std::map<std::string, std::string> namesMap=testsRequested[qtestName];
00138
00139 for(std::vector<std::string>::iterator namesItr=paramNames.begin(); namesItr!=paramNames.end(); ++namesItr){
00140 if(namesMap.find(*namesItr)==namesMap.end()){
00141 return true;
00142 }
00143 }
00144
00145 return false;
00146 }
00147
00148 bool QTestConfigurationParser::monitorElementTestsMap(){
00149
00150 std::string testON="true";
00151 std::string testOFF="false";
00152
00153 unsigned int linkTagsNum =
00154 doc()->getElementsByTagName(qtxml::_toDOMS("LINK"))->getLength();
00155
00156
00157 for (unsigned int i=0; i<linkTagsNum; ++i){
00158
00159 DOMNode* linkNode =
00160 doc()->getElementsByTagName(qtxml::_toDOMS("LINK"))->item(i);
00162 if (! linkNode){
00163 return true;
00164 }
00165 DOMElement* linkElement = static_cast<DOMElement *>(linkNode);
00166 if (! linkElement){
00167 return true;
00168 }
00169 std::string linkName = qtxml::_toString (linkElement->getAttribute (qtxml::_toDOMS ("name")));
00170
00171 DOMNodeList *testList = linkElement->getElementsByTagName (qtxml::_toDOMS ("TestName"));
00172 unsigned int numberOfTests=testList->getLength();
00173
00174 std::vector<std::string> qualityTestList;
00175 for(unsigned int tt=0; tt<numberOfTests; ++tt){
00176 DOMElement * testElement = dynamic_cast <DOMElement *> ( testList ->item(tt));
00177 if (!testElement ){
00178 return true;
00179 }
00180
00181 std::string activate = qtxml::_toString (testElement ->getAttribute (qtxml::_toDOMS ("activate")));
00182
00183 DOMText *argText = dynamic_cast <DOMText *> (testElement ->getFirstChild());
00184
00185 if(!std::strcmp(activate.c_str(),testON.c_str())) {
00186 if (!argText){
00187 return true;
00188 }else{
00189 std::string regExpValue = qtxml::_toString (argText->getData());
00190 qualityTestList.push_back(regExpValue);
00191 }
00192 }
00193 if(!std::strcmp(activate.c_str(),testOFF.c_str())) {
00194 if (argText) {
00195 std::string regExpValue = qtxml::_toString (argText->getData());
00196
00197 }
00198 }
00199
00200 }
00201
00202
00203 if(qualityTestList.size()) mapMonitorElementTests[linkName]=qualityTestList;
00204 }
00205
00206
00207 return false;
00208
00209
00210
00211 }
00212
00213