CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DetectorDescription/RegressionTest/interface/DDErrorDetection.h

Go to the documentation of this file.
00001 #ifndef DD_DDErrorDetection_h
00002 #define DD_DDErrorDetection_h
00003 
00004 #include <map>
00005 #include <set>
00006 #include <string>
00007 
00008 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00009 #include "DetectorDescription/Core/interface/DDMaterial.h"
00010 #include "DetectorDescription/Core/interface/DDSolid.h"
00011 #include "DetectorDescription/Core/interface/DDTransform.h"
00012 #include "DetectorDescription/Core/interface/DDSpecifics.h"
00013 #include <DetectorDescription/Core/interface/DDCompactView.h>
00014 
00015 //=================
00016 #include "DetectorDescription/Base/interface/Singleton.h"
00017 typedef DDI::Singleton<std::map<std::string,std::set<DDLogicalPart> > > lp_err;
00018 typedef DDI::Singleton<std::map<std::string,std::set<DDMaterial> > >    ma_err;
00019 typedef DDI::Singleton<std::map<std::string,std::set<DDSolid> > >       so_err;
00020 typedef DDI::Singleton<std::map<std::string,std::set<DDRotation> > >    ro_err;
00021 typedef DDI::Singleton<std::map<std::string,std::set<DDSpecifics> > >   sp_err;
00022 
00023 //==================
00024 //*********************************************************************************************************************************
00025 
00026 typedef std::map<std::string, std::set<std::string> > ns_type;
00027 typedef std::map<std::string, std::set<DDName> > ns_nm_type;
00028 
00029 //*********************************************************************************************************************************
00030 
00031 
00032 
00033 template<class T> std::ostream & operator<<(std::ostream & o, const std::set<T> & v)
00034 {
00035   typename std::set<T>::const_iterator it(v.begin()), ed(v.end());
00036   for(; it != ed; ++it) {
00037     o << it->ddname() << ' ';
00038   }
00039   return o;
00040 }
00041 
00042 /*
00043 ostream & operator<<(ostream & o, const std::set<DDLogicalPart> & v)
00044 {
00045   std::set<DDLogicalPart>::const_iterator it(v.begin()), ed(v.end());
00046   for(; it != ed; ++it) {
00047     o << it->ddname().name() << ' ';
00048   }
00049   return o;
00050 }
00051 */
00052 template<class T> std::ostream & operator<<(std::ostream & o, const std::map<std::string, std::set<T> > & m) {
00053   typedef typename std::map<std::string, std::set<T> >::const_iterator c_it;
00054   c_it it(m.begin()), ed(m.end());
00055   for (; it != ed; ++it) {
00056     o << it->first << ": " << it->second;
00057     o << std::endl;
00058   }
00059   return o;
00060 }
00061 
00062 template<class T, class N> std::ostream & operator<<(std::ostream & o, const std::map<N, std::set<T> > & m) {
00063   typedef typename std::map<N, std::set<T> >::const_iterator c_it;
00064   c_it it(m.begin()), ed(m.end());
00065   for (; it != ed; ++it) {
00066     o << it->first.ddname() << ": " << it->second;
00067     o << std::endl;
00068   }
00069   return o;
00070 }
00071 
00072 template<typename T>
00073 bool findNameSpaces(T dummy, ns_type & m)
00074 {
00075    bool result=true;
00076    typename T::template iterator<T> it,ed;
00077    ed.end();
00078    for (; it != ed; ++it) {
00079      result = it->isDefined().second;
00080      if (!result) 
00081        DDI::Singleton<std::map<std::string,std::set<T> > >::instance()[it->name().ns()].insert(*it);
00082      m[it->name().ns()].insert(it->name().name());
00083    }
00084    return result;
00085 }
00086 
00087 
00088 template<typename T>
00089 bool findNameSpaces(T dummy, ns_nm_type & m)
00090 {
00091    bool result=true;
00092    typename T::template iterator<T> it,ed;
00093    ed.end();
00094    for (; it != ed; ++it) {
00095      result = it->isDefined().second;
00096      if (!result) 
00097        DDI::Singleton<std::map<std::string,std::set<T> > >::instance()[it->name().ns()].insert(*it);
00098      m[it->name().ns()].insert(it->name().name());
00099    }
00100    return result;
00101 }
00102 
00103 
00104 template <class C> const std::map<std::string, std::set<C> > & dd_error_scan(const C &)
00105 {
00106     typedef std::map<std::string, std::set<C> > error_type;
00107     static error_type result_;
00108     typename C::template iterator<C> it;
00109     typename C::template iterator<C> ed(C::end());
00110     for (; it != ed; ++it) {
00111       if (!it->isDefined().second) {
00112         result_[it->name().ns()].insert(*it);
00113       }
00114     }  
00115     return result_;
00116 }
00117 
00118 class DDErrorDetection
00119 {
00120 public:
00121   DDErrorDetection(const DDCompactView& cpv);    
00122   ~DDErrorDetection();
00123 
00124   void scan( const DDCompactView& cpv);
00125   
00126   void errors();
00127   
00128   void warnings();
00129   
00130   const std::map<std::string, std::set<DDLogicalPart> > & lp_cpv(const DDCompactView& cpv);
00131   const std::map<DDMaterial, std::set<DDLogicalPart> > & ma_lp();
00132   const std::map<DDSolid, std::set<DDLogicalPart> > & so_lp();
00133   const std::map<DDSolid, std::set<DDSolid> > & so();
00134 
00135   void nix();
00136   
00137   const std::vector<std::pair<std::string,DDName> > &  ma();
00138 
00139   void report(const DDCompactView& cpv, std::ostream & o); 
00140 
00141   bool noErrorsInTheReport(const DDCompactView& cpv);
00142 
00143  private:
00144   DDErrorDetection() { };
00145 
00146 };
00147 
00148 #endif