CMS 3D CMS Logo

DDErrorDetection.cc
Go to the documentation of this file.
2 
3 #include <fstream>
4 
6 //***** Explicit template instantiation of Singleton
7 #include "DetectorDescription/Core/interface/Singleton.icc"
20 //**** to get rid of compile errors about ambiguous delete of Stores
25 
26 using namespace std;
27 
33 
34 //*****
35 
37  DDMaterial::StoreT::instance().setReadOnly(false);
38  DDSolid::StoreT::instance().setReadOnly(false);
39  DDLogicalPart::StoreT::instance().setReadOnly(false);
40  DDSpecifics::StoreT::instance().setReadOnly(false);
41  DDRotation::StoreT::instance().setReadOnly(false);
42 
43  scan(cpv);
44 }
45 
47  DDMaterial::StoreT::instance().setReadOnly(true);
48  DDSolid::StoreT::instance().setReadOnly(true);
49  DDLogicalPart::StoreT::instance().setReadOnly(true);
50  DDSpecifics::StoreT::instance().setReadOnly(true);
51  DDRotation::StoreT::instance().setReadOnly(true);
52 }
53 
55  std::cout << "DDErrorDetection::scan(): Scanning for DDD errors ..." << std::flush;
56 
57  DDLogicalPart lp_dummy;
58  DDMaterial ma_dummy;
59  DDRotation ro_dummy;
60  DDSpecifics sp_dummy;
61  DDSolid so_dummy;
62 
63  lp_err::instance() = dd_error_scan(lp_dummy);
64  ma_err::instance() = dd_error_scan(ma_dummy);
65  ro_err::instance() = dd_error_scan(ro_dummy);
66  sp_err::instance() = dd_error_scan(sp_dummy);
67  so_err::instance() = dd_error_scan(so_dummy);
68 
69  std::cout << " ... finished." << std::endl;
70 }
71 
72 void DDErrorDetection::errors() { std::cout << "What does DDErrorDetection::errors() do? nothing." << std::endl; }
73 
74 void DDErrorDetection::warnings() { std::cout << "What does DDErrorDetection::warnings() do? nothing." << std::endl; }
75 
76 // ddname as std::string, std::set<edges>
77 const std::map<std::string, std::set<DDLogicalPart>>& DDErrorDetection::lp_cpv(const DDCompactView& cpv) {
78  static std::map<std::string, std::set<DDLogicalPart>> result_;
79  if (!result_.empty())
80  return result_;
81 
82  const auto& g = cpv.graph();
83 
84  std::map<std::string, std::set<DDLogicalPart>>::const_iterator it(lp_err::instance().begin()),
85  ed(lp_err::instance().end());
86  for (; it != ed; ++it) {
87  std::set<DDLogicalPart>::const_iterator sit(it->second.begin()), sed(it->second.end());
88  for (; sit != sed; ++sit) {
89  const DDLogicalPart& lp = *sit;
90  auto er = g.edges(lp);
91  if (g.nodeIndex(lp).second) {
92  result_.insert(make_pair(lp.ddname().fullname(), std::set<DDLogicalPart>()));
93  }
94  for (; er.first != er.second; ++er.first) {
95  result_[lp.ddname().fullname()].insert(g.nodeData(er.first->first));
96  }
97  }
98  }
99  return result_;
100 }
101 
102 const std::map<DDSolid, std::set<DDLogicalPart>>& DDErrorDetection::so_lp() {
103  static std::map<DDSolid, std::set<DDLogicalPart>> result_;
104  if (!result_.empty())
105  return result_;
106 
107  const std::map<DDSolid, std::set<DDSolid>>& err_mat = so();
108  std::map<DDSolid, std::set<DDSolid>>::const_iterator it(err_mat.begin()), ed(err_mat.end());
109  for (; it != ed; ++it) {
110  std::set<DDLogicalPart> s;
111  DDSolid m(it->first);
112  result_[m] = s;
113  std::set<DDSolid>::const_iterator sit(it->second.begin()), sed(it->second.end());
114  for (; sit != sed; ++sit) {
115  result_[*sit] = s;
116  }
117  //std::cout << "insert: " << m.name() << std::endl;
118  }
119  DDLogicalPart::iterator<DDLogicalPart> lpit, lped;
120  lped.end();
121  for (; lpit != lped; ++lpit) {
122  if (lpit->isDefined().second) {
123  std::map<DDSolid, std::set<DDLogicalPart>>::iterator i = result_.find(lpit->solid());
124  //std::cout << "searching: " << lpit->name() << std::endl;
125  if (i != result_.end()) {
126  //std::cout << std::endl << "FOUND: " << lpit->name() << std::endl << std::endl;
127  i->second.insert(*lpit);
128  }
129  }
130  }
131  return result_;
132 }
133 
134 /*
135 const std::map<DDSpecifics, std::set<pair<DDLogicalPart, std::string> > & DDErrorDetection::sp()
136 {
137  static std::map<DDSpecifics, std::set<pair<DDLogicalPart, std::string> result_;
138  if (result_.size()) return result_;
139 }
140 */
141 
142 const std::map<DDMaterial, std::set<DDLogicalPart>>& DDErrorDetection::ma_lp() {
143  static std::map<DDMaterial, std::set<DDLogicalPart>> result_;
144  if (!result_.empty())
145  return result_;
146 
147  const std::vector<pair<std::string, std::string>>& err_mat = ma();
148  std::vector<pair<std::string, std::string>>::const_iterator it(err_mat.begin()), ed(err_mat.end());
149  for (; it != ed; ++it) {
150  std::set<DDLogicalPart> s;
151  DDMaterial m(it->second);
152  result_[m] = s;
153  }
154  DDLogicalPart::iterator<DDLogicalPart> lpit, lped;
155  lped.end();
156  for (; lpit != lped; ++lpit) {
157  if (lpit->isDefined().second) {
158  std::map<DDMaterial, std::set<DDLogicalPart>>::iterator i = result_.find(lpit->material());
159  if (i != result_.end()) {
160  //std::cout << std::endl << "FOUND: " << lpit->name() << std::endl << std::endl;
161  i->second.insert(*lpit);
162  }
163  }
164  }
165  return result_;
166 }
167 
168 const std::vector<pair<std::string, std::string>>& DDErrorDetection::ma() {
169  static std::vector<pair<std::string, std::string>> result_;
170  ofstream o("/dev/null");
171 
172  if (!result_.empty())
173  return result_;
174 
175  DDCheckMaterials(o, &result_);
176  return result_;
177 
178  /*
179  */
180 }
181 
182 const std::map<DDSolid, std::set<DDSolid>>& DDErrorDetection::so() {
183  static std::map<DDSolid, std::set<DDSolid>> result_;
184  if (!result_.empty())
185  return result_;
186 
187  // build the material dependency graph
188  using ma_graph_t = math::Graph<DDSolid, double>;
189  using ma_walker_t = math::GraphWalker<DDSolid, double>;
190 
191  ma_graph_t mag;
192  std::vector<DDSolid> errs;
193  DDSolid::iterator<DDSolid> it, ed;
194  ed.end();
195  for (; it != ed; ++it) {
196  DDSolid ma = *it;
197  if (ma.isDefined().second) {
198  DDSolidShape sh = ma.shape();
199  if ((sh == DDSolidShape::ddunion) || (sh == DDSolidShape::ddintersection) ||
200  (sh == DDSolidShape::ddsubtraction)) {
201  DDBooleanSolid bs(ma);
202  DDSolid a(bs.solidA()), b(bs.solidB());
203  //DDRotation r(bs.rotation());
204  //DDTranslation t(bs.translation);
205  mag.addEdge(a, ma, 0);
206  mag.addEdge(b, ma, 0);
207  }
208  } else {
209  errs.emplace_back(ma);
210  }
211  }
212 
213  std::vector<DDSolid>::const_iterator mit(errs.begin()), med(errs.end());
214  for (; mit != med; ++mit) {
215  ma_walker_t w(mag, *mit);
216  while (w.next()) {
217  result_[*mit].insert(w.current().first);
218  }
219  std::cout << std::endl;
220  }
221 
222  return result_;
223 }
224 
225 void DDErrorDetection::report(const DDCompactView& cpv, ostream& o) {
226  o << std::endl << std::endl << "---> DDD ERROR REPORT <---" << std::endl << std::endl;
227  o << "MISSING DEFINITIONS:" << std::endl << std::endl;
228  o << "LogicalParts:" << std::endl << lp_err::instance() << std::endl;
229  o << "Materials:" << std::endl << ma_err::instance() << std::endl;
230  o << "Solids:" << std::endl << so_err::instance() << std::endl;
231  o << "Rotations:" << std::endl << ro_err::instance() << std::endl;
232  o << "Specifics:" << std::endl << sp_err::instance() << std::endl;
233  o << std::endl << "IMPLICATIONS OF MISSING DEFINITIONS:" << std::endl << std::endl;
234 
235  o << "A) LogicalParts that have missing definitions but are used in the geometr. hierarchy (PosParts):" << std::endl
236  << " Format: namespace:name: [name of child]*" << std::endl;
237  o << lp_cpv(cpv) << std::endl;
238 
239  o << "B) Detailed report on Materials:" << std::endl;
240  const std::vector<pair<std::string, std::string>>& res = ma();
241  std::vector<pair<std::string, std::string>>::const_iterator it(res.begin()), ed(res.end());
242  for (; it != ed; ++it) {
243  std::cout << it->second << ": " << it->first << std::endl;
244  }
245  std::cout << std::endl;
246 
247  o << "C) Solids affected by Solids that have missing definitions:" << std::endl;
248  o << so() << std::endl;
249 
250  o << "D) LogicalParts affected by Materials of B):" << std::endl;
251  o << ma_lp() << std::endl;
252 
253  o << "E) LogicalParts affected by Solids of C):" << std::endl;
254  o << so_lp() << std::endl;
255 
256  // Did this ever exist?
257  // o << "F) Parent-Child positionings affected by Rotations that have missing definitions:" << std::endl;
258  o << std::endl;
259  //nix();
260 }
261 
263  return lp_err::instance().empty() && ma_err::instance().empty() && so_err::instance().empty() &&
264  ro_err::instance().empty() && sp_err::instance().empty() && lp_cpv(cpv).empty() && ma().empty() &&
265  so().empty() && ma_lp().empty() && so_lp().empty();
266 }
void scan(const DDCompactView &cpv)
const std::map< DDSolid, std::set< DDSolid > > & so()
T w() const
const std::vector< std::pair< std::string, std::string > > & ma()
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
const std::map< DDMaterial, std::set< DDLogicalPart > > & ma_lp()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
Definition: Electron.h:6
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
static value_type & instance()
const std::map< std::string, std::set< DDLogicalPart > > & lp_cpv(const DDCompactView &cpv)
const std::map< std::string, std::set< C > > & dd_error_scan(const C &)
bool noErrorsInTheReport(const DDCompactView &cpv)
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:123
const std::map< DDSolid, std::set< DDLogicalPart > > & so_lp()
void report(const DDCompactView &cpv, std::ostream &o)
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
const N & ddname() const
Definition: DDBase.h:61
DDSolidShape
Definition: DDSolidShapes.h:6
const std::string fullname() const
Definition: DDName.h:43
double b
Definition: hdecay.h:118
bool DDCheckMaterials(std::ostream &, std::vector< std::pair< std::string, std::string > > *=nullptr)
double a
Definition: hdecay.h:119
const Graph & graph() const
Provides read-only access to the data structure of the compact-view.
def_type isDefined() const
Definition: DDBase.h:90
Interface to attach user specific data to nodes in the expanded-view.
Definition: DDSpecifics.h:41