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 {
38  DDMaterial::StoreT::instance().setReadOnly(false);
39  DDSolid::StoreT::instance().setReadOnly(false);
40  DDLogicalPart::StoreT::instance().setReadOnly(false);
41  DDSpecifics::StoreT::instance().setReadOnly(false);
42  DDRotation::StoreT::instance().setReadOnly(false);
43 
44  scan(cpv);
45 }
46 
48  DDMaterial::StoreT::instance().setReadOnly(true);
49  DDSolid::StoreT::instance().setReadOnly(true);
50  DDLogicalPart::StoreT::instance().setReadOnly(true);
51  DDSpecifics::StoreT::instance().setReadOnly(true);
52  DDRotation::StoreT::instance().setReadOnly(true);
53 }
54 
55 
57 {
58  std::cout << "DDErrorDetection::scan(): Scanning for DDD errors ..." << std::flush;
59 
60  DDLogicalPart lp_dummy;
61  DDMaterial ma_dummy;
62  DDRotation ro_dummy;
63  DDSpecifics sp_dummy;
64  DDSolid so_dummy;
65 
66  lp_err::instance() = dd_error_scan(lp_dummy);
67  ma_err::instance() = dd_error_scan(ma_dummy);
68  ro_err::instance() = dd_error_scan(ro_dummy);
69  sp_err::instance() = dd_error_scan(sp_dummy);
70  so_err::instance() = dd_error_scan(so_dummy);
71 
72  std::cout << " ... finished." << std::endl;
73 }
74 
76 {
77  std::cout << "What does DDErrorDetection::errors() do? nothing." << std::endl;
78 }
79 
81 {
82  std::cout << "What does DDErrorDetection::warnings() do? nothing." << std::endl;
83 }
84 
85 // ddname as std::string, std::set<edges>
86 const std::map<std::string, std::set<DDLogicalPart> > & DDErrorDetection::lp_cpv( const DDCompactView & cpv)
87 {
88  static std::map<std::string, std::set<DDLogicalPart> > result_;
89  if (!result_.empty()) return result_;
90 
91  const auto & g = cpv.graph();
92 
93  std::map<std::string, std::set<DDLogicalPart> >::const_iterator it(lp_err::instance().begin()),
94  ed(lp_err::instance().end());
95  for (; it != ed; ++it) {
96  std::set<DDLogicalPart>::const_iterator sit(it->second.begin()), sed(it->second.end());
97  for( ; sit != sed; ++sit) {
98  const DDLogicalPart & lp = *sit;
99  auto er = g.edges(lp);
100  if (g.nodeIndex(lp).second) {
101  result_.insert(make_pair(lp.ddname().fullname(), std::set<DDLogicalPart>()));
102  }
103  for (; er.first != er.second; ++er.first) {
104  result_[lp.ddname().fullname()].insert(g.nodeData(er.first->first));
105  }
106  }
107  }
108  return result_;
109 }
110 
111 
112 const std::map<DDSolid, std::set<DDLogicalPart> > & DDErrorDetection::so_lp()
113 {
114  static std::map<DDSolid, std::set<DDLogicalPart> > result_;
115  if (!result_.empty()) return result_;
116 
117  const std::map<DDSolid, std::set<DDSolid> > & err_mat = so();
118  std::map<DDSolid, std::set<DDSolid> >::const_iterator it(err_mat.begin()), ed(err_mat.end());
119  for (; it != ed; ++it) {
120  std::set<DDLogicalPart> s;
121  DDSolid m(it->first);
122  result_[m]=s;
123  std::set<DDSolid>::const_iterator sit(it->second.begin()), sed(it->second.end());
124  for(; sit != sed; ++sit) {
125  result_[*sit] = s;
126  }
127  //std::cout << "insert: " << m.name() << std::endl;
128  }
129  DDLogicalPart::iterator<DDLogicalPart> lpit,lped; lped.end();
130  for (; lpit != lped; ++lpit) {
131  if (lpit->isDefined().second) {
132  std::map<DDSolid, std::set<DDLogicalPart> >::iterator i = result_.find(lpit->solid());
133  //std::cout << "searching: " << lpit->name() << std::endl;
134  if ( i != result_.end() ) {
135  //std::cout << std::endl << "FOUND: " << lpit->name() << std::endl << std::endl;
136  i->second.insert(*lpit);
137  }
138  }
139  }
140  return result_;
141 }
142 
143 /*
144 const std::map<DDSpecifics, std::set<pair<DDLogicalPart, std::string> > & DDErrorDetection::sp()
145 {
146  static std::map<DDSpecifics, std::set<pair<DDLogicalPart, std::string> result_;
147  if (result_.size()) return result_;
148 }
149 */
150 
151 const std::map<DDMaterial, std::set<DDLogicalPart> > & DDErrorDetection::ma_lp()
152 {
153  static std::map<DDMaterial, std::set<DDLogicalPart> > result_;
154  if (!result_.empty()) return result_;
155 
156  const std::vector<pair<std::string,DDName> > & err_mat = ma();
157  std::vector<pair<std::string,DDName> >::const_iterator it(err_mat.begin()), ed(err_mat.end());
158  for (; it != ed; ++it) {
159  std::set<DDLogicalPart> s;
160  DDMaterial m(it->second);
161  result_[m]=s;
162  //std::cout << "insert: " << m.name() << std::endl;
163  }
164  DDLogicalPart::iterator<DDLogicalPart> lpit,lped; lped.end();
165  for (; lpit != lped; ++lpit) {
166  if (lpit->isDefined().second) {
167  std::map<DDMaterial, std::set<DDLogicalPart> >::iterator i = result_.find(lpit->material());
168  //std::cout << "searching: " << lpit->name() << std::endl;
169  if ( i != result_.end() ) {
170  //std::cout << std::endl << "FOUND: " << lpit->name() << std::endl << std::endl;
171  i->second.insert(*lpit);
172  }
173  }
174  }
175  return result_;
176 }
177 
178 
179 const std::vector<pair<std::string,DDName> > & DDErrorDetection::ma()
180 {
181  static std::vector<pair<std::string,DDName> > result_;
182  ofstream o("/dev/null");
183 
184  if (!result_.empty()) return result_;
185 
186  DDCheckMaterials(o,&result_);
187  return result_;
188 
189 /*
190  */
191 }
192 
193 
194 const std::map<DDSolid,std::set<DDSolid> > & DDErrorDetection::so()
195 {
196  static std::map<DDSolid, std::set<DDSolid> > result_;
197  if (!result_.empty()) return result_;
198 
199  // build the material dependency graph
200  using ma_graph_t = math::Graph<DDSolid,double>;
201  using ma_walker_t = math::GraphWalker<DDSolid,double>;
202 
203  ma_graph_t mag;
204  std::vector<DDSolid> errs;
205  DDSolid::iterator<DDSolid> it, ed; ed.end();
206  for (; it != ed; ++it) {
207  DDSolid ma = *it;
208  if (ma.isDefined().second) {
209  DDSolidShape sh = ma.shape();
211  DDBooleanSolid bs(ma);
212  DDSolid a(bs.solidA()),b(bs.solidB());
213  //DDRotation r(bs.rotation());
214  //DDTranslation t(bs.translation);
215  mag.addEdge(a, ma, 0);
216  mag.addEdge(b, ma, 0);
217  }
218  }
219  else {
220  errs.emplace_back(ma);
221  }
222  }
223 
224  std::vector<DDSolid>::const_iterator mit(errs.begin()),
225  med(errs.end());
226  for (; mit != med; ++mit) {
227 
228  ma_walker_t w(mag,*mit);
229  while (w.next()) {
230  result_[*mit].insert(w.current().first);
231  }
232  std::cout << std::endl;
233  }
234 
235  return result_;
236 }
237 
238 
239 void DDErrorDetection::report(const DDCompactView& cpv, ostream & o)
240 {
241 
242  o << std::endl << std::endl << "---> DDD ERROR REPORT <---" << std::endl << std::endl;
243  o << "MISSING DEFINITIONS:" << std::endl << std::endl;
244  o << "LogicalParts:" << std::endl
245  << lp_err::instance() << std::endl;
246  o << "Materials:" << std::endl
247  << ma_err::instance() << std::endl;
248  o << "Solids:" << std::endl
249  << so_err::instance() << std::endl;
250  o << "Rotations:" << std::endl
251  << ro_err::instance() << std::endl;
252  o << "Specifics:" << std::endl
253  << sp_err::instance() << std::endl;
254  o << std::endl << "IMPLICATIONS OF MISSING DEFINITIONS:" << std::endl << std::endl;
255 
256  o << "A) LogicalParts that have missing definitions but are used in the geometr. hierarchy (PosParts):" << std::endl
257  << " Format: namespace:name: [name of child]*" << std::endl;
258  o << lp_cpv(cpv) << std::endl;
259 
260  o << "B) Detailed report on Materials:" << std::endl;
261  const std::vector<pair<std::string,DDName> > & res = ma();
262  std::vector<pair<std::string,DDName> >::const_iterator it(res.begin()), ed(res.end());
263  for (; it != ed; ++it) {
264  std::cout << it->second << ": " << it->first << std::endl;
265  }
266  std::cout << std::endl;
267 
268 
269  o << "C) Solids affected by Solids that have missing definitions:" << std::endl;
270  o << so() << std::endl;
271 
272  o << "D) LogicalParts affected by Materials of B):" << std::endl;
273  o << ma_lp() << std::endl;
274 
275  o << "E) LogicalParts affected by Solids of C):" << std::endl;
276  o << so_lp() << std::endl;
277 
278  // Did this ever exist?
279  // o << "F) Parent-Child positionings affected by Rotations that have missing definitions:" << std::endl;
280  o << std::endl;
281  //nix();
282 }
283 
285 {
286  return lp_err::instance().empty() &&
287  ma_err::instance().empty() &&
288  so_err::instance().empty() &&
289  ro_err::instance().empty() &&
290  sp_err::instance().empty() &&
291  lp_cpv(cpv).empty() &&
292  ma().empty() &&
293  so().empty() &&
294  ma_lp().empty() &&
295  so_lp().empty();
296 }
void scan(const DDCompactView &cpv)
def_type isDefined() const
Definition: DDBase.h:110
const std::map< DDSolid, std::set< DDSolid > > & so()
const double w
Definition: UKUtility.cc:23
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
DDSolidShape
Definition: DDSolidShapes.h:4
const std::map< DDMaterial, std::set< DDLogicalPart > > & ma_lp()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:83
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:38
DDSolid solidB(void) const
Definition: DDSolid.cc:617
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:67
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)
const std::string fullname() const
Definition: DDName.h:52
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:92
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:138
#define end
Definition: vmac.h:39
const std::vector< std::pair< std::string, DDName > > & ma()
DDSolid solidA(void) const
Definition: DDSolid.cc:611
const Graph & graph() const
Provides read-only access to the data structure of the compact-view.
const std::map< DDSolid, std::set< DDLogicalPart > > & so_lp()
void report(const DDCompactView &cpv, std::ostream &o)
double b
Definition: hdecay.h:120
#define begin
Definition: vmac.h:32
double a
Definition: hdecay.h:121
bool DDCheckMaterials(std::ostream &, std::vector< std::pair< std::string, DDName > > *=0)
Checks all registered materials and sends a report /p os.
Interface to attach user specific data to nodes in the expanded-view.
Definition: DDSpecifics.h:42
const N & ddname() const
Definition: DDBase.h:80