CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DetectorDescription/Parser/src/DDLRotationByAxis.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002                           DDLRotationByAxis.cc  -  description
00003                              -------------------
00004     begin                : Wed Nov 19, 2003
00005     email                : case@ucdhep.ucdavis.edu
00006  ***************************************************************************/
00007 
00008 /***************************************************************************
00009  *                                                                         *
00010  *           DDDParser sub-component of DDD                                *
00011  *                                                                         *
00012  ***************************************************************************/
00013 
00014 #include "DetectorDescription/Parser/src/DDLRotationByAxis.h"
00015 
00016 #include "DetectorDescription/Core/interface/DDTransform.h"
00017 #include "DetectorDescription/Base/interface/DDdebug.h"
00018 #include "DetectorDescription/ExprAlgo/interface/ExprEvalSingleton.h"
00019 
00020 #include <Math/RotationX.h>
00021 #include <Math/RotationY.h>
00022 #include <Math/RotationZ.h>
00023 
00024 DDLRotationByAxis::DDLRotationByAxis( DDLElementRegistry* myreg )
00025   : DDXMLElement( myreg ) 
00026 {}
00027 
00028 DDLRotationByAxis::~DDLRotationByAxis( void )
00029 {}
00030 
00031 void
00032 DDLRotationByAxis::preProcessElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
00033 {
00034   pNameSpace = nmspace;
00035   pName = name;
00036 }
00037 
00038 void
00039 DDLRotationByAxis::processElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
00040 {
00041   DCOUT_V('P', "DDLRotationByAxis::processElement started " << name);
00042 
00043   //  std::cout << "my parent is : " << parent() << std::endl;
00044   DDXMLAttribute atts = getAttributeSet();
00045   if (parent() != "RotationSequence")
00046   {
00047     std::string axis = atts.find("axis")->second;
00048     std::string angle = atts.find("angle")->second;
00049       
00050     DDRotationMatrix R;
00051     R = processOne(R, axis, angle);
00052 
00053     DDRotationMatrix* ddr = new DDRotationMatrix(R);
00054     if (atts.find("name") == atts.end())
00055     {
00056       //how do we make up a ddname! damn_it!
00057       //          DDXMLElement * myRealParent = DDLElementRegistry::instance()->getElement(parent());
00058       DDXMLElement * myRealParent = myRegistry_->getElement(parent());
00059       DDName pName = myRealParent->getDDName(nmspace);
00060       std::string tn = pName.name() + std::string("Rotation");
00061       std::vector<std::string> names;
00062       names.push_back("name");
00063       //no need, used already names.push_back("axis");
00064       //no need, used already names.push_back("angle");
00065 
00066       std::vector<std::string> values;
00067       values.push_back(tn);
00068       //no need, used already values.push_back(atts.find("axis")->second);
00069       //no need, used already values.push_back(atts.find("angle")->second);
00070       clear();
00071       loadAttributes(name, names, values, nmspace, cpv);
00072     }
00073     DDRotation rot = DDrot(getDDName(nmspace), ddr);
00074       
00075     clear();
00076   }
00077   else { } //let the parent handle the clearing, etc.
00078 
00079   DCOUT_V('P', "DDLRotationByAxis::processElement completed");
00080 }
00081 
00082 DDRotationMatrix
00083 DDLRotationByAxis::processOne( DDRotationMatrix R, std::string& axis, std::string& angle )
00084 {
00088   ExprEvalInterface & ev = ExprEvalSingleton::instance();
00089   double dAngle = ev.eval(pNameSpace, angle);
00090   //  CLHEP::HepRotation R;
00091 
00092   if ( axis == "x") {
00093     R = ROOT::Math::RotationX(dAngle);
00094   }
00095   else if ( axis == "y" ) {
00096     R = ROOT::Math::RotationY(dAngle);      
00097   }
00098   else if ( axis =="z" ) {
00099     R = ROOT::Math::RotationZ(dAngle);
00100   }
00101   else {
00102     std::string msg = "\nDDLRotationByAxis invalid axis... you must not have validated XML sources!  Element is ";
00103     msg += pName;
00104     throwError(msg);
00105   }
00106   
00107   return R;
00108 }