9 inline std::vector<uint32_t> split_string_to_uints(
const std::string&
str) {
10 std::vector<uint32_t>
out{};
11 std::size_t iStart{
str.find_first_not_of(
" ,\n")}, iEnd{};
12 while (std::string::npos != iStart) {
13 iEnd =
str.find_first_of(
" ,\n", iStart);
14 out.push_back(std::stoul(
str.substr(iStart, iEnd),
nullptr, 0));
15 iStart =
str.find_first_not_of(
" ,\n", iEnd);
20 class TrackerTopologyExtractor :
public tinyxml2::XMLVisitor {
22 bool VisitEnter(
const tinyxml2::XMLElement& elem,
const tinyxml2::XMLAttribute*)
override {
23 if (std::strcmp(elem.Value(),
"Vector") == 0) {
25 if (att_type ==
"numeric") {
27 if (0 == att_name.compare(0, SubdetName.size(), SubdetName)) {
28 const std::string att_nEntries{elem.Attribute(
"nEntries")};
29 const std::size_t nEntries = att_nEntries.empty() ? 0 : std::stoul(att_nEntries);
30 const auto vals = split_string_to_uints(elem.GetText());
32 if (nEntries != vals.size()) {
34 "StandaloneTrackerTopology",
35 (
"Problem parsing element with name '" + att_name +
"': " +
"'nEntries' attribute claims " +
38 const auto subDet = std::stoi(att_name.substr(SubdetName.size()));
41 pxbVals_.layerStartBit_ = vals[0];
42 pxbVals_.ladderStartBit_ = vals[1];
43 pxbVals_.moduleStartBit_ = vals[2];
45 pxbVals_.layerMask_ = vals[3];
46 pxbVals_.ladderMask_ = vals[4];
47 pxbVals_.moduleMask_ = vals[5];
53 pxfVals_.sideStartBit_ = vals[0];
54 pxfVals_.diskStartBit_ = vals[1];
55 pxfVals_.bladeStartBit_ = vals[2];
56 pxfVals_.panelStartBit_ = vals[3];
57 pxfVals_.moduleStartBit_ = vals[4];
59 pxfVals_.sideMask_ = vals[5];
60 pxfVals_.diskMask_ = vals[6];
61 pxfVals_.bladeMask_ = vals[7];
62 pxfVals_.panelMask_ = vals[8];
63 pxfVals_.moduleMask_ = vals[9];
69 tibVals_.layerStartBit_ = vals[0];
70 tibVals_.str_fw_bwStartBit_ = vals[1];
71 tibVals_.str_int_extStartBit_ = vals[2];
72 tibVals_.strStartBit_ = vals[3];
73 tibVals_.moduleStartBit_ = vals[4];
74 tibVals_.sterStartBit_ = vals[5];
76 tibVals_.layerMask_ = vals[6];
77 tibVals_.str_fw_bwMask_ = vals[7];
78 tibVals_.str_int_extMask_ = vals[8];
79 tibVals_.strMask_ = vals[9];
80 tibVals_.moduleMask_ = vals[10];
81 tibVals_.sterMask_ = vals[11];
87 tidVals_.sideStartBit_ = vals[0];
88 tidVals_.wheelStartBit_ = vals[1];
89 tidVals_.ringStartBit_ = vals[2];
90 tidVals_.module_fw_bwStartBit_ = vals[3];
91 tidVals_.moduleStartBit_ = vals[4];
92 tidVals_.sterStartBit_ = vals[5];
94 tidVals_.sideMask_ = vals[6];
95 tidVals_.wheelMask_ = vals[7];
96 tidVals_.ringMask_ = vals[8];
97 tidVals_.module_fw_bwMask_ = vals[9];
98 tidVals_.moduleMask_ = vals[10];
99 tidVals_.sterMask_ = vals[11];
105 tobVals_.layerStartBit_ = vals[0];
106 tobVals_.rod_fw_bwStartBit_ = vals[1];
107 tobVals_.rodStartBit_ = vals[2];
108 tobVals_.moduleStartBit_ = vals[3];
109 tobVals_.sterStartBit_ = vals[4];
111 tobVals_.layerMask_ = vals[5];
112 tobVals_.rod_fw_bwMask_ = vals[6];
113 tobVals_.rodMask_ = vals[7];
114 tobVals_.moduleMask_ = vals[8];
115 tobVals_.sterMask_ = vals[9];
121 tecVals_.sideStartBit_ = vals[0];
122 tecVals_.wheelStartBit_ = vals[1];
123 tecVals_.petal_fw_bwStartBit_ = vals[2];
124 tecVals_.petalStartBit_ = vals[3];
125 tecVals_.ringStartBit_ = vals[4];
126 tecVals_.moduleStartBit_ = vals[5];
127 tecVals_.sterStartBit_ = vals[6];
129 tecVals_.sideMask_ = vals[7];
130 tecVals_.wheelMask_ = vals[8];
131 tecVals_.petal_fw_bwMask_ = vals[9];
132 tecVals_.petalMask_ = vals[10];
133 tecVals_.ringMask_ = vals[11];
134 tecVals_.moduleMask_ = vals[12];
135 tecVals_.sterMask_ = vals[13];
147 if (!(foundPXB && foundPXF && foundTIB && foundTID && foundTOB && foundTEC)) {
148 throw cms::Exception(
"StandaloneTrackerTopology",
"Could not find parameters for all tracker subdetectors");
150 return TrackerTopology(pxbVals_, pxfVals_, tecVals_, tibVals_, tidVals_, tobVals_);
161 bool foundPXB =
false, foundPXF =
false, foundTIB =
false, foundTID =
false, foundTOB =
false, foundTEC =
false;
169 tinyxml2::XMLDocument xmlDoc;
170 xmlDoc.LoadFile(xmlFileName.c_str());
171 if (!xmlDoc.Error()) {
172 TrackerTopologyExtractor extr{};
173 xmlDoc.Accept(&extr);
174 return extr.getTrackerTopology();
177 std::string{
"Failed to parse file "} + xmlFileName +
": " + xmlDoc.ErrorStr());
181 tinyxml2::XMLDocument xmlDoc;
182 xmlDoc.Parse(xmlContent.c_str());
183 if (!xmlDoc.Error()) {
184 TrackerTopologyExtractor extr{};
185 xmlDoc.Accept(&extr);
186 return extr.getTrackerTopology();
static constexpr auto TEC
static std::string to_string(const XMLCh *ch)
static constexpr auto TOB
static constexpr auto TIB
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
TrackerTopology fromTrackerParametersXMLString(const std::string &xmlContent)
static constexpr auto TID