12 #include "xercesc/util/PlatformUtils.hpp" 30 XmlConfigParser::XmlConfigParser()
33 kTagRunSettings(nullptr),
41 kTagExclBoards(nullptr),
46 kTagProcessor(nullptr),
56 XMLPlatformUtils::Initialize();
58 kTagHw = XMLString::transcode(
"system");
59 kTagAlgo = XMLString::transcode(
"algo");
61 kTagDb = XMLString::transcode(
"db");
62 kTagKey = XMLString::transcode(
"key");
63 kTagLoad = XMLString::transcode(
"load");
65 kTagParam = XMLString::transcode(
"param");
66 kTagMask = XMLString::transcode(
"mask");
71 kTagTypes = XMLString::transcode(
"types");
72 kTagRow = XMLString::transcode(
"row");
74 kTagRole = XMLString::transcode(
"role");
75 kTagCrate = XMLString::transcode(
"crate");
76 kTagSlot = XMLString::transcode(
"slot");
77 kTagDaqTtc = XMLString::transcode(
"daqttc-mgr");
78 kAttrId = XMLString::transcode(
"id");
80 kAttrDelim = XMLString::transcode(
"delimiter");
84 parser_ =
new XercesDOMParser();
85 parser_->setValidationScheme(XercesDOMParser::Val_Auto);
86 parser_->setDoNamespaces(
false);
94 kTagRunSettings(nullptr),
101 kTagDisable(nullptr),
102 kTagExclBoards(nullptr),
103 kTagExclude(nullptr),
104 kTagColumns(nullptr),
107 kTagProcessor(nullptr),
115 kAttrModule(nullptr),
116 kTypeTable(
"table") {
117 XMLPlatformUtils::Initialize();
119 kTagHw = XMLString::transcode(
"system");
120 kTagAlgo = XMLString::transcode(
"algo");
122 kTagDb = XMLString::transcode(
"db");
123 kTagKey = XMLString::transcode(
"key");
124 kTagLoad = XMLString::transcode(
"load");
126 kTagParam = XMLString::transcode(
"param");
127 kTagMask = XMLString::transcode(
"mask");
132 kTagTypes = XMLString::transcode(
"types");
133 kTagRow = XMLString::transcode(
"row");
135 kTagRole = XMLString::transcode(
"role");
136 kTagCrate = XMLString::transcode(
"crate");
137 kTagSlot = XMLString::transcode(
"slot");
138 kTagDaqTtc = XMLString::transcode(
"daqttc-mgr");
139 kAttrId = XMLString::transcode(
"id");
140 kAttrType = XMLString::transcode(
"type");
141 kAttrDelim = XMLString::transcode(
"delimiter");
150 XMLPlatformUtils::Terminate();
154 MemBufInputSource xmlstr_buf((
const XMLByte*)(
str.c_str()),
str.size(),
"xmlstrbuf");
161 MemBufInputSource xmlstr_buf((
const XMLByte*)(
str.c_str()),
str.size(),
"xmlstrbuf");
190 DOMElement* rootElement =
doc_->getDocumentElement();
192 if (rootElement->getNodeType() == DOMNode::ELEMENT_NODE) {
196 throw std::runtime_error(
"No xml root element found");
215 if (!sysId.empty()) {
222 char* sysId_ = xercesc::XMLString::transcode(element->getAttribute(
kAttrId));
227 DOMNodeList* processors = element->getElementsByTagName(
kTagProcessor);
228 XMLSize_t nodeCount = processors->getLength();
229 for (XMLSize_t
xx = 0;
xx < nodeCount; ++
xx) {
230 DOMNode* currentNode = processors->item(
xx);
231 if (currentNode->getNodeType() && currentNode->getNodeType() == DOMNode::ELEMENT_NODE) {
232 DOMElement* currentElement =
static_cast<DOMElement*
>(currentNode);
236 string role, crate, slot;
238 DOMNodeList* roles = currentElement->getElementsByTagName(
kTagRole);
240 if (roles->getLength() != 1)
241 throw std::runtime_error(
string(
"Configutration specify not exactly one role"));
245 DOMNodeList* roleChilds = roles->item(
i)->getChildNodes();
246 if (roleChilds->getLength() != 1)
247 throw std::runtime_error(
string(
"Configutration specify not exactly one role"));
251 if (roleChilds->item(
j)->getNodeType() == DOMNode::TEXT_NODE) {
258 DOMNodeList* crates = currentElement->getElementsByTagName(
kTagCrate);
260 if (crates->getLength() != 1)
261 throw std::runtime_error(
string(
"Configutration specify not exactly one crate"));
265 DOMNodeList* crateChilds = crates->item(
i)->getChildNodes();
266 if (crateChilds->getLength() != 1)
267 throw std::runtime_error(
string(
"Configutration specify not exactly one crate"));
271 if (crateChilds->item(
j)->getNodeType() == DOMNode::TEXT_NODE) {
278 DOMNodeList* slots = currentElement->getElementsByTagName(
kTagSlot);
280 if (slots->getLength() != 1)
281 throw std::runtime_error(
string(
"Configutration specify not exactly one slot"));
285 DOMNodeList* slotChilds = slots->item(
i)->getChildNodes();
286 if (slotChilds->getLength() != 1)
287 throw std::runtime_error(
string(
"Configutration specify not exactly one slot"));
291 if (slotChilds->item(
j)->getNodeType() == DOMNode::TEXT_NODE) {
298 aTriggerSystem.
addProcessor(
proc.c_str(), role.c_str(), crate.c_str(), slot.c_str());
303 DOMNodeList* daqttcs = element->getElementsByTagName(
kTagDaqTtc);
304 nodeCount = daqttcs->getLength();
305 for (XMLSize_t
xx = 0;
xx < nodeCount; ++
xx) {
306 DOMNode* currentNode = daqttcs->item(
xx);
307 if (currentNode->getNodeType() && currentNode->getNodeType() == DOMNode::ELEMENT_NODE) {
308 DOMElement* currentElement =
static_cast<DOMElement*
>(currentNode);
312 DOMNodeList* roles = currentElement->getElementsByTagName(
kTagRole);
314 if (roles->getLength() != 1)
315 throw std::runtime_error(
string(
"Configutration specify not exactly one role"));
319 DOMNodeList* roleChilds = roles->item(
i)->getChildNodes();
320 if (roleChilds->getLength() != 1)
321 throw std::runtime_error(
string(
"Configutration specify not exactly one role"));
325 if (roleChilds->item(
j)->getNodeType() == DOMNode::TEXT_NODE) {
332 DOMNodeList* crates = currentElement->getElementsByTagName(
kTagCrate);
334 if (crates->getLength() != 1)
335 throw std::runtime_error(
string(
"Configutration specify not exactly one crate"));
339 DOMNodeList* crateChilds = crates->item(
i)->getChildNodes();
340 if (crateChilds->getLength() != 1)
341 throw std::runtime_error(
string(
"Configutration specify not exactly one crate"));
345 if (crateChilds->item(
j)->getNodeType() == DOMNode::TEXT_NODE) {
352 aTriggerSystem.
addDaq(daqttc.c_str(), role.c_str(), crate.c_str());
357 DOMNodeList* exclBoards = element->getElementsByTagName(
kTagExclBoards);
358 for (XMLSize_t
xx = 0;
xx < exclBoards->getLength(); ++
xx) {
359 DOMElement* exclBoardElem =
static_cast<DOMElement*
>(exclBoards->item(
xx));
361 for (DOMElement* elem = static_cast<DOMElement*>(exclBoardElem->getFirstChild()); elem;
362 elem =
static_cast<DOMElement*
>(elem->getNextSibling())) {
363 if (elem->getNodeType() == DOMNode::ELEMENT_NODE) {
378 if (systemId.empty()) {
379 systemId = aTriggerSystem.
systemId();
382 DOMNodeList* contextElements = element->getElementsByTagName(
kTagContext);
384 for (XMLSize_t
i = 0;
i < contextElements->getLength(); ++
i) {
385 DOMElement* contextElement =
static_cast<DOMElement*
>(contextElements->item(
i));
389 for (DOMElement* elem = static_cast<DOMElement*>(contextElement->getFirstChild()); elem;
390 elem =
static_cast<DOMElement*
>(elem->getNextSibling())) {
391 if (elem->getNodeType() == DOMNode::ELEMENT_NODE) {
405 DOMNodeList* colElements = elem->getElementsByTagName(
kTagColumns);
406 for (XMLSize_t
j = 0;
j < colElements->getLength(); ++
j) {
407 DOMNodeList* colChilds = colElements->item(
j)->getChildNodes();
408 for (XMLSize_t
k = 0;
k < colChilds->getLength(); ++
k) {
409 if (colChilds->item(
k)->getNodeType() == DOMNode::TEXT_NODE) {
412 char*
cStr = xercesc::XMLString::transcode(colChilds->item(
k)->getNodeValue());
413 char *saveptr,
first = 1;
414 for (
char*
item = strtok_r(
cStr, delim.c_str(), &saveptr);
item !=
nullptr;
415 item = strtok_r(
nullptr, delim.c_str(), &saveptr),
first = 0)
424 DOMNodeList* colTypesElements = elem->getElementsByTagName(
kTagTypes);
425 for (XMLSize_t
j = 0;
j < colTypesElements->getLength(); ++
j) {
426 DOMNodeList* colTypesChilds = colTypesElements->item(
j)->getChildNodes();
427 for (XMLSize_t
k = 0;
k < colTypesChilds->getLength(); ++
k) {
428 if (colTypesChilds->item(
k)->getNodeType() == DOMNode::TEXT_NODE) {
431 char* tStr = xercesc::XMLString::transcode(colTypesChilds->item(
k)->getNodeValue());
432 char *saveptr,
first = 1;
433 for (
char*
item = strtok_r(tStr, delim.c_str(), &saveptr);
item !=
nullptr;
434 item = strtok_r(
nullptr, delim.c_str(), &saveptr),
first = 0)
442 std::vector<std::string> rowStrs;
443 DOMNodeList* rowElements = elem->getElementsByTagName(
kTagRow);
444 for (XMLSize_t
j = 0;
j < rowElements->getLength(); ++
j) {
445 DOMNodeList* rowChilds = rowElements->item(
j)->getChildNodes();
446 for (XMLSize_t
k = 0;
k < rowChilds->getLength(); ++
k) {
447 if (rowChilds->item(
k)->getNodeType() == DOMNode::TEXT_NODE) {
451 char* rStr = xercesc::XMLString::transcode(rowChilds->item(
k)->getNodeValue());
452 char *saveptr,
first = 1;
454 for (
char*
item = strtok_r(rStr, delim.c_str(), &saveptr);
item !=
nullptr;
455 item = strtok_r(
nullptr, delim.c_str(), &saveptr),
first = 0)
458 rowStrs.push_back(row);
465 id.c_str(), contextId.c_str(), columnsStr.c_str(), typesStr.c_str(), rowStrs, delim.c_str());
469 DOMNodeList* valNodes = elem->getChildNodes();
470 for (XMLSize_t
j = 0;
j < valNodes->getLength(); ++
j) {
471 if (valNodes->item(
j)->getNodeType() == DOMNode::TEXT_NODE) {
480 aTriggerSystem.
addParameter(
id.c_str(), contextId.c_str(),
type.c_str(),
value.c_str(), delim.c_str());
488 aTriggerSystem.
addMask(
id.c_str(), contextId.c_str());
505 for (DOMElement* elem = static_cast<DOMElement*>(keyElement->getFirstChild()); elem;
506 elem =
static_cast<DOMElement*
>(elem->getNextSibling())) {
507 if (elem->getNodeType() == DOMNode::ELEMENT_NODE) {
514 throw std::runtime_error(
"Key not found: " +
key);
519 DOMElement* rootElement =
doc_->getDocumentElement();
521 DOMNodeList* keyElements = rootElement->getElementsByTagName(
kTagKey);
523 for (XMLSize_t
i = 0;
i < keyElements->getLength(); ++
i) {
524 DOMElement* keyElement =
static_cast<DOMElement*
>(keyElements->item(
i));
536 DOMNodeList* loadElements = keyElement->getElementsByTagName(
kTagLoad);
537 for (XMLSize_t
i = 0;
i < loadElements->getLength(); ++
i) {
538 DOMElement* loadElement =
static_cast<DOMElement*
>(loadElements->item(
i));
544 pos = topPath.find_last_of(
'/');
545 if (
pos != std::string::npos) {
546 topDir = topPath.substr(0,
pos + 1);
551 DOMDocument* subDoc =
nullptr;
561 DOMElement* subDocRootElement = subDoc->getDocumentElement();
565 DOMNode* importedNode =
doc_->importNode(subDocRootElement,
true);
566 parentNode->appendChild(importedNode);
572 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
573 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
574 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
575 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
576 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
577 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
578 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
579 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
580 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
583 size_t alphanumBegin = 0, alphanumEnd = strlen(
str) - 1;
590 str[alphanumEnd + 1] =
'\0';
591 return str + alphanumBegin;
595 std::size_t alphanumBegin =
str.find_first_not_of(
"\n\t ");
596 std::size_t alphanumEnd =
str.find_last_not_of(
"\n\t ");
597 if (alphanumBegin != std::string::npos) {
598 if (alphanumEnd != std::string::npos) {
599 str =
str.substr(alphanumBegin, alphanumEnd - alphanumBegin + 1);
601 str =
str.substr(alphanumBegin);
void addDaq(const char *daq, const char *role, const char *crate)
void pruneString(std::string &str)
const std::string kTypeTable
void readDOMFromFile(const std::string &fName, xercesc::DOMDocument *&doc)
void setSystemId(const char *id) noexcept
const XMLCh * kTagExclBoards
void readElement(const xercesc::DOMElement *element, TriggerSystem &aTriggerSystem, const std::string &sysId="")
const XMLCh * kTagProcessor
Log< level::Error, false > LogError
const char XmlConfigParser_reject_symbols[256]
const XMLCh * kTagContext
void readContext(const xercesc::DOMElement *element, const std::string &sysId, TriggerSystem &aTriggerSystem)
std::string toString(XMLCh const *toTranscode)
const XMLCh * kTagColumns
void readDOMFromString(const std::string &str, xercesc::DOMDocument *&doc)
void addTable(const char *id, const char *procOrRole, const char *columns, const char *types, const std::vector< std::string > &rows, const char *delim)
void buildGlobalDoc(const std::string &key, const std::string &topPath="")
ZStr< char > cStr(XMLCh const *str)
void appendNodesFromSubDoc(xercesc::DOMNode *parentNode, xercesc::DOMDocument *subDoc)
key
prepare the HTCondor submission files and eventually submit them
void addMask(const char *id, const char *procOrRoleOrDaq)
xercesc::DOMDocument * doc_
xercesc::DOMElement * getKeyElement(const std::string &key)
bool equals(const edm::RefToBase< Jet > &j1, const edm::RefToBase< Jet > &j2)
const XMLCh * kTagExclude
const XMLCh * kTagDisable
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
void readContexts(const std::string &key, const std::string &sysId, TriggerSystem &aTriggerSystem)
void addProcessor(const char *processor, const char *role, const char *crate, const char *slot)
void addParameter(const char *id, const char *procOrRole, const char *type, const char *value, const char *delim=",")
const XMLCh * kAttrModule
void readHwDescription(const xercesc::DOMElement *element, TriggerSystem &aTriggerSystem, const std::string &sysId="")
std::string systemId(void) const noexcept
void disableProcOrRoleOrDaq(const char *procOrRoleOrDaq)
xercesc::XercesDOMParser * parser_
const XMLCh * kTagRunSettings