lcsim/src/org/lcsim/util/event
diff -u -r1.2 -r1.3
--- SubdetectorLocator.java 7 Feb 2006 17:54:49 -0000 1.2
+++ SubdetectorLocator.java 8 Feb 2006 00:58:56 -0000 1.3
@@ -1,24 +1,57 @@
package org.lcsim.util.event;
import org.lcsim.event.EventHeader.LCMetaData;
-import org.lcsim.geometry.CalorimeterIDDecoder;
+import org.lcsim.geometry.IDDecoder;
import org.lcsim.geometry.Subdetector;
/**
- * This class enables us to find the subdector and sampling fraction from
- * a hit ID plus an LCMetaData. The problem is that LCIO format does not mandate
- * how this should be done. Two obvious possibilities are:
+ * This class enables us to find the subdector and sampling fraction from a hit
+ * ID plus an LCMetaData. The problem is that LCIO format does not mandate how
+ * this should be done. Two obvious possibilities are:
* <ol>
* <li>The ID contains a SystemID which leads us to the detector
* <li>Each collection is associated to a specific subdetector.
* </ol>
* Currently it cheats and uses a method which should not exist.
+ *
* @author tonyj
*/
class SubdetectorLocator
{
- static Subdetector locateSubdetector(LCMetaData d, long id)
- {
- return d.getIDDecoder().getSubdetector();
- }
+ static Subdetector locateSubdetector(LCMetaData d, long rawid)
+ {
+ IDDecoder decoder = d.getIDDecoder();
+ decoder.setID(rawid);
+ Subdetector subdet = null;
+
+ // First, try looking up using System ID.
+ int sysid = -1;
+ try
+ {
+ sysid = decoder.getSystemID();
+ //System.out.println("lookup sysid: " + sysid);
+ subdet = d.getEvent().getDetector().getSubdetector(sysid);
+ }
+ catch (Exception e)
+ {}
+
+ // Next, try using the reference setup by Detector.
+ if (subdet == null)
+ {
+ subdet = d.getIDDecoder().getSubdetector();
+
+ if (subdet.getSystemID() != sysid)
+ {
+ System.err.println("");
+ }
+ }
+
+ // If not found with either method, throw an exception.
+ if (subdet == null)
+ {
+ throw new RuntimeException("SubdetectorLocator unable to find Subdetector for " + d.getName());
+ }
+
+ return subdet;
+ }
}
\ No newline at end of file