2 added + 1 modified, total 3 files
lcsim/src/org/lcsim/util/loop
diff -N StdhepDriver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ StdhepDriver.java 27 Mar 2007 16:43:28 -0000 1.1
@@ -0,0 +1,65 @@
+package org.lcsim.util.loop;
+
+import hep.io.stdhep.StdhepEvent;
+import hep.io.stdhep.StdhepWriter;
+import java.io.File;
+import java.io.IOException;
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+
+/**
+ * A driver for writing out LCIO events.
+ * @author tonyj
+ */
+public class StdhepDriver extends Driver
+{
+ private StdhepWriter writer;
+
+ public StdhepDriver(String file, String title, String comment, int expectedEvents)
+ {
+ try
+ {
+ writer = new StdhepWriter(file, title, comment, expectedEvents);
+ }
+ catch (IOException x)
+ {
+ throw new RuntimeException("Error opening Stdhep file",x);
+ }
+ }
+ public StdhepDriver(File file, String title, String comment, int expectedEvents)
+ {
+ try
+ {
+ writer = new StdhepWriter(file.getAbsolutePath(), title, comment, expectedEvents);
+ }
+ catch (IOException x)
+ {
+ throw new RuntimeException("Error opening Stdhep file",x);
+ }
+ }
+
+ protected void process(EventHeader event)
+ {
+ try
+ {
+ StdhepEvent se = (StdhepEvent) event.get("StdhepEvent");
+ writer.writeRecord(se);
+ }
+ catch (IOException x)
+ {
+ throw new RuntimeException("Error writing Stdhep file",x);
+ }
+ }
+
+ protected void endOfData()
+ {
+ try
+ {
+ writer.close();
+ }
+ catch (IOException x)
+ {
+ throw new RuntimeException("Error closing Stdhep file",x);
+ }
+ }
+}
\ No newline at end of file
lcsim/src/org/lcsim/util/loop
diff -u -r1.5 -r1.6
--- StdhepConverter.java 8 Dec 2006 23:58:21 -0000 1.5
+++ StdhepConverter.java 27 Mar 2007 16:43:28 -0000 1.6
@@ -21,7 +21,7 @@
* A class that converts MCEvent<-->StdhepEvent.
* This version uses the Ron Cassell algorithm for deciding on parent/child relationships.
* @author Tony Johnson ([log in to unmask])
- * @version $Id: StdhepConverter.java,v 1.5 2006/12/08 23:58:21 tonyj Exp $
+ * @version $Id: StdhepConverter.java,v 1.6 2007/03/27 16:43:28 tonyj Exp $
*/
class StdhepConverter
{
@@ -89,6 +89,8 @@
}
}
event.put(MCEvent.MC_PARTICLES,Arrays.asList(particle));
+ // Add original stdhep event in case we want to write it out.
+ event.put("StdhepEvent",hepevt);
return event;
}
private void checkAndAddDaughter(BasicParticle[] particle, List<Set<BasicParticle>> ancestors, int parentID, int childID)
lcsim/test
diff -N StdhepFilterTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ StdhepFilterTest.java 27 Mar 2007 16:43:29 -0000 1.1
@@ -0,0 +1,44 @@
+import java.io.File;
+import java.net.URL;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.lcsim.util.cache.FileCache;
+import org.lcsim.util.loop.LCSimLoop;
+import org.lcsim.util.loop.StdhepDriver;
+
+/**
+ *
+ * @author Tony Johnson
+ */
+public class StdhepFilterTest extends TestCase
+{
+ public StdhepFilterTest(String testName)
+ {
+ super(testName);
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(StdhepFilterTest.class);
+ }
+ /**
+ * @param args the command line arguments
+ */
+ public void testStdhepFilter() throws Exception
+ {
+ final String detectorName = "sidaug05";
+ URL url = new URL("ftp://ftp-lcd.slac.stanford.edu/lcd/NewData/NLC500/ZZ/stdhep/pythia/pythiaZZ_nunu_bbbar.stdhep");
+ FileCache cache = new FileCache();
+ File stdhep = cache.getCachedFile(url);
+
+ StdhepDriver writer = new StdhepDriver("filter.stdhep","myTitle","myComment",0);
+
+ LCSimLoop loop = new LCSimLoop();
+ loop.setStdhepRecordSource(stdhep,detectorName);
+ loop.add(writer);
+ loop.loop(100);
+ assertEquals(100,loop.getTotalCountableSupplied());
+ loop.dispose();
+ }
+}
\ No newline at end of file
CVSspam 0.2.8