lcsim/src/org/lcsim/util/loop
diff -u -r1.1 -r1.2
--- LCIOEventSource.java 11 Mar 2005 16:49:25 -0000 1.1
+++ LCIOEventSource.java 19 Jul 2005 22:42:09 -0000 1.2
@@ -3,6 +3,8 @@
import java.io.EOFException;
import java.io.File;
import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
import org.freehep.record.source.EndOfSourceException;
import org.freehep.record.source.NoSuchRecordException;
import org.freehep.record.source.SequentialRecordSource;
@@ -12,19 +14,29 @@
/**
* Convert an LCIOReader to a SequentialRecordSource
* @author tonyj
- * @version $Id: LCIOEventSource.java,v 1.1 2005/03/11 16:49:25 tonyj Exp $
+ * @version $Id: LCIOEventSource.java,v 1.2 2005/07/19 22:42:09 tonyj Exp $
*/
public class LCIOEventSource implements SequentialRecordSource
{
- private File file;
+ private List<File> files;
private boolean atEnd;
private LCIOReader reader;
private EventHeader currentEvent;
+ private int currentFile = 0;
+ private String name;
public LCIOEventSource(File file) throws IOException
{
reader = new LCIOReader(file);
- this.file = file;
+ this.files = Collections.singletonList(file);
+ this.name = file.getName();
+ }
+ public LCIOEventSource(String name, List<File> files) throws IOException
+ {
+ if (files.isEmpty()) throw new IOException("File list is empty");
+ reader = new LCIOReader(files.get(0));
+ this.files = files;
+ this.name = name;
}
public Object getCurrentRecord() throws NoSuchRecordException, IOException, EndOfSourceException
@@ -46,7 +58,7 @@
public String getSourceName()
{
- return file.getName();
+ return name;
}
public void next() throws IOException
@@ -57,7 +69,13 @@
}
catch (EOFException x)
{
- atEnd = true;
+ currentFile++;
+ if (currentFile >= files.size()) atEnd = true;
+ else
+ {
+ reader.close();
+ reader = new LCIOReader(files.get(currentFile));
+ }
}
}
public void releaseRecord(Object obj)
@@ -66,8 +84,9 @@
}
public void rewind() throws IOException
{
+ currentFile = 0;
reader.close();
- reader = new LCIOReader(file);
+ reader = new LCIOReader(files.get(currentFile));
atEnd = false;
}
public void close() throws IOException