File indexing completed on 2023-05-07 22:50:11
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
0022
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
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
0091
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 for (; git != gend; ++git) {
0099 const DDLogicalPart& ddLP = gra.nodeData(git);
0100 if (lpStore.find(ddLP) != lpStore.end() && !ddLP.attachedSpecifics().empty()) {
0101 dump << ddLP.toString() << ": ";
0102 dumpSpec(ddLP.attachedSpecifics(), dump);
0103 }
0104 lpStore.insert(ddLP);
0105
0106 if (!git->empty()) {
0107
0108 for (const auto& cit : *git) {
0109 const DDLogicalPart& ddcurLP = gra.nodeData(cit.first);
0110 if (lpStore.find(ddcurLP) != lpStore.end() && !ddcurLP.attachedSpecifics().empty()) {
0111 dump << ddcurLP.toString() << ": ";
0112 dumpSpec(ddcurLP.attachedSpecifics(), dump);
0113 }
0114 lpStore.insert(ddcurLP);
0115 }
0116 }
0117 }
0118 dump.close();
0119 }
0120 }
0121
0122 void GeometryInfoDump::dumpSpec(const std::vector<std::pair<const DDPartSelection*, const DDsvalues_type*> >& attspec,
0123 std::ostream& dump) {
0124 std::vector<std::pair<const DDPartSelection*, const DDsvalues_type*> >::const_iterator bit(attspec.begin()),
0125 eit(attspec.end());
0126 for (; bit != eit; ++bit) {
0127
0128 std::vector<DDPartSelectionLevel>::const_iterator psit(bit->first->begin()), pseit(bit->first->end());
0129 for (; psit != pseit; ++psit) {
0130 switch (psit->selectionType_) {
0131 case ddunknown:
0132 throw cms::Exception("DetectorDescriptionSpecPar") << "Can not have an unknown selection type!";
0133 break;
0134 case ddanynode:
0135 dump << "//*";
0136 break;
0137 case ddanychild:
0138 dump << "/*";
0139 break;
0140 case ddanylogp:
0141 dump << "//" << psit->lp_.toString();
0142 break;
0143 case ddanyposp:
0144 dump << "//" << psit->lp_.toString() << "[" << psit->copyno_ << "]";
0145 break;
0146 case ddchildlogp:
0147 dump << "/" << psit->lp_.toString();
0148 break;
0149 case ddchildposp:
0150 dump << "/" << psit->lp_.toString() << "[" << psit->copyno_ << "]";
0151 break;
0152 default:
0153 throw cms::Exception("DetectorDescriptionSpecPar")
0154 << "Can not end up here! default of switch on selectionTyp_";
0155 }
0156 }
0157 dump << " ";
0158
0159 DDsvalues_type::const_iterator bsit(bit->second->begin()), bseit(bit->second->end());
0160 for (; bsit != bseit; ++bsit) {
0161 dump << bsit->second.name() << " ";
0162 dump << (bsit->second.isEvaluated() ? "eval " : "NOT eval ");
0163 size_t sdind(0);
0164 for (; sdind != bsit->second.strings().size(); ++sdind) {
0165 if (bsit->second.isEvaluated()) {
0166 dump << bsit->second.doubles()[sdind];
0167 } else {
0168 dump << bsit->second.strings()[sdind];
0169 }
0170 if (sdind != bsit->second.strings().size() - 1)
0171 dump << ", ";
0172 }
0173 if (!bsit->second.strings().empty() && bsit + 1 != bseit)
0174 dump << " | ";
0175 }
0176 if (!bit->second->empty() && bit + 1 != eit)
0177 dump << " | ";
0178 }
0179 dump << std::endl;
0180 }