GeomConverter/src/org/lcsim/detector
diff -N PhysicalVolumeNavigator.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ PhysicalVolumeNavigator.java 3 Mar 2007 02:24:51 -0000 1.1
@@ -0,0 +1,67 @@
+package org.lcsim.detector;
+
+public class PhysicalVolumeNavigator
+implements IPhysicalVolumeNavigator
+{
+ private IPhysicalVolume pvTop;
+
+ public PhysicalVolumeNavigator(IPhysicalVolume pvTop)
+ {
+ if ( pvTop == null )
+ {
+ throw new IllegalArgumentException("PhysicalVolumeNavigator cannot be setup with a null PhysicalVolume!");
+ }
+ setTopPhysicalVolume(pvTop);
+ }
+
+ private String[] splitPath(String path)
+ {
+ // Eat the first slash.
+ if (path.charAt(0) == '/')
+ {
+ path = path.substring(1);
+ }
+
+ // Split on remaining slashes.
+ return path.split("/");
+ }
+
+ public IPhysicalVolumePath getPath(String path)
+ {
+ String[] names = splitPath(path);
+ IPhysicalVolumePath physvols = new PhysicalVolumePath();
+ IPhysicalVolume pv = getTopPhysicalVolume();
+ for (String name : names)
+ {
+ //System.out.println("looking for physvol = " + name);
+
+ PhysicalVolumeContainer pvSearch =
+ pv.getLogicalVolume().getDaughters().findByName(name);
+ if (pvSearch.size() > 1)
+ {
+ throw new RuntimeException("Got multiple matches on name <"+name+"> in mom <"+pv.getName() + ">.");
+ }
+ else if (pvSearch.size() == 0)
+ {
+ throw new RuntimeException("Path component <"+name+"> was not found!");
+ }
+ else {
+ IPhysicalVolume pvFound = pvSearch.get(0);
+ //System.out.println("found match = " + pvFound.getName());
+ physvols.add(pvFound);
+ pv = pvSearch.get(0);
+ }
+ }
+ return physvols;
+ }
+
+ public IPhysicalVolume getTopPhysicalVolume()
+ {
+ return pvTop;
+ }
+
+ public void setTopPhysicalVolume(IPhysicalVolume physvol)
+ {
+ pvTop = physvol;
+ }
+}
GeomConverter/src/org/lcsim/detector
diff -N PhysicalVolumePath.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ PhysicalVolumePath.java 3 Mar 2007 02:24:51 -0000 1.1
@@ -0,0 +1,18 @@
+package org.lcsim.detector;
+
+import java.util.ArrayList;
+
+public class PhysicalVolumePath
+extends ArrayList<IPhysicalVolume>
+implements IPhysicalVolumePath
+{
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+ for (IPhysicalVolume physvol : this)
+ {
+ sb.append("/"+physvol.getName());
+ }
+ return sb.toString();
+ }
+}
\ No newline at end of file
GeomConverter/src/org/lcsim/detector
diff -u -r1.1 -r1.2
--- DetectorTestUtil.java 3 Mar 2007 01:19:38 -0000 1.1
+++ DetectorTestUtil.java 3 Mar 2007 02:24:51 -0000 1.2
@@ -1,6 +1,8 @@
package org.lcsim.detector;
+import static org.lcsim.units.clhep.SystemOfUnits.cm;
import static org.lcsim.units.clhep.SystemOfUnits.m;
+import hep.physics.vec.BasicHep3Vector;
import org.lcsim.detector.material.IMaterial;
import org.lcsim.detector.material.MaterialElement;
@@ -13,12 +15,13 @@
public static IPhysicalVolume createTestSetup()
{
IPhysicalVolume world = createWorld();
- createBox(world);
+ createTestDetector(world);
return world;
}
- public static final void createBox(IPhysicalVolume mom)
+ public static final void createTestDetector(IPhysicalVolume mom)
{
+ // Simple box.
Box box = new Box("test_box",1.0*m,1.0*m,1.0*m);
LogicalVolume lvTest = new LogicalVolume("lvTest",box,dummymat);
new PhysicalVolume(
@@ -27,6 +30,17 @@
lvTest,
mom.getLogicalVolume(),
1);
+
+ // Box daughter volume.
+ Box box2 = new Box("test_box2",10.0*cm,10.0*cm,10.0*cm);
+ LogicalVolume lvTest2 = new LogicalVolume("lvTest2",box2,dummymat);
+ new PhysicalVolume(
+ new CoordinateTransformation3D(
+ new BasicHep3Vector(1.0,0.0,0.0)),
+ "test2",
+ lvTest2,
+ lvTest,
+ 1);
}
public static final IPhysicalVolume createWorld()
GeomConverter/src/org/lcsim/detector
diff -u -r1.4 -r1.5
--- ILogicalVolume.java 3 Mar 2007 01:19:38 -0000 1.4
+++ ILogicalVolume.java 3 Mar 2007 02:24:51 -0000 1.5
@@ -21,6 +21,7 @@
public ISolid getSolid();
public IMaterial getMaterial();
public IPhysicalVolumeContainer getDaughters();
+ public int getNumberOfDaughters();
public void addDaughter(IPhysicalVolume physvol);
public IPhysicalVolume getDaughter(int i);
public boolean isDaughter(IPhysicalVolume physvol);
GeomConverter/src/org/lcsim/detector
diff -u -r1.1 -r1.2
--- IPhysicalVolumeNavigator.java 3 Mar 2007 01:19:38 -0000 1.1
+++ IPhysicalVolumeNavigator.java 3 Mar 2007 02:24:51 -0000 1.2
@@ -2,9 +2,10 @@
public interface IPhysicalVolumeNavigator
{
+ public IPhysicalVolume getTopPhysicalVolume();
public void setTopPhysicalVolume(IPhysicalVolume physvol);
- public IPhysicalVolumePath getPath(IPhysicalVolume physvol);
public IPhysicalVolumePath getPath(String path);
+ //public IPhysicalVolumePath getPath(IPhysicalVolume physvol);
//public IPhysicalVolumePath getPath(String[] path);
//public IPhysicalVolumePath getPath(int[] copyNums);
//public ICoordinateTransformation3D getTransformation(IPhysicalVolume physvol);