Print

Print


Commit in lcio on random_access_io_branch
config/lcio.properties+2-21.69.4.1 -> 1.69.4.2
src/java/hep/lcio/implementation/sio/RandomAccessBlock.java+121.1.2.1 -> 1.1.2.2
                                    /IndexBlock.java+151.1.2.1 -> 1.1.2.2
                                    /SIOLCReader.java+142-871.16.10.1 -> 1.16.10.2
bin/runAnalysisJob.sh+2-21.4.10.1 -> 1.4.10.2
+173-91
5 modified files
Another interim checkin. Seems to be partially working now!

lcio/config
lcio.properties 1.69.4.1 -> 1.69.4.2
diff -u -r1.69.4.1 -r1.69.4.2
--- lcio.properties	20 Oct 2009 23:18:22 -0000	1.69.4.1
+++ lcio.properties	27 Oct 2009 23:39:05 -0000	1.69.4.2
@@ -1,7 +1,7 @@
 # ANT property file for LCIO
 #
 # Author: Mark Donszelmann
-# Version: $Id: lcio.properties,v 1.69.4.1 2009/10/20 23:18:22 tonyj Exp $
+# Version: $Id: lcio.properties,v 1.69.4.2 2009/10/27 23:39:05 tonyj Exp $
 #
 debug=true
 
@@ -25,7 +25,7 @@
 test.classpath=lib/lcio.jar;tools/sio.jar;tools/commons-cli-1.0.jar;tools/commons-lang-2.1.jar
 test.format=frames
 
-classpath=src/java;tools/saxpath.jar;tools/jel.jar;tools/jdom.jar;tools/jaxen-core.jar;tools/jaxen-jdom.jar;tools/commons-cli-1.0.jar;tools/commons-lang-2.1.jar;tools/freehep-physics-2.1.jar;tools/freehep-mcfio-2.0.2-SNAPSHOT.jar;tools/freehep-sio-2.1-SNAPSHOT.jar;tools/freehep-stdhep-2.0.3-SNAPSHOT.jar;tools/freehep-xdr-2.0.4-SNAPSHOT.jar
+classpath=src/java;tools/saxpath.jar;tools/jel.jar;tools/jdom.jar;tools/jaxen-core.jar;tools/jaxen-jdom.jar;tools/commons-cli-1.0.jar;tools/commons-lang-2.1.jar;tools/freehep-physics-2.1.jar;tools/freehep-mcfio-2.0.2-SNAPSHOT.jar;tools/freehep-sio-2.1-SNAPSHOT.jar;tools/freehep-stdhep-2.0.3-SNAPSHOT.jar;tools/freehep-xdr-2.0.4-SNAPSHOT.jar;tools/commons-math-1.2.jar
 
 srcpath=src/java
 exp.srcpath=

lcio/src/java/hep/lcio/implementation/sio
RandomAccessBlock.java 1.1.2.1 -> 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- RandomAccessBlock.java	20 Oct 2009 23:18:21 -0000	1.1.2.1
+++ RandomAccessBlock.java	27 Oct 2009 23:39:06 -0000	1.1.2.2
@@ -81,6 +81,18 @@
         sio.close();
     }
 
+    int getRecordCount() {
+        return nRunHeaders+nEvents;
+    }
+
+    int getRunHeaderCount() {
+        return nRunHeaders;
+    }
+
+    int getEventCount() {
+        return nEvents;
+    }
+
     long getIndexLocation() {
         return indexLocation;
     }

lcio/src/java/hep/lcio/implementation/sio
IndexBlock.java 1.1.2.1 -> 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- IndexBlock.java	20 Oct 2009 23:18:21 -0000	1.1.2.1
+++ IndexBlock.java	27 Oct 2009 23:39:06 -0000	1.1.2.2
@@ -9,6 +9,7 @@
 import hep.lcio.event.LCRunHeader;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -152,6 +153,20 @@
         return nRunHeaders;
     }
 
+    long getLocation(RunEvent re) {
+        int position = Collections.binarySearch(index, re);
+        if (position < 0) return -1;
+        else return index.get(position).recordLocation;
+    }
+    
+    long findRecordHeader(long startPosition) {
+        // FIXME: Do something more efficient
+        for (IndexEntry entry : index) {
+           if (entry.recordLocation>startPosition && entry.getEvent() == -1) return entry.recordLocation;
+        }
+        return -1;
+    }
+
     private static class IndexEntry extends RunEvent {
 
         private long recordLocation;

lcio/src/java/hep/lcio/implementation/sio
SIOLCReader.java 1.16.10.1 -> 1.16.10.2
diff -u -r1.16.10.1 -r1.16.10.2
--- SIOLCReader.java	20 Oct 2009 23:18:21 -0000	1.16.10.1
+++ SIOLCReader.java	27 Oct 2009 23:39:06 -0000	1.16.10.2
@@ -16,22 +16,23 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 
 /**
  *
  * @author Tony Johnson
- * @version $Id: SIOLCReader.java,v 1.16.10.1 2009/10/20 23:18:21 tonyj Exp $
+ * @version $Id: SIOLCReader.java,v 1.16.10.2 2009/10/27 23:39:06 tonyj Exp $
  */
 class SIOLCReader implements LCReader
 {
    private List eventListeners = new ArrayList();
    private List runListeners = new ArrayList();
-   private RandomAccessBlock fileRandomAccessBlock;
-   private List<RandomAccessBlock> indexRandomAccessBlocks = new ArrayList<RandomAccessBlock>();
    private SIOReader reader;
-   private boolean indexBlocksRead;
+   private RandomAccessSupport randomAccess;
+   private long lastRecordPosition;
 
    private String[] _filenames ;
    private int _currentIndex ;
@@ -44,6 +45,7 @@
    public void open(String filename) throws IOException
    {
       reader = new SIOReader(filename);
+      randomAccess = new RandomAccessSupport(reader);
    }
 
     /** Opens a list of files for reading (read-only). All subsequent
@@ -98,7 +100,7 @@
          {
             SIORecord record = reader.readRecord();
             String name = record.getRecordName();
-            if (name.equals("LCIORandomAccess")) addRandomAccessRecord(record);
+            if (name.equals("LCIORandomAccess")) randomAccess.addRandomAccessRecord(record);
             if (!name.equals(SIOFactory.eventHeaderRecordName))
                continue;
 
@@ -118,23 +120,24 @@
       }
    }
 
-   public void skipNEvents(int n) 
+   public void skipNEvents(int n) throws IOException
    {
-      int nEvents = 0 ;
-	  try
-	  {
-	     while( nEvents < n )
-	     {
-		    SIORecord record = reader.readRecord();
-		    String name = record.getRecordName();
-		    if ( ! name.equals( SIOFactory.eventHeaderRecordName) )
-			   continue;
-             ++nEvents ;
-	     }
-	  }
-	  catch (IOException x)
-	  {
- 	  }
+      if (randomAccess != null)
+      {
+
+      }
+      else
+      {
+          int nEvents = 0;
+          while( nEvents < n )
+          {
+            SIORecord record = reader.readRecord();
+            String name = record.getRecordName();
+            if ( ! name.equals( SIOFactory.eventHeaderRecordName) )
+               continue;
+            ++nEvents ;
+          }
+      }
    }
    public LCEvent readNextEvent() throws IOException
    {
@@ -148,33 +151,54 @@
 
    public LCRunHeader readNextRunHeader(int accessMode) throws IOException
    {
-      try
+      if (randomAccess != null)
       {
-         for (;;)
+         long position = randomAccess.findNextRunHeader(lastRecordPosition);
+         if (position < 0) return null;
+         else
          {
-            SIORecord record = reader.readRecord();
-            String name = record.getRecordName();
-            if (!name.equals(SIOFactory.runRecordName))
-               continue;
-
+            SIORecord record = reader.readRecord(position);
+            lastRecordPosition = position;
             SIOBlock block = record.getBlock();
-			int major = block.getMajorVersion() ;
-			int minor = block.getMinorVersion() ;
-			if (( major < 1) && ( minor < 8))
+            int major = block.getMajorVersion() ;
+            int minor = block.getMinorVersion() ;
+            if (( major < 1) && ( minor < 8))
                throw new IOException("Sorry: files created with versions older than v00-08" + " are no longer supported !");
 
-	    // FIX ME: need to set access mode here....
+            // FIX ME: need to set access mode here....
             return new SIORunHeader(block.getData(),major,minor);
          }
       }
-      catch (EOFException x)
+      else
       {
-	if( _filenames != null  && ++_currentIndex < _filenames.length ){
-	    close() ;
-	    open( _filenames[ _currentIndex ] ) ;
-	    return readNextRunHeader( accessMode ) ;
-	} 
-         return null;
+          try
+          {
+             for (;;)
+             {
+                SIORecord record = reader.readRecord();
+                String name = record.getRecordName();
+                if (!name.equals(SIOFactory.runRecordName))
+                   continue;
+
+                SIOBlock block = record.getBlock();
+                int major = block.getMajorVersion() ;
+                int minor = block.getMinorVersion() ;
+                if (( major < 1) && ( minor < 8))
+                   throw new IOException("Sorry: files created with versions older than v00-08" + " are no longer supported !");
+
+                // FIX ME: need to set access mode here....
+                return new SIORunHeader(block.getData(),major,minor);
+             }
+          }
+          catch (EOFException x)
+          {
+            if( _filenames != null  && ++_currentIndex < _filenames.length ){
+                close() ;
+                open( _filenames[ _currentIndex ] ) ;
+                return readNextRunHeader( accessMode ) ;
+            }
+             return null;
+          }
       }
    }
 
@@ -261,58 +285,89 @@
       runListeners.remove(ls);
    }
 
-   private void addRandomAccessRecord(SIORecord record) throws IOException
-   {
-      RandomAccessBlock ra = new RandomAccessBlock(record);
-      System.out.println("Found ra="+ra);
-      if (ra.getIndexLocation() == 0) fileRandomAccessBlock = ra;
-      else indexRandomAccessBlocks.add(ra);
-   }
+    private static class RandomAccessSupport {
 
-   private long findNextRunHeader() throws IOException {
-      RandomAccessBlock fab = findFileRandomAccessBlock();
-      for (RandomAccessBlock rab : findIndexRandomAccessBlocks()) {
-          
-      }
-   }
+        private RandomAccessBlock fileRandomAccessBlock;
+        private List<RandomAccessBlock> indexRandomAccessBlocks = new ArrayList<RandomAccessBlock>();
+        private boolean indexBlocksRead;
+        private SIOReader reader;
+        private Map<RandomAccessBlock,IndexBlock> indexHash = new HashMap<RandomAccessBlock,IndexBlock>();
 
-   private long findEvent(int run, int event) throws IOException {
-      if (!indexBlocksRead) readIndexBlocks();
-      // FIXME: Assumes records are ordered
-      RunEvent re = new RunEvent(run,event);
-      if (!fileRandomAccessBlock.contains(re)) return -1;
-
-      int location = Collections.binarySearch(indexRandomAccessBlocks,re);
-      return 0;
-   }
-
-    private void readIndexBlocks() throws IOException {
-       RandomAccessBlock fab = findFileRandomAccessBlock();
-
-       if (indexRandomAccessBlocks.isEmpty()) {
-           SIORecord record = reader.readRecord(fab.getPreviousLocation());
-           RandomAccessBlock rab = new RandomAccessBlock(record);
-           indexRandomAccessBlocks.add(rab);
-           indexBlocksRead =  rab.getNextLocation() == 0;
-       }
-       while (!indexBlocksRead) {
-           long nextLocation = indexRandomAccessBlocks.get(indexRandomAccessBlocks.size()-1).getNextLocation();
-           SIORecord record = reader.readRecord(nextLocation);
-           RandomAccessBlock rab = new RandomAccessBlock(record);
-           indexRandomAccessBlocks.add(rab);
-           indexBlocksRead =  rab.getNextLocation() == 0;
-       }
-    }
+        RandomAccessSupport(SIOReader reader) {
+            this.reader = reader;
+        }
 
-    private RandomAccessBlock findFileRandomAccessBlock() throws IOException {
-        if (fileRandomAccessBlock == null) {
-           SIORecord record = reader.readRecord(0);
-           fileRandomAccessBlock = new RandomAccessBlock(record);
+        private void addRandomAccessRecord(SIORecord record) throws IOException {
+            RandomAccessBlock ra = new RandomAccessBlock(record);
+            System.out.println("Found ra=" + ra);
+            if (ra.getIndexLocation() == 0) {
+                fileRandomAccessBlock = ra;
+            } else {
+                indexRandomAccessBlocks.add(ra);
+            }
+        }
+
+        private long findNextRunHeader(long currentPosition) throws IOException {
+            List<RandomAccessBlock> iab = findIndexRandomAccessBlocks();
+            for (RandomAccessBlock rab : iab) {
+               // FIXME: Do something more efficient
+               if (rab.getRunHeaderCount() > 0)
+               {
+                   IndexBlock ib = findIndexBlock(rab);
+                   long position = ib.findRecordHeader(currentPosition);
+                   if (position >= 0) return position;
+               }
+            }
+            return -1;
+        }
+
+        private long findEvent(int run, int event) throws IOException {
+            RunEvent re = new RunEvent(run, event);
+
+            RandomAccessBlock fab = findFileRandomAccessBlock();
+            if (!fab.contains(re)) {
+                return -1;
+            }
+
+            List<RandomAccessBlock> iab = findIndexRandomAccessBlocks();
+            int location = Collections.binarySearch(iab, re);
+            IndexBlock ib = findIndexBlock(iab.get(location));
+            return ib.getLocation(re);
+        }
+
+        private RandomAccessBlock findFileRandomAccessBlock() throws IOException {
+            if (fileRandomAccessBlock == null) {
+                SIORecord record = reader.readRecord(0);
+                fileRandomAccessBlock = new RandomAccessBlock(record);
+            }
+            return fileRandomAccessBlock;
         }
-        return fileRandomAccessBlock;
-    }
 
-    private Iterable<RandomAccessBlock> findIndexRandomAccessBlocks() {
-        throw new UnsupportedOperationException("Not yet implemented");
+        private List<RandomAccessBlock> findIndexRandomAccessBlocks() throws IOException {
+            RandomAccessBlock fab = findFileRandomAccessBlock();
+            if (indexRandomAccessBlocks.isEmpty()) {
+                SIORecord record = reader.readRecord(fab.getPreviousLocation());
+                RandomAccessBlock rab = new RandomAccessBlock(record);
+                indexRandomAccessBlocks.add(rab);
+                indexBlocksRead = rab.getNextLocation() == 0;
+            }
+            while (!indexBlocksRead) {
+                long nextLocation = indexRandomAccessBlocks.get(indexRandomAccessBlocks.size() - 1).getNextLocation();
+                SIORecord record = reader.readRecord(nextLocation);
+                RandomAccessBlock rab = new RandomAccessBlock(record);
+                indexRandomAccessBlocks.add(rab);
+                indexBlocksRead = rab.getNextLocation() == 0;
+            }
+            return indexRandomAccessBlocks;
+        }
+
+        private IndexBlock findIndexBlock(RandomAccessBlock rab) throws IOException {
+            IndexBlock result = indexHash.get(rab);
+            if (result == null) {
+                result = new IndexBlock(reader.readRecord(rab.getIndexLocation()));
+                indexHash.put(rab,result);
+            }
+            return result;
+        }
     }
 }

lcio/bin
runAnalysisJob.sh 1.4.10.1 -> 1.4.10.2
diff -u -r1.4.10.1 -r1.4.10.2
--- runAnalysisJob.sh	20 Oct 2009 23:18:22 -0000	1.4.10.1
+++ runAnalysisJob.sh	27 Oct 2009 23:39:06 -0000	1.4.10.2
@@ -11,8 +11,8 @@
 # For Cygwin, switch paths to Windows format before running java
 if $cygwin; then
   LOCALCLASSPATH=`cygpath --path --windows "$LOCALCLASSPATH"`
-  java -cp "$LOCALCLASSPATH" hep.lcio.example.AnalysisJob $@
+  java $JVM_ARGS -cp "$LOCALCLASSPATH" hep.lcio.example.AnalysisJob $@
 else
-  java -cp $LOCALCLASSPATH hep.lcio.example.AnalysisJob $@
+  java $JVM_ARGS -cp $LOCALCLASSPATH hep.lcio.example.AnalysisJob $@
 fi
 
CVSspam 0.2.8