CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
StandaloneTrackerTopology.cc
Go to the documentation of this file.
2 
3 #include "tinyxml2.h"
6 
7 namespace {
8  // split into tokens and convert them to uint32_t
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);
16  }
17  return out;
18  }
19 
20  class TrackerTopologyExtractor : public tinyxml2::XMLVisitor {
21  public:
22  bool VisitEnter(const tinyxml2::XMLElement& elem, const tinyxml2::XMLAttribute*) override {
23  if (std::strcmp(elem.Value(), "Vector") == 0) {
24  const std::string att_type{elem.Attribute("type")};
25  if (att_type == "numeric") {
26  const std::string att_name{elem.Attribute("name")};
27  if (0 == att_name.compare(0, SubdetName.size(), SubdetName)) { // starts with
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());
31 
32  if (nEntries != vals.size()) {
33  throw cms::Exception(
34  "StandaloneTrackerTopology",
35  ("Problem parsing element with name '" + att_name + "': " + "'nEntries' attribute claims " +
36  std::to_string(nEntries) + " elements, but parsed " + std::to_string(vals.size())));
37  }
38  const auto subDet = std::stoi(att_name.substr(SubdetName.size()));
39  switch (subDet) {
40  case PixelSubdetector::PixelBarrel: // layer, ladder module
41  pxbVals_.layerStartBit_ = vals[0];
42  pxbVals_.ladderStartBit_ = vals[1];
43  pxbVals_.moduleStartBit_ = vals[2];
44 
45  pxbVals_.layerMask_ = vals[3];
46  pxbVals_.ladderMask_ = vals[4];
47  pxbVals_.moduleMask_ = vals[5];
48 
49  foundPXB = true;
50  break;
51 
52  case PixelSubdetector::PixelEndcap: // side, disk, blade, panel, module
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];
58 
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];
64 
65  foundPXF = true;
66  break;
67 
68  case StripSubdetector::TIB: // layer, str_fw_bw, str_int_ext, str, module, ster
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];
75 
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];
82 
83  foundTIB = true;
84  break;
85 
86  case StripSubdetector::TID: // side, wheel, ring, module_fw_bw, module, ster
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];
93 
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];
100 
101  foundTID = true;
102  break;
103 
104  case StripSubdetector::TOB: // layer, rod_fw_bw, rod, module, ster
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];
110 
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];
116 
117  foundTOB = true;
118  break;
119 
120  case StripSubdetector::TEC: // side, wheel, petal_fw_bw, petal, ring, module, ster
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];
128 
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];
136 
137  foundTEC = true;
138  break;
139  }
140  }
141  }
142  }
143  return true;
144  }
145 
146  TrackerTopology getTrackerTopology() const {
147  if (!(foundPXB && foundPXF && foundTIB && foundTID && foundTOB && foundTEC)) {
148  throw cms::Exception("StandaloneTrackerTopology", "Could not find parameters for all tracker subdetectors");
149  }
150  return TrackerTopology(pxbVals_, pxfVals_, tecVals_, tibVals_, tidVals_, tobVals_);
151  }
152 
153  private:
160 
161  bool foundPXB = false, foundPXF = false, foundTIB = false, foundTID = false, foundTOB = false, foundTEC = false;
162 
163  const std::string SubdetName = "Subdetector";
164  };
165 } // namespace
166 
167 namespace StandaloneTrackerTopology {
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();
175  } else {
176  throw cms::Exception("StandaloneTrackerTopology",
177  std::string{"Failed to parse file "} + xmlFileName + ": " + xmlDoc.ErrorStr());
178  }
179  }
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();
187  } else {
188  throw cms::Exception("StandaloneTrackerTopology", std::string{"Error while parsing XML: "} + xmlDoc.ErrorStr());
189  }
190  }
191 } // namespace StandaloneTrackerTopology
static constexpr auto TEC
std::string to_string(const V &value)
Definition: OMSAccess.h:71
static constexpr auto TOB
static constexpr auto TIB
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
TrackerTopology fromTrackerParametersXMLString(const std::string &xmlContent)
#define str(s)
static constexpr auto TID