CMS 3D CMS Logo

DDErrorDetection.cc
Go to the documentation of this file.
1 namespace std { } using namespace std;
2 
4 
5 #include <fstream>
6 
8 //***** Explicit template instantiation of Singleton
9 #include "DetectorDescription/Core/interface/Singleton.icc"
22 //**** to get rid of compile errors about ambiguous delete of Stores
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_.size()) return result_;
90 
91  // DDCompactView cpv;
92  const DDCompactView::graph_type & g = cpv.graph();
93 
94  std::map<std::string, std::set<DDLogicalPart> >::const_iterator it(lp_err::instance().begin()),
95  ed(lp_err::instance().end());
96  for (; it != ed; ++it) {
97  std::set<DDLogicalPart>::const_iterator sit(it->second.begin()), sed(it->second.end());
98  for( ; sit != sed; ++sit) {
99  const DDLogicalPart & lp = *sit;
101  if (g.nodeIndex(lp).second) {
102  result_.insert(make_pair(lp.ddname().fullname(), std::set<DDLogicalPart>()));
103  }
104  for (; er.first != er.second; ++er.first) {
105  result_[lp.ddname().fullname()].insert(g.nodeData(er.first->first));
106  }
107  }
108  }
109  return result_;
110 }
111 
112 
113 const std::map<DDSolid, std::set<DDLogicalPart> > & DDErrorDetection::so_lp()
114 {
115  static std::map<DDSolid, std::set<DDLogicalPart> > result_;
116  if (result_.size()) return result_;
117 
118  const std::map<DDSolid, std::set<DDSolid> > & err_mat = so();
119  std::map<DDSolid, std::set<DDSolid> >::const_iterator it(err_mat.begin()), ed(err_mat.end());
120  for (; it != ed; ++it) {
121  std::set<DDLogicalPart> s;
122  DDSolid m(it->first);
123  result_[m]=s;
124  std::set<DDSolid>::const_iterator sit(it->second.begin()), sed(it->second.end());
125  for(; sit != sed; ++sit) {
126  result_[*sit] = s;
127  }
128  //std::cout << "insert: " << m.name() << std::endl;
129  }
130  DDLogicalPart::iterator<DDLogicalPart> lpit,lped; lped.end();
131  for (; lpit != lped; ++lpit) {
132  if (lpit->isDefined().second) {
133  std::map<DDSolid, std::set<DDLogicalPart> >::iterator i = result_.find(lpit->solid());
134  //std::cout << "searching: " << lpit->name() << std::endl;
135  if ( i != result_.end() ) {
136  //std::cout << std::endl << "FOUND: " << lpit->name() << std::endl << std::endl;
137  i->second.insert(*lpit);
138  }
139  }
140  }
141  return result_;
142 }
143 
144 /*
145 const std::map<DDSpecifics, std::set<pair<DDLogicalPart, std::string> > & DDErrorDetection::sp()
146 {
147  static std::map<DDSpecifics, std::set<pair<DDLogicalPart, std::string> result_;
148  if (result_.size()) return result_;
149 }
150 */
151 
152 const std::map<DDMaterial, std::set<DDLogicalPart> > & DDErrorDetection::ma_lp()
153 {
154  static std::map<DDMaterial, std::set<DDLogicalPart> > result_;
155  if (result_.size()) return result_;
156 
157  const std::vector<pair<std::string,DDName> > & err_mat = ma();
158  std::vector<pair<std::string,DDName> >::const_iterator it(err_mat.begin()), ed(err_mat.end());
159  for (; it != ed; ++it) {
160  std::set<DDLogicalPart> s;
161  DDMaterial m(it->second);
162  result_[m]=s;
163  //std::cout << "insert: " << m.name() << std::endl;
164  }
165  DDLogicalPart::iterator<DDLogicalPart> lpit,lped; lped.end();
166  for (; lpit != lped; ++lpit) {
167  if (lpit->isDefined().second) {
168  std::map<DDMaterial, std::set<DDLogicalPart> >::iterator i = result_.find(lpit->material());
169  //std::cout << "searching: " << lpit->name() << std::endl;
170  if ( i != result_.end() ) {
171  //std::cout << std::endl << "FOUND: " << lpit->name() << std::endl << std::endl;
172  i->second.insert(*lpit);
173  }
174  }
175  }
176  return result_;
177 }
178 
179 
180 const std::vector<pair<std::string,DDName> > & DDErrorDetection::ma()
181 {
182  static std::vector<pair<std::string,DDName> > result_;
183  ofstream o("/dev/null");
184 
185  if (result_.size()) return result_;
186 
187  DDCheckMaterials(o,&result_);
188  return result_;
189 
190 /*
191  */
192 }
193 
194 
195 const std::map<DDSolid,std::set<DDSolid> > & DDErrorDetection::so()
196 {
197  static std::map<DDSolid, std::set<DDSolid> > result_;
198  if (result_.size()) return result_;
199 
200  // build the material dependency graph
201  typedef graph<DDSolid,double> ma_graph_t;
202  typedef graphwalker<DDSolid,double> ma_walker_t;
203 
204  ma_graph_t mag;
205  std::vector<DDSolid> errs;
206  DDSolid::iterator<DDSolid> it, ed; ed.end();
207  for (; it != ed; ++it) {
208  DDSolid ma = *it;
209  if (ma.isDefined().second) {
210  DDSolidShape sh = ma.shape();
211  if ( (sh == ddunion) || (sh == ddintersection) || (sh == ddsubtraction) ) {
212  DDBooleanSolid bs(ma);
213  DDSolid a(bs.solidA()),b(bs.solidB());
214  //DDRotation r(bs.rotation());
215  //DDTranslation t(bs.translation);
216  mag.addEdge(a, ma, 0);
217  mag.addEdge(b, ma, 0);
218  }
219  }
220  else {
221  errs.push_back(ma);
222  }
223  }
224 
225  std::vector<DDSolid>::const_iterator mit(errs.begin()),
226  med(errs.end());
227  for (; mit != med; ++mit) {
228 
229  try {
230  // loop over erroreous materials
231  ma_walker_t w(mag,*mit);
232  while (w.next()) {
233  result_[*mit].insert(w.current().first);
234  }
235  std::cout << std::endl;
236  }
237  catch(DDSolid m) {
238  ;
239  //std::cout << "no such material: " << m << " for creating a walker." << std::endl;
240  }
241  }
242  return result_;
243 }
244 
245 
246 void DDErrorDetection::report(const DDCompactView& cpv, ostream & o)
247 {
248 
249  o << std::endl << std::endl << "---> DDD ERROR REPORT <---" << std::endl << std::endl;
250  o << "MISSING DEFINITIONS:" << std::endl << std::endl;
251  o << "LogicalParts:" << std::endl
252  << lp_err::instance() << std::endl;
253  o << "Materials:" << std::endl
254  << ma_err::instance() << std::endl;
255  o << "Solids:" << std::endl
256  << so_err::instance() << std::endl;
257  o << "Rotations:" << std::endl
258  << ro_err::instance() << std::endl;
259  o << "Specifics:" << std::endl
260  << sp_err::instance() << std::endl;
261  o << std::endl << "IMPLICATIONS OF MISSING DEFINITIONS:" << std::endl << std::endl;
262 
263  o << "A) LogicalParts that have missing definitions but are used in the geometr. hierarchy (PosParts):" << std::endl
264  << " Format: namespace:name: [name of child]*" << std::endl;
265  o << lp_cpv(cpv) << std::endl;
266 
267  o << "B) Detailed report on Materials:" << std::endl;
268  const std::vector<pair<std::string,DDName> > & res = ma();
269  std::vector<pair<std::string,DDName> >::const_iterator it(res.begin()), ed(res.end());
270  for (; it != ed; ++it) {
271  std::cout << it->second << ": " << it->first << std::endl;
272  }
273  std::cout << std::endl;
274 
275 
276  o << "C) Solids affected by Solids that have missing definitions:" << std::endl;
277  o << so() << std::endl;
278 
279  o << "D) LogicalParts affected by Materials of B):" << std::endl;
280  o << ma_lp() << std::endl;
281 
282  o << "E) LogicalParts affected by Solids of C):" << std::endl;
283  o << so_lp() << std::endl;
284 
285  // Did this ever exist?
286  // o << "F) Parent-Child positionings affected by Rotations that have missing definitions:" << std::endl;
287  o << std::endl;
288  //nix();
289 }
290 
292 {
293  return lp_err::instance().empty() &&
294  ma_err::instance().empty() &&
295  so_err::instance().empty() &&
296  ro_err::instance().empty() &&
297  sp_err::instance().empty() &&
298  lp_cpv(cpv).empty() &&
299  ma().empty() &&
300  so().empty() &&
301  ma_lp().empty() &&
302  so_lp().empty();
303 }
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
std::pair< const_edge_iterator, const_edge_iterator > const_edge_range
Definition: adjgraph.h:140
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:6
const graph_type & graph() const
Provides read-only access to the data structure of the compact-view.
const N & nodeData(const edge_type &) const
Definition: adjgraph.h:317
const std::map< DDMaterial, std::set< DDLogicalPart > > & ma_lp()
type of data representation of DDCompactView
Definition: DDCompactView.h:90
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:4
A DDSolid represents the shape of a part.
Definition: DDSolid.h:38
DDSolid solidB(void) const
Definition: DDSolid.cc:665
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:64
static value_type & instance()
edge_range edges(index_type nodeIndex)
Definition: adjgraph.h:277
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:141
#define end
Definition: vmac.h:37
const std::vector< std::pair< std::string, DDName > > & ma()
DDSolid solidA(void) const
Definition: DDSolid.cc:659
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:30
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.
index_result nodeIndex(const N &) const
Definition: adjgraph.h:252
Interface to attach user specific data to nodes in the expanded-view.
Definition: DDSpecifics.h:42
const N & ddname() const
Definition: DDBase.h:80