CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/DetectorDescription/Parser/src/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 #include "DetectorDescription/Parser/src/DDLCompositeMaterial.h"
00015 #include "DetectorDescription/Parser/src/DDXMLElement.h"
00016 
00017 #include "DetectorDescription/Core/interface/DDName.h"
00018 #include "DetectorDescription/Base/interface/DDdebug.h"
00019 #include "DetectorDescription/Core/interface/DDMaterial.h"
00020 
00021 #include "DetectorDescription/ExprAlgo/interface/ExprEvalSingleton.h"
00022 
00023 DDLCompositeMaterial::DDLCompositeMaterial( DDLElementRegistry* myreg )
00024   : DDLMaterial( myreg )
00025 {}
00026 
00027 DDLCompositeMaterial::~DDLCompositeMaterial( void )
00028 {}
00029 
00030 // to initialize the CompositeMaterial, clear all rMaterials in case some other 
00031 // rMaterial was used for some other element.
00032 void
00033 DDLCompositeMaterial::preProcessElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
00034 {
00035   // fyi: no need to clear MaterialFraction because it is cleared at the end of each
00036   // CompositeMaterial
00037   myRegistry_->getElement( "rMaterial" )->clear();
00038 }
00039 
00040 void
00041 DDLCompositeMaterial::processElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
00042 {
00043   DCOUT_V('P', "DDLCompositeMaterial::processElement started");
00044 
00045   ExprEvalInterface & ev = ExprEvalSingleton::instance();
00046   DDXMLAttribute atts = getAttributeSet();
00047 
00048   DDName ddn = getDDName( nmspace );
00049   DDMaterial mat;
00050 
00051   mat = DDMaterial( ddn, ev.eval( nmspace, atts.find( "density" )->second ));
00052   
00053   // Get references to relevant DDL elements that are needed.
00054   DDXMLElement* myMF = myRegistry_->getElement( "MaterialFraction" );
00055   DDXMLElement* myrMaterial = myRegistry_->getElement( "rMaterial" );
00056 
00057   // Get the names from those elements and also the namespace for the reference element.
00058   // The parent element CompositeMaterial MUST be in the same namespace as this fraction.
00059   // additionally, because it is NOT a reference, we do not try to dis-entangle the namespace.
00060   // That is, we do not use the getName() which searches the name for a colon, but instead use
00061   // the "raw" name attribute.
00062 
00063   // TO DO:  sfractions assumes that the values are "mixture by weight" (I think)
00064   // we need to retrieve the fraction attributes and then check the method
00065   // attribute of the CompositeMaterial to determine if the numbers go straight
00066   // in to the DDCore or if the numbers need to be manipulated so that the 
00067   // sfractions are really mixtures by weight going into the DDCore.  Otherwise,
00068   // the DDCore has to know which are which and right now it does not.
00069 
00070   if( myMF->size() != myrMaterial->size())
00071   {
00072     std::string msg = "/nDDLCompositeMaterial::processElement found that the ";
00073     msg += "number of MaterialFractions does not match the number ";
00074     msg += "of rMaterial names for ";
00075     msg += ddn.ns() + ":" + ddn.name() + ".";
00076     throwError( msg );
00077   }
00078   for( size_t i = 0; i < myrMaterial->size(); ++i )
00079   {
00080     atts = myMF->getAttributeSet( i );
00081     mat.addMaterial( myrMaterial->getDDName( nmspace, "name", i ),
00082                      ev.eval( nmspace, atts.find( "fraction" )->second ));
00083   }
00084   // clears and sets new reference to THIS material.
00085   DDLMaterial::setReference( nmspace, cpv );
00086   myMF->clear();
00087   clear();
00088   // print it.
00089   DCOUT_V('P', "DDLCompositeMaterial::processElement completed " << mat);
00090 }