8 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 TiXmlVisitor
23 bool VisitEnter(
const TiXmlElement&
elem,
const TiXmlAttribute*)
override 25 if ( elem.ValueStr() ==
"Vector" ) {
27 if ( att_type ==
"numeric" ) {
29 if ( 0 == att_name.compare(0, SubdetName.size(), SubdetName) ) {
30 const std::string att_nEntries{elem.Attribute(
"nEntries")};
31 const std::size_t nEntries = att_nEntries.empty() ? 0 : std::stoul(att_nEntries);
32 const auto vals = split_string_to_uints(elem.GetText());
34 if ( nEntries !=
vals.size() ) {
36 (
"Problem parsing element with name '"+att_name+
"': "+
37 "'nEntries' attribute claims "+std::to_string(nEntries)+
" elements, but parsed "+std::to_string(
vals.size())));
39 const auto subDet = std::stoi(att_name.substr(SubdetName.size()));
42 pxbVals_.layerStartBit_ =
vals[0];
43 pxbVals_.ladderStartBit_ =
vals[1];
44 pxbVals_.moduleStartBit_ =
vals[2];
46 pxbVals_.layerMask_ =
vals[3];
47 pxbVals_.ladderMask_ =
vals[4];
48 pxbVals_.moduleMask_ =
vals[5];
54 pxfVals_.sideStartBit_ =
vals[0];
55 pxfVals_.diskStartBit_ =
vals[1];
56 pxfVals_.bladeStartBit_ =
vals[2];
57 pxfVals_.panelStartBit_ =
vals[3];
58 pxfVals_.moduleStartBit_ =
vals[4];
60 pxfVals_.sideMask_ =
vals[5];
61 pxfVals_.diskMask_ =
vals[6];
62 pxfVals_.bladeMask_ =
vals[7];
63 pxfVals_.panelMask_ =
vals[8];
64 pxfVals_.moduleMask_ =
vals[9];
70 tibVals_.layerStartBit_ =
vals[ 0];
71 tibVals_.str_fw_bwStartBit_ =
vals[ 1];
72 tibVals_.str_int_extStartBit_ =
vals[ 2];
73 tibVals_.strStartBit_ =
vals[ 3];
74 tibVals_.moduleStartBit_ =
vals[ 4];
75 tibVals_.sterStartBit_ =
vals[ 5];
77 tibVals_.layerMask_ =
vals[ 6];
78 tibVals_.str_fw_bwMask_ =
vals[ 7];
79 tibVals_.str_int_extMask_ =
vals[ 8];
80 tibVals_.strMask_ =
vals[ 9];
81 tibVals_.moduleMask_ =
vals[10];
82 tibVals_.sterMask_ =
vals[11];
88 tidVals_.sideStartBit_ =
vals[ 0];
89 tidVals_.wheelStartBit_ =
vals[ 1];
90 tidVals_.ringStartBit_ =
vals[ 2];
91 tidVals_.module_fw_bwStartBit_ =
vals[ 3];
92 tidVals_.moduleStartBit_ =
vals[ 4];
93 tidVals_.sterStartBit_ =
vals[ 5];
95 tidVals_.sideMask_ =
vals[ 6];
96 tidVals_.wheelMask_ =
vals[ 7];
97 tidVals_.ringMask_ =
vals[ 8];
98 tidVals_.module_fw_bwMask_ =
vals[ 9];
99 tidVals_.moduleMask_ =
vals[10];
100 tidVals_.sterMask_ =
vals[11];
106 tobVals_.layerStartBit_ =
vals[0];
107 tobVals_.rod_fw_bwStartBit_ =
vals[1];
108 tobVals_.rodStartBit_ =
vals[2];
109 tobVals_.moduleStartBit_ =
vals[3];
110 tobVals_.sterStartBit_ =
vals[4];
112 tobVals_.layerMask_ =
vals[5];
113 tobVals_.rod_fw_bwMask_ =
vals[6];
114 tobVals_.rodMask_ =
vals[7];
115 tobVals_.moduleMask_ =
vals[8];
116 tobVals_.sterMask_ =
vals[9];
122 tecVals_.sideStartBit_ =
vals[ 0];
123 tecVals_.wheelStartBit_ =
vals[ 1];
124 tecVals_.petal_fw_bwStartBit_ =
vals[ 2];
125 tecVals_.petalStartBit_ =
vals[ 3];
126 tecVals_.ringStartBit_ =
vals[ 4];
127 tecVals_.moduleStartBit_ =
vals[ 5];
128 tecVals_.sterStartBit_ =
vals[ 6];
130 tecVals_.sideMask_ =
vals[ 7];
131 tecVals_.wheelMask_ =
vals[ 8];
132 tecVals_.petal_fw_bwMask_ =
vals[ 9];
133 tecVals_.petalMask_ =
vals[10];
134 tecVals_.ringMask_ =
vals[11];
135 tecVals_.moduleMask_ =
vals[12];
136 tecVals_.sterMask_ =
vals[13];
149 if ( ! ( foundPXB && foundPXF && foundTIB && foundTID && foundTOB && foundTEC ) ) {
150 throw cms::Exception(
"StandaloneTrackerTopology",
"Could not find parameters for all tracker subdetectors");
152 return TrackerTopology(pxbVals_, pxfVals_, tecVals_, tibVals_, tidVals_, tobVals_);
163 bool foundPXB =
false, foundPXF =
false, foundTIB =
false, foundTID =
false, foundTOB =
false, foundTEC =
false;
171 TiXmlDocument xmlDoc;
172 if ( xmlDoc.LoadFile(xmlFileName) ) {
173 TrackerTopologyExtractor extr{};
174 xmlDoc.Accept(&extr);
175 return extr.getTrackerTopology();
177 throw cms::Exception(
"StandaloneTrackerTopology",
std::string{
"Failed to parse file "}+xmlFileName+
": "+xmlDoc.ErrorDesc());
181 TiXmlDocument xmlDoc;
182 xmlDoc.Parse(xmlContent.c_str());
183 if ( ! xmlDoc.Error() ) {
184 TrackerTopologyExtractor extr{};
185 xmlDoc.Accept(&extr);
186 return extr.getTrackerTopology();
def elem(elemtype, innerHTML='', html_class='', kwargs)
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
TrackerTopology fromTrackerParametersXMLString(const std::string &xmlContent)