12 #include "xercesc/util/PlatformUtils.hpp" 30 XmlConfigParser::XmlConfigParser() :
57 XMLPlatformUtils::Initialize();
59 kTagHw = XMLString::transcode(
"system");
60 kTagAlgo = XMLString::transcode(
"algo");
62 kTagDb = XMLString::transcode(
"db");
63 kTagKey = XMLString::transcode(
"key");
64 kTagLoad = XMLString::transcode(
"load");
66 kTagParam = XMLString::transcode(
"param");
67 kTagMask = XMLString::transcode(
"mask");
72 kTagTypes = XMLString::transcode(
"types");
73 kTagRow = XMLString::transcode(
"row");
75 kTagRole = XMLString::transcode(
"role");
76 kTagCrate = XMLString::transcode(
"crate");
77 kTagSlot = XMLString::transcode(
"slot");
78 kTagDaqTtc = XMLString::transcode(
"daqttc-mgr");
79 kAttrId = XMLString::transcode(
"id");
81 kAttrDelim = XMLString::transcode(
"delimiter");
85 parser_ =
new XercesDOMParser();
86 parser_->setValidationScheme(XercesDOMParser::Val_Auto);
87 parser_->setDoNamespaces(
false);
120 XMLPlatformUtils::Initialize();
122 kTagHw = XMLString::transcode(
"system");
123 kTagAlgo = XMLString::transcode(
"algo");
125 kTagDb = XMLString::transcode(
"db");
126 kTagKey = XMLString::transcode(
"key");
127 kTagLoad = XMLString::transcode(
"load");
129 kTagParam = XMLString::transcode(
"param");
130 kTagMask = XMLString::transcode(
"mask");
135 kTagTypes = XMLString::transcode(
"types");
136 kTagRow = XMLString::transcode(
"row");
138 kTagRole = XMLString::transcode(
"role");
139 kTagCrate = XMLString::transcode(
"crate");
140 kTagSlot = XMLString::transcode(
"slot");
141 kTagDaqTtc = XMLString::transcode(
"daqttc-mgr");
142 kAttrId = XMLString::transcode(
"id");
143 kAttrType = XMLString::transcode(
"type");
144 kAttrDelim = XMLString::transcode(
"delimiter");
155 XMLPlatformUtils::Terminate();
161 MemBufInputSource xmlstr_buf((
const XMLByte*)(
str.c_str()),
str.size(),
"xmlstrbuf");
170 MemBufInputSource xmlstr_buf((
const XMLByte*)(str.c_str()), str.size(),
"xmlstrbuf");
183 edm::LogError(
"XmlConfigParser") <<
"Could not parse file " << fName <<
"\n";
196 edm::LogError(
"XmlConfigParser") <<
"Could not parse file " << fName <<
"\n";
205 DOMElement* rootElement =
doc_->getDocumentElement();
207 if (rootElement->getNodeType() == DOMNode::ELEMENT_NODE) {
211 throw std::runtime_error(
"No xml root element found");
234 if( sId != sysId )
return;
237 char *sysId_ = xercesc::XMLString::transcode( element->getAttribute(
kAttrId) );
242 DOMNodeList* processors = element->getElementsByTagName(
kTagProcessor);
243 XMLSize_t nodeCount = processors->getLength();
244 for (XMLSize_t
xx = 0;
xx < nodeCount; ++
xx) {
245 DOMNode* currentNode = processors->item(
xx);
246 if (currentNode->getNodeType() && currentNode->getNodeType() == DOMNode::ELEMENT_NODE) {
247 DOMElement* currentElement =
static_cast<DOMElement*
>( currentNode );
251 string role, crate, slot;
253 DOMNodeList* roles = currentElement->getElementsByTagName(
kTagRole);
255 if( roles->getLength() != 1 )
256 throw std::runtime_error(
string(
"Configutration specify not exactly one role") );
260 DOMNodeList* roleChilds = roles->item(i)->getChildNodes();
261 if( roleChilds->getLength() != 1 )
262 throw std::runtime_error(
string(
"Configutration specify not exactly one role") );
266 if (roleChilds->item(j)->getNodeType() == DOMNode::TEXT_NODE) {
273 DOMNodeList* crates = currentElement->getElementsByTagName(
kTagCrate);
275 if( crates->getLength() != 1 )
276 throw std::runtime_error(
string(
"Configutration specify not exactly one crate") );
280 DOMNodeList* crateChilds = crates->item(i)->getChildNodes();
281 if( crateChilds->getLength() != 1 )
282 throw std::runtime_error(
string(
"Configutration specify not exactly one crate") );
286 if (crateChilds->item(j)->getNodeType() == DOMNode::TEXT_NODE) {
293 DOMNodeList* slots = currentElement->getElementsByTagName(
kTagSlot);
295 if( slots->getLength() != 1 )
296 throw std::runtime_error(
string(
"Configutration specify not exactly one slot") );
300 DOMNodeList* slotChilds = slots->item(i)->getChildNodes();
301 if( slotChilds->getLength() != 1 )
302 throw std::runtime_error(
string(
"Configutration specify not exactly one slot") );
306 if (slotChilds->item(j)->getNodeType() == DOMNode::TEXT_NODE) {
313 aTriggerSystem.
addProcessor(proc.c_str(), role.c_str(), crate.c_str(), slot.c_str());
318 DOMNodeList* daqttcs = element->getElementsByTagName(
kTagDaqTtc);
319 nodeCount = daqttcs->getLength();
320 for (XMLSize_t
xx = 0;
xx < nodeCount; ++
xx) {
321 DOMNode* currentNode = daqttcs->item(
xx);
322 if (currentNode->getNodeType() && currentNode->getNodeType() == DOMNode::ELEMENT_NODE) {
323 DOMElement* currentElement =
static_cast<DOMElement*
>( currentNode );
327 DOMNodeList* roles = currentElement->getElementsByTagName(
kTagRole);
329 if( roles->getLength() != 1 )
330 throw std::runtime_error(
string(
"Configutration specify not exactly one role") );
334 DOMNodeList* roleChilds = roles->item(i)->getChildNodes();
335 if( roleChilds->getLength() != 1 )
336 throw std::runtime_error(
string(
"Configutration specify not exactly one role") );
340 if (roleChilds->item(j)->getNodeType() == DOMNode::TEXT_NODE) {
347 DOMNodeList* crates = currentElement->getElementsByTagName(
kTagCrate);
349 if( crates->getLength() != 1 )
350 throw std::runtime_error(
string(
"Configutration specify not exactly one crate") );
354 DOMNodeList* crateChilds = crates->item(i)->getChildNodes();
355 if( crateChilds->getLength() != 1 )
356 throw std::runtime_error(
string(
"Configutration specify not exactly one crate") );
360 if (crateChilds->item(j)->getNodeType() == DOMNode::TEXT_NODE) {
367 aTriggerSystem.
addDaq(daqttc.c_str(), role.c_str(), crate.c_str());
372 DOMNodeList* exclBoards = element->getElementsByTagName(
kTagExclBoards);
373 for (XMLSize_t
xx = 0;
xx < exclBoards->getLength(); ++
xx) {
374 DOMElement* exclBoardElem =
static_cast<DOMElement*
>(exclBoards->item(
xx));
376 for (DOMElement*
elem = static_cast<DOMElement*>(exclBoardElem->getFirstChild());
elem;
elem =
static_cast<DOMElement*
>(
elem->getNextSibling())) {
377 if (
elem->getNodeType() == DOMNode::ELEMENT_NODE) {
393 if (systemId ==
"") {
394 systemId = aTriggerSystem.
systemId();
397 DOMNodeList* contextElements = element->getElementsByTagName(
kTagContext);
399 for (XMLSize_t
i = 0;
i < contextElements->getLength(); ++
i) {
400 DOMElement* contextElement =
static_cast<DOMElement*
>(contextElements->item(
i));
404 for (DOMElement*
elem = static_cast<DOMElement*>(contextElement->getFirstChild());
elem;
elem =
static_cast<DOMElement*
>(
elem->getNextSibling())) {
405 if (
elem->getNodeType() == DOMNode::ELEMENT_NODE) {
421 for (XMLSize_t j = 0; j < colElements->getLength(); ++j) {
422 DOMNodeList* colChilds = colElements->item(j)->getChildNodes();
423 for (XMLSize_t
k = 0;
k < colChilds->getLength(); ++
k) {
424 if (colChilds->item(
k)->getNodeType() == DOMNode::TEXT_NODE) {
427 char *
cStr = xercesc::XMLString::transcode( colChilds->item(
k)->getNodeValue() );
428 char *saveptr,
first = 1;
429 for(
char *item=strtok_r(cStr,delim.c_str(),&saveptr);
431 item = strtok_r(
nullptr,delim.c_str(),&saveptr), first=0
440 DOMNodeList* colTypesElements =
elem->getElementsByTagName(
kTagTypes);
441 for (XMLSize_t j = 0; j < colTypesElements->getLength(); ++j) {
442 DOMNodeList* colTypesChilds = colTypesElements->item(j)->getChildNodes();
443 for (XMLSize_t
k = 0;
k < colTypesChilds->getLength(); ++
k) {
444 if (colTypesChilds->item(
k)->getNodeType() == DOMNode::TEXT_NODE) {
447 char *tStr = xercesc::XMLString::transcode( colTypesChilds->item(
k)->getNodeValue() );
448 char *saveptr,
first = 1;
449 for(
char *item=strtok_r(tStr,delim.c_str(),&saveptr);
451 item = strtok_r(
nullptr,delim.c_str(),&saveptr), first=0
459 std::vector<std::string> rowStrs;
460 DOMNodeList* rowElements =
elem->getElementsByTagName(
kTagRow);
461 for (XMLSize_t j = 0; j < rowElements->getLength(); ++j) {
462 DOMNodeList* rowChilds = rowElements->item(j)->getChildNodes();
463 for (XMLSize_t
k = 0;
k < rowChilds->getLength(); ++
k) {
464 if (rowChilds->item(
k)->getNodeType() == DOMNode::TEXT_NODE) {
468 char *rStr = xercesc::XMLString::transcode( rowChilds->item(
k)->getNodeValue() );
469 char *saveptr,
first = 1;
471 for(
char *item=strtok_r(rStr,delim.c_str(),&saveptr);
473 item = strtok_r(
nullptr,delim.c_str(),&saveptr), first=0
476 rowStrs.push_back(row);
482 aTriggerSystem.
addTable(
id.c_str(), contextId.c_str(), columnsStr.c_str(), typesStr.c_str(), rowStrs, delim.c_str());
486 DOMNodeList* valNodes =
elem->getChildNodes();
487 for (XMLSize_t j = 0; j < valNodes->getLength(); ++j) {
488 if (valNodes->item(j)->getNodeType() == DOMNode::TEXT_NODE) {
497 aTriggerSystem.
addParameter(
id.c_str(), contextId.c_str(), type.c_str(), value.c_str(), delim.c_str());
506 aTriggerSystem.
addMask(
id.c_str(), contextId.c_str());
525 for (DOMElement*
elem = static_cast<DOMElement*>(keyElement->getFirstChild());
elem;
elem =
static_cast<DOMElement*
>(
elem->getNextSibling())) {
526 if (
elem->getNodeType() == DOMNode::ELEMENT_NODE) {
533 throw std::runtime_error(
"Key not found: " + key);
540 DOMElement* rootElement =
doc_->getDocumentElement();
542 DOMNodeList* keyElements = rootElement->getElementsByTagName(
kTagKey);
544 for (XMLSize_t
i = 0;
i < keyElements->getLength(); ++
i) {
545 DOMElement* keyElement =
static_cast<DOMElement*
>(keyElements->item(
i));
559 DOMNodeList* loadElements = keyElement->getElementsByTagName(
kTagLoad);
560 for (XMLSize_t
i = 0;
i < loadElements->getLength(); ++
i) {
561 DOMElement* loadElement =
static_cast<DOMElement*
>(loadElements->item(
i));
563 if (fileName.find(
"/") != 0) {
567 pos = topPath.find_last_of(
"/");
568 if (pos != std::string::npos) {
569 topDir = topPath.substr(0, pos+1);
574 DOMDocument* subDoc =
nullptr;
586 DOMElement* subDocRootElement = subDoc->getDocumentElement();
589 DOMNode* importedNode =
doc_->importNode(subDocRootElement,
true);
590 parentNode->appendChild(importedNode);
596 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
597 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
598 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
599 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
600 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
601 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
602 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
603 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
604 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
605 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
606 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
607 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
608 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
609 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
610 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
611 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
612 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
613 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
614 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
615 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
616 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
617 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
618 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
619 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
620 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
625 size_t alphanumBegin = 0, alphanumEnd = strlen(str)-1;
630 str[alphanumEnd+1] =
'\0';
631 return str + alphanumBegin;
636 std::size_t alphanumBegin = str.find_first_not_of(
"\n\t ");
637 std::size_t alphanumEnd = str.find_last_not_of(
"\n\t ");
638 if (alphanumBegin != std::string::npos) {
639 if (alphanumEnd != std::string::npos) {
640 str = str.substr(alphanumBegin, alphanumEnd - alphanumBegin + 1);
642 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
TrainProcessor *const proc
const XMLCh * kTagExclBoards
void readElement(const xercesc::DOMElement *element, TriggerSystem &aTriggerSystem, const std::string &sysId="")
const XMLCh * kTagProcessor
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)
void addMask(const char *id, const char *procOrRoleOrDaq)
xercesc::DOMDocument * doc_
def elem(elemtype, innerHTML='', html_class='', kwargs)
std::string systemId(void) const noexcept
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="")
void disableProcOrRoleOrDaq(const char *procOrRoleOrDaq)
xercesc::XercesDOMParser * parser_
const XMLCh * kTagRunSettings