Commit in lcsim on MAIN
src/org/lcsim/util/loop/LCSimLoop.java+3-31.4 -> 1.5
                       /StdhepEventSource.java+48-51.2 -> 1.3
                       /LCIODriver.java+23-11.4 -> 1.5
test/LCIOReadTest.java+17-11.11 -> 1.12
+91-10
4 modified files
tj: More IO enhancements for timb

lcsim/src/org/lcsim/util/loop
LCSimLoop.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- LCSimLoop.java	17 Aug 2006 21:31:05 -0000	1.4
+++ LCSimLoop.java	25 Aug 2006 01:28:46 -0000	1.5
@@ -62,17 +62,17 @@
         super.setRecordSource(new EventGeneratorRecordSource(gen, "generator"));
     }
     
-    public void skip(int recordsToSkip) throws NoSuchRecordException, IOException
+    public void skip(long recordsToSkip) throws NoSuchRecordException, IOException
     {
        SequentialRecordSource rs = getRecordSource();
        if (rs instanceof RandomAccessRecordSource)
        {
           RandomAccessRecordSource rrs = (RandomAccessRecordSource) rs;
-          rrs.goToRecord(rrs.currentIndex()+recordsToSkip);
+          rrs.goToRecord((int) (rrs.currentIndex()+recordsToSkip));
        }
        else
        {
-          for (int i=0; i<recordsToSkip; i++)
+          for (long i=0; i<recordsToSkip; i++)
           {
              rs.next();
           }

lcsim/src/org/lcsim/util/loop
StdhepEventSource.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- StdhepEventSource.java	7 Dec 2005 19:10:20 -0000	1.2
+++ StdhepEventSource.java	25 Aug 2006 01:28:46 -0000	1.3
@@ -9,7 +9,7 @@
 import java.io.IOException;
 import org.freehep.record.source.EndOfSourceException;
 import org.freehep.record.source.NoSuchRecordException;
-import org.freehep.record.source.SequentialRecordSource;
+import org.freehep.record.source.RandomAccessRecordSource;
 import org.lcsim.event.EventHeader;
 import org.lcsim.util.event.LCSimFactory;
 
@@ -17,15 +17,16 @@
 /**
  * Convert an LCIOReader to a SequentialRecordSource
  * @author tonyj
- * @version $Id: StdhepEventSource.java,v 1.2 2005/12/07 19:10:20 tonyj Exp $
+ * @version $Id: StdhepEventSource.java,v 1.3 2006/08/25 01:28:46 tonyj Exp $
  */
-public class StdhepEventSource implements SequentialRecordSource
+public class StdhepEventSource implements RandomAccessRecordSource
 {
-   private File file;
+   private final File file;
    private boolean atEnd;
    private StdhepReader reader;
-   private StdhepConverter converter;
+   private final StdhepConverter converter;
    private EventHeader currentEvent;
+   private int currentEventNumber;
    
    public StdhepEventSource(File file, String detectorName) throws IOException
    {
@@ -66,6 +67,7 @@
             if (record instanceof StdhepEvent)
             {
                currentEvent = (EventHeader) converter.convert((StdhepEvent) record);
+               currentEventNumber++;
                break;
             }
          }
@@ -83,6 +85,7 @@
    {
       reader.rewind();
       atEnd = false;
+      currentEventNumber = 0;
    }
    public void close() throws IOException
    {
@@ -100,4 +103,44 @@
       }
       catch (IOException x) {}
    }
+
+   public void goToRecord(int numberToSkip) throws NoSuchRecordException
+   {
+      reader.
+      try
+      {
+         int target = currentEventNumber+numberToSkip;
+         for (;;)
+         {  
+            StdhepRecord record = reader.nextRecord();
+            if (record instanceof StdhepEvent)
+            {
+               currentEventNumber++;  
+               if (currentEventNumber == target)
+               {
+                  currentEvent = (EventHeader) converter.convert((StdhepEvent) record);
+                  break;
+               }
+            }
+         }
+      }
+      catch (EOFException x)
+      {
+         atEnd = true; 
+         NoSuchRecordException xx = new NoSuchRecordException();
+         xx.initCause(x);
+         throw xx;
+      }
+      catch (IOException x)
+      {
+         NoSuchRecordException xx = new NoSuchRecordException();
+         xx.initCause(x);
+         throw xx;         
+      }
+   }
+
+   public int currentIndex()
+   {
+      return currentEventNumber;
+   }
 }
\ No newline at end of file

lcsim/src/org/lcsim/util/loop
LCIODriver.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- LCIODriver.java	18 Jul 2005 19:18:28 -0000	1.4
+++ LCIODriver.java	25 Aug 2006 01:28:46 -0000	1.5
@@ -2,6 +2,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Collection;
 import org.lcsim.event.EventHeader;
 import org.lcsim.util.Driver;
 import org.lcsim.util.lcio.LCIOWriter;
@@ -36,7 +37,28 @@
          throw new RuntimeException("Error opening LCIO file",x);
       }
    }  
-
+   public LCIODriver(String file, Collection<String> listIgnore)
+   {
+      try
+      {
+         writer = new LCIOWriter(file, listIgnore);
+      }
+      catch (IOException x)
+      {
+         throw new RuntimeException("Error opening LCIO file",x);
+      }
+   }
+   public LCIODriver(File file, Collection<String> listIgnore)
+   {
+      try
+      {
+         writer = new LCIOWriter(file, listIgnore);
+      }
+      catch (IOException x)
+      {
+         throw new RuntimeException("Error opening LCIO file",x);
+      }
+   }
    protected void process(EventHeader event)
    {
       try

lcsim/test
LCIOReadTest.java 1.11 -> 1.12
diff -u -r1.11 -r1.12
--- LCIOReadTest.java	17 Aug 2006 21:31:07 -0000	1.11
+++ LCIOReadTest.java	25 Aug 2006 01:28:51 -0000	1.12
@@ -73,12 +73,28 @@
         LCSimLoop loop = new LCSimLoop();
         loop.setLCIORecordSource(file);
         loop.add(new CheatClusterDriver());
-        loop.add(new LCIODriver(new File("test.slcio")));
         loop.skip(150);
         loop.loop(-1);
         assertEquals(50, loop.getTotalCountableSupplied());
         loop.dispose();       
     }
+    public void testSkipSpeed() throws Exception
+    {
+        final String detectorName = "sidaug05";
+        URL url = new URL("ftp://ftp-lcd.slac.stanford.edu/lcd/NewData/NLC500/ZZ/stdhep/pythia/pythiaZZ_nunu_bbbar.stdhep");
+        FileCache cache = new FileCache();
+        File stdhep = cache.getCachedFile(url);
+
+        LCSimLoop loop = new LCSimLoop();
+        loop.setStdhepRecordSource(stdhep,detectorName);
+        long start = System.nanoTime();
+        loop.skip(950);
+        long stop = System.nanoTime();
+        System.out.println("Skip took "+(stop-start)/1000000.+"ms");
+        loop.loop(-1);
+        assertEquals(50, loop.getTotalCountableSupplied());
+        loop.dispose();       
+    }
     private class ReadDriver extends Driver
     {
         private int n;
CVSspam 0.2.8