Print

Print


Commit in GeomConverter/src/org/lcsim/geometry/segmentation on MAIN
AbstractCartesianGrid.java+26-321.3 -> 1.4
Change encoding of neighbor IDs to recover factor of 10 loss in speed

GeomConverter/src/org/lcsim/geometry/segmentation
AbstractCartesianGrid.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- AbstractCartesianGrid.java	2 Nov 2009 19:35:14 -0000	1.3
+++ AbstractCartesianGrid.java	19 Nov 2009 18:10:57 -0000	1.4
@@ -14,6 +14,8 @@
 import org.lcsim.detector.identifier.IIdentifierHelper;
 import org.lcsim.detector.identifier.Identifier;
 import org.lcsim.geometry.util.IDDescriptor;
+import org.lcsim.geometry.util.BaseIDDecoder;
+import org.lcsim.geometry.util.IDEncoder;
 
 /**
  * Abstract base class for Cartesian grid segmentation types.
@@ -255,57 +257,49 @@
 	{
 		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());
 		
 		// Get number of layers.
 		int nlayers = this.getNumberOfLayers();
 		
-		// Current packed id.
-		IIdentifier currId = new Identifier(this.getDecoder().getID()); 
-		
 		// Set values for current id.
-		int currLayer = helper.getValue(currId, layerIndex);
-		int currU = helper.getValue(currId, uIndex);
-		int currV = helper.getValue(currId, vIndex);
+		int currLayer = values[layerIndex];
+		int currU = gnDecoder.getValue(uIndex);
+		int currV = gnDecoder.getValue(vIndex);
 		
-		// Create an ExpandedIdentifier for the current id.
-		IExpandedIdentifier thisId = helper.unpack(currId);
-				
 		// Create return array.
 		List<Long> neighbors = new ArrayList<Long>();
 		
 		// Loop over layer range.
 		for (int ilayer=-layerRange; ilayer<=layerRange; ilayer++)
 		{
-			// Loop over X range.
-			for (int iu=-uRange; iu<=uRange; iu++)
+			// Compute layer value.
+			int neighborLayer = currLayer + ilayer;
+
+			if (neighborLayer >= 0 && neighborLayer < nlayers)
 			{
-				// Loop over Y range.
-				for (int iv=-vRange; iv<=vRange; iv++)
-				{								
-					// Compute layer value.
-					int neighborLayer = currLayer + ilayer;
-					
-					if (neighborLayer >= 0 && neighborLayer < nlayers)
-					{						
-						// Compute x value.
-						int neighborU = currU + iu;
-						
+				gnEncoder.setValue(layerIndex, neighborLayer);
+                // Loop over X range.
+                for (int iu=-uRange; iu<=uRange; iu++)
+                {
+					// Compute x value.
+					int neighborU = currU + iu;
+					gnEncoder.setValue(uIndex, neighborU);
+
+                    // Loop over Y range.
+                    for (int iv=-vRange; iv<=vRange; iv++)
+                    {
 						// Compute y value.
 						int neighborV = currV + iv;
 						
-						// Create a new ExpandedIdenfier from the base Id.
-						ExpandedIdentifier neighborId = new ExpandedIdentifier(thisId);
-					
 						// Set the neighbor fields.
-						neighborId.setValue(layerIndex, neighborLayer);
-						neighborId.setValue(uIndex, neighborU);
-						neighborId.setValue(vIndex, neighborV);
+						gnEncoder.setValue(vIndex, neighborV);
 					
 						// Add the neighbor id to the return array.
-						neighbors.add(helper.pack(neighborId).getValue());					
+						neighbors.add(gnEncoder.getID());
 					}
 				}
 			}		
CVSspam 0.2.8