Print

Print


Commit in lcsim on MAIN
src/org/lcsim/util/DriverAdapter.java+10-51.5 -> 1.6
src/org/lcsim/util/event/BaseLCSimEvent.java+44-31.21 -> 1.22
test/org/lcsim/util/event/CellIDEncodingTest.java+69added 1.1
+123-8
1 added + 2 modified, total 3 files
JM: First version of using CellIDEncoding to create an IDDecoder when no detector exists.

lcsim/src/org/lcsim/util
DriverAdapter.java 1.5 -> 1.6
diff -u -r1.5 -r1.6
--- DriverAdapter.java	3 Apr 2007 18:02:34 -0000	1.5
+++ DriverAdapter.java	25 May 2007 19:37:28 -0000	1.6
@@ -14,7 +14,7 @@
 /**
  * Drive a Driver from a Record loop
  * @author Tony Johnson
- * @version $Id: DriverAdapter.java,v 1.5 2007/04/03 18:02:34 tonyj Exp $
+ * @version $Id: DriverAdapter.java,v 1.6 2007/05/25 19:37:28 jeremy Exp $
  */
 public class DriverAdapter extends RecordAdapter
 {
@@ -66,10 +66,15 @@
          if (event instanceof EventHeader) 
          {
             EventHeader evt = (EventHeader) event;
-            if (detector != evt.getDetector()) 
-            {
-               detectorChanged(evt.getDetector());
-             }
+            // FIXME: Try block is a workaround for when a dummy detector is being used and getDetector() throws exception.
+            try {
+                if (detector != evt.getDetector()) 
+                {
+                    detectorChanged(evt.getDetector());
+                }
+            }
+            catch (Exception x)
+            {}
             driver.process(evt);
          }
       }

lcsim/src/org/lcsim/util/event
BaseLCSimEvent.java 1.21 -> 1.22
diff -u -r1.21 -r1.22
--- BaseLCSimEvent.java	9 Apr 2007 05:11:11 -0000	1.21
+++ BaseLCSimEvent.java	25 May 2007 19:37:28 -0000	1.22
@@ -1,23 +1,27 @@
 package org.lcsim.util.event;
 
 import hep.physics.event.BaseEvent;
+
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.IdentityHashMap;
 import java.util.List;
 import java.util.Map;
+
 import org.lcsim.conditions.ConditionsManager;
 import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
 import org.lcsim.event.CalorimeterHit;
 import org.lcsim.event.Cluster;
 import org.lcsim.event.EventHeader;
-import org.lcsim.event.EventHeader.LCMetaData;
 import org.lcsim.event.MCParticle;
 import org.lcsim.event.SimCalorimeterHit;
 import org.lcsim.event.SimTrackerHit;
 import org.lcsim.event.Track;
 import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.geometry.util.BaseIDDecoder;
+import org.lcsim.geometry.util.IDDescriptor;
 
 /**
  * A base implementation for EventHeader
@@ -266,11 +270,48 @@
             String[] names = stringMap.get(READOUT_NAME);
             if (names != null && names.length >= 1) readoutName = names[0];
          }
-         org.lcsim.geometry.IDDecoder result = getDetector().getDecoder(readoutName);
-         if (result == null) throw new RuntimeException("Could not find decoder for collection: "+name+" readout: "+readoutName);
+         
+         // 1) Find the IDDecoder using the Detector.
+         org.lcsim.geometry.IDDecoder result=null;
+         try {
+              result = getDetector().getDecoder(readoutName);
+         }
+         catch (RuntimeException x)
+         {}
+         
+         // 2) Detector lookup failed.  Attempt to use the CellIDEncoding collection parameter.
+         if (result == null)
+             result = createIDDecoderFromCellIDEncoding();
+         
+         // If both methods failed, then die.
+         if (result == null) throw new RuntimeException("Could not find or create an IDDecoder for the collection: "+name+", readout: "+readoutName);
+         
          return result;
       }
       
+      /**
+       * Make an IDDecoder for this MetaData using the CellIDEncoding parameter.
+       * @return An IDDecoder made built from the CellIDEncoding.
+       */
+      private IDDecoder createIDDecoderFromCellIDEncoding()
+      {
+          String[] cellIdEncoding = getStringParameters().get("CellIDEncoding");
+          IDDecoder result = null;
+          if (cellIdEncoding != null)
+          {
+              result = new BaseIDDecoder();
+              try {
+                  IDDescriptor desc = new IDDescriptor(cellIdEncoding[0]);
+                  result.setIDDescription(desc);
+              }
+              catch (IDDescriptor.IDException x)
+              {
+                  throw new RuntimeException(x);
+              }
+          }          
+          return result;
+      }
+      
       public Map<String, int[]> getIntegerParameters()
       {
          if (intMap == null) intMap = new HashMap<String, int[]>();

lcsim/test/org/lcsim/util/event
CellIDEncodingTest.java added at 1.1
diff -N CellIDEncodingTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ CellIDEncodingTest.java	25 May 2007 19:37:28 -0000	1.1
@@ -0,0 +1,69 @@
+package org.lcsim.util.event;
+
+import java.net.URL;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.conditions.ConditionsManagerImplementation;
+import org.lcsim.conditions.ConditionsReader;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.SimCalorimeterHit;
+import org.lcsim.event.EventHeader.LCMetaData;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.util.Driver;
+import org.lcsim.util.cache.FileCache;
+import org.lcsim.util.loop.LCSimLoop;
+
+/**
+ * A test that uses the {@link org.lcsim.geometry.IDDecoder}s created from 
+ * the CellIDDecoding parameter of the LCIO collection rather than the description 
+ * from the compact file.  This is the default strategy when no compact
+ * description exists.
+ * 
+ * @see org.lcsim.event.LCEventHeader$LCMetaData
+ * @see org.lcsim.conditions.ConditionsManager
+ * @see org.lcsim.conditions.ConditionsReader#createDummy()
+ * @see org.lcsim.geometry.IDDecoder
+ * @see org.lcsim.geometry.util.IDDescriptor
+ * 
+ * @author Jeremy McCormick
+ * @version $Id: CellIDEncodingTest.java,v 1.1 2007/05/25 19:37:28 jeremy Exp $
+ *
+ */
+public class CellIDEncodingTest extends TestCase
+{  
+    // A data file with an unknown detector.
+    private static final String url = "http://www.lcsim.org/test/lcio/unknown_detector.slcio";
+    
+    public void testCellIDEncoding() throws Exception
+    {
+        ConditionsManager cond = ConditionsManager.defaultInstance();
+        ((ConditionsManagerImplementation)cond).setConditionsReader(ConditionsReader.createDummy(), "UNKNOWN");
+                        
+        LCSimLoop loop = new LCSimLoop();
+        loop.setLCIORecordSource((new FileCache()).getCachedFile(new URL(url)));
+        loop.add(new IDDecoderCheck());
+        loop.loop(1);
+        loop.dispose();
+    }
+    
+    /**
+     * Loops over SimCalorimeterHit collections and checks for the correct id string.
+     */
+    private class IDDecoderCheck extends Driver
+    {
+        protected void process(EventHeader event)
+        {
+            List<List<SimCalorimeterHit>> collections = event.get(SimCalorimeterHit.class);
+            for (List<SimCalorimeterHit> collection : collections)
+            {
+                LCMetaData meta = event.getMetaData(collection);
+                IDDecoder decoder = meta.getIDDecoder();
+                assertTrue(decoder != null);
+                assertEquals("Description string is incorrect.", decoder.getIDDescription().toString(), "layer:0:7,system:7:6,barrel:13:3,theta:32:11,phi:43:11");
+            }
+        }        
+    }
+}
\ No newline at end of file
CVSspam 0.2.8