Print

Print


Commit in GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util on MAIN
Author.java+9-11.2 -> 1.3
LCDD.java+63-11.16 -> 1.17
LCDDFactory.java+151-1431.1 -> 1.2
Position.java+50-231.1 -> 1.2
Solid.java+271.1 -> 1.2
Trapezoid.java+251.1 -> 1.2
Volume.java+101.4 -> 1.5
+335-168
7 modified files
JM: Miscellaneous updates to LCDD util classes.

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
Author.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- Author.java	19 Jan 2006 01:57:38 -0000	1.2
+++ Author.java	21 Jan 2006 02:30:01 -0000	1.3
@@ -18,11 +18,19 @@
 
    public void setAuthorName(String name)
    {
+	  if ( name == null )
+	  {
+		  name = "UNKNOWN";
+	  }
       setAttribute("name",name);
    }
    
    public void setAuthorEmail(String email)
    {
-      setAttribute("email",email);
+	 if ( email == null )
+	 {
+		 email = "NONE";
+	 }
+	 setAttribute("email",email);
    }  
 }

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
LCDD.java 1.16 -> 1.17
diff -u -r1.16 -r1.17
--- LCDD.java	28 Oct 2005 00:34:22 -0000	1.16
+++ LCDD.java	21 Jan 2006 02:30:01 -0000	1.17
@@ -67,7 +67,7 @@
         worldSolid.setAttribute("x","world_x");
         worldSolid.setAttribute("y","world_y");
         worldSolid.setAttribute("z","world_z");
-        solids.addSolid(worldSolid);
+        solids.addSolid(worldSolid);        
         
         Volume worldVolume = new Volume("world_volume");
         worldVolume.setSolid(worldSolid);
@@ -124,6 +124,63 @@
         return (Solids) getChild("gdml").getChild("solids");
     }
     
+    public Solid getSolid(String name)
+    {
+    	Solid solid = null;
+    	for ( Object object : getSolids().getChildren() ) 
+    	{    		
+    		solid = (Solid) object;
+    		if ( solid != null )
+    		{
+    			if ( solid.getAttributeValue("name").compareTo(name) == 0 )
+    			{
+    				return solid;
+    			}
+    		}
+    	}
+    	return null;
+    }
+    
+    public void add(Constant constant)
+    {
+    	getDefine().addConstant(constant);
+    }
+    
+    public void add(Position position)
+    {
+    	getDefine().addPosition(position);
+    }
+    
+    public void add(Rotation rotation)
+    {
+    	getDefine().addRotation(rotation);
+    }
+    
+    public void add(Solid solid)
+    {
+    	getSolids().addSolid(solid);
+    }
+    
+    public void add(Volume volume)
+    {
+    	getStructure().addVolume(volume);
+    }
+    
+    public void add(Region region)
+    {
+        getChild("regions").addContent(region);
+    }    
+    
+    public void add(IDSpec spec)
+    {
+        getChild("iddict").addContent(spec);
+    }
+    
+    public void add(LimitSet limitset)
+    {
+        getChild("limits").addContent(limitset);
+    }
+    
     public Structure getStructure()
     {
         return (Structure) getChild("gdml").getChild("structure");
@@ -227,6 +284,11 @@
         getChild("regions").addContent(region);
     }
     
+    public Element getRegions()
+    {
+    	return getChild("regions");
+    }
+    
     public Region getRegion(String name)
     {
         Region region = null;

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
LCDDFactory.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- LCDDFactory.java	19 Jan 2006 01:57:02 -0000	1.1
+++ LCDDFactory.java	21 Jan 2006 02:30:01 -0000	1.2
@@ -1,44 +1,26 @@
 package org.lcsim.geometry.compact.converter.lcdd.util;
 
-import org.lcsim.geometry.compact.converter.lcdd.util.*;
 import java.util.List;
 
 /*
  * 
- * LCDD object factory.
+ * A collection of static utility methods for creating objects 
+ * in the org.lcsim.geometry.compact.converter.lcdd.util package.
  * 
  * @author jeremym
- * @version $Id: LCDDFactory.java,v 1.1 2006/01/19 01:57:02 jeremy Exp $
+ * @version $Id: LCDDFactory.java,v 1.2 2006/01/21 02:30:01 jeremy Exp $
  */
 public final class LCDDFactory
 {
-	private LCDD _lcdd;
-
-	boolean _autoAdd = false;
-
-	public void setLCDD(LCDD lcdd)
-	{
-		_lcdd = lcdd;
-	}
-
-	public void setAutoAdd(boolean autoAdd)
-	{
-		_autoAdd = autoAdd;
-	}
-
-	// top-level LCDD container element
-
-	public LCDD createLCDD()
+	/** Create the top-level LCDD container element. */
+	public static LCDD createLCDD()
 	{
 		LCDD lcdd = new LCDD();
 		return lcdd;
 	}
 
-	// header elements
-
-	public Detector createDetector(
-			String title,
-			String version,
+	/** Create the detector element for the header. */
+	public static Detector createDetector(String title, String version,
 			String url)
 	{
 		Detector det = new Detector();
@@ -48,9 +30,8 @@
 		return det;
 	}
 
-	public Author createAuthor(
-			String name,
-			String email)
+	/** Create the author element for the header. */
+	public static Author createAuthor(String name, String email)
 	{
 		Author author = new Author();
 		author.setName(name);
@@ -58,11 +39,9 @@
 		return author;
 	}
 
-	public Generator createGenerator(
-			String title,
-			String version,
-			String file,
-			long checksum)
+	/** Create the generator element for the header. */
+	public static Generator createGenerator(String title, String version,
+			String file, long checksum)
 	{
 		Generator generator = new Generator();
 		generator.setTitle(title);
@@ -72,14 +51,16 @@
 		return generator;
 	}
 
-	public Header createHeader(String comment)
+	/** Create the header element. */
+	public static Header createHeader(String comment)
 	{
 		Header header = new Header();
 		header.setComment(comment);
 		return header;
 	}
 
-	public Box createBox(String name, double x, double y, double z)
+	/** Create a box solid. */
+	public static Box createBox(String name, double x, double y, double z)
 	{
 		Box box = new Box(name);
 		box.setX(x);
@@ -88,8 +69,9 @@
 		return box;
 	}
 
-	public Tube createTube(String name, double rmin, double rmax, double z,
-			double deltaphi)
+	/** Create a tube solid. */
+	public static Tube createTube(String name, double rmin, double rmax,
+			double z, double deltaphi)
 	{
 		Tube tube = new Tube(name);
 		tube.setRMax(rmax);
@@ -99,13 +81,9 @@
 		return tube;
 	}
 
-	public Trapezoid createTrapezoid(
-			String name,
-			double x1,
-			double x2,
-			double y1,
-			double y2,
-			double z)
+	/** Create a trapezoid solid. */
+	public static Trapezoid createTrapezoid(String name, double x1, double x2,
+			double y1, double y2, double z)
 	{
 		Trapezoid trd = new Trapezoid(name);
 		trd.setX1(x1);
@@ -116,12 +94,9 @@
 		return trd;
 	}
 
-	public SubtractionSolid createSubtractionSolid(
-			String name,
-			Solid first,
-			Solid second,
-			Position pos,
-			Rotation rot)
+	/** Create a boolean solid using subtraction. */
+	public static SubtractionSolid createSubtractionSolid(String name,
+			Solid first, Solid second, Position pos, Rotation rot)
 	{
 		SubtractionSolid sub = new SubtractionSolid(name);
 		sub.setFirstSolid(first);
@@ -131,9 +106,42 @@
 		return sub;
 	}
 
-	// Volume
+	/** Create a polycone solid. */
+	public static Polycone createPolycone(String name, double startPhi,
+			double deltaPhi, List<ZPlane> zplanes)
+	{
+		Polycone polycone = new Polycone(name);
+		polycone.setStartPhi(startPhi);
+		polycone.setDeltaPhi(deltaPhi);
+		if (zplanes != null)
+		{
+			for (ZPlane zplane : zplanes)
+			{
+				polycone.addZPlane(zplane);
+			}
+		}
+		return polycone;
+	}
 
-	public Volume createVolume(String name, Material material, Solid solid)
+	/** Create a regular polyhedra solid. */
+	public static PolyhedraRegular createPolyhedraRegular(String name,
+			int nsides, double rmin, double rmax, double zlength)
+	{
+		PolyhedraRegular polyhedra = new PolyhedraRegular(name, nsides, rmin,
+				rmax, zlength);
+		return polyhedra;
+	}
+
+	/** Create a zplane for use by Polycone. */
+	public static ZPlane createZPlane(double rmin, double rmax, double z)
+	{
+		ZPlane zplane = new ZPlane(rmin, rmax, z);
+		return zplane;
+	}
+
+	/** Create a basic Volume. */
+	public static Volume createVolume(String name, Material material,
+			Solid solid)
 	{
 		Volume volume = new Volume(name);
 		volume.setMaterial(material);
@@ -141,15 +149,24 @@
 		return volume;
 	}
 
-	public Volume createVolume(String name, Material material, Solid solid,
-			SensitiveDetector sd, Region region, LimitSet limits,
+	/** Create a Volume with all parameters. */
+	public static Volume createVolume(String name, Material material,
+			Solid solid, SensitiveDetector sd, Region region, LimitSet limits,
 			List<PhysVol> pvs)
 	{
 		Volume volume = createVolume(name, material, solid);
 
 		volume.setSensitiveDetector(sd);
-		volume.setRegion(region);
-		volume.setRegion(region);
+		
+		if ( region != null )
+		{
+			volume.setRegion(region);
+		}
+		
+		if ( limits != null )
+		{
+			volume.setLimitSet(limits);
+		}
 
 		if (pvs != null)
 		{
@@ -162,19 +179,33 @@
 		return volume;
 	}
 
-	public Constant createConstant(String name, double value)
+	/** Create a Volume with all parameters, but copy the name from the Solid. */
+	public static Volume createVolume(Material material, Solid solid,
+			SensitiveDetector sd, Region region, LimitSet limits,
+			List<PhysVol> pvs)
+	{
+		Volume volume = createVolume(solid.getSolidName(), material, solid, sd,
+				region, limits, pvs);
+
+		return volume;
+	}
+
+	/** Create a named double constant. */
+	public static Constant createConstant(String name, double value)
 	{
 		Constant constant = new Constant(name, value);
 		return constant;
 	}
 
-	public Constant createConstant(String name, String value)
+	/** Create a named string constant. */
+	public static Constant createConstant(String name, String value)
 	{
 		Constant constant = new Constant(name, value);
 		return constant;
 	}
 
-	public IDField createIDField(String label, int start, int length,
+	/** Create an ID field. */
+	public static IDField createIDField(String label, int start, int length,
 			boolean signed)
 	{
 		IDField field = new IDField();
@@ -185,7 +216,9 @@
 		return field;
 	}
 
-	public IDSpec createIDSpec(String name, int length, List<IDField> fields)
+	/** Create an IDSpec. */
+	public static IDSpec createIDSpec(String name, int length,
+			List<IDField> fields)
 	{
 		IDSpec spec = new IDSpec(name);
 		spec.setLength(length);
@@ -199,11 +232,9 @@
 		return spec;
 	}
 
-	public Limit createLimit(
-			String name, 
-			String particles, 
-			double value,
-			String unit)
+	/** Create a single physics limit. */
+	public static Limit createLimit(String name, String particles,
+			double value, String unit)
 	{
 		Limit limit = new Limit(name);
 		limit.setParticles(particles);
@@ -212,7 +243,8 @@
 		return limit;
 	}
 
-	public LimitSet createLimitSet(String name, List<Limit> limits)
+	/** Create a set of physics limits. */
+	public static LimitSet createLimitSet(String name, List<Limit> limits)
 	{
 		LimitSet limitset = new LimitSet(name);
 		if (limits != null)
@@ -225,19 +257,30 @@
 		return limitset;
 	}
 
-	public Material createMaterial(String name)
+	/** Create a material. */
+	public static Material createMaterial(String name)
 	{
 		Material material = new Material(name);
 		return material;
 	}
 
-	public PhysVol createPhysVol(Volume volume, Position position,
-			Rotation rotation, List<PhysVolID> ids)
+	/** Create a physical volume (placement). */
+	public static PhysVol createPhysVol(Volume volume, Position position,
+			Rotation rotation)
 	{
 		PhysVol pv = new PhysVol();
 		pv.setVolume(volume);
 		pv.setPosition(position);
 		pv.setRotation(rotation);
+		return pv;
+	}
+	
+	/** Create a physical volume (placement) with a list of physical volume ids. */
+	public static PhysVol createPhysVol(Volume volume, Position position,
+			Rotation rotation, List<PhysVolID> ids)
+	{
+		PhysVol pv = createPhysVol(volume, position, rotation);
+		
 		if (ids != null)
 		{
 			for (PhysVolID id : ids)
@@ -248,37 +291,16 @@
 		return pv;
 	}
 
-	public Polycone createPolycone(String name, double startPhi,
-			double deltaPhi, List<ZPlane> zplanes)
-	{
-		Polycone polycone = new Polycone(name);
-		polycone.setStartPhi(startPhi);
-		polycone.setDeltaPhi(deltaPhi);
-		if (zplanes != null)
-		{
-			for (ZPlane zplane : zplanes)
-			{
-				polycone.addZPlane(zplane);
-			}
-		}
-		return polycone;
-	}
-
-	public PolyhedraRegular createPolyhedraRegular(String name, int nsides,
-			double rmin, double rmax, double zlength)
+	/** Create a physical volume identifier. */
+	public static PhysVolID createPhysVolID(String name, int value)
 	{
-		PolyhedraRegular polyhedra = new PolyhedraRegular(name, nsides, rmin,
-				rmax, zlength);
-		return polyhedra;
+		PhysVolID id = new PhysVolID(name, value);
+		return id;
 	}
 
-	public ZPlane createZPlane(double rmin, double rmax, double z)
-	{
-		ZPlane zplane = new ZPlane(rmin, rmax, z);
-		return zplane;
-	}
-
-	public Position createPosition(String name, double x, double y, double z)
+	/** Create an XYZ position. */
+	public static Position createPosition(String name, double x, double y,
+			double z)
 	{
 		Position position = new Position(name);
 		position.setX(x);
@@ -287,24 +309,24 @@
 		return position;
 	}
 
-	// detectors
-	
-	public Calorimeter createCalorimeter(String name, Segmentation seg)
+	/** Create a calorimeter-type sensitive detector. */
+	public static Calorimeter createCalorimeter(String name, Segmentation seg)
 	{
 		Calorimeter cal = new Calorimeter(name);
 		cal.setSegmentation(seg);
 		return cal;
 	}
-	
-	public Tracker createTracker(String name)
+
+	/** Create a tracker-type sensitive detector. */
+	public static Tracker createTracker(String name)
 	{
 		Tracker trk = new Tracker(name);
 		return trk;
 	}
 
-	// segmentations
-
-	public ProjectiveCylinder createProjectiveCylinder(int ntheta, int nphi)
+	/** Create a projective cylinder segmentation. */
+	public static ProjectiveCylinder createProjectiveCylinder(int ntheta,
+			int nphi)
 	{
 		ProjectiveCylinder seg = new ProjectiveCylinder();
 		seg.setNTheta(ntheta);
@@ -312,7 +334,8 @@
 		return seg;
 	}
 
-	public ProjectiveZPlane createProjectiveZPlane(int ntheta, int nphi)
+	/** Create a projective zplane segmentation. */
+	public static ProjectiveZPlane createProjectiveZPlane(int ntheta, int nphi)
 	{
 		ProjectiveZPlane seg = new ProjectiveZPlane();
 		seg.setNTheta(ntheta);
@@ -320,7 +343,8 @@
 		return seg;
 	}
 
-	public GridXYZ createGridXYZ(double x, double y, double z)
+	/** Create a Cartesian grid segmentation. */
+	public static GridXYZ createGridXYZ(double x, double y, double z)
 	{
 		GridXYZ seg = new GridXYZ();
 		seg.setGridSizeX(x);
@@ -329,8 +353,9 @@
 		return seg;
 	}
 
-	public NonprojectiveCylinder createNonprojectiveCylinder(double gridSizeZ,
-			double gridSizePhi)
+	/** Create a nonprojective cylinder segmentation. */
+	public static NonprojectiveCylinder createNonprojectiveCylinder(
+			double gridSizeZ, double gridSizePhi)
 	{
 		NonprojectiveCylinder seg = new NonprojectiveCylinder();
 		seg.setGridSizeZ(gridSizeZ);
@@ -338,13 +363,9 @@
 		return seg;
 	}
 
-	public Region createRegion(
-			String name, 
-			boolean storeSecondaries, 
-			double energyCut,
-			double rangeCut,
-			String eunit, 
-			String lunit)
+	/** Create a region. */
+	public static Region createRegion(String name, boolean storeSecondaries,
+			double energyCut, double rangeCut, String eunit, String lunit)
 	{
 		Region region = new Region(name);
 		region.setStoreSecondaries(storeSecondaries);
@@ -355,10 +376,8 @@
 		return region;
 	}
 
-	public Rotation createRotation(
-			String name,
-			double x,
-			double y,
+	/** Create a rotation with XYZ parameters. */
+	public static Rotation createRotation(String name, double x, double y,
 			double z)
 	{
 		Rotation rot = new Rotation(name);
@@ -368,33 +387,22 @@
 		return rot;
 	}
 
-	// mag field
-	
-	public Solenoid createSolenoid(
-			String name,
-			double BInner,
-			double BOuter,
-			double rInner,
-			double zMax)	
+	/** Create a solenoid field. */
+	public static Solenoid createSolenoid(String name, double BInner,
+			double BOuter, double rInner, double zMax)
 	{
-		Solenoid sol = new Solenoid(name);		
+		Solenoid sol = new Solenoid(name);
 		sol.setInnerField(BInner);
 		sol.setOuterField(BOuter);
 		sol.setInnerRadius(rInner);
 		sol.setZMax(zMax);
-		return sol;		
+		return sol;
 	}
-	
-	public RZFieldMap createRZFieldMap(
-			String name,
-			int numBinsR,
-			int numBinsZ,
-			double gridSizeR,
-			double gridSizeZ,
-			String lunit,
-			String funit,
-			List<RZBData> data
-			)
+
+	/** Create an RZB field map. */
+	public static RZFieldMap createRZFieldMap(String name, int numBinsR,
+			int numBinsZ, double gridSizeR, double gridSizeZ, String lunit,
+			String funit, List<RZBData> data)
 	{
 		RZFieldMap field = new RZFieldMap(name);
 		field.setNumBinsR(numBinsR);
@@ -403,9 +411,9 @@
 		field.setGridSizeZ(gridSizeZ);
 		field.setLengthUnit(lunit);
 		field.setFieldUnit(funit);
-		if ( data != null )
+		if (data != null)
 		{
-			for ( RZBData rzb : data )
+			for (RZBData rzb : data)
 			{
 				field.addRZBData(rzb);
 			}

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
Position.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- Position.java	28 Feb 2005 07:33:48 -0000	1.1
+++ Position.java	21 Jan 2006 02:30:01 -0000	1.2
@@ -1,31 +1,58 @@
 package org.lcsim.geometry.compact.converter.lcdd.util;
 
-
 /**
- *
+ * 
  * @author tonyj
  */
 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));
-   }
+	/** 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;
+	}
 }

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
Solid.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- Solid.java	28 Feb 2005 07:33:48 -0000	1.1
+++ Solid.java	21 Jan 2006 02:30:01 -0000	1.2
@@ -1,5 +1,7 @@
 package org.lcsim.geometry.compact.converter.lcdd.util;
 
+import org.jdom.Attribute;
+
 
 /**
  *
@@ -14,4 +16,29 @@
       super(type,name);
    }
    
+   public String getSolidName()
+   {
+	   return getAttributeValue("name");
+   }
+   
+   public double getDim(String name)
+   {
+	   Attribute attrib = getAttribute(name);
+	   double val = 0.0;
+	   
+	   if ( attrib == null )
+	   {
+		   throw new IllegalArgumentException("Solid " + getName() + " has no attribute called " + name);
+	   }
+	   
+	   try {
+		   val = attrib.getDoubleValue();
+	   }
+	   catch (Exception e)
+	   {
+		   throw new RuntimeException("Problem converting " + attrib.getValue() + " to double.");
+	   }
+	   
+	   return val;
+   }   
 }

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
Trapezoid.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- Trapezoid.java	25 Aug 2005 07:57:02 -0000	1.1
+++ Trapezoid.java	21 Jan 2006 02:30:01 -0000	1.2
@@ -10,6 +10,31 @@
       super("trd",name);
    }
    
+   public double x1()
+   {
+	   return getDim("x1");
+   }
+   
+   public double x2()
+   {
+	   return getDim("x2");
+   }
+   
+   public double y1()
+   {
+	   return getDim("y1");
+   }
+   
+   public double y2()
+   {
+	   return getDim("y2");
+   }
+   
+   public double z()
+   {
+	   return getDim("z");
+   }
+   
    public void setX1(double x1)
    {
        setAttribute("x1",String.valueOf(x1));

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
Volume.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- Volume.java	28 Oct 2005 00:34:22 -0000	1.4
+++ Volume.java	21 Jan 2006 02:30:01 -0000	1.5
@@ -50,4 +50,14 @@
         regionref.setAttribute("ref",region.getRefName());
         addContent(regionref);
     }
+    
+    public String getSolidRef()
+    {
+    	return getChild("solidref").getAttributeValue("ref");
+    }
+    
+    public String getVolumeName()
+    {
+    	return getAttributeValue("name");
+    }
 }
CVSspam 0.2.8