Commit in GeomConverter on MAIN
src/org/lcsim/geometry/compact/converter/lcdd/TubeSegment.java+18-661.1 -> 1.2
src/org/lcsim/geometry/compact/converter/lcdd/util/Position.java+97-491.2 -> 1.3
                                                  /Rotation.java+55-31.2 -> 1.3
                                                  /Tube.java+20-11.4 -> 1.5
src/org/lcsim/geometry/subdetector/TubeSegment.java+19added 1.1
test/org/lcsim/geometry/compact/converter/lcdd/TubeSegmentTest.java+24added 1.1
testResources/org/lcsim/geometry/subdetector/TubeSegmentTest.xml+36added 1.1
+269-119
3 added + 4 modified, total 7 files
JM: add test for new TubeSegment subdetector type; addition of rotation and position convenience constructors to lcdd cnv

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
TubeSegment.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- TubeSegment.java	29 Oct 2007 23:17:29 -0000	1.1
+++ TubeSegment.java	30 Oct 2007 18:29:23 -0000	1.2
@@ -15,7 +15,7 @@
  * LCDD implementation of a TubeSegment for beampipe elements.
  *
  * @author Jeremy McCormick
- * @version $Id: TubeSegment.java,v 1.1 2007/10/29 23:17:29 jeremy Exp $
+ * @version $Id: TubeSegment.java,v 1.2 2007/10/30 18:29:23 jeremy Exp $
  */
 public class TubeSegment
 extends LCDDSubdetector
@@ -48,12 +48,11 @@
         Material material = lcdd.getMaterial(node.getChild("material").getAttributeValue("name"));
         
         // Tube
-        Element tubsParam = node.getChild("tubs");
-        double innerR, outerR, zHalf;
-        innerR = tubsParam.getAttribute("rmin").getDoubleValue();
-        outerR = tubsParam.getAttribute("rmax").getDoubleValue();
-        zHalf = tubsParam.getAttribute("zhalf").getDoubleValue();                        
-        Tube tube = new Tube(name + "_tube", innerR, outerR, zHalf);
+        Tube tube = null;
+        if (node.getChild("tubs") != null)
+            tube = new Tube(name + "_tube", node.getChild("tubs"));
+        else
+            throw new RuntimeException("TubeSegment " + name + " is missing required tubs element");                   
         lcdd.add(tube);
         
         // Volume
@@ -61,69 +60,22 @@
         lcdd.add(volume);
         
         // Position
-        Position position = null;
-        Element positionElement = node.getChild("position");        
-        if (positionElement == null)
-        {
-            position = new Position(name + "_position");
-        }
+        Position position;
+        if (node.getChild("position") != null)
+            position = new Position(name + "_position", node.getChild("position"));
         else
-        {
-            double x,y,z;
-            x = y = z = 0.;
-            
-            if (positionElement.getAttribute("x") != null)
-            {
-                x = positionElement.getAttribute("x").getDoubleValue();
-            }
-            
-            if (positionElement.getAttribute("y") != null)
-            {
-                y = positionElement.getAttribute("y").getDoubleValue();
-            }
-            
-            if (positionElement.getAttribute("z") != null)
-            {
-                z = positionElement.getAttribute("z").getDoubleValue();
-            }           
-            
-            position.setX(x);
-            position.setY(y);
-            position.setZ(z);
-        }
-        
+            position = new Position(name + "_position");
+        lcdd.add(position);
+                
         // Rotation
         Rotation rotation = null;
-        Element rotationElement = node.getChild("rotation");
-        if (rotationElement == null)
-        {
-            rotation = new Rotation(name + "_rotation");            
-        }
-        else 
-        {
-            double x,y,z;
-            x = y = z = 0.;
-            
-            if (rotationElement.getAttribute("x") != null)
-            {
-                x = rotationElement.getAttribute("x").getDoubleValue();
-            }
-            
-            if (rotationElement.getAttribute("y") != null)
-            {
-                y = rotationElement.getAttribute("y").getDoubleValue();
-            }
-            
-            if (rotationElement.getAttribute("z") != null)
-            {
-                z = rotationElement.getAttribute("z").getDoubleValue();
-            }
-            
-            rotation.setX(x);
-            rotation.setY(y);
-            rotation.setZ(z);
-        }
+        if (node.getChild("rotation") != null)
+            rotation = new Rotation(name + "_rotation", node.getChild("rotation"));
+        else
+            rotation = new Rotation(name + "_rotation");
+        lcdd.add(rotation);
         
+        // Physical volume.
         PhysVol tubePV = new PhysVol(volume, mother, position, rotation);
         tubePV.addPhysVolID("id", id);
     }

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
Position.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- Position.java	21 Jan 2006 02:30:01 -0000	1.2
+++ Position.java	30 Oct 2007 18:29:29 -0000	1.3
@@ -1,58 +1,106 @@
 package org.lcsim.geometry.compact.converter.lcdd.util;
 
+import org.jdom.DataConversionException;
+import org.jdom.Element;
+
 /**
  * 
+ * LCDD Position element.
+ * 
  * @author tonyj
+ * @author jeremym
  */
 public class Position extends RefElement
 {
-	/** Creates a new instance of Position */
-	public Position(String name)
-	{
-		super("position", name);
-		setAttribute("x", "0.0");
-		setAttribute("y", "0.0");
-		setAttribute("z", "0.0");
-		setAttribute("unit", "mm");
-	}
-
-	public void setX(double d)
-	{
-		setAttribute("x", String.valueOf(d));
-	}
-
-	public void setY(double d)
-	{
-		setAttribute("y", String.valueOf(d));
-	}
-
-	public void setZ(double d)
-	{
-		setAttribute("z", String.valueOf(d));
-	}
-
-	public double x()
-	{
-		return dim("x");
-	}
-
-	public double y()
-	{
-		return dim("y");
-	}
-
-	public double z()
-	{
-		return dim("z");
-	}
-
-	private double dim(String name)
-	{
-		double v = 0.0;
-		try
-		{
-			v = getAttribute(name).getDoubleValue();
-		} catch (Exception e) {}		
-		return v;
-	}
+    /** Creates a new instance of Position at (0,0,0). */
+    public Position(String name)
+    {
+        super("position", name);
+        setAttribute("x", "0.0");
+        setAttribute("y", "0.0");
+        setAttribute("z", "0.0");
+        setAttribute("unit", "mm");
+    }
+
+    /**
+     * Creates a new instance of Position from an {@link org.jdom.Element}.
+     * @param element The XML element which must be called position.
+     */
+    public Position(String name, Element element)
+    {   
+        super("position", name);
+
+        if (!element.getName().equals("position"))
+            throw new IllegalArgumentException("expected position element but got " + element.getName());
+
+        try {
+            
+            double x,y,z;
+            x = y = z = 0.;
+
+            if (element.getAttribute("x") != null)
+            {
+                x = element.getAttribute("x").getDoubleValue();
+            }
+
+            if (element.getAttribute("y") != null)
+            {
+                y  = element.getAttribute("y").getDoubleValue();
+            }
+
+            if (element.getAttribute("z") != null)
+            {
+                z = element.getAttribute("z").getDoubleValue();
+            }
+            
+            setX(x);
+            setY(y);
+            setZ(z);
+        }
+        catch (DataConversionException except)
+        {
+            throw new RuntimeException(except);
+        }
+    }   
+
+    public void setX(double d)
+    {
+        setAttribute("x", String.valueOf(d));
+    }
+
+    public void setY(double d)
+    {
+        setAttribute("y", String.valueOf(d));
+    }
+
+    public void setZ(double d)
+    {
+        setAttribute("z", String.valueOf(d));
+    }
+
+    public double x()
+    {
+        return dim("x");
+    }
+
+    public double y()
+    {
+        return dim("y");
+    }
+
+    public double z()
+    {
+        return dim("z");
+    }
+
+    private double dim(String name)
+    {
+        try {
+            return getAttribute(name).getDoubleValue();
+        }
+        catch (DataConversionException x)
+        {
+            throw new RuntimeException(x);
+        }
+    }
 }

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
Rotation.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- Rotation.java	8 Mar 2005 20:55:43 -0000	1.2
+++ Rotation.java	30 Oct 2007 18:29:29 -0000	1.3
@@ -1,14 +1,21 @@
 package org.lcsim.geometry.compact.converter.lcdd.util;
 
+import org.jdom.DataConversionException;
+import org.jdom.Element;
 
 /**
  *
+ * The LCDD rotation element.
+ *
  * @author tonyj
+ * @author jeremym
  */
 public class Rotation extends RefElement
-{
-   
-   /** Creates a new instance of Rotation */
+{   
+   /** 
+    * Creates an identity rotation called <code>name</code>.
+    * @param name The unique name of this rotation. 
+    */
    public Rotation(String name)
    {
       super("rotation",name);
@@ -17,6 +24,51 @@
       setAttribute("z","0.0");
       setAttribute("unit","radian");
    } 
+   
+   /**
+    * Create a named rotation called <code>name</code> with XML element <code>element</code>.
+    * @throws IllegalArgumentException If element is not called "rotation".
+    * @throws RuntimeException If a {@link org.jdom.DataConversionException} is caught when converting.
+    * @param name The unique name of this rotation.
+    * @param element The XML element to be converted.  It must be called "rotation".
+    */
+   public Rotation(String name, Element element)
+   {
+       super("rotation", name);
+       
+       if (!element.getName().equals("rotation"))
+           throw new IllegalArgumentException("expect rotation element but got " + element.getAttributeValue("name"));
+
+       double x,y,z;
+       x = y = z = 0.;
+       
+       try {      
+          
+           if (element.getAttribute("x") != null)
+           {
+               x = element.getAttribute("x").getDoubleValue();
+           }
+           
+           if (element.getAttribute("y") != null)
+           {
+               y = element.getAttribute("y").getDoubleValue();
+           }
+           
+           if (element.getAttribute("z") != null)
+           {
+               z = element.getAttribute("z").getDoubleValue();
+           }
+       }
+       catch (DataConversionException except)
+       {
+           throw new RuntimeException(except);
+       }
+           
+       setX(x);
+       setY(y);
+       setZ(z);
+   }
+   
    public void setX(double d)
    {
       setAttribute("x",String.valueOf(d));

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
Tube.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- Tube.java	25 Oct 2007 20:06:01 -0000	1.4
+++ Tube.java	30 Oct 2007 18:29:29 -0000	1.5
@@ -1,5 +1,8 @@
 package org.lcsim.geometry.compact.converter.lcdd.util;
 
+import org.jdom.DataConversionException;
+import org.jdom.Element;
+
 /**
  *
  * @author tonyj
@@ -11,7 +14,23 @@
         super("tube",name);
         setRMin(innerR);
         setRMax(outerR);
-        setZ(zHalf);
+        // FIXME: GDML will divide this by 2 so need to double it!
+        setZ(zHalf*2);
+        setAttribute("deltaphi", String.valueOf(Math.PI * 2) );
+    }
+    
+    public Tube(String name, Element element)
+    {
+        super("tube",name);
+        try {
+            setRMin(element.getAttribute("rmin").getDoubleValue());
+            setRMax(element.getAttribute("rmax").getDoubleValue());
+            setZ(element.getAttribute("zhalf").getDoubleValue());
+        }
+        catch (DataConversionException x)
+        {
+            throw new RuntimeException(x);
+        }
         setAttribute("deltaphi", String.valueOf(Math.PI * 2) );
     }
 

GeomConverter/src/org/lcsim/geometry/subdetector
TubeSegment.java added at 1.1
diff -N TubeSegment.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ TubeSegment.java	30 Oct 2007 18:29:30 -0000	1.1
@@ -0,0 +1,19 @@
+package org.lcsim.geometry.subdetector;
+
+import org.jdom.Element;
+import org.jdom.JDOMException;
+
+/**
+ * Placehold in compact description for TubeSegment type.
+ *
+ * @author Jeremy McCormick
+ * @version $Id: TubeSegment.java,v 1.1 2007/10/30 18:29:30 jeremy Exp $
+ */
+
+public class TubeSegment extends AbstractSubdetector
+{
+    public TubeSegment(Element node) throws JDOMException
+    {
+        super(node);
+    }
+}

GeomConverter/test/org/lcsim/geometry/compact/converter/lcdd
TubeSegmentTest.java added at 1.1
diff -N TubeSegmentTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ TubeSegmentTest.java	30 Oct 2007 18:29:31 -0000	1.1
@@ -0,0 +1,24 @@
+package org.lcsim.geometry.compact.converter.lcdd;
+
+import java.io.BufferedOutputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import junit.framework.TestCase;
+
+import org.lcsim.util.test.TestUtil.TestOutputFile;
+
+/**
+ * Test of LCDD converter for TubeSegment.
+ * @author jeremym
+ */
+public class TubeSegmentTest extends TestCase
+{    
+    public void testCnv() throws Exception
+    {
+        InputStream in = TubeSegment.class.getResourceAsStream("/org/lcsim/geometry/subdetector/TubeSegmentTest.xml");
+        OutputStream out = new BufferedOutputStream(new FileOutputStream(new TestOutputFile("TubeSegmentTest.lcdd")));
+        new Main(true).convert("TubeSegmentTest",in,out);
+    }
+}

GeomConverter/testResources/org/lcsim/geometry/subdetector
TubeSegmentTest.xml added at 1.1
diff -N TubeSegmentTest.xml
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ TubeSegmentTest.xml	30 Oct 2007 18:29:31 -0000	1.1
@@ -0,0 +1,36 @@
+<lccdd xmlns:compact="http://www.lcsim.org/schemas/compact/1.0"
+       xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
+       xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/compact/1.0/compact.xsd">
+
+    <info name="TubeSegmentTest">
+        <comment>Test of TubeSegment subdetector type.</comment>
+    </info>
+
+    <define>    
+        <constant name="world_side" value="30000" />
+        <constant name="world_x" value="world_side" />
+        <constant name="world_y" value="world_side" />
+        <constant name="world_z" value="world_side" />
+        <constant name="tracking_region_radius" value="0.1*cm"/>
+        <constant name="tracking_region_zmax" value="0.1*cm"/>
+    </define>
+
+    <materials>
+    </materials>
+
+    <detectors>
+      <detector id="1" name="TubeSegment" type="TubeSegment">
+    	  <material name="Air"/>
+    	  <tubs rmin="10.0" rmax="50.0" zhalf="50.0"/>
+    	  <position x="0.0" y="0.0" z="200.0"/>
+    	  <rotation x="0.0" y="0.2" z="0."/>
+      </detector>
+    </detectors>
+
+    <readouts>
+    </readouts>
+    
+    <fields>
+   </fields>
+   
+</lccdd>
CVSspam 0.2.8