CMS 3D CMS Logo

MTDParametersFromDD.cc
Go to the documentation of this file.
1 //#define EDM_ML_DEBUG
2 
11 
12 using namespace MTDTopologyMode;
13 
14 namespace {
15  int getMTDTopologyMode(const char* s, const DDsvalues_type& sv) {
16  DDValue val(s);
17  if (DDfetch(&sv, val)) {
18  const std::vector<std::string>& fvec = val.strings();
19  if (fvec.empty()) {
20  throw cms::Exception("MTDParametersFromDD") << "Failed to get " << s << " tag.";
21  }
22 
23  int result(-1);
25  result = static_cast<int>(eparser);
26  return result;
27  } else {
28  throw cms::Exception("MTDParametersFromDD") << "Failed to get " << s << " tag.";
29  }
30  }
31 } // namespace
32 
34  std::array<std::string, 2> mtdSubdet{{"BTL", "ETL"}};
35  int subdet(0);
36  for (const auto& name : mtdSubdet) {
37  auto const& v = cvp->vector(name);
38  if (!v.empty()) {
39  subdet++;
40  std::vector<int> subdetPars = dbl_to_int(v);
41  putOne(subdet, subdetPars, ptp);
42  } else {
43  throw cms::Exception("MTDParametersFromDD") << "Not found " << name << " but needed.";
44  }
45  }
46 
47  ptp.vpars_ = dbl_to_int(cvp->vector("vPars"));
48 
49  std::string attribute = "OnlyForMTDRecNumbering";
50  DDSpecificsHasNamedValueFilter filter1{attribute};
51  DDFilteredView fv1(*cvp, filter1);
52  bool ok = fv1.firstChild();
53  int topoMode(-1);
54  if (ok) {
56  topoMode = getMTDTopologyMode("TopologyMode", sv);
57  ptp.topologyMode_ = topoMode;
58  } else {
59  throw cms::Exception("MTDParametersFromDD") << "Not found " << attribute.c_str() << " but needed.";
60  }
61 
63  std::array<std::string, 8> etlLayout{{
64  "StartCopyNo_Front_Left",
65  "StartCopyNo_Front_Right",
66  "StartCopyNo_Back_Left",
67  "StartCopyNo_Back_Right",
68  "Offset_Front_Left",
69  "Offset_Front_Right",
70  "Offset_Back_Left",
71  "Offset_Back_Right",
72  }};
73  int sector(10);
74  for (const auto& name : etlLayout) {
75  auto const& v = cvp->vector(name);
76  if (!v.empty()) {
77  sector++;
78  std::vector<int> ipos = dbl_to_int(v);
79  putOne(sector, ipos, ptp);
80  } else {
81  throw cms::Exception("MTDParametersFromDD") << "Not found " << name << " but needed.";
82  }
83  }
84  }
85 
86  return true;
87 }
88 
90  cms::DDVectorsMap vmap = cvp->detector()->vectors();
91 
92  std::array<std::string, 2> mtdSubdet{{"BTL", "ETL"}};
93  int subdet(0);
94  for (const auto& name : mtdSubdet) {
95  bool found(false);
96  for (auto const& it : vmap) {
97  if (dd4hep::dd::compareEqual(dd4hep::dd::noNamespace(it.first), name)) {
98  subdet++;
99  std::vector<int> subdetPars;
100  subdetPars.reserve(it.second.size());
101  for (const auto& i : it.second)
102  subdetPars.emplace_back(std::round(i));
103  putOne(subdet, subdetPars, ptp);
104  found = true;
105  break;
106  }
107  }
108  if (!found) {
109  throw cms::Exception("MTDParametersFromDD") << "Not found " << name << " but needed.";
110  }
111  }
112 
113  auto it = vmap.find("vPars");
114  if (it != end(vmap)) {
115  std::vector<int> tmpVec;
116  for (const auto& i : it->second)
117  tmpVec.emplace_back(std::round(i));
118  ptp.vpars_ = tmpVec;
119  }
120 
121  cms::DDSpecParRefs ref;
122  const cms::DDSpecParRegistry& mypar = cvp->specpars();
123  std::string attribute = "OnlyForMTDRecNumbering";
124  mypar.filter(ref, attribute, "MTD");
125 
126  std::string topoModeS(mypar.specPar("mtdNumbering")->strValue("TopologyMode"));
127  int topoMode(-1);
128  if (!topoModeS.empty()) {
130  topoMode = static_cast<int>(eparser);
131  ptp.topologyMode_ = topoMode;
132  } else {
133  throw cms::Exception("MTDParametersFromDD") << "Not found " << attribute.c_str() << " but needed.";
134  }
135 
137  std::array<std::string, 8> etlLayout{{
138  "StartCopyNo_Front_Left",
139  "StartCopyNo_Front_Right",
140  "StartCopyNo_Back_Left",
141  "StartCopyNo_Back_Right",
142  "Offset_Front_Left",
143  "Offset_Front_Right",
144  "Offset_Back_Left",
145  "Offset_Back_Right",
146  }};
147  int sector(10); // add vector index with offset, to distinguish from subdet
148  for (const auto& name : etlLayout) {
149  bool found(false);
150  for (auto const& it : vmap) {
151  if (dd4hep::dd::compareEqual(dd4hep::dd::noNamespace(it.first), name)) {
152  sector++;
153  std::vector<int> ipos;
154  ipos.reserve(it.second.size());
155  for (const auto& i : it.second)
156  ipos.emplace_back(std::round(i));
157  putOne(sector, ipos, ptp);
158  found = true;
159  break;
160  }
161  }
162  if (!found) {
163  throw cms::Exception("MTDParametersFromDD") << "Not found " << name << " but needed.";
164  }
165  }
166  }
167 
168  return true;
169 }
170 
171 void MTDParametersFromDD::putOne(int subdet, std::vector<int>& vpars, PMTDParameters& ptp) {
173  item.id_ = subdet;
174  item.vpars_ = vpars;
175  ptp.vitems_.emplace_back(item);
176 #ifdef EDM_ML_DEBUG
177  auto print_item = [&]() {
178  std::stringstream ss;
179  ss << item.id_ << " with " << item.vpars_.size() << " elements:";
180  for (const auto& thePar : item.vpars_) {
181  ss << " " << thePar;
182  }
183  return ss.str();
184  };
185  edm::LogInfo("MTDParametersFromDD") << "Adding PMTDParameters item: " << print_item();
186 #endif
187 }
std::vector< Item > vitems_
dd4hep::SpecParRefs DDSpecParRefs
Definition: DDCompactView.h:29
std::vector< double > const & vector(std::string_view iKey) const
returns an empty container if not found
const cms::DDDetector * detector() const
Definition: DDCompactView.h:34
DDSpecParRegistry const & specpars() const
Definition: DDCompactView.h:35
void putOne(int, std::vector< int > &, PMTDParameters &)
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
std::vector< int > vpars_
std::unordered_map< std::string, std::vector< double > > DDVectorsMap
Definition: DDNamespace.h:20
dd4hep::SpecParRegistry DDSpecParRegistry
Definition: DDCompactView.h:28
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12
Mode MTDStringToEnumParser(const std::string &)
ETLDetId::EtlLayout etlLayoutFromTopoMode(const int &topoMode)
std::vector< int > dbl_to_int(const std::vector< double > &vecdbl)
Converts a std::vector of doubles to a std::vector of int.
Definition: DDutils.h:7
DDsvalues_type mergedSpecifics() const
Log< level::Info, false > LogInfo
bool build(const DDCompactView *, PMTDParameters &)
bool firstChild()
set the current node to the first child ...
cms::DDVectorsMap const & vectors() const
Definition: DDDetector.h:17