CMS 3D CMS Logo

QTestConfigurationParser.cc
Go to the documentation of this file.
4 #include <cstring>
5 #include <stdexcept>
12 using namespace xercesc;
13 
15 
17  qtestParamNames = new QTestParameterNames();
18 
19  try {
20  if (s_numberOfInstances == 0)
22  } catch (const XMLException &e) {
23  throw(std::runtime_error("Standard pool exception : Fatal Error on pool::TrivialFileCatalog"));
24  }
25 
26  ++s_numberOfInstances;
27 }
28 
30  delete qtestParamNames;
31  qtestParamNames = nullptr;
32 }
33 
35  testsToDisable.clear();
36  testsRequested.clear();
37  mapMonitorElementTests.clear();
38  bool qtErrors = this->qtestsConfig();
39  bool meErrors = this->monitorElementTestsMap();
40  return (qtErrors || meErrors);
41 }
42 
44  std::string testActivationOFF = "false";
45 
46  unsigned int qtestTagsNum = doc()->getElementsByTagName(qtxml::_toDOMS("QTEST"))->getLength();
47 
48  for (unsigned int i = 0; i < qtestTagsNum; ++i) {
50  DOMNode *qtestNode = doc()->getElementsByTagName(qtxml::_toDOMS("QTEST"))->item(i);
51 
53  if (!qtestNode) {
54  return true;
55  }
56  DOMElement *qtestElement = static_cast<DOMElement *>(qtestNode);
57  if (!qtestElement) {
58  return true;
59  }
60  std::string qtestName = qtxml::_toString(qtestElement->getAttribute(qtxml::_toDOMS("name")));
61  std::string activate = qtxml::_toString(qtestElement->getAttribute(qtxml::_toDOMS("activate")));
62  if (!std::strcmp(activate.c_str(), testActivationOFF.c_str())) {
63  testsToDisable.push_back(qtestName);
64  } else {
66  DOMNodeList *typeNodePrefix = qtestElement->getElementsByTagName(qtxml::_toDOMS("TYPE"));
67 
68  if (typeNodePrefix->getLength() != 1)
69  return true;
70 
71  DOMElement *prefixNode = dynamic_cast<DOMElement *>(typeNodePrefix->item(0));
72  if (!prefixNode)
73  return true;
74 
75  DOMText *prefixText = dynamic_cast<DOMText *>(prefixNode->getFirstChild());
76  if (!prefixText)
77  return true;
78 
79  std::string qtestType = qtxml::_toString(prefixText->getData());
80 
81  testsRequested[qtestName] = this->getParams(qtestElement, qtestType);
82 
83  if (this->checkParameters(qtestName, qtestType))
84  return true;
85  }
86 
87  } //loop on qtestTagsNum
88 
89  return false;
90 }
91 
92 std::map<std::string, std::string> QTestConfigurationParser::getParams(DOMElement *qtestElement,
93  std::string qtestType) {
94  std::map<std::string, std::string> paramNamesValues;
95  paramNamesValues["type"] = qtestType;
96 
97  DOMNodeList *arguments = qtestElement->getElementsByTagName(qtxml::_toDOMS("PARAM"));
98 
99  for (unsigned int i = 0; i < arguments->getLength(); ++i) {
100  DOMElement *argNode = dynamic_cast<DOMElement *>(arguments->item(i));
101  std::string regExp = qtxml::_toString(argNode->getAttribute(qtxml::_toDOMS("name")));
102  DOMText *argText = dynamic_cast<DOMText *>(argNode->getFirstChild());
103  if (!argText) {
104  break;
105  }
106 
107  std::string regExpValue = qtxml::_toString(argText->getData());
108  paramNamesValues[regExp] = regExpValue;
109  }
110 
111  return paramNamesValues;
112 }
113 
115  std::vector<std::string> paramNames = qtestParamNames->getTestParamNames(qtestType);
116  // commenting out as does not seem to be logical SDutta 22/3/2013
117  /*if(paramNames.size() == 0) {
118 
119  return true;
120  }*/
121 
122  paramNames.push_back("error");
123  paramNames.push_back("warning");
124 
125  std::map<std::string, std::string> namesMap = testsRequested[qtestName];
126 
127  for (std::vector<std::string>::iterator namesItr = paramNames.begin(); namesItr != paramNames.end(); ++namesItr) {
128  if (namesMap.find(*namesItr) == namesMap.end()) {
129  return true;
130  }
131  }
132 
133  return false;
134 }
135 
137  std::string testON = "true";
138  std::string testOFF = "false";
139 
140  unsigned int linkTagsNum = doc()->getElementsByTagName(qtxml::_toDOMS("LINK"))->getLength();
141 
142  for (unsigned int i = 0; i < linkTagsNum; ++i) {
143  DOMNode *linkNode = doc()->getElementsByTagName(qtxml::_toDOMS("LINK"))->item(i);
145  if (!linkNode) {
146  return true;
147  }
148  DOMElement *linkElement = static_cast<DOMElement *>(linkNode);
149  if (!linkElement) {
150  return true;
151  }
152  std::string linkName = qtxml::_toString(linkElement->getAttribute(qtxml::_toDOMS("name")));
153 
154  DOMNodeList *testList = linkElement->getElementsByTagName(qtxml::_toDOMS("TestName"));
155  unsigned int numberOfTests = testList->getLength();
156 
157  std::vector<std::string> qualityTestList;
158  for (unsigned int tt = 0; tt < numberOfTests; ++tt) {
159  DOMElement *testElement = dynamic_cast<DOMElement *>(testList->item(tt));
160  if (!testElement) {
161  return true;
162  }
163 
164  std::string activate = qtxml::_toString(testElement->getAttribute(qtxml::_toDOMS("activate")));
165 
166  DOMText *argText = dynamic_cast<DOMText *>(testElement->getFirstChild());
167 
168  if (!std::strcmp(activate.c_str(), testON.c_str())) {
169  if (!argText) {
170  return true;
171  } else {
172  std::string regExpValue = qtxml::_toString(argText->getData());
173  qualityTestList.push_back(regExpValue);
174  }
175  }
176  if (!std::strcmp(activate.c_str(), testOFF.c_str())) {
177  if (argText) {
178  std::string regExpValue = qtxml::_toString(argText->getData());
179  // Create List of QTests to unattach from current ME
180  }
181  }
182  }
183 
184  if (!qualityTestList.empty())
185  mapMonitorElementTests[linkName] = qualityTestList;
186  }
187 
188  return false;
189 }
std::map< std::string, std::string > getParams(xercesc::DOMElement *qtestElement, std::string test)
~QTestConfigurationParser() override
Destructor.
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)
void xercesInitialize()
Definition: Xerces.cc:18
const T & getParams(const std::vector< T > &params, size_t index)
Definition: LHCInfo.cc:117
XMLCh * _toDOMS(std::string temp)