5 #include <xercesc/parsers/XercesDOMParser.hpp> 6 #include <xercesc/sax/HandlerBase.hpp> 7 #include <xercesc/dom/DOM.hpp> 21 inline std::string xmlc_to_stdstring(
const XMLCh* xcstr)
23 char* cstr = XMLString::transcode(xcstr);
33 auto_XMLString(XMLCh* xch) : m_xch(xch) {}
34 XMLCh*
get()
const {
return m_xch; }
37 auto_XMLString(
const auto_XMLString&) =
delete;
38 auto_XMLString& operator=(
const auto_XMLString&) =
delete;
39 auto_XMLString(auto_XMLString&&
other) { m_xch =
other.m_xch;
other.m_xch =
nullptr; }
40 auto_XMLString& operator=(auto_XMLString&&
other) { m_xch =
other.m_xch;
other.m_xch =
nullptr;
return *
this; }
45 std::string getAttr(
const DOMNamedNodeMap* attrMap,
const auto_XMLString& attrName )
47 if ( attrMap->getNamedItem(attrName.get()) ) {
48 return xmlc_to_stdstring(attrMap->getNamedItem(attrName.get())->getTextContent());
55 inline std::vector<uint32_t> split_string_to_uints(
const std::string&
str)
57 std::vector<uint32_t>
out{};
58 std::size_t iStart{str.find_first_not_of(
" ,\n")}, iEnd{};
59 while ( std::string::npos != iStart ) {
60 iEnd = str.find_first_of(
" ,\n", iStart);
61 out.push_back(std::stoul(str.substr(iStart, iEnd),
nullptr, 0));
62 iStart = str.find_first_not_of(
" ,\n", iEnd);
80 }
catch (
const XMLException& xmlEx ) {
82 "XML exception at initialization : " + xmlc_to_stdstring(xmlEx.getMessage()));
86 std::unique_ptr<XercesDOMParser>
parser{
new XercesDOMParser()};
87 parser->setValidationScheme(XercesDOMParser::Val_Always);
89 std::unique_ptr<ErrorHandler> errHandler{
static_cast<ErrorHandler*
>(
new HandlerBase())};
90 parser->setErrorHandler(errHandler.get());
93 parser->parse(xmlFileName.c_str());
94 }
catch (
const XMLException& xmlEx ) {
96 "XML exception when parsing " + xmlFileName +
" : " + xmlc_to_stdstring(xmlEx.getMessage()));
97 }
catch (
const DOMException& domEx ) {
99 "DOM exception when parsing " + xmlFileName +
" : " + xmlc_to_stdstring(domEx.getMessage()));
100 }
catch (
const SAXException& saxEx ) {
102 "SAX exception when parsing " + xmlFileName +
" : " + xmlc_to_stdstring(saxEx.getMessage()));
106 auto_XMLString nm_type{XMLString::transcode(
"type")};
107 auto_XMLString nm_name{XMLString::transcode(
"name")};
108 auto_XMLString nm_nEntries{XMLString::transcode(
"nEntries")};
112 DOMElement* docRootNode{
doc->getDocumentElement()};
113 DOMNodeIterator* walker =
doc->createNodeIterator(docRootNode, DOMNodeFilter::SHOW_ELEMENT,
nullptr,
true);
114 for ( DOMNode* currentNode = walker->nextNode(); currentNode; currentNode = walker->nextNode() ) {
115 const auto thisNodeName = xmlc_to_stdstring(currentNode->getNodeName());
116 if ( thisNodeName ==
"Vector" ) {
117 const auto attrs = currentNode->getAttributes();
118 const auto att_type = getAttr(attrs, nm_type);
119 if ( att_type ==
"numeric" ) {
120 const auto att_name = getAttr(attrs, nm_name);;
121 if ( 0 == att_name.compare(0, subdetName.size(), subdetName) ) {
122 const auto att_nEntries = getAttr(attrs, nm_nEntries);
123 const std::size_t nEntries = att_nEntries.empty() ? 0 : std::stoul(att_nEntries);
124 const auto vals = split_string_to_uints(xmlc_to_stdstring(currentNode->getTextContent()));
125 if ( nEntries !=
vals.size() ) {
127 (
"Problem parsing element with name '"+att_name+
"' from '"+xmlFileName+
"': "+
128 "'nEntries' attribute claims "+std::to_string(nEntries)+
" elements, but parsed "+std::to_string(
vals.size())));
130 const auto subDet = std::stoi(att_name.substr(subdetName.size()));
224 }
catch (
const DOMException& domEx ) {
226 "DOM exception in "+xmlFileName+
" : "+xmlc_to_stdstring(domEx.getMessage()));
232 return TrackerTopology(pxbVals, pxfVals, tecVals, tibVals, tidVals, tobVals);
unsigned int sterStartBit_
unsigned int ringStartBit_
unsigned int layerStartBit_
unsigned int str_int_extStartBit_
unsigned int wheelStartBit_
unsigned int sterStartBit_
unsigned int layerStartBit_
TrackerTopology fromTrackerParametersXML(const std::string &xmlFileName)
unsigned int layerStartBit_
unsigned int rodStartBit_
unsigned int petal_fw_bwStartBit_
unsigned int ladderStartBit_
unsigned int petal_fw_bwMask_
unsigned int petalStartBit_
unsigned int strStartBit_
unsigned int moduleStartBit_
unsigned int sterStartBit_
unsigned int rod_fw_bwStartBit_
unsigned int rod_fw_bwMask_
unsigned int str_fw_bwStartBit_
unsigned int moduleStartBit_
unsigned int moduleStartBit_
unsigned int wheelStartBit_
unsigned int str_int_extMask_
unsigned int moduleStartBit_
unsigned int sideStartBit_
unsigned int bladeStartBit_
unsigned int module_fw_bwStartBit_
unsigned int moduleStartBit_
unsigned int sideStartBit_
unsigned int module_fw_bwMask_
unsigned int diskStartBit_
unsigned int panelStartBit_
unsigned int moduleStartBit_
unsigned int sideStartBit_
unsigned int sterStartBit_
unsigned int str_fw_bwMask_
unsigned int ringStartBit_