Print

Print


Author: [log in to unmask]
Date: Wed Jan  7 17:06:35 2015
New Revision: 3483

Log:
Have Driver add slcio file extension if necessary.

Modified:
    projects/lcsim/trunk/event-processing/src/main/java/org/lcsim/util/loop/LCIODriver.java

Modified: projects/lcsim/trunk/event-processing/src/main/java/org/lcsim/util/loop/LCIODriver.java
 =============================================================================
--- projects/lcsim/trunk/event-processing/src/main/java/org/lcsim/util/loop/LCIODriver.java	(original)
+++ projects/lcsim/trunk/event-processing/src/main/java/org/lcsim/util/loop/LCIODriver.java	Wed Jan  7 17:06:35 2015
@@ -12,154 +12,123 @@
 import org.lcsim.lcio.LCIOWriter;
 
 /**
- * A driver for writing out LCIO events. 
+ * A driver for writing out LCIO events.
  * 
- * By default this will write out the entire event, but you can control
- * what collections are written out by using {@link #setIgnoreCollection(String)},
- * {@link #setIgnoreCollections(String[])}, {@link #setWriteOnlyCollection(String)},
- * and {@link #setWriteOnlyCollections(String[])}.  
+ * By default this will write out the entire event, but you can control what collections are written 
+ * out by using {@link #setIgnoreCollection(String)}, {@link #setIgnoreCollections(String[])},
+ * {@link #setWriteOnlyCollection(String)}, and {@link #setWriteOnlyCollections(String[])}.
  * 
  * @author tonyj
  * @see org.lcsim.util.lcio.LCIOWriter
  */
-public class LCIODriver extends Driver
-{
-	private LCIOWriter writer;
-	private Set<String> listIgnore = new HashSet<String>();
-	private Set<String> listKeep = new HashSet<String>();
-	private File outputFile;
-	
-	public LCIODriver(String file)
-	{
-		this(file, null);
-	}
-	
-	public LCIODriver(File file)
-	{
-		this(file, null);
-	}
-	
-	public LCIODriver(String file, Collection<String> listIgnore)
-	{
-		this(new File(file),listIgnore);
-	}
-	
-	public LCIODriver(File file, Collection<String> listIgnore)
-	{
+public class LCIODriver extends Driver {
+    private LCIOWriter writer;
+    private Set<String> listIgnore = new HashSet<String>();
+    private Set<String> listKeep = new HashSet<String>();
+    private File outputFile;
+
+    public LCIODriver(String file) {
+        this(addFileExtension(file), null);
+    }
+
+    public LCIODriver(File file) {
+        this(file, null);
+    }
+
+    public LCIODriver(String file, Collection<String> listIgnore) {
+        this(new File(addFileExtension(file)), listIgnore);
+    }
+
+    public LCIODriver(File file, Collection<String> listIgnore) {
         this.outputFile = file;
-        if (listIgnore != null)
-        {
+        if (listIgnore != null) {
             this.listIgnore.addAll(listIgnore);
         }
-	}
-		
-	public LCIODriver()
-	{}
-		
-	public void setOutputFilePath(String filePath)
-	{	
-		if (!filePath.endsWith(".slcio"))
-			filePath += ".slcio";
-        outputFile = new File(filePath);
-	}
-	
-	public void setIgnoreCollections(String[] ignoreCollections)
-	{
-		listIgnore.addAll(Arrays.asList(ignoreCollections));
-	}
-	
-	public void setWriteOnlyCollections(String [] keepCollections)
-	{
-		listKeep.addAll(Arrays.asList(keepCollections));
-	}
+    }
 
-    public void setIgnoreCollection(String ignoreCollection)
-    {
+    public LCIODriver() {
+    }
+
+    public void setOutputFilePath(String filePath) {
+        outputFile = new File(addFileExtension(filePath));
+    }
+
+    public void setIgnoreCollections(String[] ignoreCollections) {
+        listIgnore.addAll(Arrays.asList(ignoreCollections));
+    }
+
+    public void setWriteOnlyCollections(String[] keepCollections) {
+        listKeep.addAll(Arrays.asList(keepCollections));
+    }
+
+    public void setIgnoreCollection(String ignoreCollection) {
         listIgnore.add(ignoreCollection);
     }
 
-    public void setWriteOnlyCollection(String writeOnlyCollection)
-    {
+    public void setWriteOnlyCollection(String writeOnlyCollection) {
         listKeep.add(writeOnlyCollection);
     }
-	
-    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); 
+
+    private void setupWriter() {
+        // Cleanup existing writer.
+        if (writer != null) {
+            try {
+                writer.flush();
+                writer.close();
+                writer = null;
+            } catch (IOException x) {
+                System.err.println(x.getMessage());
+            }
         }
-        catch (IOException x)
-        {
-            throw new RuntimeException("Error creating writer",x);
+
+        // Setup new writer.
+        try {
+            writer = new LCIOWriter(outputFile);
+        } catch (IOException x) {
+            throw new RuntimeException("Error creating writer", x);
         }
         writer.addAllIgnore(listIgnore);
         writer.addAllWriteOnly(listKeep);
-        
-        try 
-        {
+
+        try {
             writer.reOpen();
-		}
-		catch (IOException x)
-		{
-			throw new RuntimeException("Error rewinding LCIO file",x);
-		}
+        } catch (IOException x) {
+            throw new RuntimeException("Error rewinding LCIO file", x);
+        }
     }
-	
-	protected void startOfData()
-	{
+
+    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)
-	{
-		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);
-		}
-	}
+    protected void endOfData() {
+        try {
+            writer.close();
+        } catch (IOException x) {
+            throw new RuntimeException("Error rewinding LCIO file", x);
+        }
+    }
+
+    protected void process(EventHeader 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);
+        }
+    }
+
+    private static String addFileExtension(String filePath) {
+        if (!filePath.endsWith(".slcio")) {
+            return filePath + ".slcio";
+        } else
+            return filePath;
+    }
 }

########################################################################
Use REPLY-ALL to reply to list

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