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