Commit in GeomConverter/src/org/lcsim/geometry/subdetector on MAIN
HPSEcal3.java+106-221.1 -> 1.2
support for remove crystals in compact xml

GeomConverter/src/org/lcsim/geometry/subdetector
HPSEcal3.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- HPSEcal3.java	1 Sep 2011 23:58:41 -0000	1.1
+++ HPSEcal3.java	8 Sep 2011 07:26:06 -0000	1.2
@@ -1,8 +1,10 @@
 package org.lcsim.geometry.subdetector;
 
+import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.jdom.Element;
@@ -17,7 +19,7 @@
  * 
  * @author Jeremy McCormick <[log in to unmask]>
  * @author Timothy Nelson <[log in to unmask]>
- * @version $Id: HPSEcal3.java,v 1.1 2011/09/01 23:58:41 jeremy Exp $
+ * @version $Id: HPSEcal3.java,v 1.2 2011/09/08 07:26:06 jeremy Exp $
  */
 public class HPSEcal3 extends AbstractSubdetector
 {
@@ -26,6 +28,7 @@
     private double beamgap;
     private double dface;
     private boolean oddX;
+    List<CrystalRange> removeCrystals = new ArrayList<CrystalRange>();
 
     public static class NeighborMap extends HashMap<Long,Set<Long>>
     {
@@ -69,7 +72,99 @@
         
         if (nx % 2 != 0)
             oddX = true;
-     }
+                       
+        // Setup range of indices to be skipped.
+        for (Object obj : layout.getChildren("remove"))
+        {
+            Element remove = (Element)obj;
+            try 
+            {
+                removeCrystals.add(new CrystalRange(remove));
+            }
+            catch (Exception x)
+            {
+                throw new RuntimeException(x);
+            }
+        }
+        
+        /*
+        <remove ixmin="2" ixmax="10" iymin="-1" iymax="1"/>
+        */
+    }
+    
+    private static class CrystalRange
+    {
+        int ixmin;
+        int ixmax;
+        int iymin;
+        int iymax;
+                                              
+        CrystalRange(Element elem) throws Exception
+        {
+            ixmin = ixmax = iymin = iymax = 0;
+                                    
+            if (elem.getAttribute("ixmin") != null)
+            {
+                ixmin = elem.getAttribute("ixmin").getIntValue();                
+            }
+            else               
+            {
+                throw new RuntimeException("Missing ixmin parameter.");
+            }
+            
+            if (elem.getAttribute("ixmax") != null)
+            {
+                ixmax = elem.getAttribute("ixmax").getIntValue();
+            }
+            else               
+            {
+                throw new RuntimeException("Missing ixmax parameter.");
+            }
+            
+            if (elem.getAttribute("iymin") != null)
+            {
+                iymin = elem.getAttribute("iymin").getIntValue();
+            }
+            else               
+            {
+                throw new RuntimeException("Missing ixmax parameter.");
+            }
+            
+            if (elem.getAttribute("iymax") != null)
+            {
+                iymax = elem.getAttribute("iymax").getIntValue();
+            }
+            else
+            {
+                throw new RuntimeException("Missing iymax parameter.");
+            }                                   
+        }
+    }
+    
+    private boolean isValidXY(int ix, int iy)
+    {
+        if (!isValidX(ix))
+            return false;
+        if (!isValidY(iy))
+            return false;
+        return checkRange(ix, iy, this.removeCrystals);
+    }
+    
+    private boolean checkRange(int ix, int iy, List<CrystalRange> ranges)
+    {
+        if (ranges.size() == 0)
+            return true;
+        for (CrystalRange range : ranges)
+        {
+            if ((ix >= range.ixmin && ix <= range.ixmax) 
+                    && ((iy >= range.iymin) && (iy <= range.iymax)))
+            {
+                return false;
+            }
+            
+        }
+        return true;
+    }
     
     public double distanceToFace()
     {
@@ -204,6 +299,11 @@
                     continue;
                 }
                 
+                // Check for valid neighbor.
+                // FIXME: Duplication of isValidX + isValidY.
+                if (!isValidXY(jx, jy))
+                    continue;
+                
                 neighbors.add(new XY(jx,jy));
             }
         }
@@ -321,28 +421,14 @@
             hnx /= 2;
         }
                 
-        //for (int side=-1; side <=1; side++)
-        //{            
-        //    if (side == 0) continue;            
-        //    vals[dec.getFieldIndex("side")] = side;
-            // Loop over y.
+        // Loop over y.
         for (int iy = -ny; iy <= ny; iy++)
-        {
-            if (!isValidY(iy))
-                continue;
-            
+        {            
             int loopx = (int)Math.floor(nx/2);
             // Loop over x.
             for (int ix = -loopx; ix <= loopx; ix++)
-            {                
-                // Loop for positive and negative x.
-                //for (int j=-1; j<=1; j++)
-                //{
-                //    if (j == 0)
-                //        continue;
-                
-                //System.out.println();
-                if (!isValidX(ix))
+            {                                
+                if (!isValidXY(ix, iy))
                     continue;
 
                 vals[idxx] = ix;
@@ -352,10 +438,8 @@
                 Set<Long> neighbors = getNeighbors(id);
                 
                 neighborMap.put(id, neighbors);
-                //}
             }
         }
-        //}
         
         return neighborMap;
     }    
CVSspam 0.2.8