CMS 3D CMS Logo

DDLCompositeMaterial.cc
Go to the documentation of this file.
2 
3 #include <stddef.h>
4 #include <map>
5 #include <utility>
13 
14 class DDCompactView;
15 
17  : DDLMaterial( myreg )
18 {}
19 
20 // to initialize the CompositeMaterial, clear all rMaterials in case some other
21 // rMaterial was used for some other element.
22 void
24 {
25  // fyi: no need to clear MaterialFraction because it is cleared at the end of each
26  // CompositeMaterial
27  myRegistry_->getElement( "rMaterial" )->clear();
28 }
29 
30 void
32 {
35 
36  DDName ddn = getDDName( nmspace );
37  DDMaterial mat;
38 
39  mat = DDMaterial( ddn, ev.eval( nmspace, atts.find( "density" )->second ));
40 
41  // Get references to relevant DDL elements that are needed.
42  auto myMF = myRegistry_->getElement( "MaterialFraction" );
43  auto myrMaterial = myRegistry_->getElement( "rMaterial" );
44 
45  // Get the names from those elements and also the namespace for the reference element.
46  // The parent element CompositeMaterial MUST be in the same namespace as this fraction.
47  // additionally, because it is NOT a reference, we do not try to dis-entangle the namespace.
48  // That is, we do not use the getName() which searches the name for a colon, but instead use
49  // the "raw" name attribute.
50 
51  // TO DO: sfractions assumes that the values are "mixture by weight" (I think)
52  // we need to retrieve the fraction attributes and then check the method
53  // attribute of the CompositeMaterial to determine if the numbers go straight
54  // in to the DDCore or if the numbers need to be manipulated so that the
55  // sfractions are really mixtures by weight going into the DDCore. Otherwise,
56  // the DDCore has to know which are which and right now it does not.
57 
58  if( myMF->size() != myrMaterial->size())
59  {
60  std::string msg = "/nDDLCompositeMaterial::processElement found that the ";
61  msg += "number of MaterialFractions does not match the number ";
62  msg += "of rMaterial names for ";
63  msg += ddn.ns() + ":" + ddn.name() + ".";
64  throwError( msg );
65  }
66  for( size_t i = 0; i < myrMaterial->size(); ++i )
67  {
68  atts = myMF->getAttributeSet( i );
69  mat.addMaterial( myrMaterial->getDDName( nmspace, "name", i ),
70  ev.eval( nmspace, atts.find( "fraction" )->second ));
71  }
72  // clears and sets new reference to THIS material.
73  DDLMaterial::setReference( nmspace, cpv );
74  myMF->clear();
75  clear();
76 }
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:172
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a "row" of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:73
void throwError(const std::string &keyMessage) const
format std::string for throw an error.
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:104
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
bool ev
type of data representation of DDCompactView
Definition: DDCompactView.h:90
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:75
ClhepEvaluator & evaluator()
DDLCompositeMaterial(DDLElementRegistry *myreg)
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:17
void preProcessElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Called by loadAttributes AFTER attributes are loaded.
double eval(const std::string &ns, const std::string &expr)
The main class for processing parsed elements.
virtual void clear(void)
clear this element&#39;s contents.
Definition: DDXMLElement.cc:55
virtual const DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:80
const std::string & name() const
Returns the name.
Definition: DDName.cc:90