CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  DDXMLElement* myMF = myRegistry_->getElement( "MaterialFraction" );
43  DDXMLElement* 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 }
int i
Definition: DBlmapReader.cc:9
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 &quot;row&quot; 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:16
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
DDXMLElement * getElement(const std::string &name)
THE most important part. Getting the pointer to a given element type.
ClhepEvaluator & evaluator()
DDLCompositeMaterial(DDLElementRegistry *myreg)
virtual size_t size(void) const
Number of elements accumulated.
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.
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:48
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