Print

Print


Commit in GeomConverter/src/org/lcsim/geometry on MAIN
compact/SystemIDMap.java+47added 1.1
       /Detector.java+15-11.14 -> 1.15
util/BaseIDDecoder.java+15-61.5 -> 1.6
+77-7
1 added + 2 modified, total 3 files
JM: support lookup of Subdetectors by system id

GeomConverter/src/org/lcsim/geometry/compact
SystemIDMap.java added at 1.1
diff -N SystemIDMap.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ SystemIDMap.java	7 Feb 2006 18:47:10 -0000	1.1
@@ -0,0 +1,47 @@
+package org.lcsim.geometry.compact;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A map of system ID to Subdetectors, used by org.lcsim.geometry.compact.Detector.
+ * 
+ * @author jeremym
+ *
+ */
+class SystemIDMap
+{
+    Map<Integer, Subdetector> _subdetectors = new HashMap<Integer, Subdetector>();
+
+    /** 
+     * Add an entry mapping system id to a Subdetector. 
+     * @param sysid System ID which must be > 0
+     * @param subdetector Subdetector with this sysid 
+     */
+    void add(int sysid, Subdetector subdetector)
+    {
+        if (_subdetectors.containsKey(sysid))
+        {
+            System.err.println("WARNING: The System ID " + sysid + " of " + subdetector.getName()
+                    + " is already used in this Detector.  System ID was NOT assigned.");
+        }
+        else
+        {
+            if (sysid > 0)
+            {
+                _subdetectors.put(sysid, subdetector);
+            }
+            else {
+                System.err.println("WARNING: The system id <" + sysid + "> of Subdetector <" 
+                        + subdetector.getName() 
+                        + "> was ignored, because it is not greater than zero.");
+            }
+        }
+    }
+
+    /** Retrieve a Subdetector by system ID. */
+    Subdetector get(int sysid)
+    {
+        return _subdetectors.get(sysid);
+    }
+}

GeomConverter/src/org/lcsim/geometry/compact
Detector.java 1.14 -> 1.15
diff -u -r1.14 -r1.15
--- Detector.java	14 Dec 2005 19:56:45 -0000	1.14
+++ Detector.java	7 Feb 2006 18:47:10 -0000	1.15
@@ -21,6 +21,8 @@
     private Map<String,Region> regions = new HashMap<String,Region>();
     private XMLMaterialManager materialMgr;
     
+    private SystemIDMap idmap = new SystemIDMap();
+    
     /**
      * Called by the reader to create a new Detector
      * @param element The JDOM element corresponding to the detector definition in the XML file.
@@ -103,8 +105,20 @@
      * @param sub The sub-detector to add.
      */
     protected void addSubdetector(Subdetector sub)
-    {
+    {        
         subdetectors.put(sub.getName(),sub);
+     
+        // add subdetector to system ID map
+        idmap.add(sub.getSystemID(), sub);
+    }
+    
+    /**
+     * Get a Subdetector by system ID.
+     * @param system ID
+     */    
+    protected Subdetector getSubdetector(int sysid)
+    {
+        return idmap.get(sysid);
     }
     
     /*

GeomConverter/src/org/lcsim/geometry/util
BaseIDDecoder.java 1.5 -> 1.6
diff -u -r1.5 -r1.6
--- BaseIDDecoder.java	7 Feb 2006 17:26:10 -0000	1.5
+++ BaseIDDecoder.java	7 Feb 2006 18:47:10 -0000	1.6
@@ -7,9 +7,9 @@
 
 package org.lcsim.geometry.util;
 
-import org.lcsim.geometry.ExpandedIdentifier;
 import org.lcsim.geometry.Subdetector;
 import org.lcsim.geometry.subdetector.BarrelEndcapFlag;
+import static org.lcsim.geometry.IDDecoder.INVALID_INDEX;
 
 /**
  * A basic implementation of org.lcsim.geometry.IDDecoder
@@ -159,11 +159,6 @@
     {
         return BarrelEndcapFlag.createBarrelEndcapFlag(getValue("barrel"));
     }
-
-//    public int getSystemID()
-//    {
-//        return getValue("system");
-//    }        
     
     public void setSubdetector(Subdetector d)
     {
@@ -184,6 +179,20 @@
     {
         return values[layerIndex];
     }
+    
+    public int getSystemID()
+    {
+        int idx = descriptor.indexOf("system");
+        int sysid = -1;
+        if (idx != INVALID_INDEX)
+        {
+            sysid = decoder.getValue("system");
+        }
+        else {
+            throw new RuntimeException("IDDecoder is missing system field.");
+        }
+        return sysid;
+    }
 
     public long[] getNeighbourIDs(int deltaLayer, int deltaTheta, int deltaPhi)
     {
CVSspam 0.2.8