View Javadoc

1   package org.lcsim.detector.converter.lcdd;
2   
3   import org.jdom.Element;
4   import org.jdom.JDOMException;
5   import org.lcsim.detector.converter.XMLConverter;
6   import org.lcsim.detector.material.IMaterial;
7   import org.lcsim.detector.material.MaterialElement;
8   
9   /**
10   * 
11   * This converter takes a GDML element and converts
12   * it to a MaterialElement.
13   * 
14   * @author Jeremy McCormick <jeremym@slac.stanford.edu>
15   */
16  public class MaterialElementConverter 
17  implements XMLConverter
18  {
19  	public void convert(Element element) throws JDOMException
20  	{
21  		if ( element.getName().equals("element") )
22  		{
23  			String name = element.getAttributeValue("name");		
24  			double z = element.getAttribute("Z").getDoubleValue();
25  			
26  			Element atom = element.getChild("atom");
27  			
28  			if ( atom != null )
29  			{
30  				double a = atom.getAttribute("value").getDoubleValue();
31  				
32  				// FIXME: Application of a unit means this doesn't 
33  				//        end up matching the old materials db!
34  				//        Leave it out for now.
35  				
36  				//double unit = g / mole;
37  				//if ( atom.getAttribute("unit") != null )
38  				//{
39  				//	unit = atom.getAttribute("unit").getDoubleValue();
40  				//}				
41  				//a = a * unit;				
42  				
43                  // FIXME: Get state, temperature, and pressure from the XML file.
44  				new MaterialElement(
45                          name, 
46                          z, 
47                          a, 
48                          1.0, 
49                          IMaterial.Unknown, 
50                          IMaterial.defaultTemperature, 
51                          IMaterial.defaultPressure);				
52  			}
53  			else {
54  				throw new JDOMException("The MaterialElement <" + name + "> is missing <atom>.");
55  			}				
56  		}
57  		else {
58  			throw new JDOMException("Invalid element <" + element.getName() + "> for MaterialElementConverter.");
59  		}
60  	}	
61  }