CMS 3D CMS Logo

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
TrackerTopology::TOBValues
Definition: TrackerTopology.h:88
PixelSubdetector::PixelEndcap
Definition: PixelSubdetector.h:11
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
TrackerTopology
Definition: TrackerTopology.h:16
TrackerTopology::PixelBarrelValues
Definition: TrackerTopology.h:18
TrackerTopology::TIDValues
Definition: TrackerTopology.h:73
TrackerTopology::TECValues
Definition: TrackerTopology.h:40
StandaloneTrackerTopology
Definition: StandaloneTrackerTopology.h:6
StandaloneTrackerTopology::fromTrackerParametersXMLString
TrackerTopology fromTrackerParametersXMLString(const std::string &xmlContent)
Definition: StandaloneTrackerTopology.cc:180
TrackerTopology::PixelEndcapValues
Definition: TrackerTopology.h:27
StandaloneTrackerTopology.h
str
#define str(s)
Definition: TestProcessor.cc:53
StripSubdetector::TIB
static constexpr auto TIB
Definition: StripSubdetector.h:16
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
StripSubdetector::TEC
static constexpr auto TEC
Definition: StripSubdetector.h:19
Exception
Definition: hltDiff.cc:245
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
Exception.h
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
TrackerTopology::TIBValues
Definition: TrackerTopology.h:57
StripSubdetector.h
StandaloneTrackerTopology::fromTrackerParametersXMLFile
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
Definition: StandaloneTrackerTopology.cc:168
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17