Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:55:06

0001 #include "DetectorDescription/Parser/src/DDLCompositeMaterial.h"
0002 #include "DetectorDescription/Core/interface/DDMaterial.h"
0003 #include "DetectorDescription/Core/interface/DDName.h"
0004 #include "DetectorDescription/Core/interface/ClhepEvaluator.h"
0005 #include "DetectorDescription/Parser/interface/DDLElementRegistry.h"
0006 #include "DetectorDescription/Parser/src/DDLMaterial.h"
0007 #include "DetectorDescription/Parser/src/DDXMLElement.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 
0010 #include <cstddef>
0011 #include <map>
0012 #include <utility>
0013 
0014 class DDCompactView;
0015 
0016 DDLCompositeMaterial::DDLCompositeMaterial(DDLElementRegistry* myreg) : DDLMaterial(myreg) {}
0017 
0018 // to initialize the CompositeMaterial, clear all rMaterials in case some other
0019 // rMaterial was used for some other element.
0020 void DDLCompositeMaterial::preProcessElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) {
0021   // fyi: no need to clear MaterialFraction because it is cleared at the end of each
0022   // CompositeMaterial
0023   myRegistry_->getElement("rMaterial")->clear();
0024 }
0025 
0026 void DDLCompositeMaterial::processElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) {
0027   ClhepEvaluator& ev = myRegistry_->evaluator();
0028   DDXMLAttribute atts = getAttributeSet();
0029 
0030   DDName ddn = getDDName(nmspace);
0031   DDMaterial mat;
0032 
0033   mat = DDMaterial(ddn, ev.eval(nmspace, atts.find("density")->second));
0034 
0035   // Get references to relevant DDL elements that are needed.
0036   auto myMF = myRegistry_->getElement("MaterialFraction");
0037   auto myrMaterial = myRegistry_->getElement("rMaterial");
0038 
0039   // Get the names from those elements and also the namespace for the reference element.
0040   // The parent element CompositeMaterial MUST be in the same namespace as this fraction.
0041   // additionally, because it is NOT a reference, we do not try to dis-entangle the namespace.
0042   // That is, we do not use the getName() which searches the name for a colon, but instead use
0043   // the "raw" name attribute.
0044 
0045   // TO DO:  sfractions assumes that the values are "mixture by weight" (I think)
0046   // we need to retrieve the fraction attributes and then check the method
0047   // attribute of the CompositeMaterial to determine if the numbers go straight
0048   // in to the DDCore or if the numbers need to be manipulated so that the
0049   // sfractions are really mixtures by weight going into the DDCore.  Otherwise,
0050   // the DDCore has to know which are which and right now it does not.
0051 
0052   if (myMF->size() != myrMaterial->size()) {
0053     std::string msg = "/nDDLCompositeMaterial::processElement found that the ";
0054     msg += "number of MaterialFractions does not match the number ";
0055     msg += "of rMaterial names for ";
0056     msg += ddn.ns() + ":" + ddn.name() + ".";
0057     throwError(msg);
0058   }
0059   for (size_t i = 0; i < myrMaterial->size(); ++i) {
0060     atts = myMF->getAttributeSet(i);
0061     mat.addMaterial(myrMaterial->getDDName(nmspace, "name", i), ev.eval(nmspace, atts.find("fraction")->second));
0062   }
0063   // clears and sets new reference to THIS material.
0064   DDLMaterial::setReference(nmspace, cpv);
0065   myMF->clear();
0066   clear();
0067 }