CMS 3D CMS Logo

StandaloneTrackerTopology.cc
Go to the documentation of this file.
2 
3 #include "tinyxml.h"
5 
6 namespace {
7  // split into tokens and convert them to uint32_t
8  inline std::vector<uint32_t> split_string_to_uints(const std::string& str)
9  {
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 TiXmlVisitor
21  {
22  public:
23  bool VisitEnter(const TiXmlElement& elem, const TiXmlAttribute*) override
24  {
25  if ( elem.ValueStr() == "Vector" ) {
26  const std::string att_type{elem.Attribute("type")};
27  if ( att_type == "numeric" ) {
28  const std::string att_name{elem.Attribute("name")};
29  if ( 0 == att_name.compare(0, SubdetName.size(), SubdetName) ) { // starts with
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());
33 
34  if ( nEntries != vals.size() ) {
35  throw cms::Exception("StandaloneTrackerTopology",
36  ("Problem parsing element with name '"+att_name+"': "+
37  "'nEntries' attribute claims "+std::to_string(nEntries)+" elements, but parsed "+std::to_string(vals.size())));
38  }
39  const auto subDet = std::stoi(att_name.substr(SubdetName.size()));
40  switch (subDet) {
41  case PixelSubdetector::PixelBarrel: // layer, ladder module
42  pxbVals_.layerStartBit_ = vals[0];
43  pxbVals_.ladderStartBit_ = vals[1];
44  pxbVals_.moduleStartBit_ = vals[2];
45 
46  pxbVals_.layerMask_ = vals[3];
47  pxbVals_.ladderMask_ = vals[4];
48  pxbVals_.moduleMask_ = vals[5];
49 
50  foundPXB = true;
51  break;
52 
53  case PixelSubdetector::PixelEndcap: // side, disk, blade, panel, module
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];
59 
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];
65 
66  foundPXF = true;
67  break;
68 
69  case StripSubdetector::TIB: // layer, str_fw_bw, str_int_ext, str, module, ster
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];
76 
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];
83 
84  foundTIB = true;
85  break;
86 
87  case StripSubdetector::TID: // side, wheel, ring, module_fw_bw, module, ster
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];
94 
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];
101 
102  foundTID = true;
103  break;
104 
105  case StripSubdetector::TOB: // layer, rod_fw_bw, rod, module, ster
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];
111 
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];
117 
118  foundTOB = true;
119  break;
120 
121  case StripSubdetector::TEC: // side, wheel, petal_fw_bw, petal, ring, module, ster
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];
129 
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];
137 
138  foundTEC = true;
139  break;
140  }
141  }
142  }
143  }
144  return true;
145  }
146 
147  TrackerTopology getTrackerTopology() const
148  {
149  if ( ! ( foundPXB && foundPXF && foundTIB && foundTID && foundTOB && foundTEC ) ) {
150  throw cms::Exception("StandaloneTrackerTopology", "Could not find parameters for all tracker subdetectors");
151  }
152  return TrackerTopology(pxbVals_, pxfVals_, tecVals_, tibVals_, tidVals_, tobVals_);
153  }
154 
155  private:
162 
163  bool foundPXB = false, foundPXF = false, foundTIB = false, foundTID = false, foundTOB = false, foundTEC = false;
164 
165  const std::string SubdetName = "Subdetector";
166  };
167 }
168 
169 namespace StandaloneTrackerTopology {
171  TiXmlDocument xmlDoc;
172  if ( xmlDoc.LoadFile(xmlFileName) ) {
173  TrackerTopologyExtractor extr{};
174  xmlDoc.Accept(&extr);
175  return extr.getTrackerTopology();
176  } else {
177  throw cms::Exception("StandaloneTrackerTopology", std::string{"Failed to parse file "}+xmlFileName+": "+xmlDoc.ErrorDesc());
178  }
179 }
181  TiXmlDocument 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.ErrorDesc());
189  }
190 }
191 }
def elem(elemtype, innerHTML='', html_class='', kwargs)
Definition: HTMLExport.py:18
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
TrackerTopology fromTrackerParametersXMLString(const std::string &xmlContent)