Print

Print


Commit in hps-java/src/main/java/org/lcsim/hps/util on MAIN
HPSLCIOFilterDriver.java+88added 1.1
Abstract base class for event filtering.

hps-java/src/main/java/org/lcsim/hps/util
HPSLCIOFilterDriver.java added at 1.1
diff -N HPSLCIOFilterDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HPSLCIOFilterDriver.java	10 Jan 2013 18:11:17 -0000	1.1
@@ -0,0 +1,88 @@
+/*
+ * 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 HPSLCIOFilterDriver extends Driver {
+    protected String outputFile;
+    protected LCIOWriter writer;
+   
+    
+    public HPSLCIOFilterDriver() {        
+    }
+    
+    public void setOutputFilePath(String output) {
+        this.outputFile = output;
+    }
+    
+    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);
+        }
+    }
+    
+}
CVSspam 0.2.12


Use REPLY-ALL to reply to list

To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1