lcsim/test
diff -N ReadoutTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ReadoutTest.java 26 Jul 2005 14:46:01 -0000 1.1
@@ -0,0 +1,69 @@
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.EventHeader.LCMetaData;
+import org.lcsim.event.SimCalorimeterHit;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.util.Driver;
+import org.lcsim.util.cache.FileCache;
+import org.lcsim.util.loop.LCIODriver;
+import org.lcsim.util.loop.LCSimLoop;
+/**
+ *
+ * @author tonyj
+ */
+public class ReadoutTest extends TestCase
+{
+ public ReadoutTest(String testName)
+ {
+ super(testName);
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(ReadoutTest.class);
+ }
+
+ public void testLCIORead() throws Exception
+ {
+ URL url = new URL("http://www.lcsim.org/datasamples/slic_sdjan03_K0S_Theta90_1-10GeV.slcio");
+ FileCache cache = new FileCache();
+ File file = cache.getCachedFile(url);
+
+ LCSimLoop loop = new LCSimLoop();
+ loop.setLCIORecordSource(file);
+ loop.add(new CopyDriver());
+ loop.add(new LCIODriver(new File("test2.slcio")));
+ loop.loop(-1);
+ loop.dispose();
+ }
+ private class CopyDriver extends Driver
+ {
+ public void process(EventHeader event)
+ {
+ // Loop over all calorimeter hits, add
+ List<List<SimCalorimeterHit>> collections = event.get(SimCalorimeterHit.class);
+ int nBefore = collections.size();
+ for (List<SimCalorimeterHit> collection : collections)
+ {
+ LCMetaData meta = event.getMetaData(collection);
+ List copy = new ArrayList(collection);
+ event.put(meta.getName()+"Copy",copy,SimCalorimeterHit.class,meta.getFlags(),meta.getName());
+ }
+ collections = event.get(SimCalorimeterHit.class);
+ int nAfter = collections.size();
+ assertEquals(2*nBefore,nAfter);
+ for (List<SimCalorimeterHit> collection : collections)
+ {
+ LCMetaData meta = event.getMetaData(collection);
+ IDDecoder decoder = meta.getIDDecoder();
+ assertNotNull(decoder);
+ }
+ }
+ }
+}