CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
QTestConfigurationParser.cc
Go to the documentation of this file.
4 #include <cstring>
5 #include <stdexcept>
14 using namespace xercesc;
15 
17 
18 
20 
21  qtestParamNames=new QTestParameterNames();
22 
23  try {
24  if (s_numberOfInstances==0)
25  XMLPlatformUtils::Initialize();
26  }
27  catch (const XMLException& e) {
28  throw(std::runtime_error("Standard pool exception : Fatal Error on pool::TrivialFileCatalog"));
29  }
30 
31  ++s_numberOfInstances;
32 }
33 
35  delete qtestParamNames;
36  qtestParamNames = 0;
37 }
38 
40  testsToDisable.clear();
41  testsRequested.clear();
42  mapMonitorElementTests.clear();
43  bool qtErrors= this->qtestsConfig();
44  bool meErrors= this->monitorElementTestsMap();
45  return (qtErrors||meErrors);
46 
47 }
48 
50 
51  std::string testActivationOFF="false";
52 
53  unsigned int qtestTagsNum =
54  doc()->getElementsByTagName(qtxml::_toDOMS("QTEST"))->getLength();
55 
56  for (unsigned int i=0; i<qtestTagsNum; ++i){
58  DOMNode* qtestNode =
59  doc()->getElementsByTagName(qtxml::_toDOMS("QTEST"))->item(i);
60 
61 
63  if (! qtestNode){
64  return true;
65  }
66  DOMElement* qtestElement = static_cast<DOMElement *>(qtestNode);
67  if (! qtestElement){
68  return true;
69  }
70  std::string qtestName = qtxml::_toString (qtestElement->getAttribute (qtxml::_toDOMS ("name")));
71  std::string activate = qtxml::_toString (qtestElement->getAttribute (qtxml::_toDOMS ("activate")));
72  if(!std::strcmp(activate.c_str(),testActivationOFF.c_str())) {
73  testsToDisable.push_back(qtestName);
74  }else{
75 
77  DOMNodeList *typeNodePrefix
78  = qtestElement->getElementsByTagName (qtxml::_toDOMS ("TYPE"));
79 
80  if (typeNodePrefix->getLength () != 1)return true;
81 
82 
83  DOMElement *prefixNode = dynamic_cast <DOMElement *> (typeNodePrefix->item (0));
84  if (!prefixNode)return true;
85 
86  DOMText *prefixText = dynamic_cast <DOMText *> (prefixNode->getFirstChild());
87  if (!prefixText)return true;
88 
89  std::string qtestType = qtxml::_toString (prefixText->getData ());
90 
91  testsRequested[qtestName]= this->getParams(qtestElement, qtestType);
92 
93  if( this->checkParameters(qtestName, qtestType)) return true;
94  }
95 
96  } //loop on qtestTagsNum
97 
98  return false;
99 
100 }
101 
102 std::map<std::string, std::string> QTestConfigurationParser::getParams(DOMElement* qtestElement, std::string qtestType){
103 
104  std::map<std::string, std::string> paramNamesValues;
105  paramNamesValues["type"]=qtestType;
106 
107  DOMNodeList *arguments = qtestElement->getElementsByTagName (qtxml::_toDOMS ("PARAM"));
108 
109  for (unsigned int i=0; i<arguments->getLength(); ++i){
110  DOMElement *argNode = dynamic_cast <DOMElement *> ( arguments ->item(i));
111  std::string regExp = qtxml::_toString (argNode->getAttribute (qtxml::_toDOMS ("name")));
112  DOMText *argText = dynamic_cast <DOMText *> (argNode->getFirstChild());
113  if (!argText){
114  break;
115  }
116 
117  std::string regExpValue = qtxml::_toString (argText->getData());
118  paramNamesValues[regExp]=regExpValue;
119  }
120 
121  return paramNamesValues;
122 
123 }
124 
125 bool QTestConfigurationParser::checkParameters(std::string qtestName, std::string qtestType){
126 
127  std::vector<std::string> paramNames=qtestParamNames->getTestParamNames(qtestType);
128  if(paramNames.size() == 0) {
129 
130  return true;
131  }
132  paramNames.push_back("error");
133  paramNames.push_back("warning");
134 
135  std::map<std::string, std::string> namesMap=testsRequested[qtestName];
136 
137  for(std::vector<std::string>::iterator namesItr=paramNames.begin(); namesItr!=paramNames.end(); ++namesItr){
138  if(namesMap.find(*namesItr)==namesMap.end()){
139  return true;
140  }
141  }
142 
143  return false;
144 }
145 
147 
148  std::string testON="true";
149  std::string testOFF="false";
150 
151  unsigned int linkTagsNum =
152  doc()->getElementsByTagName(qtxml::_toDOMS("LINK"))->getLength();
153 
154 
155  for (unsigned int i=0; i<linkTagsNum; ++i){
156 
157  DOMNode* linkNode =
158  doc()->getElementsByTagName(qtxml::_toDOMS("LINK"))->item(i);
160  if (! linkNode){
161  return true;
162  }
163  DOMElement* linkElement = static_cast<DOMElement *>(linkNode);
164  if (! linkElement){
165  return true;
166  }
167  std::string linkName = qtxml::_toString (linkElement->getAttribute (qtxml::_toDOMS ("name")));
168 
169  DOMNodeList *testList = linkElement->getElementsByTagName (qtxml::_toDOMS ("TestName"));
170  unsigned int numberOfTests=testList->getLength();
171 
172  std::vector<std::string> qualityTestList;
173  for(unsigned int tt=0; tt<numberOfTests; ++tt){
174  DOMElement * testElement = dynamic_cast <DOMElement *> ( testList ->item(tt));
175  if (!testElement ){
176  return true;
177  }
178 
179  std::string activate = qtxml::_toString (testElement ->getAttribute (qtxml::_toDOMS ("activate")));
180 
181  DOMText *argText = dynamic_cast <DOMText *> (testElement ->getFirstChild());
182 
183  if(!std::strcmp(activate.c_str(),testON.c_str())) {
184  if (!argText){
185  return true;
186  }else{
187  std::string regExpValue = qtxml::_toString (argText->getData());
188  qualityTestList.push_back(regExpValue);
189  }
190  }
191  if(!std::strcmp(activate.c_str(),testOFF.c_str())) {
192  if (argText) {
193  std::string regExpValue = qtxml::_toString (argText->getData());
194  // Create List of QTests to unattach from current ME
195  }
196  }
197 
198  }
199 
200 
201  if(qualityTestList.size()) mapMonitorElementTests[linkName]=qualityTestList;
202  }
203 
204 
205  return false;
206 
207 
208 
209 }
210 
211 
int i
Definition: DBlmapReader.cc:9
std::map< std::string, std::string > getParams(xercesc::DOMElement *qtestElement, std::string test)
bool parseQTestsConfiguration()
Methor that parses the xml file configFile, returns false if no errors are encountered.
std::string _toString(const XMLCh *toTranscode)
bool checkParameters(std::string qtestName, std::string qtestType)
tuple doc
Definition: asciidump.py:381
XMLCh * _toDOMS(std::string temp)