Print

Print


Commit in GeomConverter/src/org/lcsim on MAIN
detector/converter/compact/DetectorConverter.java+17-291.1 -> 1.2
                          /IDetectorConverter.java+2-21.1 -> 1.2
geometry/GeometryReader.java+53-241.5 -> 1.6
geometry/compact/CompactReader.java+13-21.31 -> 1.32
+85-57
4 modified files
JM: Enable support for org.lcsim.detector from within GeomConverter's GeometryReader.

GeomConverter/src/org/lcsim/detector/converter/compact
DetectorConverter.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- DetectorConverter.java	15 Mar 2007 02:09:14 -0000	1.1
+++ DetectorConverter.java	15 Mar 2007 22:49:35 -0000	1.2
@@ -1,7 +1,6 @@
 package org.lcsim.detector.converter.compact;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -45,38 +44,27 @@
 	{
 		return subdetectorConverters.get(klass);
 	}
-    	
-	public IPhysicalVolume convert(Detector detector, String resource)  throws JDOMException, IOException
-	{
-		return convert(detector, this.getClass().getResourceAsStream(resource));
-	}
-	
-	public IPhysicalVolume convert(Detector detector, InputStream in) throws JDOMException, IOException
-	{
-        //System.out.println("DetectorConverter.convert - start");
-                
-		Document doc;
-		try {
-			doc = CompactDocumentBuilder.build(in);
-		}
-		catch ( Exception x )
-		{
-			throw new RuntimeException(x);
-		}
-		
-		IPhysicalVolume pvWorld = buildWorldVolume(detector);
-		
-		convertMaterials("/org/lcsim/material/elements.xml");
-		convertMaterials("/org/lcsim/material/materials.xml");
-		convertMaterials(doc);
+    
+    public IPhysicalVolume convert(Detector detector, String resource) throws JDOMException, IOException
+    {
+        return convert( detector, CompactDocumentBuilder.build(resource) );
+    }
+    	    
+    public IPhysicalVolume convert(Detector detector, Document doc)  throws JDOMException, IOException
+    {
+        IPhysicalVolume pvWorld = buildWorldVolume(detector);
         
-		convertSubdetectors(detector, pvWorld);		
+        convertMaterials("/org/lcsim/material/elements.xml");
+        convertMaterials("/org/lcsim/material/materials.xml");
+        convertMaterials(doc);
+        
+        convertSubdetectors(detector, pvWorld);     
         
         //System.out.println("DetectorConverter.convert - end");
         
-		return pvWorld;
-	}
-	
+        return pvWorld;
+    }
+		
 	private void convertMaterials(Document doc) throws JDOMException
 	{
 		(new MaterialsConverter()).convert(doc);

GeomConverter/src/org/lcsim/detector/converter/compact
IDetectorConverter.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- IDetectorConverter.java	15 Mar 2007 02:09:14 -0000	1.1
+++ IDetectorConverter.java	15 Mar 2007 22:49:35 -0000	1.2
@@ -2,12 +2,12 @@
 
 import java.io.IOException;
 
+import org.jdom.Document;
 import org.jdom.JDOMException;
 import org.lcsim.detector.IPhysicalVolume;
 import org.lcsim.geometry.Detector;
 
 public interface IDetectorConverter 
 {
-//	public IPhysicalVolume convert(Detector detector, InputStream in)  throws JDOMException;
-	public IPhysicalVolume convert(Detector detector, String resource)  throws JDOMException, IOException;
+	public IPhysicalVolume convert(Detector detector, Document doc) throws JDOMException, IOException;
 }

GeomConverter/src/org/lcsim/geometry
GeometryReader.java 1.5 -> 1.6
diff -u -r1.5 -r1.6
--- GeometryReader.java	18 Jul 2005 18:00:01 -0000	1.5
+++ GeometryReader.java	15 Mar 2007 22:49:35 -0000	1.6
@@ -2,39 +2,68 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+
 import org.jdom.JDOMException;
+import org.lcsim.detector.converter.compact.DetectorConverter;
 import org.lcsim.geometry.compact.CompactElementFactory;
 import org.lcsim.geometry.compact.CompactReader;
-import org.lcsim.util.xml.ElementFactory.ElementCreationException;
 import org.lcsim.geometry.compact.Field;
 import org.lcsim.geometry.compact.Segmentation;
 import org.lcsim.geometry.compact.Subdetector;
+import org.lcsim.util.xml.ElementFactory.ElementCreationException;
 
 /**
  *
- * @author tonyj
+ * The GeometryReader extends the CompactReader and
+ * creates specific types based on the type attribute
+ * of an XML element.  The type string must match
+ * a class within the registered package for that
+ * base class.  Currently supported base classes
+ * with specific types are Subdetector, Segmentation,
+ * and Field. 
+ * 
+ * For example, this compact XML will instantiate a
+ * Subdetector with specific type of 'CylindricalBarrelCalorimeter'.
+ * 
+ * <detector type="CylindricalBarrelCalorimeter" ... />
+ * 
+ * Support added for detailed geometry representation.
+ * --JM, 15 March 2007
+ *
+ * @author Tony Johnson <[log in to unmask]>
+ * @author Jeremy McCormick <[log in to unmask]>
  */
 public class GeometryReader extends CompactReader
 {
-   public GeometryReader()
-   {
-      super(new GeometryFactory());
-   }
-   
-   public Detector read(InputStream in) throws IOException, JDOMException, ElementCreationException
-   {
-      return (Detector) super.read(in);
-   }
-   
-   static class GeometryFactory extends CompactElementFactory
-   {
-      GeometryFactory()
-      {
-         super();
-         register(Detector.class);
-         register(Subdetector.class,"org.lcsim.geometry.subdetector");
-         register(Segmentation.class,"org.lcsim.geometry.segmentation");
-         register(Field.class,"org.lcsim.geometry.field");
-      }
-   }
-}
+    public GeometryReader()
+    {
+        super(new GeometryFactory());
+    }
+
+    public Detector read(InputStream in) throws IOException, JDOMException, ElementCreationException
+    {    
+        // Build a compact description with support for specific types.
+        Detector detector = (Detector)super.read(in);
+
+        // Build the detailed detector description.
+        DetectorConverter cnv = new DetectorConverter();
+        cnv.convert(
+                detector, 
+                getDocument() 
+        );
+
+        return detector;
+    }
+
+    static class GeometryFactory extends CompactElementFactory
+    {
+        GeometryFactory()
+        {
+            super();
+            register(Detector.class);
+            register(Subdetector.class,"org.lcsim.geometry.subdetector");
+            register(Segmentation.class,"org.lcsim.geometry.segmentation");
+            register(Field.class,"org.lcsim.geometry.field");
+        }
+    }
+}
\ No newline at end of file

GeomConverter/src/org/lcsim/geometry/compact
CompactReader.java 1.31 -> 1.32
diff -u -r1.31 -r1.32
--- CompactReader.java	15 Mar 2007 02:09:15 -0000	1.31
+++ CompactReader.java	15 Mar 2007 22:49:35 -0000	1.32
@@ -26,13 +26,14 @@
  * org.lcsim.geometry.GeometryReader class, which extends this.
  *
  * @author tonyj
- * @version $Id: CompactReader.java,v 1.31 2007/03/15 02:09:15 jeremy Exp $
+ * @version $Id: CompactReader.java,v 1.32 2007/03/15 22:49:35 jeremy Exp $
  *
  */
 public class CompactReader
 {
     private ElementFactory factory;
     private JDOMExpressionFactory expr;
+    private Document doc;
     
     /**
      * Create a CompactReader using a DefaultElementFactory.
@@ -75,7 +76,7 @@
         // Add an EntityResolver that caches to ~/.cache
         builder.setEntityResolver(new CachingEntityResolver());
        
-        Document doc = builder.build(in);
+        doc = builder.build(in);
         
         Element lccdd = doc.getRootElement();
         Detector det = factory.createElement(Detector.class,lccdd,null);
@@ -270,6 +271,16 @@
     	}
     }
     
+    public void resetDocument()
+    {
+        doc = null;  
+    }
+    
+    public Document getDocument()
+    {
+        return doc;
+    }
+    
     /**
      * Setup scaling variables for compact description.
      * These are usable within subsequent <detector> elements. 
CVSspam 0.2.8