GeomConverter/src/org/lcsim/material
diff -u -r1.1 -r1.2
--- MaterialFromGDMLCnv.java 30 Jun 2005 00:37:50 -0000 1.1
+++ MaterialFromGDMLCnv.java 1 Jul 2005 00:08:01 -0000 1.2
@@ -20,23 +20,19 @@
*/
public class MaterialFromGDMLCnv
{
- LCDD _lcdd;
-
- /** Default temperature in kelvin = 1.0 */
- public static final double defaultTemperature = 273.15;
-
- /** Default pressure in atmospheres = 1.0 */
- public static final double defaultPressure = 1.0;
+ LCDD _lcdd;
/** Creates a new instance of MaterialCnv */
public MaterialFromGDMLCnv(LCDD lcdd)
{
_lcdd = lcdd;
+ MaterialManager.instance();
}
public MaterialFromGDMLCnv()
{
_lcdd = null;
+ MaterialManager.instance();
}
public void setLCDD(LCDD lcdd)
@@ -44,9 +40,17 @@
_lcdd = lcdd;
}
- /** Make an org.lcsim.material.Material object from a material tag. */
+ /**
+ * Make an org.lcsim.material.Material object from a GDML material tag.
+ *
+ * Resolve references outside materials tag (e.g. within define tag) using
+ * the lcdd parameter (which is allowed to be null).
+ *
+ */
public Material makeMaterial(org.jdom.Element materialElement, LCDD lcdd) throws JDOMException
- {
+ {
+ //System.out.println("cnv makeMaterial - " + materialElement.getAttributeValue("name"));
+
_lcdd = lcdd;
Material material = null;
@@ -59,7 +63,7 @@
double temperature;
density = pressure = temperature = 0;
- /* Allow this function to throw, because D or Dref is a required tag. */
+ /* Allow this exception to propagate, because D or Dref is a required tag. */
density = getDensity(materialElement);
/* Get pressure or use default. */
@@ -69,7 +73,7 @@
}
catch (JDOMException jde)
{
- pressure = defaultPressure;
+ pressure = Material.DEFAULT_PRESSURE;
}
/* Get temperature or use default. */
@@ -79,7 +83,7 @@
}
catch (JDOMException jde)
{
- temperature = defaultTemperature;
+ temperature = Material.DEFAULT_TEMPERATURE;
}
MaterialDefinitionType mdt = MaterialDefinitionType.getMaterialDefinitionType(materialElement);
@@ -93,6 +97,8 @@
if ( mdt == MaterialDefinitionType.ATOM )
{
+ //System.out.println("atom def");
+
double A = materialElement.getChild( tagname ).getAttribute("value").getDoubleValue();
double Z = 0;
if ( materialElement.getAttribute("Z") != null )
@@ -114,9 +120,15 @@
}
else
{
+ //System.out.println("fraction or composite def");
+
int nComponents = 0;
- nComponents = materialElement.getChildren(tagname).size();
+ //System.out.println("tagname: " + tagname);
+
+ nComponents = materialElement.getChildren(tagname).size();
+
+ //System.out.println("ncomp: " + nComponents);
material = new Material(name,
nComponents,
@@ -128,6 +140,8 @@
/* Fill in composite. */
if ( mdt == MaterialDefinitionType.COMPOSITE )
{
+ //System.out.println("composite def");
+
for ( Object o : materialElement.getChildren( tagname ) )
{
org.jdom.Element compositeElement = (org.jdom.Element) o;
@@ -137,7 +151,7 @@
MaterialElement me = MaterialManager.getElement(elementName);
if ( me != null )
- {
+ {
material.addElement(me, n);
}
else
@@ -149,9 +163,13 @@
/* Fill in mass fraction. */
else
{
+ //System.out.println("fraction def");
for ( Object o : materialElement.getChildren(tagname) )
- {
+ {
org.jdom.Element fractionElement = (org.jdom.Element) o;
+
+ //System.out.println(tagname + " " + fractionElement.getAttributeValue("ref"));
+
String refName = fractionElement.getAttributeValue("ref");
double f = fractionElement.getAttribute("n").getDoubleValue();
@@ -159,6 +177,7 @@
if ( me != null )
{
+ //System.out.println("adding element: " + refName);
material.addElement(me, f);
}
else
@@ -251,6 +270,5 @@
}
return value;
- }
-
+ }
}
\ No newline at end of file