Print

Print


Commit in lcsim/test/org/lcsim/event/base on MAIN
CalorimeterHitSimpleIOTest.java+91added 1.1


lcsim/test/org/lcsim/event/base
CalorimeterHitSimpleIOTest.java added at 1.1
diff -N CalorimeterHitSimpleIOTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ CalorimeterHitSimpleIOTest.java	23 Nov 2010 23:13:25 -0000	1.1
@@ -0,0 +1,91 @@
+package org.lcsim.event.base;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.lcio.LCIOConstants;
+import org.lcsim.util.lcio.LCIOReader;
+import org.lcsim.util.lcio.LCIOUtil;
+import org.lcsim.util.lcio.LCIOWriter;
+import org.lcsim.util.test.TestUtil.TestOutputFile;
+
+/**
+ *
+ * @author jeremym
+ *
+ * @version $Id: CalorimeterHitSimpleIOTest.java,v 1.1 2010/11/23 23:13:25 jeremy Exp $
+ */
+public class CalorimeterHitSimpleIOTest extends TestCase
+{
+    public void testSimpleIO() throws IOException
+    {
+        // Create a dummy hit.
+        long id = Long.parseLong("10000001", 16);
+        //long id = 0;
+        double[] position = new double[] { 1.0, 2.0, 3.0 };
+        double energy = 100.;
+        double energyError = 10.;
+        double time = 1.1;
+        int type = 137;
+
+        CalorimeterHit myHit = new CalorimeterHitImpl(energy, energyError, position, time, id, type);
+
+//        System.out.println("test hit: ");
+//        System.out.println(myHit);
+//        System.out.println();
+
+        // Create an empty event.
+        EventHeader event = new BaseLCSimEvent(0, 0, "test");
+
+        // Create a test collection of hits.
+        List<CalorimeterHit> hits = new ArrayList<CalorimeterHit>();
+
+        // Add the hit to the collection.
+        hits.add(myHit);
+
+        // Set the flags.
+        int flag = 0;
+        flag = LCIOUtil.bitSet(flag, LCIOConstants.RCHBIT_LONG, true);
+        flag = LCIOUtil.bitSet(flag, LCIOConstants.RCHBIT_ENERGY_ERROR, true);
+        flag = LCIOUtil.bitSet(flag, LCIOConstants.RCHBIT_TIME, true);
+
+        // Add the collection to the event.
+        event.put("TestCalorimeterHits", hits, CalorimeterHit.class, flag);        
+
+        // Write out the event to a file.
+        File outfile = new TestOutputFile("CalorimeterHitSimpleIOTest.slcio");
+        LCIOWriter writer = new LCIOWriter(outfile);
+        writer.write(event);
+        writer.close();
+
+        // Read the event back.
+        LCIOReader reader = new LCIOReader(outfile);
+        EventHeader eventcheck = reader.read();
+
+        // Get the hit collection.
+        List<CalorimeterHit> hitsCheck = eventcheck.get(CalorimeterHit.class,"TestCalorimeterHits");
+
+        // Get the hit.
+        CalorimeterHit hit = hitsCheck.get(0);
+        
+//        System.out.println("read hit: ");
+//        System.out.println(hit);
+//        System.out.println();
+
+        // Test that read hit matches original hit.
+        assertEquals("cellId not equal", hit.getCellID(), myHit.getCellID());
+        //assertEquals("32-bit cellId not equal", (int)hit.getCellID(), (int)myHit.getCellID());
+        assertEquals("position[0] not equal", hit.getPosition()[0], myHit.getPosition()[0]);
+        assertEquals("position[1] not equal", hit.getPosition()[1], myHit.getPosition()[1]);
+        assertEquals("position[2] not equal", hit.getPosition()[2], myHit.getPosition()[2]);                    
+        assertEquals("energy not equal", hit.getCorrectedEnergy(), myHit.getCorrectedEnergy());
+        assertEquals("energy error not equal", hit.getEnergyError(), myHit.getEnergyError());
+        assertEquals("time not equal", hit.getTime(), myHit.getTime(), 1e-7);
+    }   
+}
\ No newline at end of file
CVSspam 0.2.8