8 inline std::vector<uint32_t> split_string_to_uints(
const std::string&
str) {
9 std::vector<uint32_t>
out{};
10 std::size_t iStart{str.find_first_not_of(
" ,\n")}, iEnd{};
11 while (std::string::npos != iStart) {
12 iEnd = str.find_first_of(
" ,\n", iStart);
13 out.push_back(std::stoul(str.substr(iStart, iEnd),
nullptr, 0));
14 iStart = str.find_first_not_of(
" ,\n", iEnd);
19 class TrackerTopologyExtractor :
public tinyxml2::XMLVisitor {
21 bool VisitEnter(
const tinyxml2::XMLElement&
elem,
const tinyxml2::XMLAttribute*)
override {
22 if (std::strcmp(elem.Value(),
"Vector") == 0) {
24 if (att_type ==
"numeric") {
26 if (0 == att_name.compare(0, SubdetName.size(), SubdetName)) {
27 const std::string att_nEntries{elem.Attribute(
"nEntries")};
28 const std::size_t nEntries = att_nEntries.empty() ? 0 : std::stoul(att_nEntries);
29 const auto vals = split_string_to_uints(elem.GetText());
31 if (nEntries !=
vals.size()) {
33 "StandaloneTrackerTopology",
34 (
"Problem parsing element with name '" + att_name +
"': " +
"'nEntries' attribute claims " +
35 std::to_string(nEntries) +
" elements, but parsed " + std::to_string(
vals.size())));
37 const auto subDet = std::stoi(att_name.substr(SubdetName.size()));
40 pxbVals_.layerStartBit_ =
vals[0];
41 pxbVals_.ladderStartBit_ =
vals[1];
42 pxbVals_.moduleStartBit_ =
vals[2];
44 pxbVals_.layerMask_ =
vals[3];
45 pxbVals_.ladderMask_ =
vals[4];
46 pxbVals_.moduleMask_ =
vals[5];
52 pxfVals_.sideStartBit_ =
vals[0];
53 pxfVals_.diskStartBit_ =
vals[1];
54 pxfVals_.bladeStartBit_ =
vals[2];
55 pxfVals_.panelStartBit_ =
vals[3];
56 pxfVals_.moduleStartBit_ =
vals[4];
58 pxfVals_.sideMask_ =
vals[5];
59 pxfVals_.diskMask_ =
vals[6];
60 pxfVals_.bladeMask_ =
vals[7];
61 pxfVals_.panelMask_ =
vals[8];
62 pxfVals_.moduleMask_ =
vals[9];
68 tibVals_.layerStartBit_ =
vals[0];
69 tibVals_.str_fw_bwStartBit_ =
vals[1];
70 tibVals_.str_int_extStartBit_ =
vals[2];
71 tibVals_.strStartBit_ =
vals[3];
72 tibVals_.moduleStartBit_ =
vals[4];
73 tibVals_.sterStartBit_ =
vals[5];
75 tibVals_.layerMask_ =
vals[6];
76 tibVals_.str_fw_bwMask_ =
vals[7];
77 tibVals_.str_int_extMask_ =
vals[8];
78 tibVals_.strMask_ =
vals[9];
79 tibVals_.moduleMask_ =
vals[10];
80 tibVals_.sterMask_ =
vals[11];
86 tidVals_.sideStartBit_ =
vals[0];
87 tidVals_.wheelStartBit_ =
vals[1];
88 tidVals_.ringStartBit_ =
vals[2];
89 tidVals_.module_fw_bwStartBit_ =
vals[3];
90 tidVals_.moduleStartBit_ =
vals[4];
91 tidVals_.sterStartBit_ =
vals[5];
93 tidVals_.sideMask_ =
vals[6];
94 tidVals_.wheelMask_ =
vals[7];
95 tidVals_.ringMask_ =
vals[8];
96 tidVals_.module_fw_bwMask_ =
vals[9];
97 tidVals_.moduleMask_ =
vals[10];
98 tidVals_.sterMask_ =
vals[11];
104 tobVals_.layerStartBit_ =
vals[0];
105 tobVals_.rod_fw_bwStartBit_ =
vals[1];
106 tobVals_.rodStartBit_ =
vals[2];
107 tobVals_.moduleStartBit_ =
vals[3];
108 tobVals_.sterStartBit_ =
vals[4];
110 tobVals_.layerMask_ =
vals[5];
111 tobVals_.rod_fw_bwMask_ =
vals[6];
112 tobVals_.rodMask_ =
vals[7];
113 tobVals_.moduleMask_ =
vals[8];
114 tobVals_.sterMask_ =
vals[9];
120 tecVals_.sideStartBit_ =
vals[0];
121 tecVals_.wheelStartBit_ =
vals[1];
122 tecVals_.petal_fw_bwStartBit_ =
vals[2];
123 tecVals_.petalStartBit_ =
vals[3];
124 tecVals_.ringStartBit_ =
vals[4];
125 tecVals_.moduleStartBit_ =
vals[5];
126 tecVals_.sterStartBit_ =
vals[6];
128 tecVals_.sideMask_ =
vals[7];
129 tecVals_.wheelMask_ =
vals[8];
130 tecVals_.petal_fw_bwMask_ =
vals[9];
131 tecVals_.petalMask_ =
vals[10];
132 tecVals_.ringMask_ =
vals[11];
133 tecVals_.moduleMask_ =
vals[12];
134 tecVals_.sterMask_ =
vals[13];
146 if (!(foundPXB && foundPXF && foundTIB && foundTID && foundTOB && foundTEC)) {
147 throw cms::Exception(
"StandaloneTrackerTopology",
"Could not find parameters for all tracker subdetectors");
149 return TrackerTopology(pxbVals_, pxfVals_, tecVals_, tibVals_, tidVals_, tobVals_);
160 bool foundPXB =
false, foundPXF =
false, foundTIB =
false, foundTID =
false, foundTOB =
false, foundTEC =
false;
168 tinyxml2::XMLDocument xmlDoc;
169 xmlDoc.LoadFile(xmlFileName.c_str());
170 if (!xmlDoc.Error()) {
171 TrackerTopologyExtractor extr{};
172 xmlDoc.Accept(&extr);
173 return extr.getTrackerTopology();
176 std::string{
"Failed to parse file "} + xmlFileName +
": " + xmlDoc.ErrorStr());
180 tinyxml2::XMLDocument xmlDoc;
181 xmlDoc.Parse(xmlContent.c_str());
182 if (!xmlDoc.Error()) {
183 TrackerTopologyExtractor extr{};
184 xmlDoc.Accept(&extr);
185 return extr.getTrackerTopology();
def elem(elemtype, innerHTML='', html_class='', kwargs)
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
TrackerTopology fromTrackerParametersXMLString(const std::string &xmlContent)