Commit in GeomConverter on MAIN
src/org/lcsim/geometry/compact/CompactReader.java+4-11.36 -> 1.37
src/org/lcsim/geometry/compact/converter/lcdd/Main.java+1-11.16 -> 1.17
src/org/lcsim/geometry/compact/converter/lcdd/util/LCDD.java+75-71.24 -> 1.25
test/org/lcsim/geometry/compact/GDMLIncludeTest.java+21added 1.1
testResources/org/lcsim/geometry/compact/GDMLIncludeTest.xml+66added 1.1
+167-9
2 added + 3 modified, total 5 files
JM: First working version of GDML include mechanism in compact description (requested by Norman)

GeomConverter/src/org/lcsim/geometry/compact
CompactReader.java 1.36 -> 1.37
diff -u -r1.36 -r1.37
--- CompactReader.java	14 Dec 2007 22:04:13 -0000	1.36
+++ CompactReader.java	8 Jan 2008 23:50:52 -0000	1.37
@@ -28,7 +28,7 @@
  * org.lcsim.geometry.GeometryReader class, which extends this.
  *
  * @author tonyj
- * @version $Id: CompactReader.java,v 1.36 2007/12/14 22:04:13 jeremy Exp $
+ * @version $Id: CompactReader.java,v 1.37 2008/01/08 23:50:52 jeremy Exp $
  *
  */
 public class CompactReader
@@ -296,6 +296,9 @@
         {
             Element gdmlFile = (Element)o;
             String ref = gdmlFile.getAttributeValue("ref");
+            
+            //System.out.println("merging in " + ref);
+            
             try {
                 det.addGDMLReference(new URL(ref));
             }

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
Main.java 1.16 -> 1.17
diff -u -r1.16 -r1.17
--- Main.java	14 Dec 2007 22:04:13 -0000	1.16
+++ Main.java	8 Jan 2008 23:50:53 -0000	1.17
@@ -39,7 +39,7 @@
       OutputStream out = args.length == 1 ? System.out : new BufferedOutputStream(new FileOutputStream(args[1]));
       new Main(validateDefault).convert(args[0],in,out);
    }
-   Main(boolean validate) throws Exception
+   public Main(boolean validate) throws Exception
    {
       this.validate = validate;
    }

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
LCDD.java 1.24 -> 1.25
diff -u -r1.24 -r1.25
--- LCDD.java	14 Dec 2007 21:57:51 -0000	1.24
+++ LCDD.java	8 Jan 2008 23:50:53 -0000	1.25
@@ -1,9 +1,9 @@
 package org.lcsim.geometry.compact.converter.lcdd.util;
 
-import java.io.IOException;
 import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import org.jdom.Attribute;
@@ -453,11 +453,12 @@
     }
  
     /**
-     * Merge in an existing GDML file into this LCDD document.
+     * Merge an existing GDML file into this LCDD document.
      * @param in InputStream from a GDML data source.
      */
     public void mergeGDML(InputStream in)
     {
+        // Build the GDML input document.        
         SAXBuilder builder = new SAXBuilder();
         Document doc = null;
         try {
@@ -476,19 +477,86 @@
         }
         
         Element gdml = getChild("gdml");
-                                       
+        
+        // Find the world and tracking volumes in the target document.
+        
+        Element targetWorld = null;
+        Element targetTracking = null;
+        for (Object o : gdml.getChild("structure").getChildren())
+        {
+            Element e = (Element)o;
+            if (e.getAttributeValue("name").equals("world_volume"))
+            {
+                targetWorld = e;
+            }
+            else if (e.getAttributeValue("name").equals("tracking_volume"))
+            {
+                targetTracking = e;
+            }
+        }
+                                            
+        // Process top level sections in the source GDML document.
         for (Object o1 : root.getChildren())
         {
-            Element section = (Element)o1;       
+            Element section = (Element)o1;
             
+            //System.out.println("merging in section " + section.getName());
+            
+            // Ignore the setup section of the source document.
             if (!section.getName().equals("setup"))
             {
                 Element target = gdml.getChild(section.getName());
-                                    
+                                 
+                // Process children in this section.
                 for (Object o2 : section.getChildren())
-                {
+                {                    
                     Element element = (Element)o2;
-                    target.addContent(element);
+                    
+                    // Check if physvols need to be merged into the target tracking or world volumes. 
+                    if (
+                            element.getName().equals("volume") && 
+                            (element.getAttributeValue("name").equals("world_volume") 
+                                    || element.getAttributeValue("name").equals("tracking_volume")))
+                    {
+                        Element targetVol = null;
+                        
+                        if (element.getAttributeValue("name").equals("world_volume"))
+                        {
+                            targetVol = targetWorld;
+                        }
+                        else if (element.getAttributeValue("name").equals("tracking_volume"))
+                        {
+                            targetVol = targetTracking;
+                        }
+                        
+                        for (Object o : element.getChildren("physvol"))
+                        {
+                            Element physvol = (Element)o;
+                            boolean skip = false;
+                            if (targetTracking != null && physvol.getChild("volumeref").getAttributeValue("ref").equals("tracking_volume"))
+                                skip = true;
+                            if (!skip)
+                                targetVol.addContent((Element)physvol.clone());
+                        }                            
+                    }
+                    // Generic merge-in of this element into target section, checking for duplicates.
+                    else
+                    {
+                        // Check for dup names in target section.
+                        List targetElements = target.getChildren(element.getName());
+                        boolean dup = false;
+                        for (Object o : targetElements)
+                        {
+                            Element targetElement = (Element)o;
+                            if (targetElement.getAttributeValue("name").equals(element.getAttributeValue("name")))
+                            {
+                                dup = true;
+                                break;
+                            }
+                        }
+                        
+                        if (!dup) target.addContent((Element)element.clone());
+                    }                        
                 }
             }
         }

GeomConverter/test/org/lcsim/geometry/compact
GDMLIncludeTest.java added at 1.1
diff -N GDMLIncludeTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ GDMLIncludeTest.java	8 Jan 2008 23:50:53 -0000	1.1
@@ -0,0 +1,21 @@
+package org.lcsim.geometry.compact;
+
+import java.io.BufferedOutputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import junit.framework.TestCase;
+
+import org.lcsim.geometry.compact.converter.lcdd.Main;
+import org.lcsim.util.test.TestUtil.TestOutputFile;
+
+public class GDMLIncludeTest extends TestCase
+{        
+    public void testMerge() throws Exception
+    {
+        InputStream in = GDMLIncludeTest.class.getResourceAsStream("/org/lcsim/geometry/compact/GDMLIncludeTest.xml");
+        OutputStream out = new BufferedOutputStream(new FileOutputStream(new TestOutputFile("GDMLIncludeTest.lcdd")));
+        new Main(false).convert("GDMLIncludeTest",in,out);        
+    }    
+}
\ No newline at end of file

GeomConverter/testResources/org/lcsim/geometry/compact
GDMLIncludeTest.xml added at 1.1
diff -N GDMLIncludeTest.xml
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ GDMLIncludeTest.xml	8 Jan 2008 23:50:53 -0000	1.1
@@ -0,0 +1,66 @@
+<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 tag containing author, version, time, unique id (url) -->
+  <info name="GDMLIncludeTest">
+    <comment>
+      Test of the compact format for sdjan03 detector.
+    </comment>
+  </info>
+
+  <!-- Constants -->
+  <define>
+  
+    <constant name="cm" value="10"/>  
+    <!-- world -->
+    <constant name="world_side" value="15000" />
+    <constant name="world_x" value="world_side" />
+    <constant name="world_y" value="world_side" />
+    <constant name="world_z" value="world_side" />
+    
+    <!-- tracking region -->
+    <constant name="tracking_region_radius" value="127.0*cm"/>
+    <constant name="tracking_region_zmax" value="168.0*cm"/>
+        
+  </define>
+
+  <materials>
+
+    <!-- so can easily replace references 
+         with something more realistic later -->
+    <material  name="MuonAir"  >
+      <D type="density" unit="g/cm3" value="0.0012"/>
+      <fraction n="0.7803"  ref="N"/>
+      <fraction n="0.2103"  ref="O"/>
+      <fraction n="0.0094"  ref="Ar"/>
+    </material>
+    
+  </materials>
+    
+  <detectors>
+    
+    <detector id="1" name="HADBarrel" type="CylindricalBarrelCalorimeter" readout="HcalBarrHits">
+      <dimensions inner_r = "144.0*cm" outer_z = "286.0*cm" />
+      <layer repeat="1">
+        <slice material = "Polystyrene" thickness = "1.0*cm" sensitive = "yes" />
+      </layer>
+      <parameter name="CALTYPE">HCAL</parameter>
+    </detector>    
+  </detectors>
+
+  <readouts>
+    <readout name="HcalBarrHits"> 
+      <segmentation type="ProjectiveCylinder" thetaBins="600" phiBins="1200"/>
+      <id>layer:7,system:3,barrel:3,theta:32:11,phi:11</id>
+    </readout>
+  </readouts>
+
+  <fields>    
+  </fields>
+
+  <includes>
+    <gdmlFile ref="http://www.lcsim.org/test/gdml/box.gdml" />
+  </includes>
+
+</lccdd>
CVSspam 0.2.8