Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DetectorDescription/Parser/src/DDLRotationByAxis.h"
0002 #include "DetectorDescription/Core/interface/DDName.h"
0003 #include "DetectorDescription/Core/interface/DDTransform.h"
0004 #include "DetectorDescription/Core/interface/ClhepEvaluator.h"
0005 #include "DetectorDescription/Parser/interface/DDLElementRegistry.h"
0006 #include "DetectorDescription/Parser/src/DDXMLElement.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "Math/GenVector/RotationX.h"
0009 #include "Math/GenVector/RotationY.h"
0010 #include "Math/GenVector/RotationZ.h"
0011 
0012 #include <map>
0013 #include <utility>
0014 #include <vector>
0015 
0016 class DDCompactView;
0017 
0018 DDLRotationByAxis::DDLRotationByAxis(DDLElementRegistry* myreg) : DDXMLElement(myreg) {}
0019 
0020 void DDLRotationByAxis::preProcessElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) {
0021   pNameSpace = nmspace;
0022   pName = name;
0023 }
0024 
0025 void DDLRotationByAxis::processElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) {
0026   DDXMLAttribute atts = getAttributeSet();
0027   if (parent() != "RotationSequence") {
0028     std::string axis = atts.find("axis")->second;
0029     std::string angle = atts.find("angle")->second;
0030 
0031     DDRotationMatrix R;
0032     R = processOne(R, axis, angle);
0033 
0034     if (atts.find("name") == atts.end()) {
0035       auto myRealParent = myRegistry_->getElement(parent());
0036       DDName pName = myRealParent->getDDName(nmspace);
0037       std::string tn = pName.name() + std::string("Rotation");
0038       std::vector<std::string> names;
0039       names.emplace_back("name");
0040 
0041       std::vector<std::string> values;
0042       values.emplace_back(tn);
0043 
0044       clear();
0045       loadAttributes(name, names, values, nmspace, cpv);
0046     }
0047     DDRotation rot = DDrot(getDDName(nmspace), std::make_unique<DDRotationMatrix>(R));
0048 
0049     clear();
0050   }
0051 }
0052 
0053 DDRotationMatrix DDLRotationByAxis::processOne(DDRotationMatrix R, std::string& axis, std::string& angle) {
0054   /** Get the name, axis and angle of the RotationByAxis and do it. 
0055    */
0056 
0057   ClhepEvaluator& ev = myRegistry_->evaluator();
0058   double dAngle = ev.eval(pNameSpace, angle);
0059 
0060   if (axis == "x") {
0061     R = ROOT::Math::RotationX(dAngle);
0062   } else if (axis == "y") {
0063     R = ROOT::Math::RotationY(dAngle);
0064   } else if (axis == "z") {
0065     R = ROOT::Math::RotationZ(dAngle);
0066   } else {
0067     std::string msg = "\nDDLRotationByAxis invalid axis... you must not have validated XML sources!  Element is ";
0068     msg += pName;
0069     throwError(msg);
0070   }
0071 
0072   return R;
0073 }