CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/DetectorDescription/RegressionTest/src/DDErrorDetection.cc

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