Back to home page

Project CMSSW displayed by LXR

 
 

    


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 // Upon encountering a PosPart, store the label, simple.
0019 // Just in case some left-over Rotation has not been cleared, make sure
0020 // that it is cleared.
0021 // I commented out the others because the last element
0022 // that made use of them should have cleared them.
0023 void DDLPosPart::preProcessElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) {
0024   // Clear out child elements.
0025   myRegistry_->getElement("Rotation")->clear();
0026   myRegistry_->getElement("ReflectionRotation")->clear();
0027 }
0028 
0029 // Upon encountering the end tag of the PosPart we should have in the meantime
0030 // hit two rLogicalPart calls and one of Rotation or rRotation and a Translation.
0031 // So, retrieve them and make the call to DDCore.
0032 void DDLPosPart::processElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) {
0033   // get all internal elements.
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   // FIXME!!! add in the new RotationByAxis element...
0042 
0043   // At this time, PosPart is becoming the most complex of the elements.
0044   // For simply reflections/rotations we have 4 possible internal "components"
0045   // to the PosPart.  We take them in the following order of priority
0046   //     rRotation, Rotation, rReflectionRotation, ReflectionRotation.
0047   //
0048   // The idea in the following if-else-if is that no matter
0049   // what was used inside the PosPart element, the order in which we
0050   // will look for and use an internal element is:
0051   // rRotation, Rotation, ReflectionRotation, rReflectionRotation.
0052   // If it falls through here, a default call will result in a nameless
0053   // "identity" rotation being passed to DDCore.
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   // if rotation is named ...
0074   if (!rotn.name().empty() && !rotn.ns().empty()) {
0075     myDDRotation = std::make_unique<DDRotation>(rotn);
0076   } else {
0077     // rotn is not assigned a name anywhere therefore the DDPos assumes the identity matrix.
0078     myDDRotation = std::make_unique<DDRotation>(DDName(std::string("identity"), std::string("generatedForDDD")));
0079     // if the identity is not yet defined, then...
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   // clear all "children" and attributes
0100   myParent->clear();
0101   myChild->clear();
0102   myTranslation->clear();
0103   myDDLRotation->clear();
0104   myrRotation->clear();
0105   myDDLRefl->clear();
0106   myrRefl->clear();
0107 
0108   // after a pos part is done, we know we can clear it.
0109   clear();
0110 }