CMS 3D CMS Logo

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

Generated on Tue Jun 9 17:32:24 2009 for CMSSW by  doxygen 1.5.4