Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:55:09

0001 #ifndef DETECTOR_DESCRIPTION_DD_ERROR_DETECTION_H
0002 #define DETECTOR_DESCRIPTION_DD_ERROR_DETECTION_H
0003 
0004 #include "DetectorDescription/Core/interface/DDCompactView.h"
0005 #include <map>
0006 #include <ostream>
0007 #include <set>
0008 #include <string>
0009 #include <utility>
0010 #include <vector>
0011 
0012 #include "DetectorDescription/Core/interface/Singleton.h"
0013 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0014 #include "DetectorDescription/Core/interface/DDMaterial.h"
0015 #include "DetectorDescription/Core/interface/DDSolid.h"
0016 #include "DetectorDescription/Core/interface/DDSpecifics.h"
0017 #include "DetectorDescription/Core/interface/DDTransform.h"
0018 
0019 class DDCompactView;
0020 class DDLogicalPart;
0021 class DDMaterial;
0022 class DDName;
0023 class DDRotation;
0024 class DDSolid;
0025 class DDSpecifics;
0026 
0027 using lp_err = DDI::Singleton<std::map<std::string, std::set<DDLogicalPart>>>;
0028 using ma_err = DDI::Singleton<std::map<std::string, std::set<DDMaterial>>>;
0029 using so_err = DDI::Singleton<std::map<std::string, std::set<DDSolid>>>;
0030 using ro_err = DDI::Singleton<std::map<std::string, std::set<DDRotation>>>;
0031 using sp_err = DDI::Singleton<std::map<std::string, std::set<DDSpecifics>>>;
0032 
0033 using ns_type = std::map<std::string, std::set<std::string>>;
0034 using ns_nm_type = std::map<std::string, std::set<DDName>>;
0035 
0036 template <class T>
0037 std::ostream& operator<<(std::ostream& o, const std::set<T>& v) {
0038   typename std::set<T>::const_iterator it(v.begin()), ed(v.end());
0039   for (; it != ed; ++it) {
0040     o << it->ddname() << ' ';
0041   }
0042   return o;
0043 }
0044 
0045 template <class T>
0046 std::ostream& operator<<(std::ostream& o, const std::map<std::string, std::set<T>>& m) {
0047   typedef typename std::map<std::string, std::set<T>>::const_iterator c_it;
0048   c_it it(m.begin()), ed(m.end());
0049   for (; it != ed; ++it) {
0050     o << it->first << ": " << it->second;
0051     o << std::endl;
0052   }
0053   return o;
0054 }
0055 
0056 template <class T, class N>
0057 std::ostream& operator<<(std::ostream& o, const std::map<N, std::set<T>>& m) {
0058   typedef typename std::map<N, std::set<T>>::const_iterator c_it;
0059   c_it it(m.begin()), ed(m.end());
0060   for (; it != ed; ++it) {
0061     o << it->first.ddname() << ": " << it->second;
0062     o << std::endl;
0063   }
0064   return o;
0065 }
0066 
0067 template <typename T>
0068 bool findNameSpaces(T dummy, ns_type& m) {
0069   bool result = true;
0070   typename T::template iterator<T> it, ed;
0071   ed.end();
0072   for (; it != ed; ++it) {
0073     result = it->isDefined().second;
0074     if (!result)
0075       DDI::Singleton<std::map<std::string, std::set<T>>>::instance()[it->name().ns()].insert(*it);
0076     m[it->name().ns()].insert(it->name().name());
0077   }
0078   return result;
0079 }
0080 
0081 template <typename T>
0082 bool findNameSpaces(T dummy, ns_nm_type& m) {
0083   bool result = true;
0084   typename T::template iterator<T> it, ed;
0085   ed.end();
0086   for (; it != ed; ++it) {
0087     result = it->isDefined().second;
0088     if (!result)
0089       DDI::Singleton<std::map<std::string, std::set<T>>>::instance()[it->name().ns()].insert(*it);
0090     m[it->name().ns()].insert(it->name().name());
0091   }
0092   return result;
0093 }
0094 
0095 template <class C>
0096 const std::map<std::string, std::set<C>>& dd_error_scan(const C&) {
0097   typedef std::map<std::string, std::set<C>> error_type;
0098   static error_type result_;
0099   typename C::template iterator<C> it;
0100   typename C::template iterator<C> ed(C::end());
0101   for (; it != ed; ++it) {
0102     if (!it->isDefined().second) {
0103       result_[it->name().ns()].insert(*it);
0104     }
0105   }
0106   return result_;
0107 }
0108 
0109 class DDErrorDetection {
0110 public:
0111   DDErrorDetection(const DDCompactView& cpv);
0112   ~DDErrorDetection();
0113 
0114   void scan(const DDCompactView& cpv);
0115 
0116   void errors();
0117 
0118   void warnings();
0119 
0120   const std::map<std::string, std::set<DDLogicalPart>>& lp_cpv(const DDCompactView& cpv);
0121   const std::map<DDMaterial, std::set<DDLogicalPart>>& ma_lp();
0122   const std::map<DDSolid, std::set<DDLogicalPart>>& so_lp();
0123   const std::map<DDSolid, std::set<DDSolid>>& so();
0124 
0125   void nix();
0126 
0127   const std::vector<std::pair<std::string, std::string>>& ma();
0128 
0129   void report(const DDCompactView& cpv, std::ostream& o);
0130 
0131   bool noErrorsInTheReport(const DDCompactView& cpv);
0132 
0133 private:
0134   DDErrorDetection(){};
0135 };
0136 
0137 #endif