Print

Print


Author: [log in to unmask]
Date: Thu May 14 12:32:53 2015
New Revision: 2968

Log:
Preliminary version of utility for patching LCIO files with bad Cluster data.  HPSJAVA-502

Added:
    java/trunk/users/src/main/java/org/hps/users/jeremym/PatchLcioFile.java

Added: java/trunk/users/src/main/java/org/hps/users/jeremym/PatchLcioFile.java
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/jeremym/PatchLcioFile.java	(added)
+++ java/trunk/users/src/main/java/org/hps/users/jeremym/PatchLcioFile.java	Thu May 14 12:32:53 2015
@@ -0,0 +1,53 @@
+package org.hps.users.jeremym;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.lcio.LCIOReader;
+import org.lcsim.lcio.LCIOWriter;
+
+/**
+ * Read in an LCIO file and write it to a new location, which should fix 
+ * the SIOCluster issue.  
+ */
+public final class PatchLcioFile {
+
+    public static void main(String[] args) {
+        
+        File oldFile = new File(args[0]);
+        File newFile = new File(args[1]);
+
+        LCIOReader reader = null;
+        LCIOWriter writer = null;
+        try {
+            System.out.println("opening " + oldFile.getPath() + " for reading");
+            reader = new LCIOReader(oldFile);
+            
+            System.out.println("opening " + newFile.getPath() + " for writing");
+            writer = new LCIOWriter(newFile);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        EventHeader event = null;
+        try {
+            while ((event = reader.read()) != null) {
+                writer.write(event);
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        } finally {
+            try {
+                reader.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            try {
+                writer.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        } 
+        System.out.println("done patching " + oldFile.getPath());
+    }
+}