Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DetectorDescription/Core/interface/DDPartSelection.h"
0002 #include "DetectorDescription/Core/interface/DDValue.h"
0003 #include "DetectorDescription/OfflineDBLoader/interface/GeometryInfoDump.h"
0004 #include "DetectorDescription/Core/interface/DDRotationMatrix.h"
0005 #include "DetectorDescription/Core/interface/DDTranslation.h"
0006 #include "DetectorDescription/Core/interface/DDCompactView.h"
0007 #include "DetectorDescription/Core/interface/DDExpandedNode.h"
0008 #include "DetectorDescription/Core/interface/DDExpandedView.h"
0009 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0010 #include "FWCore/Utilities/interface/Exception.h"
0011 
0012 #include <cassert>
0013 #include <fstream>
0014 #include <map>
0015 #include <set>
0016 #include <vector>
0017 
0018 using Graph = DDCompactView::Graph;
0019 using adjl_iterator = Graph::const_adj_iterator;
0020 
0021 // For output of values to four decimal places, round negative values
0022 // equivalent to 0 within the precision to 0 to prevent printing "-0".
0023 template <class valType>
0024 static constexpr valType roundNeg0(valType value) {
0025   if (value < 0. && value > -5.0e-5)
0026     return (0.0);
0027   else
0028     return (value);
0029 }
0030 
0031 GeometryInfoDump::GeometryInfoDump() {}
0032 
0033 GeometryInfoDump::~GeometryInfoDump() {}
0034 
0035 void GeometryInfoDump::dumpInfo(
0036     bool dumpHistory, bool dumpSpecs, bool dumpPosInfo, const DDCompactView& cpv, std::string fname, int nVols) {
0037   fname = "dump" + fname;
0038   DDExpandedView epv(cpv);
0039   std::cout << "Top Most LogicalPart =" << epv.logicalPart() << std::endl;
0040   if (dumpHistory || dumpPosInfo) {
0041     if (dumpPosInfo) {
0042       std::cout << "After the GeoHistory in the output file dumpGeoHistoryOnRead you will see x, y, z, r11, r12, r13, "
0043                    "r21, r22, r23, r31, r32, r33"
0044                 << std::endl;
0045     }
0046     typedef DDExpandedView::nav_type nav_type;
0047     typedef std::map<nav_type, int> id_type;
0048     id_type idMap;
0049     int id = 0;
0050     std::ofstream dump(fname.c_str());
0051     bool notReachedDepth(true);
0052     char buf[256];
0053 
0054     do {
0055       nav_type pos = epv.navPos();
0056       idMap[pos] = id;
0057       //      dump << id
0058       dump << " - " << epv.geoHistory();
0059       DD3Vector x, y, z;
0060       epv.rotation().GetComponents(x, y, z);
0061       if (dumpPosInfo) {
0062         size_t s = snprintf(buf,
0063                             256,
0064                             ",%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f",
0065                             roundNeg0(epv.translation().x()),
0066                             roundNeg0(epv.translation().y()),
0067                             roundNeg0(epv.translation().z()),
0068                             roundNeg0(x.X()),
0069                             roundNeg0(y.X()),
0070                             roundNeg0(z.X()),
0071                             roundNeg0(x.Y()),
0072                             roundNeg0(y.Y()),
0073                             roundNeg0(z.Y()),
0074                             roundNeg0(x.Z()),
0075                             roundNeg0(y.Z()),
0076                             roundNeg0(z.Z()));
0077         assert(s < 256);
0078         dump << buf;
0079       }
0080       dump << "\n";
0081       ;
0082       ++id;
0083       if (nVols != 0 && id > nVols)
0084         notReachedDepth = false;
0085     } while (epv.next() && notReachedDepth);
0086     dump << std::flush;
0087     dump.close();
0088   }
0089   if (dumpSpecs) {
0090     // dump specifics at every compact-view nodes to have the most detailed "true"
0091     // final destination of the DDSpecifics
0092     std::string dsname = "dumpSpecs" + fname;
0093     std::ofstream dump(dsname.c_str());
0094     const auto& gra = cpv.graph();
0095     std::set<DDLogicalPart> lpStore;
0096     adjl_iterator git = gra.begin();
0097     adjl_iterator gend = gra.end();
0098     Graph::index_type i = 0;
0099     for (; git != gend; ++git) {
0100       const DDLogicalPart& ddLP = gra.nodeData(git);
0101       if (lpStore.find(ddLP) != lpStore.end() && !ddLP.attachedSpecifics().empty()) {
0102         dump << ddLP.toString() << ": ";
0103         dumpSpec(ddLP.attachedSpecifics(), dump);
0104       }
0105       lpStore.insert(ddLP);
0106 
0107       ++i;
0108       if (!git->empty()) {
0109         // ask for children of ddLP
0110         for (const auto& cit : *git) {
0111           const DDLogicalPart& ddcurLP = gra.nodeData(cit.first);
0112           if (lpStore.find(ddcurLP) != lpStore.end() && !ddcurLP.attachedSpecifics().empty()) {
0113             dump << ddcurLP.toString() << ": ";
0114             dumpSpec(ddcurLP.attachedSpecifics(), dump);
0115           }
0116           lpStore.insert(ddcurLP);
0117         }  // iterate over children
0118       }    // if (children)
0119     }      // iterate over graph nodes
0120     dump.close();
0121   }
0122 }
0123 
0124 void GeometryInfoDump::dumpSpec(const std::vector<std::pair<const DDPartSelection*, const DDsvalues_type*> >& attspec,
0125                                 std::ostream& dump) {
0126   std::vector<std::pair<const DDPartSelection*, const DDsvalues_type*> >::const_iterator bit(attspec.begin()),
0127       eit(attspec.end());
0128   for (; bit != eit; ++bit) {
0129     //  DDPartSelection is a std::vector<DDPartSelectionLevel>
0130     std::vector<DDPartSelectionLevel>::const_iterator psit(bit->first->begin()), pseit(bit->first->end());
0131     for (; psit != pseit; ++psit) {
0132       switch (psit->selectionType_) {
0133         case ddunknown:
0134           throw cms::Exception("DetectorDescriptionSpecPar") << "Can not have an unknown selection type!";
0135           break;
0136         case ddanynode:
0137           dump << "//*";
0138           break;
0139         case ddanychild:
0140           dump << "/*";
0141           break;
0142         case ddanylogp:
0143           dump << "//" << psit->lp_.toString();
0144           break;
0145         case ddanyposp:
0146           dump << "//" << psit->lp_.toString() << "[" << psit->copyno_ << "]";
0147           break;
0148         case ddchildlogp:
0149           dump << "/" << psit->lp_.toString();
0150           break;
0151         case ddchildposp:
0152           dump << "/" << psit->lp_.toString() << "[" << psit->copyno_ << "]";
0153           break;
0154         default:
0155           throw cms::Exception("DetectorDescriptionSpecPar")
0156               << "Can not end up here! default of switch on selectionTyp_";
0157       }
0158     }
0159     dump << " ";
0160     // DDsvalues_type is typedef std::vector< std::pair<unsigned int, DDValue> > DDsvalues_type;
0161     DDsvalues_type::const_iterator bsit(bit->second->begin()), bseit(bit->second->end());
0162     for (; bsit != bseit; ++bsit) {
0163       dump << bsit->second.name() << " ";
0164       dump << (bsit->second.isEvaluated() ? "eval " : "NOT eval ");
0165       size_t sdind(0);
0166       for (; sdind != bsit->second.strings().size(); ++sdind) {
0167         if (bsit->second.isEvaluated()) {
0168           dump << bsit->second.doubles()[sdind];
0169         } else {
0170           dump << bsit->second.strings()[sdind];
0171         }
0172         if (sdind != bsit->second.strings().size() - 1)
0173           dump << ", ";
0174       }
0175       if (!bsit->second.strings().empty() && bsit + 1 != bseit)
0176         dump << " | ";
0177     }
0178     if (!bit->second->empty() && bit + 1 != eit)
0179       dump << " | ";
0180   }
0181   dump << std::endl;
0182 }