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 if(paramNames.size() == 0) {
00129
00130 return true;
00131 }
00132 paramNames.push_back("error");
00133 paramNames.push_back("warning");
00134
00135 std::map<std::string, std::string> namesMap=testsRequested[qtestName];
00136
00137 for(std::vector<std::string>::iterator namesItr=paramNames.begin(); namesItr!=paramNames.end(); ++namesItr){
00138 if(namesMap.find(*namesItr)==namesMap.end()){
00139 return true;
00140 }
00141 }
00142
00143 return false;
00144 }
00145
00146 bool QTestConfigurationParser::monitorElementTestsMap(){
00147
00148 std::string testON="true";
00149 std::string testOFF="false";
00150
00151 unsigned int linkTagsNum =
00152 doc->getElementsByTagName(qtxml::_toDOMS("LINK"))->getLength();
00153
00154
00155 for (unsigned int i=0; i<linkTagsNum; ++i){
00156
00157 DOMNode* linkNode =
00158 doc->getElementsByTagName(qtxml::_toDOMS("LINK"))->item(i);
00160 if (! linkNode){
00161 return true;
00162 }
00163 DOMElement* linkElement = static_cast<DOMElement *>(linkNode);
00164 if (! linkElement){
00165 return true;
00166 }
00167 std::string linkName = qtxml::_toString (linkElement->getAttribute (qtxml::_toDOMS ("name")));
00168
00169 DOMNodeList *testList = linkElement->getElementsByTagName (qtxml::_toDOMS ("TestName"));
00170 unsigned int numberOfTests=testList->getLength();
00171
00172 std::vector<std::string> qualityTestList;
00173 for(unsigned int tt=0; tt<numberOfTests; ++tt){
00174 DOMElement * testElement = dynamic_cast <DOMElement *> ( testList ->item(tt));
00175 if (!testElement ){
00176 return true;
00177 }
00178
00179 std::string activate = qtxml::_toString (testElement ->getAttribute (qtxml::_toDOMS ("activate")));
00180
00181 DOMText *argText = dynamic_cast <DOMText *> (testElement ->getFirstChild());
00182
00183 if(!std::strcmp(activate.c_str(),testON.c_str())) {
00184 if (!argText){
00185 return true;
00186 }else{
00187 std::string regExpValue = qtxml::_toString (argText->getData());
00188 qualityTestList.push_back(regExpValue);
00189 }
00190 }
00191 if(!std::strcmp(activate.c_str(),testOFF.c_str())) {
00192 if (argText) {
00193 std::string regExpValue = qtxml::_toString (argText->getData());
00194
00195 }
00196 }
00197
00198 }
00199
00200
00201 if(qualityTestList.size()) mapMonitorElementTests[linkName]=qualityTestList;
00202 }
00203
00204
00205 return false;
00206
00207
00208
00209 }
00210
00211