CMS 3D CMS Logo

DDLCompositeMaterial.cc
Go to the documentation of this file.
9 
10 #include <cstddef>
11 #include <map>
12 #include <utility>
13 
14 class DDCompactView;
15 
17 
18 // to initialize the CompositeMaterial, clear all rMaterials in case some other
19 // rMaterial was used for some other element.
21  // fyi: no need to clear MaterialFraction because it is cleared at the end of each
22  // CompositeMaterial
23  myRegistry_->getElement("rMaterial")->clear();
24 }
25 
29 
30  DDName ddn = getDDName(nmspace);
31  DDMaterial mat;
32 
33  mat = DDMaterial(ddn, ev.eval(nmspace, atts.find("density")->second));
34 
35  // Get references to relevant DDL elements that are needed.
36  auto myMF = myRegistry_->getElement("MaterialFraction");
37  auto myrMaterial = myRegistry_->getElement("rMaterial");
38 
39  // Get the names from those elements and also the namespace for the reference element.
40  // The parent element CompositeMaterial MUST be in the same namespace as this fraction.
41  // additionally, because it is NOT a reference, we do not try to dis-entangle the namespace.
42  // That is, we do not use the getName() which searches the name for a colon, but instead use
43  // the "raw" name attribute.
44 
45  // TO DO: sfractions assumes that the values are "mixture by weight" (I think)
46  // we need to retrieve the fraction attributes and then check the method
47  // attribute of the CompositeMaterial to determine if the numbers go straight
48  // in to the DDCore or if the numbers need to be manipulated so that the
49  // sfractions are really mixtures by weight going into the DDCore. Otherwise,
50  // the DDCore has to know which are which and right now it does not.
51 
52  if (myMF->size() != myrMaterial->size()) {
53  std::string msg = "/nDDLCompositeMaterial::processElement found that the ";
54  msg += "number of MaterialFractions does not match the number ";
55  msg += "of rMaterial names for ";
56  msg += ddn.ns() + ":" + ddn.name() + ".";
57  throwError(msg);
58  }
59  for (size_t i = 0; i < myrMaterial->size(); ++i) {
60  atts = myMF->getAttributeSet(i);
61  mat.addMaterial(myrMaterial->getDDName(nmspace, "name", i), ev.eval(nmspace, atts.find("fraction")->second));
62  }
63  // clears and sets new reference to THIS material.
64  DDLMaterial::setReference(nmspace, cpv);
65  myMF->clear();
66  clear();
67 }
void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Processing the element.
DDLMaterial processes Box elements.
Definition: DDLMaterial.h:29
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:173
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:45
int addMaterial(const DDMaterial &m, double fm)
adds a material to the mixture proportional to its fraction-mass fm.
Definition: DDMaterial.cc:63
const std::string & name() const
Returns the name.
Definition: DDName.cc:41
ClhepEvaluator & evaluator()
DDLCompositeMaterial(DDLElementRegistry *myreg)
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a "row" of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:54
std::shared_ptr< DDXMLElement > getElement(const std::string &name)
THE most important part. Getting the pointer to a given element type.
virtual void setReference(const std::string &nmspace, DDCompactView &cpv)
Definition: DDLMaterial.cc:13
void preProcessElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Called by loadAttributes AFTER attributes are loaded.
tuple msg
Definition: mps_check.py:286
The main class for processing parsed elements.
virtual void clear(void)
clear this element&#39;s contents.
Definition: DDXMLElement.cc:40
void throwError(const std::string &keyMessage) const
format std::string for throw an error.
virtual const DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:56
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:52