00001 namespace std { } using namespace std;
00002
00003 #include "DetectorDescription/RegressionTest/interface/DDErrorDetection.h"
00004 #include "DetectorDescription/Core/interface/DDCompactView.h"
00005 #include "DetectorDescription/Core/src/DDCheck.h"
00006 #include <iostream>
00007 #include <fstream>
00008
00009 DDErrorDetection::DDErrorDetection()
00010 {
00011 scan();
00012 }
00013
00014
00015 void DDErrorDetection::scan()
00016 {
00017 cout << "DDErrorDetection::scan(): Scanning for DDD errors ..." << flush;
00018
00019 DDLogicalPart lp_dummy;
00020 DDMaterial ma_dummy;
00021 DDRotation ro_dummy;
00022 DDSpecifics sp_dummy;
00023 DDSolid so_dummy;
00024
00025 lp_err::instance() = dd_error_scan(lp_dummy);
00026 ma_err::instance() = dd_error_scan(ma_dummy);
00027 ro_err::instance() = dd_error_scan(ro_dummy);
00028 sp_err::instance() = dd_error_scan(sp_dummy);
00029 so_err::instance() = dd_error_scan(so_dummy);
00030
00031 cout << " ... finished." << endl;
00032 }
00033
00034 void DDErrorDetection::errors()
00035 {
00036 }
00037
00038 void DDErrorDetection::warnings()
00039 {
00040 }
00041
00042
00043
00044
00045
00046
00047 const map<string, set<DDLogicalPart> > & DDErrorDetection::lp_cpv()
00048 {
00049 static map<string, set<DDLogicalPart> > result_;
00050 if (result_.size()) return result_;
00051
00052 DDCompactView cpv;
00053 const graph_type & g = cpv.graph();
00054
00055 map<string, set<DDLogicalPart> >::const_iterator it(lp_err::instance().begin()),
00056 ed(lp_err::instance().end());
00057 for (; it != ed; ++it) {
00058 set<DDLogicalPart>::const_iterator sit(it->second.begin()), sed(it->second.end());
00059 for( ; sit != sed; ++sit) {
00060 const DDLogicalPart & lp = *sit;
00061 graph_type::const_edge_range er = g.edges(lp);
00062 if (g.nodeIndex(lp).second) {
00063 result_.insert(make_pair(string(lp.ddname()), set<DDLogicalPart>()));
00064 }
00065 for (; er.first != er.second; ++er.first) {
00066 result_[lp.ddname()].insert(g.nodeData(er.first->first));
00067 }
00068 }
00069 }
00070 return result_;
00071 }
00072
00073
00074 const map<DDSolid, set<DDLogicalPart> > & DDErrorDetection::so_lp()
00075 {
00076 static map<DDSolid, set<DDLogicalPart> > result_;
00077 if (result_.size()) return result_;
00078
00079 const map<DDSolid, set<DDSolid> > & err_mat = so();
00080 map<DDSolid, set<DDSolid> >::const_iterator it(err_mat.begin()), ed(err_mat.end());
00081 for (; it != ed; ++it) {
00082 set<DDLogicalPart> s;
00083 DDSolid m(it->first);
00084 result_[m]=s;
00085 set<DDSolid>::const_iterator sit(it->second.begin()), sed(it->second.end());
00086 for(; sit != sed; ++sit) {
00087 result_[*sit] = s;
00088 }
00089
00090 }
00091 DDLogicalPart::iterator<DDLogicalPart> lpit,lped; lped.end();
00092 for (; lpit != lped; ++lpit) {
00093 if (lpit->isDefined().second) {
00094 map<DDSolid, set<DDLogicalPart> >::iterator i = result_.find(lpit->solid());
00095
00096 if ( i != result_.end() ) {
00097
00098 i->second.insert(*lpit);
00099 }
00100 }
00101 }
00102 return result_;
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 const map<DDMaterial, set<DDLogicalPart> > & DDErrorDetection::ma_lp()
00114 {
00115 static map<DDMaterial, set<DDLogicalPart> > result_;
00116 if (result_.size()) return result_;
00117
00118 const vector<pair<string,DDName> > & err_mat = ma();
00119 vector<pair<string,DDName> >::const_iterator it(err_mat.begin()), ed(err_mat.end());
00120 for (; it != ed; ++it) {
00121 set<DDLogicalPart> s;
00122 DDMaterial m(it->second);
00123 result_[m]=s;
00124
00125 }
00126 DDLogicalPart::iterator<DDLogicalPart> lpit,lped; lped.end();
00127 for (; lpit != lped; ++lpit) {
00128 if (lpit->isDefined().second) {
00129 map<DDMaterial, set<DDLogicalPart> >::iterator i = result_.find(lpit->material());
00130
00131 if ( i != result_.end() ) {
00132
00133 i->second.insert(*lpit);
00134 }
00135 }
00136 }
00137 return result_;
00138 }
00139
00140
00141 const vector<pair<string,DDName> > & DDErrorDetection::ma()
00142 {
00143 static vector<pair<string,DDName> > result_;
00144 ofstream o("/dev/null");
00145
00146 if (result_.size()) return result_;
00147
00148 DDCheckMaterials(o,&result_);
00149 return result_;
00150
00151
00152
00153 }
00154
00155
00156 const map<DDSolid,set<DDSolid> > & DDErrorDetection::so()
00157 {
00158 static map<DDSolid, set<DDSolid> > result_;
00159 if (result_.size()) return result_;
00160
00161
00162 typedef graph<DDSolid,double> ma_graph_t;
00163 typedef graphwalker<DDSolid,double> ma_walker_t;
00164
00165 ma_graph_t mag;
00166 vector<DDSolid> errs;
00167 DDSolid::iterator<DDSolid> it, ed; ed.end();
00168 for (; it != ed; ++it) {
00169 DDSolid ma = *it;
00170 if (ma.isDefined().second) {
00171 DDSolidShape sh = ma.shape();
00172 if ( (sh == ddunion) || (sh == ddintersection) || (sh == ddsubtraction) ) {
00173 DDBooleanSolid bs(ma);
00174 DDSolid a(bs.solidA()),b(bs.solidB());
00175
00176
00177 mag.addEdge(a, ma, 0);
00178 mag.addEdge(b, ma, 0);
00179 }
00180 }
00181 else {
00182 errs.push_back(ma);
00183 }
00184 }
00185
00186 vector<DDSolid>::const_iterator mit(errs.begin()),
00187 med(errs.end());
00188 for (; mit != med; ++mit) {
00189
00190 try {
00191
00192 ma_walker_t w(mag,*mit);
00193 while (w.next()) {
00194 result_[*mit].insert(w.current().first);
00195 }
00196 cout << endl;
00197 }
00198 catch(DDSolid m) {
00199 ;
00200
00201 }
00202 }
00203 return result_;
00204 }
00205
00206
00207 void DDErrorDetection::report(ostream & o)
00208 {
00209
00210 o << endl << endl << "---> DDD ERROR REPORT <---" << endl << endl;
00211 o << "MISSING DEFINITIONS:" << endl << endl;
00212 o << "LogicalParts:" << endl
00213 << lp_err::instance() << endl;
00214 o << "Materials:" << endl
00215 << ma_err::instance() << endl;
00216 o << "Solids:" << endl
00217 << so_err::instance() << endl;
00218 o << "Rotations:" << endl
00219 << ro_err::instance() << endl;
00220 o << "Specifics:" << endl
00221 << sp_err::instance() << endl;
00222 o << endl << "IMPLICATIONS OF MISSING DEFINITIONS:" << endl << endl;
00223
00224 o << "A) LogicalParts that have missing definitions but are used in the geometr. hierarchy (PosParts):" << endl
00225 << " Format: namespace:name: [name of child]*" << endl;
00226 o << lp_cpv() << endl;
00227
00228 o << "B) Detailed report on Materials:" << endl;
00229 const vector<pair<string,DDName> > & res = ma();
00230 vector<pair<string,DDName> >::const_iterator it(res.begin()), ed(res.end());
00231 for (; it != ed; ++it) {
00232 cout << it->second << ": " << it->first << endl;
00233 }
00234 cout << endl;
00235
00236
00237 o << "C) Solids affected by Solids that have missing definitions:" << endl;
00238 o << so() << endl;
00239
00240 o << "D) LogicalParts affected by Materials of B):" << endl;
00241 o << ma_lp() << endl;
00242
00243 o << "E) LogicalParts affected by Solids of C):" << endl;
00244 o << so_lp() << endl;
00245
00246
00247
00248 o << endl;
00249
00250 }