Print

Print


Commit in GeomConverter/src/org/lcsim/geometry/util on MAIN
BaseIDDecoder.java+95-121.3 -> 1.4
JM: consolidate stuff from CalorimeterIDDecoder and TrackerIDDecoder into BaseIDDecoder

GeomConverter/src/org/lcsim/geometry/util
BaseIDDecoder.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- BaseIDDecoder.java	3 Feb 2006 18:44:00 -0000	1.3
+++ BaseIDDecoder.java	7 Feb 2006 17:14:59 -0000	1.4
@@ -7,18 +7,26 @@
 
 package org.lcsim.geometry.util;
 
+import org.lcsim.geometry.ExpandedIdentifier;
+import org.lcsim.geometry.Subdetector;
+import org.lcsim.geometry.subdetector.BarrelEndcapFlag;
+
 /**
- *
+ * A basic implementation of org.lcsim.geometry.IDDecoder
+ * for others to extend.  It uses the org.lcsim.geometry.util
+ * classes for functionality.
+ * 
  * @author jeremym
  */
 public class BaseIDDecoder
         implements org.lcsim.geometry.IDDecoder
-{
-    
+{       
     protected org.lcsim.geometry.util.IDDecoder decoder;
     protected IDDescriptor descriptor;
     protected int[] values;
     protected boolean valid = false;
+    protected Subdetector detector;
+    protected int layerIndex;
     
     public BaseIDDecoder()
     {}
@@ -28,6 +36,31 @@
         setIDDescription(id);
     }
     
+    public org.lcsim.geometry.ExpandedIdentifier getExpandedIdentifier()
+    {
+        ExpandedIdentifier id = new org.lcsim.geometry.util.ExpandedIdentifier();
+        if (isValid())
+        {            
+            for (int i=0; i < descriptor.fieldCount(); i++)
+            {
+                String fieldname = descriptor.fieldName(i);
+                int value = decoder.getValue(fieldname);
+                id.put(fieldname, value);
+            }
+            assert(id.fields().size() == decoder.getFieldCount());
+        }
+        else {
+            throw new RuntimeException("Failed to make IDExpanded because id is not set in decoder.");
+        }
+        return id;
+    }
+    
+    public org.lcsim.geometry.ExpandedIdentifier getExpandedIdentifier(long id)
+    {
+        setID(id);
+        return getExpandedIdentifier();
+    }
+    
     public double getX()
     {
         return 0;
@@ -42,12 +75,7 @@
     {
         return 0;
     }
-    
-    public int getLayer()
-    {
-        return -1;
-    }
-    
+        
     public double getPhi()
     {
         return 0;
@@ -67,46 +95,55 @@
     {
         decoder.setID(id);
         decoder.getValues(values);
-        valid = true;
+        valid = true;        
     }
     
+    // FIXME: dup of util.IDDecoder method
     public int getValue(String field)
     {
         return decoder.getValue(field);
     }
     
+    // FIXME: dup of util.IDDecoder method
     public int getValue(int index)
     {
         return decoder.getValue(index);
     }
     
+    // FIXME: dup of util.IDDecoder method
     public String getFieldName(int index)
     {
         return decoder.getFieldName(index);
     }
     
+    // FIXME: dup of util.IDDecoder method
     public int getFieldIndex(String name)
     {
         return decoder.getFieldIndex(name);
     }
     
+    // FIXME: dup of util.IDDecoder method
     public int getFieldCount()
     {
         return values.length;
     }
     
     public void setIDDescription(IDDescriptor id)
-    {
+    {        
         descriptor = id;
         decoder = new org.lcsim.geometry.util.IDDecoder(id);
         values = new int[id.fieldCount()];
+        
+        // FIXME: doesn't belong here
+        setLayerIndex(id);
     }
-    
+        
     public IDDescriptor getIDDescription()
     {
         return descriptor;
     }
     
+    // FIXME: dup of util.IDDecoder method
     public String toString()
     {
         return decoder == null ? "NoDecoder" : decoder.toString();
@@ -116,4 +153,50 @@
     {
         return valid;
     }
+
+    public BarrelEndcapFlag getBarrelEndcapFlag()
+    {
+        return BarrelEndcapFlag.createBarrelEndcapFlag(getValue("barrel"));
+    }
+
+//    public int getSystemID()
+//    {
+//        return getValue("system");
+//    }        
+    
+    public void setSubdetector(Subdetector d)
+    {
+        detector = d;
+    }
+    
+    public Subdetector getSubdetector()
+    {
+        return detector;
+    }
+    
+    private void setLayerIndex(IDDescriptor id)
+    {
+        layerIndex = id.indexOf("layer");
+    }
+    
+    public int getLayer()
+    {
+        return values[layerIndex];
+    }
+
+    public long[] getNeighbourIDs(int deltaLayer, int deltaTheta, int deltaPhi)
+    {
+        long[] dummyNeighbours = {0, 0, 0};
+        return dummyNeighbours;
+    }
+    
+    public boolean supportsNeighbours()
+    {
+        return false;
+    }
+    
+    public long[] getNeighbourIDs()
+    {
+        return getNeighbourIDs(1,1,1);
+    }    
 }
\ No newline at end of file
CVSspam 0.2.8