Commit in GeomConverter/src/org/lcsim/geometry/segmentation on MAIN
EcalBarrelCartesianGridXY.java+34-371.1 -> 1.2
RegularNgonCartesianGridXY.java+46-441.1 -> 1.2
RegularNgonCartesianGridXZ.java+30-261.1 -> 1.2
+110-107
3 modified files
Bug fixes + faster

GeomConverter/src/org/lcsim/geometry/segmentation
EcalBarrelCartesianGridXY.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- EcalBarrelCartesianGridXY.java	18 Nov 2009 12:48:18 -0000	1.1
+++ EcalBarrelCartesianGridXY.java	20 Nov 2009 18:04:41 -0000	1.2
@@ -14,6 +14,8 @@
 import org.lcsim.detector.identifier.Identifier;
 import org.lcsim.detector.solids.Box;
 import org.lcsim.geometry.util.IDDescriptor;
+import org.lcsim.geometry.util.BaseIDDecoder;
+import org.lcsim.geometry.util.IDEncoder;
 
 /**
  * XY Cartesian grid segmentation for overlapping staves.
@@ -78,29 +80,24 @@
 	{
 		if (this.getDecoder().getID() == 0)
 			throw new RuntimeException("No current ID is set.");
+        IDEncoder gnEncoder = new IDEncoder(descriptor);
+        BaseIDDecoder gnDecoder = new BaseIDDecoder(descriptor);
+        gnEncoder.setValues(values);
+        gnDecoder.setID(gnEncoder.getID());
 
-		// Get the IdentifierHelper.
-		IIdentifierHelper helper = detector.getDetectorElement().getIdentifierHelper();
-
-		// Current packed id.
-		IIdentifier currId = new Identifier(this.getDecoder().getID());
-
-        // Create an ExpandedIdentifier for the current id.
-		IExpandedIdentifier thisId = helper.unpack(currId);
 // Check if we need initialization
         if(validXplusP == null)
         {
-            initializeMappings(this.getNumberOfLayers());
+            initializeMappings();
         }
 		// Set values for current id.
-		int currLayer = helper.getValue(currId, layerIndex);
-		int currX = helper.getValue(currId, xIndex);
-		int currY = helper.getValue(currId, yIndex);
-		int currModule = helper.getValue(currId, moduleIndex);
-		// Create a new ExpandedIdenfier from the base Id.
-		ExpandedIdentifier neighborId = new ExpandedIdentifier(thisId);
+		int currLayer = gnDecoder.getValue(layerIndex);
+		int currX = gnDecoder.getValue(xIndex);
+		int currY = gnDecoder.getValue(yIndex);
+		int currModule = gnDecoder.getValue(moduleIndex);
+
         // Find the neighbors within the current module
-        List<Long> nl = getNeighbourIDs(layerRange, xRange, yRange, helper, neighborId, currLayer, currX, currY);
+        List<Long> nl = getNeighbourIDs(layerRange, xRange, yRange, gnEncoder, currLayer, currX, currY);
         // Check for border problems
         boolean bp1 = false;
         boolean bp2 = false;
@@ -161,15 +158,15 @@
             }
             // Set the module
             int neighborModule = (currModule +1)%nmodules;
-			neighborId.setValue(moduleIndex, neighborModule);
+			gnEncoder.setValue(moduleIndex, neighborModule);
             // Loop over the layer range
             for(int neighborLayer = minl;neighborLayer<maxl;neighborLayer++)
             {
-				neighborId.setValue(layerIndex, neighborLayer);
+				gnEncoder.setValue(layerIndex, neighborLayer);
                 // Ugly, need to set the slice bin
                 int iSlice = 2;
                 if(neighborLayer == 0)iSlice = 0;
-				neighborId.setValue(sliceIndex, iSlice);
+				gnEncoder.setValue(sliceIndex, iSlice);
                 // In this module's coordinate system, calculate the
                 // intersection of y=yc(layer) with the box to find the
                 // X coordinate range inside the box.
@@ -183,15 +180,15 @@
                 // Loop over X bins
                 for(int neighborX=xbmin;neighborX <= xbmax;neighborX++)
                 {
-                    neighborId.setValue(xIndex, neighborX);
+                    gnEncoder.setValue(xIndex, neighborX);
                     // Loop over the Z range
                     for (int iy=-yRange; iy<=yRange; iy++)
                     {
                         // Compute y value.
                         int neighborY = currY + iy;
-                        neighborId.setValue(yIndex, neighborY);
+                        gnEncoder.setValue(yIndex, neighborY);
                         // Add the neighbor
-                        nl.add(helper.pack(neighborId).getValue());
+                        nl.add(gnEncoder.getID());
                     }
                 }
             }
@@ -207,7 +204,7 @@
         // To get here we have overlap with module m-1. Add the
         // neighbors in module m-1.
         int neighborModule = (nmodules+currModule -1)%nmodules;
-        neighborId.setValue(moduleIndex, neighborModule);
+        gnEncoder.setValue(moduleIndex, neighborModule);
         double ycmax = 0.;
         double ycmin = 0.;
         // The layer separation depends on where we are
@@ -247,10 +244,10 @@
         // Loop over layer range
         for(int neighborLayer = minl;neighborLayer<maxl;neighborLayer++)
         {
-            neighborId.setValue(layerIndex, neighborLayer);
+            gnEncoder.setValue(layerIndex, neighborLayer);
             int iSlice = 2;
             if(neighborLayer == 0)iSlice = 0;
-            neighborId.setValue(sliceIndex, iSlice);
+            gnEncoder.setValue(sliceIndex, iSlice);
             // Find intersection of y=yc[layer] with box to determine
             // X range
             double xpmax = Math.min(xcmax*secth + yc[neighborLayer]*tanth,
@@ -263,13 +260,13 @@
             // Loop and add neighbors
             for(int neighborX=xbmin;neighborX <= xbmax;neighborX++)
             {
-                neighborId.setValue(xIndex, neighborX);
+                gnEncoder.setValue(xIndex, neighborX);
                 for(int neighborY=Math.max(validZminus,currY-yRange);
                     neighborY<=Math.min(validZplus,currY+yRange);
                     neighborY++)
                 {
-                    neighborId.setValue(yIndex, neighborY);
-                    nl.add(helper.pack(neighborId).getValue());
+                    gnEncoder.setValue(yIndex, neighborY);
+                    nl.add(gnEncoder.getID());
                 }
             }
         }
@@ -282,7 +279,7 @@
         }
         return result;
     }
-    protected List<Long> getNeighbourIDs(int layerRange, int xRange, int yRange, IIdentifierHelper helper, ExpandedIdentifier neighborId, int currLayer, int currX, int currY)
+    protected List<Long> getNeighbourIDs(int layerRange, int xRange, int yRange, IDEncoder gnEncoder, int currLayer, int currX, int currY)
     {
         // Find neighbors within the currect module
         List<Long> rl = new ArrayList<Long>();
@@ -290,21 +287,21 @@
             neighborLayer<=Math.min(nlayers-1,currLayer+layerRange);
             neighborLayer++)
         {
-			neighborId.setValue(layerIndex, neighborLayer);
+			gnEncoder.setValue(layerIndex, neighborLayer);
             int iSlice = 2;
             if(neighborLayer == 0)iSlice = 0;
-			neighborId.setValue(sliceIndex, iSlice);
+			gnEncoder.setValue(sliceIndex, iSlice);
             for(int neighborX=Math.max(validXminusG[neighborLayer],currX-xRange);
                 neighborX<=Math.min(validXplusG[neighborLayer],currX+xRange);
                 neighborX++)
             {
-                neighborId.setValue(xIndex, neighborX);
+                gnEncoder.setValue(xIndex, neighborX);
                 for(int neighborY=Math.max(validZminus,currY-yRange);
                     neighborY<=Math.min(validZplus,currY+yRange);
                     neighborY++)
                 {
-                    neighborId.setValue(yIndex, neighborY);
-                    rl.add(helper.pack(neighborId).getValue());
+                    gnEncoder.setValue(yIndex, neighborY);
+                    if( this.getDecoder().getID()!= gnEncoder.getID())rl.add(gnEncoder.getID());
                 }
             }
         }
@@ -320,12 +317,12 @@
 		sliceIndex = id.indexOf("slice");
 	}
 
-    protected void initializeMappings(int nl)
+    protected void initializeMappings()
     {
         // Initialize all the needed parameters for the neighbor
         // finding across borders
 		// Get number of layers.
-		nlayers = nl;
+		nlayers = this.getNumberOfLayers();
         // The valid X bins vary by layer
         validXplusP = new int[this.getNumberOfLayers()];
         validXminusP = new int[this.getNumberOfLayers()];
@@ -407,7 +404,7 @@
     {
         if(validXplusP == null)
         {
-            initializeMappings(this.getNumberOfLayers());
+            initializeMappings();
         }
 // Get the helper and identifiers needed to manipulate the id
 		IIdentifierHelper helper = detector.getDetectorElement().getIdentifierHelper();

GeomConverter/src/org/lcsim/geometry/segmentation
RegularNgonCartesianGridXY.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- RegularNgonCartesianGridXY.java	18 Nov 2009 12:48:18 -0000	1.1
+++ RegularNgonCartesianGridXY.java	20 Nov 2009 18:04:41 -0000	1.2
@@ -18,6 +18,8 @@
 import org.lcsim.detector.solids.Box;
 import org.lcsim.detector.solids.Inside;
 import org.lcsim.geometry.util.IDDescriptor;
+import org.lcsim.geometry.util.BaseIDDecoder;
+import org.lcsim.geometry.util.IDEncoder;
 
 /**
  * Extend XY Cartesian grid segmentation for neighboring across
@@ -65,32 +67,31 @@
 	{
 		if (this.getDecoder().getID() == 0)
 			throw new RuntimeException("No current ID is set.");
-
-		// Get the IdentifierHelper.
-		IIdentifierHelper helper = detector.getDetectorElement().getIdentifierHelper();
+        IDEncoder gnEncoder = new IDEncoder(descriptor);
+        BaseIDDecoder gnDecoder = new BaseIDDecoder(descriptor);
+        gnEncoder.setValues(values);
+        gnDecoder.setID(gnEncoder.getID());
+        IDEncoder dupEncoder = new IDEncoder(descriptor);
+        BaseIDDecoder dupDecoder = new BaseIDDecoder(descriptor);
+        dupEncoder.setValues(values);
+        dupDecoder.setID(dupEncoder.getID());
 
 		// Get number of layers.
 		int nlayers = this.getNumberOfLayers();
 
-		// Current packed id.
-		IIdentifier currId = new Identifier(this.getDecoder().getID());
-		// Create an ExpandedIdentifier for the current id.
-		IExpandedIdentifier thisId = helper.unpack(currId);
+		// Set values for current id.
+		int currLayer = values[layerIndex];
+		int currX = gnDecoder.getValue(xIndex);
+		int currY = gnDecoder.getValue(yIndex);
+        int currModule = gnDecoder.getValue(moduleIndex);
+
         // Initialize the border arrays the first time in
         if (nvalidx == null)
         {
-            initializeBorders(thisId);
+            initializeBorders();
         }
-		// Set values for current id.
-		int currLayer = helper.getValue(currId, layerIndex);
-		int currX = helper.getValue(currId, xIndex);
-		int currY = helper.getValue(currId, yIndex);
-		int currModule = helper.getValue(currId, moduleIndex);
 		// Create return array.
 		List<Long> neighbors = new ArrayList<Long>();
-		// Create a new ExpandedIdenfier from the base Id.
-		ExpandedIdentifier neighborId = new ExpandedIdentifier(thisId);
-		ExpandedIdentifier dupId = new ExpandedIdentifier(thisId);
 
 		// Loop over layer range.
 		for (int ilayer=-layerRange; ilayer<=layerRange; ilayer++)
@@ -100,7 +101,7 @@
 
 			if (neighborLayer >= 0 && neighborLayer < nlayers)
 			{
-				neighborId.setValue(layerIndex, neighborLayer);
+				gnEncoder.setValue(layerIndex, neighborLayer);
                 // Loop over X range.
                 for (int ix=-xRange; ix<=xRange; ix++)
                 {
@@ -146,25 +147,25 @@
                             if(borderCellIsDuplicate[neighborLayer])neighborX++;
                         }
                     }
-					neighborId.setValue(xIndex, neighborX);
+					gnEncoder.setValue(xIndex, neighborX);
+                    gnEncoder.setValue(moduleIndex, neighborModule);
                     // Loop over Y range.
                     for (int iy=-yRange; iy<=yRange; iy++)
                     {
 						// Compute y value.
 						int neighborY = currY + iy;
 						// Set the neighbor fields.
-						neighborId.setValue(yIndex, neighborY);
-                        if(neighborModule != currModule)neighborId.setValue(moduleIndex, neighborModule);
+						gnEncoder.setValue(yIndex, neighborY);
 						// Add the neighbor id to the return array.
-						neighbors.add(helper.pack(neighborId).getValue());
+						if( this.getDecoder().getID()!= gnEncoder.getID())neighbors.add(gnEncoder.getID());
                         // If we have a duplicate cell, add it
                         if(dup)
                         {
-                            dupId.setValue(yIndex, neighborY);
-                            dupId.setValue(xIndex, dupX);
-                            dupId.setValue(layerIndex, neighborLayer);
-                            dupId.setValue(moduleIndex, dupModule);
-                            neighbors.add(helper.pack(dupId).getValue());
+                            dupEncoder.setValue(yIndex, neighborY);
+                            dupEncoder.setValue(xIndex, dupX);
+                            dupEncoder.setValue(layerIndex, neighborLayer);
+                            dupEncoder.setValue(moduleIndex, dupModule);
+                            neighbors.add(dupEncoder.getID());
                         }
 					}
 				}
@@ -180,36 +181,37 @@
 		}
 		return result;
 	}
-    protected void initializeBorders(IExpandedIdentifier thisId)
+    protected void initializeBorders()
     {
+		IIdentifierHelper helper = detector.getDetectorElement().getIdentifierHelper();
+        // Current packed id.
+        IIdentifier currId = new Identifier(this.getDecoder().getID());
+        // Create an ExpandedIdentifier for the current id.
+        IExpandedIdentifier thisId = helper.unpack(currId);
         // nvalidx is the number of valid xbins in the elements half
         // length per layer.
         nvalidx = new int[this.getNumberOfLayers()];
         // borderCellIsDuplicate - true if we treat the partial cell\
         // on each side of the boundary as a single cell
         borderCellIsDuplicate = new boolean[this.getNumberOfLayers()];
-		IIdentifierHelper helper = detector.getDetectorElement().getIdentifierHelper();
         ExpandedIdentifier testId = new ExpandedIdentifier(thisId);
+        testId.setValue(moduleIndex,0);
+        long save = this.getDecoder().getID();
         for(int layer=0;layer<this.getNumberOfLayers();layer++)
         {
 			testId.setValue(layerIndex, layer);
-            IIdentifier geomId = makeGeometryIdentifier(helper.pack(testId).getValue());
-            IDetectorElementContainer deSrch = getSubdetector().getDetectorElement().findDetectorElement(geomId);
-            IDetectorElement de = deSrch.get(0);
-            if (de.getGeometry().getLogicalVolume().getSolid() instanceof Box)
-            {
-                Box sensorBox = (Box)de.getGeometry().getLogicalVolume().getSolid();
-                double xhl = sensorBox.getXHalfLength();
-                nvalidx[layer] = (int)(xhl/gridSizeX) + 1;
-                double bcw = (nvalidx[layer]*gridSizeX - xhl)/gridSizeX;
-                borderCellIsDuplicate[layer] = false;
-                if(bcw < .5)borderCellIsDuplicate[layer] = true;
-            }
-            else
-            {
-                throw new RuntimeException("Don't know how to bounds check solid " + de.getGeometry().getLogicalVolume().getSolid().getName() + ".");
-            }
+            this.getDecoder().setID(helper.pack(testId).getValue());
+            this.computeGlobalPosition();
+            double yc = this.globalPosition[1];
+            double xhl = yc*Math.tan(Math.PI/nmodules);
+            nvalidx[layer] = (int)(xhl/gridSizeX) + 1;
+            double bcw = (nvalidx[layer]*gridSizeX - xhl)/gridSizeX;
+            borderCellIsDuplicate[layer] = false;
+            if(bcw < .5)borderCellIsDuplicate[layer] = true;
         }
+// Put back the cellID
+        this.getDecoder().setID(save);
+        this.computeGlobalPosition();
     }
 	public void setupGeomFields(IDDescriptor id)
 	{

GeomConverter/src/org/lcsim/geometry/segmentation
RegularNgonCartesianGridXZ.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- RegularNgonCartesianGridXZ.java	18 Nov 2009 12:48:18 -0000	1.1
+++ RegularNgonCartesianGridXZ.java	20 Nov 2009 18:04:41 -0000	1.2
@@ -14,6 +14,8 @@
 import org.lcsim.detector.identifier.Identifier;
 import org.lcsim.detector.solids.Trd;
 import org.lcsim.geometry.util.IDDescriptor;
+import org.lcsim.geometry.util.BaseIDDecoder;
+import org.lcsim.geometry.util.IDEncoder;
 
 /**
  * XZ Cartesian grid segmentation. 
@@ -68,32 +70,30 @@
 	{
 		if (this.getDecoder().getID() == 0)
 			throw new RuntimeException("No current ID is set.");
-
-		// Get the IdentifierHelper.
-		IIdentifierHelper helper = detector.getDetectorElement().getIdentifierHelper();
+        IDEncoder gnEncoder = new IDEncoder(descriptor);
+        BaseIDDecoder gnDecoder = new BaseIDDecoder(descriptor);
+        gnEncoder.setValues(values);
+        gnDecoder.setID(gnEncoder.getID());
+        IDEncoder dupEncoder = new IDEncoder(descriptor);
+        BaseIDDecoder dupDecoder = new BaseIDDecoder(descriptor);
+        dupEncoder.setValues(values);
+        dupDecoder.setID(dupEncoder.getID());
 
 		// Get number of layers.
 		int nlayers = this.getNumberOfLayers();
 
-		// Current packed id.
-		IIdentifier currId = new Identifier(this.getDecoder().getID());
-		// Create an ExpandedIdentifier for the current id.
-		IExpandedIdentifier thisId = helper.unpack(currId);
         // Initialize the border arrays the first time in
         if (nvalidx == null)
         {
-            initializeBorders(thisId);
+            initializeBorders();
         }
 		// Set values for current id.
-		int currLayer = helper.getValue(currId, layerIndex);
-		int currX = helper.getValue(currId, xIndex);
-		int currZ = helper.getValue(currId, zIndex);
-		int currModule = helper.getValue(currId, moduleIndex);
+		int currLayer = gnDecoder.getValue(layerIndex);
+		int currX = gnDecoder.getValue(xIndex);
+		int currZ = gnDecoder.getValue(zIndex);
+		int currModule = gnDecoder.getValue(moduleIndex);
 		// Create return array.
 		List<Long> neighbors = new ArrayList<Long>();
-        // Create a new ExpandedIdenfier from the base Id.
-        ExpandedIdentifier neighborId = new ExpandedIdentifier(thisId);
-        ExpandedIdentifier dupId = new ExpandedIdentifier(thisId);
 
         // Loop over Z range.
         for (int iz=-zRange; iz<=zRange; iz++)
@@ -102,7 +102,7 @@
             int neighborZ = currZ + iz;
             if(neighborZ >= zbinmin && neighborZ <= zbinmax)
             {
-                neighborId.setValue(zIndex, neighborZ);
+                gnEncoder.setValue(zIndex, neighborZ);
                 int Zindex = neighborZ + nzbins/2;
                 // Loop over X range.
                 for (int ix=-xRange; ix<=xRange; ix++)
@@ -149,7 +149,8 @@
                             if(borderCellIsDuplicate[Zindex])neighborX++;
                         }
                     }
-                    neighborId.setValue(xIndex, neighborX);
+                    gnEncoder.setValue(xIndex, neighborX);
+                    gnEncoder.setValue(moduleIndex, neighborModule);
                     // Loop over layer range.
                     for (int ilayer=-layerRange; ilayer<=layerRange; ilayer++)
                     {
@@ -160,18 +161,17 @@
                         {
 
                             // Set the neighbor fields.
-                            neighborId.setValue(layerIndex, neighborLayer);
-                            if(neighborModule != currModule)neighborId.setValue(moduleIndex, neighborModule);
+                            gnEncoder.setValue(layerIndex, neighborLayer);
                             // Add the neighbor id to the return array.
-                            neighbors.add(helper.pack(neighborId).getValue());
+                            if( this.getDecoder().getID()!= gnEncoder.getID())neighbors.add(gnEncoder.getID());
                             // If we have a duplicate cell, add it
                             if(dup)
                             {
-                                dupId.setValue(zIndex, neighborZ);
-                                dupId.setValue(xIndex, dupX);
-                                dupId.setValue(layerIndex, neighborLayer);
-                                dupId.setValue(moduleIndex, dupModule);
-                                neighbors.add(helper.pack(dupId).getValue());
+                                dupEncoder.setValue(zIndex, neighborZ);
+                                dupEncoder.setValue(xIndex, dupX);
+                                dupEncoder.setValue(layerIndex, neighborLayer);
+                                dupEncoder.setValue(moduleIndex, dupModule);
+                                neighbors.add(dupEncoder.getID());
                             }
                         }
 					}
@@ -188,9 +188,13 @@
 		}
 		return result;
     }
-    protected void initializeBorders(IExpandedIdentifier thisId)
+    protected void initializeBorders()
     {
 		IIdentifierHelper helper = detector.getDetectorElement().getIdentifierHelper();
+		// Current packed id.
+		IIdentifier currId = new Identifier(this.getDecoder().getID());
+		// Create an ExpandedIdentifier for the current id.
+		IExpandedIdentifier thisId = helper.unpack(currId);
         IIdentifier id = new Identifier(this.getDecoder().getID());
         ExpandedIdentifier testId = new ExpandedIdentifier(thisId);
         int barrelVal = helper.getValue(id, barrelIndex);
CVSspam 0.2.8