GeomConverter/src/org/lcsim/geometry/layer
diff -N LayerFromCompactCnv.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ LayerFromCompactCnv.java 1 Jul 2005 00:11:51 -0000 1.1
@@ -0,0 +1,129 @@
+/*
+ * LayerBuilder.java
+ *
+ * Created on April 1, 2005, 4:23 PM
+ */
+
+package org.lcsim.geometry.layer;
+
+import org.jdom.Element;
+import org.jdom.Attribute;
+import org.jdom.JDOMException;
+import java.util.Iterator;
+import org.jdom.DataConversionException;
+import org.lcsim.material.MaterialManager;
+import org.lcsim.material.Material;
+
+/**
+ *
+ * @author jeremym
+ */
+public class LayerFromCompactCnv
+{
+ private LayerFromCompactCnv()
+ {}
+
+ public static LayerStack makeLayerStackFromCompact(Element e) throws JDOMException, DataConversionException
+ {
+ LayerStack layerStack = new LayerStack();
+
+ for (Iterator i = e.getChildren("layer").iterator(); i.hasNext();)
+ {
+ Element lyrElem = (Element) i.next();
+
+ /* Start a new layer. */
+ Layer lyr = new Layer();
+
+ /* Default to one repetition. */
+ int repeat = 1;
+
+ /* Get repeat value from element if exists. */
+ Attribute repAttrib = lyrElem.getAttribute("repeat");
+ if ( repAttrib != null ) {
+ repeat = repAttrib.getIntValue();
+ }
+
+ /* Iterate over the slices in the layer. */
+ if ( lyrElem.getChildren("slice").size() == 0 ) {
+ throw new JDOMException("No slice elements found in this layer.");
+ }
+
+ for (Iterator j = lyrElem.getChildren("slice").iterator(); j.hasNext(); )
+ {
+ Element slice = (Element) j.next();
+
+ Attribute matAttrib = slice.getAttribute("material");
+
+ if ( matAttrib == null )
+ {
+ throw new JDOMException("No material attribute found in this slice.");
+ }
+
+ String matName = slice.getAttributeValue("material");
+
+ Attribute thickness = slice.getAttribute("thickness");
+
+ if ( thickness == null ) {
+ throw new JDOMException("No thickness attribute found in this slice.");
+ }
+
+ Attribute sensAttrib = slice.getAttribute("sensitive");
+
+ /* Default to not sensitive. */
+ boolean isSens = false;
+
+ if ( sensAttrib != null ) {
+ isSens = sensAttrib.getBooleanValue();
+ }
+
+ /* Make a new slice. Ctor will look up material. */
+ LayerSlice s = new LayerSlice(matName,
+ thickness.getDoubleValue(),
+ isSens);
+
+ if ( s == null )
+ {
+ throw new RuntimeException("slice is null");
+ }
+
+ if ( lyr == null )
+ {
+ throw new RuntimeException("layer is null");
+ }
+
+ /* Add slice to current layer. */
+ lyr.addSlice(s);
+ }
+
+ /* Add layer to stack once for each repetition. */
+ for (int k = 0; k < repeat; k++)
+ {
+ layerStack.addLayer(lyr);
+ }
+ }
+
+ return layerStack;
+ }
+
+ public static double computeDetectorThickness(Element node) throws JDOMException
+ {
+ return LayerFromCompactCnv.makeLayerStackFromCompact(node).getTotalThickness();
+ }
+
+ /** Compute the thickness of a single layer, ignoring the repeat attribute. */
+ public static double computeSingleLayerThickness(Element node) throws JDOMException
+ {
+ if ( node.getName() != "layer" )
+ {
+ throw new JDOMException("LayerCompactCnv.computeLayerThickness() takes layer element, not " + node.getName() );
+ }
+
+ double thickness = 0.0;
+ for ( Object o : node.getChildren("slice") )
+ {
+ Element sliceElem = (Element) o;
+ thickness += sliceElem.getAttribute("thickness").getDoubleValue();
+ }
+ return thickness;
+ }
+}
GeomConverter/src/org/lcsim/geometry/layer
diff -N LayerCompactCnv.java
--- LayerCompactCnv.java 21 Jun 2005 22:07:00 -0000 1.6
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,120 +0,0 @@
-/*
- * LayerBuilder.java
- *
- * Created on April 1, 2005, 4:23 PM
- */
-
-package org.lcsim.geometry.layer;
-
-import org.jdom.Element;
-import org.jdom.Attribute;
-import org.jdom.JDOMException;
-import java.util.Iterator;
-import org.jdom.DataConversionException;
-
-/**
- *
- * @author jeremym
- */
-public class LayerCompactCnv
-{
- private LayerCompactCnv()
- {}
-
- public static LayerStack makeLayerStackFromCompact(Element e) throws JDOMException, DataConversionException
- {
- LayerStack layerStack = new LayerStack();
-
- for (Iterator i = e.getChildren("layer").iterator(); i.hasNext();)
- {
- Element lyrElem = (Element) i.next();
-
- /* Start a new layer. */
- Layer lyr = new Layer();
-
- /* Default to one repetition. */
- int repeat = 1;
-
- /* Get repeat value from element if exists. */
- Attribute repAttrib = lyrElem.getAttribute("repeat");
- if ( repAttrib != null ) {
- repeat = repAttrib.getIntValue();
- }
-
- /* Iterate over the slices in the layer. */
- if ( lyrElem.getChildren("slice").size() == 0 ) {
- throw new JDOMException("No slice elements found in this layer.");
- }
-
- for (Iterator j = lyrElem.getChildren("slice").iterator(); j.hasNext(); )
- {
- Element slice = (Element) j.next();
-
- Attribute matName = slice.getAttribute("material");
- Attribute thickness = slice.getAttribute("thickness");
-
- if ( matName == null || thickness == null ) {
- throw new JDOMException("Required material or thickness attribute missing from slice element.");
- }
-
- Attribute sensAttrib = slice.getAttribute("sensitive");
-
- /* Default to not sensitive. */
- boolean isSens = false;
-
- if ( sensAttrib != null ) {
- isSens = sensAttrib.getBooleanValue();
- }
-
- /* Make a new slice. */
- LayerSlice s = new LayerSlice(matName.getValue(),
- thickness.getDoubleValue(),
- isSens);
-
- if ( s == null )
- {
- throw new RuntimeException("slice is null");
- }
-
- if ( lyr == null )
- {
- throw new RuntimeException("layer is null");
- }
-
- /* Add slice to current layer. */
- lyr.addSlice(s);
- }
-
- /* Add layer to stack once for each repetition. */
- for (int k = 0; k < repeat; k++)
- {
- layerStack.addLayer(lyr);
- }
- }
-
- return layerStack;
- }
-
- /** FIXME: This function should not require creation of a LayerStack. */
- public static double computeDetectorThickness(Element node) throws JDOMException
- {
- return LayerCompactCnv.makeLayerStackFromCompact(node).getTotalThickness();
- }
-
- /** Compute the thickness of a single layer, ignoring the repeat attribute. */
- public static double computeSingleLayerThickness(Element node) throws JDOMException
- {
- if ( node.getName() != "layer" )
- {
- throw new JDOMException("LayerCompactCnv.computeLayerThickness() takes layer element, not " + node.getName() );
- }
-
- double thickness = 0.0;
- for ( Object o : node.getChildren("slice") )
- {
- Element sliceElem = (Element) o;
- thickness += sliceElem.getAttribute("thickness").getDoubleValue();
- }
- return thickness;
- }
-}