CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DetectorDescription/Parser/src/DDLPosPart.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002                           DDLPosPart.cc  -  description
00003                              -------------------
00004     begin                : Tue Oct 30 2001
00005     email                : case@ucdhep.ucdavis.edu
00006  ***************************************************************************/
00007 
00008 /***************************************************************************
00009  *                                                                         *
00010  *           DDDParser sub-component of DDD                                *
00011  *                                                                         *
00012  ***************************************************************************/
00013 
00014 #include "DetectorDescription/Parser/src/DDLPosPart.h"
00015 
00016 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00017 #include "DetectorDescription/Core/interface/DDName.h"
00018 #include "DetectorDescription/Base/interface/DDdebug.h"
00019 
00020 #include "DetectorDescription/ExprAlgo/interface/ExprEvalSingleton.h"
00021 
00022 DDLPosPart::DDLPosPart( DDLElementRegistry* myreg )
00023   : DDXMLElement( myreg )
00024 {}
00025 
00026 DDLPosPart::~DDLPosPart( void )
00027 {}
00028 
00029 // Upon encountering a PosPart, store the label, simple.
00030 // Just in case some left-over Rotation has not been cleared, make sure
00031 // that it is cleared.  
00032 // I commented out the others because the last element
00033 // that made use of them should have cleared them.
00034 void
00035 DDLPosPart::preProcessElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
00036 {
00037   DCOUT_V('P', "DDLPosPart::preProcessElement started");
00038 
00039   // Clear out child elements.
00040   myRegistry_->getElement("Rotation")->clear();
00041   myRegistry_->getElement("ReflectionRotation")->clear();
00042 
00043   DCOUT_V('P', "DDLPosPart::preProcessElement completed");
00044 }
00045 
00046 // Upon encountering the end tag of the PosPart we should have in the meantime
00047 // hit two rLogicalPart calls and one of Rotation or rRotation and a Translation.
00048 // So, retrieve them and make the call to DDCore.
00049 void
00050 DDLPosPart::processElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
00051 {
00052   DCOUT_V('P', "DDLPosPart::processElement started");
00053   
00054   // get all internal elements.
00055   DDXMLElement* myParent     = myRegistry_->getElement("rParent");
00056   DDXMLElement* myChild      = myRegistry_->getElement("rChild");
00057   DDXMLElement* myTranslation= myRegistry_->getElement("Translation");
00058   DDXMLElement* myDDLRotation= myRegistry_->getElement("Rotation");
00059   DDXMLElement* myrRotation  = myRegistry_->getElement("rRotation");
00060   DDXMLElement* myDDLRefl    = myRegistry_->getElement("ReflectionRotation");
00061   DDXMLElement* myrRefl      = myRegistry_->getElement("rReflectionRotation");
00062   // FIXME!!! add in the new RotationByAxis element...
00063 
00064   // At this time, PosPart is becoming the most complex of the elements.
00065   // For simply reflections/rotations we have 4 possible internal "components"
00066   // to the PosPart.  We take them in the following order of priority
00067   //     rRotation, Rotation, rReflectionRotation, ReflectionRotation.
00068   //
00069   // The idea in the following if-else-if is that no matter
00070   // what was used inside the PosPart element, the order in which we
00071   // will look for and use an internal element is:
00072   // rRotation, Rotation, ReflectionRotation, rReflectionRotation.
00073   // If it falls through here, a default call will result in a nameless 
00074   // "identity" rotation being passed to DDCore.
00075   DDName rotn;
00076   if (myrRotation->size() > 0){
00077     rotn = myrRotation->getDDName(nmspace);
00078   }
00079   else if (myDDLRotation->size() > 0) {
00080     // The assumption here is that the Rotation element created 
00081     // a DDRotation already, and so we can use this as an rRotation
00082     // just provide DDCore with the name of the one just added... 
00083     // How to handle name conflicts? OVERWRITTEN by DDCore for now.
00084     rotn = myDDLRotation->getDDName(nmspace);
00085   }
00086   else if (myDDLRefl->size() > 0) {
00087     // The assumption is that a ReflectionRotation has been created and therefore 
00088     // we can refer to it as the rotation associated with this PosPart.
00089     // we can further assume that the namespace is the same as this PosPart.
00090     rotn = myDDLRefl->getDDName(nmspace);
00091   }
00092   else if (myrRefl->size() > 0) {
00093     rotn = myrRefl->getDDName(nmspace);
00094   }
00095 
00096   DCOUT_V('P', "DDLPosPart::processElement:  Final Rotation info: " << rotn);
00097 
00098   ExprEvalInterface & ev = ExprEvalSingleton::instance();
00099 
00100   double x = 0.0, y = 0.0, z = 0.0;
00101   if (myTranslation->size() > 0)
00102   {
00103     const DDXMLAttribute & atts = myTranslation->getAttributeSet();
00104     x = ev.eval(nmspace, atts.find("x")->second);
00105     y = ev.eval(nmspace, atts.find("y")->second);
00106     z = ev.eval(nmspace, atts.find("z")->second);
00107   }
00108 
00109   DCOUT_V('P', "DDLPosPart::processElement:  Final Translation info x=" << x << " y=" << y << " z=" << z);
00110 
00111   DDRotation* myDDRotation;
00112   // if rotation is named ...
00113   if ( rotn.name() != "" && rotn.ns() != "" ) {
00114     DDRotation temp(rotn);
00115     myDDRotation = &temp;
00116   } else { 
00117     // rotn is not assigned a name anywhere therefore the DDPos assumes the identity matrix.
00118     DDRotation temp(DDName(std::string("identity"),std::string("generatedForDDD")));
00119     myDDRotation = &temp;
00120     // if the identity is not yet defined, then...
00121     if ( !myDDRotation->isValid() ) {
00122       DDRotationMatrix* dmr = new DDRotationMatrix;
00123       temp = DDrot(DDName(std::string("identity"),std::string("generatedForDDD")), dmr );
00124       myDDRotation = &temp;
00125     }
00126   }
00127 
00128 
00129   DDTranslation myDDTranslation(x, y, z);
00130 
00131   DCOUT_V('P', "about to make a PosPart ...");
00132   DCOUT_V('p', "  myDDRotation    : " << *myDDRotation);
00133   DCOUT_V('p', "  myDDTranslation : " << myDDTranslation);
00134   DCOUT_V('p', "  parentDDName    : " << myParent->getDDName(nmspace));
00135   DCOUT_V('p', "  selfDDName      : " << myChild->getDDName(nmspace));
00136 
00137   const DDXMLAttribute & atts = getAttributeSet();
00138   std::string copyno = "";
00139   if (atts.find("copyNumber") != atts.end())
00140     copyno = atts.find("copyNumber")->second;
00141     
00142   cpv.position(DDLogicalPart(myChild->getDDName(nmspace))
00143                , DDLogicalPart(myParent->getDDName(nmspace))
00144                , copyno
00145                , myDDTranslation
00146                , *myDDRotation);
00147   
00148   // clear all "children" and attributes
00149   myParent->clear();
00150   myChild->clear();
00151   myTranslation->clear();
00152   myDDLRotation->clear();
00153   myrRotation->clear();
00154   myDDLRefl->clear();
00155   myrRefl->clear();
00156 
00157   // after a pos part is done, we know we can clear it.
00158   clear();
00159 
00160   DCOUT_V('P', "DDLPosPart::processElement completed");
00161 }