File indexing completed on 2024-04-06 12:05:33
0001 #include "DetectorDescription/Parser/src/DDLPosPart.h"
0002 #include "DetectorDescription/Core/interface/DDRotationMatrix.h"
0003 #include "DetectorDescription/Core/interface/DDTranslation.h"
0004 #include "DetectorDescription/Core/interface/DDCompactView.h"
0005 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0006 #include "DetectorDescription/Core/interface/DDName.h"
0007 #include "DetectorDescription/Core/interface/DDTransform.h"
0008 #include "DetectorDescription/Core/interface/ClhepEvaluator.h"
0009 #include "DetectorDescription/Parser/interface/DDLElementRegistry.h"
0010 #include "DetectorDescription/Parser/src/DDXMLElement.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012
0013 #include <map>
0014 #include <utility>
0015
0016 DDLPosPart::DDLPosPart(DDLElementRegistry* myreg) : DDXMLElement(myreg) {}
0017
0018
0019
0020
0021
0022
0023 void DDLPosPart::preProcessElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) {
0024
0025 myRegistry_->getElement("Rotation")->clear();
0026 myRegistry_->getElement("ReflectionRotation")->clear();
0027 }
0028
0029
0030
0031
0032 void DDLPosPart::processElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) {
0033
0034 auto myParent = myRegistry_->getElement("rParent");
0035 auto myChild = myRegistry_->getElement("rChild");
0036 auto myTranslation = myRegistry_->getElement("Translation");
0037 auto myDDLRotation = myRegistry_->getElement("Rotation");
0038 auto myrRotation = myRegistry_->getElement("rRotation");
0039 auto myDDLRefl = myRegistry_->getElement("ReflectionRotation");
0040 auto myrRefl = myRegistry_->getElement("rReflectionRotation");
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 DDName rotn(
0055 (myrRotation->size() > 0)
0056 ? myrRotation->getDDName(nmspace)
0057 : ((myDDLRotation->size() > 0)
0058 ? myDDLRotation->getDDName(nmspace)
0059 : ((myDDLRefl->size() > 0) ? myDDLRefl->getDDName(nmspace)
0060 : ((myrRefl->size() > 0) ? myrRefl->getDDName(nmspace) : DDName("")))));
0061
0062 ClhepEvaluator& ev = myRegistry_->evaluator();
0063
0064 double x = 0.0, y = 0.0, z = 0.0;
0065 if (myTranslation->size() > 0) {
0066 const DDXMLAttribute& atts = myTranslation->getAttributeSet();
0067 x = ev.eval(nmspace, atts.find("x")->second);
0068 y = ev.eval(nmspace, atts.find("y")->second);
0069 z = ev.eval(nmspace, atts.find("z")->second);
0070 }
0071
0072 std::unique_ptr<DDRotation> myDDRotation;
0073
0074 if (!rotn.name().empty() && !rotn.ns().empty()) {
0075 myDDRotation = std::make_unique<DDRotation>(rotn);
0076 } else {
0077
0078 myDDRotation = std::make_unique<DDRotation>(DDName(std::string("identity"), std::string("generatedForDDD")));
0079
0080 if (!myDDRotation->isValid()) {
0081 myDDRotation = DDrotPtr(DDName(std::string("identity"), std::string("generatedForDDD")),
0082 std::make_unique<DDRotationMatrix>());
0083 }
0084 }
0085
0086 DDTranslation myDDTranslation(x, y, z);
0087
0088 const DDXMLAttribute& atts = getAttributeSet();
0089 std::string copyno = "";
0090 if (atts.find("copyNumber") != atts.end())
0091 copyno = atts.find("copyNumber")->second;
0092
0093 cpv.position(DDLogicalPart(myChild->getDDName(nmspace)),
0094 DDLogicalPart(myParent->getDDName(nmspace)),
0095 copyno,
0096 myDDTranslation,
0097 *myDDRotation);
0098
0099
0100 myParent->clear();
0101 myChild->clear();
0102 myTranslation->clear();
0103 myDDLRotation->clear();
0104 myrRotation->clear();
0105 myDDLRefl->clear();
0106 myrRefl->clear();
0107
0108
0109 clear();
0110 }