Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:34

0001 #include "DetectorDescription/RegressionTest/src/DDCheck.h"
0002 
0003 #include <map>
0004 
0005 #include "DetectorDescription/Core/interface/DDCompactView.h"
0006 #include "DetectorDescription/Core/interface/DDExpandedView.h"
0007 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0008 #include "DetectorDescription/Core/interface/DDMaterial.h"
0009 #include "DetectorDescription/Core/interface/DDName.h"
0010 #include "DetectorDescription/Core/interface/DDPosData.h"
0011 #include "DetectorDescription/Core/interface/DDSolid.h"
0012 #include "DetectorDescription/Core/interface/DDSolidShapes.h"
0013 #include "DetectorDescription/Core/interface/DDTransform.h"
0014 #include "DataFormats/Math/interface/Graph.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 
0017 bool DDCheckLP(const DDLogicalPart& lp, std::ostream& os) {
0018   bool result = false;
0019   // is it defined or just declared?
0020   if (!lp) {
0021     os << "LogicalPart: " << lp << " is not defined!" << std::endl;
0022   } else {
0023     // check solid
0024     if (!lp.solid()) {
0025       os << "LogicalPart: " << lp << "| no solid defined, solid=" << lp.solid() << std::endl;
0026     } else if (lp.solid().shape() == DDSolidShape::dd_not_init) {
0027       os << "LogicalPart: " << lp << "| solid not init, solid=" << lp.solid() << std::endl;
0028     }
0029     // check material
0030     if (!lp.material()) {
0031       os << "LogicalPart: " << lp << "| no material defined, material=" << lp.material() << std::endl;
0032     } else {  // check consituents recursively
0033     }
0034   }
0035   return result;
0036 }
0037 
0038 // checks PosData* if it contains sensfull stuff ...
0039 //:void DDCheckPD(const DDLogicalPart & lp, Graph::neighbour_type & nb, std::ostream & os)
0040 bool DDCheckPD(const DDLogicalPart& lp,
0041                DDCompactView::Graph::edge_range nb,
0042                const DDCompactView::Graph& g,
0043                std::ostream& os) {
0044   bool result = false;
0045   if (nb.first != nb.second) {
0046     for (; nb.first != nb.second; ++(nb.first)) {
0047       if (!nb.first->second) {
0048         edm::LogInfo("DDCheck") << "PosData of LogicalPart " << lp.name() << " missing." << std::endl;
0049         edm::LogInfo("DDCheck") << "  the LogicalPart is meant to be a daughter volume, but its position is missing!"
0050                                 << std::endl;
0051       } else {  // check for the rotation matrix being present
0052         const DDRotation& r = g.edgeData(nb.first->second)->ddrot();
0053         if (!r.isDefined().second) {
0054           //if (! nb.first->second->rot_.rotation() ) {
0055           const DDRotation& r = g.edgeData(nb.first->second)->ddrot();
0056           os << "Rotationmatrix is not defined: " << r << std::endl;
0057         }
0058       }
0059     }
0060   }
0061   return result;
0062 }
0063 
0064 bool DDCheckConnect(const DDCompactView& cpv, std::ostream& os) {
0065   bool result = false;
0066   os << std::endl << "Checking connectivity of CompactView:" << std::endl;
0067 
0068   // Algorithm:
0069   // Pass 1: walk the whole graph, mark every visited LogicalPart-node
0070   // Pass 2: iterate over all nodes, check with marked nodes from Pass 1
0071 
0072   // Pass 1:
0073   std::map<DDLogicalPart, bool> visited;
0074   auto wkr = math::GraphWalker<DDLogicalPart, DDPosData*>(cpv.graph(), cpv.root());
0075   visited[wkr.current().first] = true;
0076   while (wkr.next()) {
0077     //    std::cout << "DDCheck" << "   " << wkr.current().first << std::endl;
0078     visited[wkr.current().first] = true;
0079   }
0080   os << " CompactView has " << visited.size() << " (multiple-)connected LogicalParts with root=" << cpv.root().ddname()
0081      << std::endl;
0082 
0083   // Pass 2:
0084   DDCompactView::Graph& g = const_cast<DDCompactView::Graph&>(cpv.graph());
0085 
0086   int uc = 0;
0087   DDCompactView::Graph::adj_list::size_type it = 0;
0088 
0089   for (; it < g.size(); ++it) {
0090     if (!visited[g.nodeData(it)]) {
0091       ++uc;
0092       os << " " << g.nodeData(it).ddname();
0093     }
0094   }
0095   os << std::endl;
0096   os << " There were " << uc << " unconnected nodes found." << std::endl << std::endl;
0097   if (uc) {
0098     os << std::endl;
0099     os << " ****************************************************************************" << std::endl;
0100     os << " WARNING: The geometrical hierarchy may not be complete. " << std::endl
0101        << "          Expect unpredicted behaviour using DDCore/interface (i.e. SEGFAULT)" << std::endl;
0102     os << " ****************************************************************************" << std::endl;
0103     os << std::endl;
0104   }
0105   return result;
0106 }
0107 
0108 // iterates over the whole compactview and chechs whether the posdata
0109 // (edges in the acyclic graph ..) are complete
0110 bool DDCheckAll(const DDCompactView& cpv, std::ostream& os) {
0111   bool result = false;
0112   // const_cast because Graph does not provide const_iterators!
0113   DDCompactView::Graph& g = const_cast<DDCompactView::Graph&>(cpv.graph());
0114 
0115   // basic debuggger
0116   std::map<std::pair<std::string, std::string>, int> lp_names;
0117 
0118   DDCompactView::Graph::adj_list::size_type it = 0;
0119   for (; it < g.size(); ++it) {
0120     const DDLogicalPart& lp = g.nodeData(it);
0121     lp_names[std::make_pair(lp.name().ns(), lp.name().name())]++;
0122   }
0123 
0124   for (const auto& mit : lp_names) {
0125     if (mit.second > 1) {
0126       os << "interesting: " << mit.first.first << ":" << mit.first.second << " counted " << mit.second << " times!"
0127          << std::endl;
0128       os << " Names of LogicalParts seem not to be unique!" << std::endl << std::endl;
0129       result = true;
0130     }
0131   }
0132   // iterate over all nodes in the graph (nodes are logicalparts,
0133   // edges are posdata*
0134   for (it = 0; it < g.size(); ++it) {
0135     const DDLogicalPart& lp = g.nodeData(it);
0136     result |= DDCheckLP(lp, os);
0137     result |= DDCheckPD(lp, g.edges(it), g, os);
0138   }
0139 
0140   // Check the connectivity of the graph..., takes quite some time & memory
0141   result |= DDCheckConnect(cpv, os);
0142   return result;
0143 }
0144 
0145 // comprehensive check, very cpu intensive!
0146 // - expands the compact-view
0147 // - detects cyclic containment of parts (not yet)
0148 // - checks for completeness of solid & material definition / logical-part
0149 bool DDCheck(std::ostream& os) {
0150   bool result = false;
0151   os << "DDCore: start comprehensive checking" << std::endl;
0152   DDCompactView cpv;  // THE one and only (prototype restriction) CompactView
0153   DDExpandedView exv(cpv);
0154   result |= DDCheckAll(cpv, os);
0155 
0156   // done
0157   os << "DDCore: end of comprehensive checking" << std::endl;
0158 
0159   if (result) {  // at least one error found
0160     edm::LogError("DDCheck") << std::endl << "DDD:DDCore:DDCheck: found inconsistency problems!" << std::endl;
0161   }
0162 
0163   return result;
0164 }
0165 
0166 bool DDCheck(const DDCompactView& cpv, std::ostream& os) {
0167   bool result = false;
0168   os << "DDCore: start comprehensive checking" << std::endl;
0169   //   DDCompactView cpv; // THE one and only (prototype restriction) CompactView
0170   DDExpandedView exv(cpv);
0171   result |= DDCheckAll(cpv, os);
0172 
0173   // done
0174   os << "DDCore: end of comprehensive checking" << std::endl;
0175 
0176   if (result) {  // at least one error found
0177     edm::LogError("DDCheck") << std::endl << "DDD:DDCore:DDCheck: found inconsistency problems!" << std::endl;
0178   }
0179 
0180   return result;
0181 }