hps-java/src/main/java/org/lcsim/hps/util
diff -N LCIOFilterDriver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ LCIOFilterDriver.java 6 Mar 2013 03:10:22 -0000 1.1
@@ -0,0 +1,92 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.lcsim.hps.util;
+import java.io.IOException;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.Track;
+import org.lcsim.util.Driver;
+import org.lcsim.util.lcio.LCIOWriter;
+
+/**
+ *
+ * @author phansson
+ */
+public abstract class LCIOFilterDriver extends Driver {
+ protected String outputFile;
+ protected LCIOWriter writer;
+ protected boolean debug = false;
+
+ public LCIOFilterDriver() {
+ }
+
+ public void setOutputFilePath(String output) {
+ this.outputFile = output;
+ }
+
+ public void setDebug(boolean debug) {
+ this.debug = debug;
+ }
+
+ abstract boolean eventFilter(EventHeader event);
+
+ private void setupWriter() {
+ // Cleanup existing writer.
+ if (writer != null) {
+ try {
+ writer.flush();
+ writer.close();
+ writer = null;
+ } catch (IOException x) {
+ System.err.println(x.getMessage());
+ }
+ }
+
+ // Setup new writer.
+ try {
+ writer = new LCIOWriter(outputFile);
+ } catch (IOException x) {
+ throw new RuntimeException("Error creating writer", x);
+ }
+
+
+ try {
+ writer.reOpen();
+ } catch (IOException x) {
+ throw new RuntimeException("Error rewinding LCIO file", x);
+ }
+ }
+
+ protected void startOfData() {
+ setupWriter();
+ }
+
+ protected void endOfData() {
+ try {
+ writer.close();
+ } catch (IOException x) {
+ throw new RuntimeException("Error rewinding LCIO file", x);
+ }
+ }
+
+ protected void process(EventHeader event) {
+
+ if(eventFilter(event)) {
+ try {
+ writer.write(event);
+ } catch (IOException x) {
+ throw new RuntimeException("Error writing LCIO file", x);
+ }
+ }
+ }
+
+ protected void suspend() {
+ try {
+ writer.flush();
+ } catch (IOException x) {
+ throw new RuntimeException("Error flushing LCIO file", x);
+ }
+ }
+
+}
hps-java/src/main/java/org/lcsim/hps/util
diff -N TwoTrackFilterDriver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ TwoTrackFilterDriver.java 6 Mar 2013 03:10:22 -0000 1.1
@@ -0,0 +1,54 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.lcsim.hps.util;
+
+import org.lcsim.hps.util.LCIOFilterDriver;
+import java.io.IOException;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.Track;
+import org.lcsim.util.Driver;
+
+/**
+ *
+ * @author phansson
+ */
+public class TwoTrackFilterDriver extends LCIOFilterDriver {
+ private String trackCollectionName = "MatchedTracks";
+
+ public TwoTrackFilterDriver() {
+ }
+
+ public void setTrackCollectionNamePath(String trackCollection) {
+ this.trackCollectionName = trackCollection;
+ }
+
+ @Override
+ boolean eventFilter(EventHeader event) {
+ boolean pass = false;
+
+ if(!event.hasCollection(Track.class, trackCollectionName)) {
+ throw new RuntimeException("Error, event doesn't have the track collection");
+ }
+
+ if(this.debug) {
+ System.out.printf("%s: %d tracks in this event\n",this.getClass().getSimpleName(),event.get(Track.class, trackCollectionName).size());
+ }
+
+ if (event.get(Track.class, trackCollectionName).size()>1) {
+ try {
+ if(this.debug) {
+ System.out.printf("%s: write event %d \n",this.getClass().getSimpleName(),event.getEventNumber());
+ }
+ writer.write(event);
+ } catch (IOException x) {
+ throw new RuntimeException("Error writing LCIO file", x);
+ }
+ }
+
+
+ return pass;
+ }
+
+}