CMS 3D CMS Logo

DDLCompositeMaterial.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002                           DDLCompositeMaterial.cc  -  description
00003                              -------------------
00004     begin                : Wed Oct 31 2001
00005     email                : case@ucdhep.ucdavis.edu
00006  ***************************************************************************/
00007 
00008 /***************************************************************************
00009  *                                                                         *
00010  *           DDDParser sub-component of DDD                                *
00011  *                                                                         *
00012  ***************************************************************************/
00013 
00014 
00015 
00016 // -------------------------------------------------------------------------
00017 // Includes
00018 // -------------------------------------------------------------------------
00019 #include "DDLCompositeMaterial.h"
00020 #include "DDLElementRegistry.h"
00021 #include "DDXMLElement.h"
00022 
00023 // DDCore dependencies
00024 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00025 #include "DetectorDescription/Core/interface/DDName.h"
00026 #include "DetectorDescription/Base/interface/DDdebug.h"
00027 #include "DetectorDescription/Core/interface/DDMaterial.h"
00028 #include "DetectorDescription/Base/interface/DDException.h"
00029 
00030 #include "DetectorDescription/ExprAlgo/interface/ExprEvalSingleton.h"
00031 
00032 //#include <strstream>
00033 #include <string>
00034 
00035 // Default constructor.
00036 DDLCompositeMaterial::DDLCompositeMaterial()
00037 {
00038 }
00039 
00040 // Default destructor.
00041 DDLCompositeMaterial::~DDLCompositeMaterial()
00042 {
00043 }
00044 
00045 // to initialize the CompositeMaterial, clear all rMaterials in case some other 
00046 // rMaterial was used for some other element.
00047 void DDLCompositeMaterial::preProcessElement (const std::string& type, const std::string& nmspace)
00048 {
00049   // fyi: no need to clear MaterialFraction because it is cleared at the end of each
00050   // CompositeMaterial
00051   DDLElementRegistry::getElement("rMaterial")->clear();
00052 }
00053 
00054 void DDLCompositeMaterial::processElement (const std::string& type, const std::string& nmspace)
00055 {
00056   DCOUT_V('P', "DDLCompositeMaterial::processElement started");
00057 
00058 
00059   ExprEvalInterface & ev = ExprEvalSingleton::instance();
00060   DDXMLAttribute atts = getAttributeSet();
00061 
00062   DDName ddn = getDDName(nmspace);
00063   DDMaterial mat;
00064 
00065   mat = DDMaterial(ddn, ev.eval(nmspace, atts.find("density")->second));
00066   
00067   // Get references to relevant DDL elements that are needed.
00068   DDXMLElement* myMF = DDLElementRegistry::getElement("MaterialFraction");
00069   DDXMLElement* myrMaterial = DDLElementRegistry::getElement("rMaterial");
00070 
00071   // Get the names from those elements and also the namespace for the reference element.
00072   // The parent element CompositeMaterial MUST be in the same namespace as this fraction.
00073   // additionally, because it is NOT a reference, we do not try to dis-entangle the namespace.
00074   // That is, we do not use the getName() which searches the name for a colon, but instead use
00075   // the "raw" name attribute.
00076 
00077   // TO DO:  sfractions assumes that the values are "mixture by weight" (I think)
00078   // we need to retrieve the fraction attributes and then check the method
00079   // attribute of the CompositeMaterial to determine if the numbers go straight
00080   // in to the DDCore or if the numbers need to be manipulated so that the 
00081   // sfractions are really mixtures by weight going into the DDCore.  Otherwise,
00082   // the DDCore has to know which are which and right now it does not.
00083 
00084   if (myMF->size() != myrMaterial->size())
00085     {
00086       std::string msg = "/nDDLCompositeMaterial::processElement found that the ";
00087       msg += "number of MaterialFractions does not match the number ";
00088       msg += "of rMaterial names for ";
00089       msg += ddn.ns() + ":" + ddn.name() + ".";
00090       throwError(msg);
00091     }
00092   for (size_t i = 0; i < myrMaterial->size(); ++i)
00093     {
00094       atts = myMF->getAttributeSet(i);
00095       mat.addMaterial(myrMaterial->getDDName(nmspace, "name", i)
00096                       , ev.eval(nmspace, atts.find("fraction")->second));
00097     }
00098 
00099   // clears and sets new reference to THIS material.
00100   DDLMaterial::setReference(nmspace);
00101   myMF->clear();
00102   clear();
00103   // print it.
00104   DCOUT_V('P', "DDLCompositeMaterial::processElement completed " << mat);
00105 }

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