Print

Print


Commit in lcsim on MAIN
src/org/lcsim/util/loop/LCSimLoop.java+20-11.3 -> 1.4
test/LCIOReadTest.java+16-71.10 -> 1.11
+36-8
2 modified files
TJ: Add ability for LCSimLoop to skip records (modelled on contrib.timb)

lcsim/src/org/lcsim/util/loop
LCSimLoop.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- LCSimLoop.java	29 Jul 2005 02:43:56 -0000	1.3
+++ LCSimLoop.java	17 Aug 2006 21:31:05 -0000	1.4
@@ -1,11 +1,13 @@
 package org.lcsim.util.loop;
 
-import java.util.List;
 import java.io.File;
 import java.io.IOException;
 import java.util.TooManyListenersException;
 
 import org.freehep.record.loop.SequentialRecordLoopImpl;
+import org.freehep.record.source.NoSuchRecordException;
+import org.freehep.record.source.RandomAccessRecordSource;
+import org.freehep.record.source.SequentialRecordSource;
 import org.lcsim.util.Driver;
 import org.lcsim.util.DriverAdapter;
 import org.lcsim.util.event.LCSimEventGenerator;
@@ -59,4 +61,21 @@
     {
         super.setRecordSource(new EventGeneratorRecordSource(gen, "generator"));
     }
+    
+    public void skip(int recordsToSkip) throws NoSuchRecordException, IOException
+    {
+       SequentialRecordSource rs = getRecordSource();
+       if (rs instanceof RandomAccessRecordSource)
+       {
+          RandomAccessRecordSource rrs = (RandomAccessRecordSource) rs;
+          rrs.goToRecord(rrs.currentIndex()+recordsToSkip);
+       }
+       else
+       {
+          for (int i=0; i<recordsToSkip; i++)
+          {
+             rs.next();
+          }
+       }
+    }
 }

lcsim/test
LCIOReadTest.java 1.10 -> 1.11
diff -u -r1.10 -r1.11
--- LCIOReadTest.java	8 Feb 2006 01:18:47 -0000	1.10
+++ LCIOReadTest.java	17 Aug 2006 21:31:07 -0000	1.11
@@ -33,8 +33,6 @@
 
     public void testLCIORead() throws Exception
     {
-        // URL url = new
-        // URL("http://www.lcsim.org/datasamples/slic_sdjan03_K0S_Theta90_1-10GeV.slcio");
         URL url = new URL("http://www.lcsim.org/test/lcio/muons_SLIC_v1r9p1_sidmay05.slcio");
         FileCache cache = new FileCache();
         File file = cache.getCachedFile(url);
@@ -45,16 +43,13 @@
         loop.add(new ReadDriver());
         loop.add(new LCIODriver(new File("test.slcio")));
         loop.loop(-1);
-        // assertEquals(1000, loop.getTotalCountableSupplied());
         assertEquals(200, loop.getTotalCountableSupplied());
         loop.dispose();
     }
 
     public void testLCIOReadChain() throws Exception
     {
-        // URL url = new
-        // URL("http://www.lcsim.org/datasamples/slic_sdjan03_K0S_Theta90_1-10GeV.slcio");
-         URL url = new URL("http://www.lcsim.org/test/lcio/muons_SLIC_v1r9p1_sidmay05.slcio");
+        URL url = new URL("http://www.lcsim.org/test/lcio/muons_SLIC_v1r9p1_sidmay05.slcio");
         FileCache cache = new FileCache();
         File file = cache.getCachedFile(url);
 
@@ -66,10 +61,24 @@
         LCSimLoop loop = new LCSimLoop();
         loop.setLCIORecordSource(es);
         loop.loop(-1);
-        // assertEquals(2000, loop.getTotalCountableSupplied());
         assertEquals(400, loop.getTotalCountableSupplied());
         loop.dispose();
     }
+    public void testSkip() throws Exception
+    {
+        URL url = new URL("http://www.lcsim.org/test/lcio/muons_SLIC_v1r9p1_sidmay05.slcio");
+        FileCache cache = new FileCache();
+        File file = cache.getCachedFile(url);
+
+        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();       
+    }
     private class ReadDriver extends Driver
     {
         private int n;
CVSspam 0.2.8