Commit in lcio on MAIN
doc/versions.readme+121.88 -> 1.89
src/aid/IO/LCReader.aid+24-41.15 -> 1.16
src/cpp/include/SIO/SIOReader.h+31-51.27 -> 1.28
src/cpp/src/SIO/SIOReader.cc+51-171.56 -> 1.57
src/cpp/src/TESTS/test_randomaccess.cc+21-11.4 -> 1.5
src/java/hep/lcio/example/AnalysisJob.java+91.6 -> 1.7
src/java/hep/lcio/implementation/sio/SIOLCRandomAccessReader.java+50-51.3 -> 1.4
                                    /SIOLCReader.java+28-91.17 -> 1.18
+226-41
8 modified files
  - implemented method LCReader::readRunHeader(int runNumber )  (Java & C++)
  - added access mode to  
      LCReader::readRunHeader(int runNumber, int accessMode )   (Java & C++)
      LCReader::readEvent(int runNumber, int evtNumber, int accessMode ) 

lcio/doc
versions.readme 1.88 -> 1.89
diff -u -r1.88 -r1.89
--- versions.readme	22 Nov 2010 11:34:30 -0000	1.88
+++ versions.readme	7 Dec 2010 14:23:09 -0000	1.89
@@ -2,6 +2,18 @@
  Describes the changes for the different versions/tags of LCIO
 ---------------------------------------------------------------
 ==========
+ v01-52
+==========
+     - implemented method LCReader::readRunHeader(int runNumber ) 
+     - added access mode to  
+         LCReader::readRunHeader(int runNumber, int accessMode ) 
+         LCReader::readEvent(int runNumber, int evtNumber, int accessMode ) 
+     
+     - added example for creating a simple NTuple from MCParticle collection
+       (  ./examples/cpp/rootDict/writeNTuple.C )
+
+
+==========
  v01-51-02
 ==========
      - patch release:

lcio/src/aid/IO
LCReader.aid 1.15 -> 1.16
diff -u -r1.15 -r1.16
--- LCReader.aid	22 Jun 2010 13:47:42 -0000	1.15
+++ LCReader.aid	7 Dec 2010 14:23:09 -0000	1.16
@@ -70,15 +70,35 @@
      * @throws IOException
      */
     public void skipNEvents(int n) throws IOException;
-    /** Reads the specified event from file. 
-     *  To be used with care: events have to be read in sequential 
-     *  order (as LCIO has no direct access yet).  Returns NULL if
-     * 'EOF' read, i.e. the specified event hasn't been found in the file.
+
+    /** Reads the specified runHeader from file. Returns NULL if
+     *  the specified runHeader hasn't been found in the file.
+     *
+     * @throws IOException
+     */
+    public LCRunHeader* readRunHeader(int runNumber ) throws IOException  ;
+    
+    /** Same as LCEvent* readRunHeader(int runNumber) 
+     *  allowing to set the access mode LCIO::READ_ONLY (default) or LCIO::Update.
+     *
+     * @throws IOException
+     */
+    public LCRunHeader* readRunHeader(int runNumber, int accessMode) throws IOException  ;
+
+    /** Reads the specified event from file. Returns NULL if
+     *  the specified event hasn't been found in the file.
      *
      * @throws IOException
      */
     public LCEvent* readEvent(int runNumber, int evtNumber) throws IOException  ;
 
+    /** Same as LCEvent* readEvent(int runNumber, int evtNumber) 
+     *  allowing to set the access mode LCIO::READ_ONLY (default) or LCIO::Update.
+     *
+     * @throws IOException
+     */
+    public LCEvent* readEvent(int runNumber, int evtNumber, int accessMode) throws IOException  ;
+
     /** Closes the output file/stream etc.
      *
      * @throws IOException

lcio/src/cpp/include/SIO
SIOReader.h 1.27 -> 1.28
diff -u -r1.27 -r1.28
--- SIOReader.h	22 Jun 2010 13:49:55 -0000	1.27
+++ SIOReader.h	7 Dec 2010 14:23:09 -0000	1.28
@@ -13,6 +13,7 @@
 
 #include "LCIORandomAccessMgr.h"
 #include "LCIOTypes.h"
+#include "EVENT/LCIO.h"
 
 
 class SIO_record ;
@@ -27,7 +28,7 @@
 /** Concrete implementation of LCWriter using SIO.
  * 
  * @author gaede
- * @version $Id: SIOReader.h,v 1.27 2010/06/22 13:49:55 gaede Exp $
+ * @version $Id: SIOReader.h,v 1.28 2010/12/07 14:23:09 gaede Exp $
  */
   class SIOReader : public IO::LCReader {
     
@@ -94,15 +95,40 @@
     virtual void skipNEvents(int n)   throw (IO::IOException, std::exception )  ;
 
 
-    /** Reads the specified event from file. 
-     *  To be used with care: events have to be read in sequential 
-     *  order (as LCIO has no direct access yet).
+
+    /** Reads the specified runHeader from file. Returns NULL if
+     *  the specified runHeader hasn't been found in the file.
+     *
+     * @throws IOException
+     */
+    virtual EVENT::LCRunHeader * readRunHeader(int runNumber ) 
+      throw (IO::IOException , std::exception) ;
+
+    /** Same as LCEvent* readRunHeader(int runNumber) 
+     *  allowing to set the access mode LCIO::READ_ONLY (default) or LCIO::Update.
+     *
+     * @throws IOException
+     */
+    virtual EVENT::LCRunHeader * readRunHeader(int runNumber, int accessMode ) 
+      throw (IO::IOException , std::exception) ;
+
+    /** Reads the specified event from file. Returns NULL if
+     *  the specified event hasn't been found in the file.
      *
      * @throws IOException
      */
     virtual EVENT::LCEvent * readEvent(int runNumber, int evtNumber) 
-      throw (IO::IOException, std::exception/*, EVENT::NotAvailableException */) ;
+      throw (IO::IOException, std::exception ) ;
 
+
+    /** Same as LCEvent* readEvent(int runNumber, int evtNumber) 
+     *  allowing to set the access mode LCIO::READ_ONLY (default) or LCIO::Update.
+     *
+     * @throws IOException
+     */
+    virtual EVENT::LCEvent * readEvent(int runNumber, int evtNumber, int accessMode) 
+      throw (IO::IOException, std::exception ) ;
+    
     /** Closes the output file/stream etc.
      *
      * @throws IOException

lcio/src/cpp/src/SIO
SIOReader.cc 1.56 -> 1.57
diff -u -r1.56 -r1.57
--- SIOReader.cc	22 Jun 2010 13:49:55 -0000	1.56
+++ SIOReader.cc	7 Dec 2010 14:23:09 -0000	1.57
@@ -13,8 +13,6 @@
 
 #include "LCIOSTLTypes.h"
 
-#include "EVENT/LCIO.h"
-
 #include "SIO_streamManager.h" 
 #include "SIO_recordManager.h" 
 #include "SIO_blockManager.h" 
@@ -372,26 +370,62 @@
     
   }
 
-  EVENT::LCEvent * SIOReader::readEvent(int runNumber, int evtNumber) 
+  EVENT::LCRunHeader * SIOReader::readRunHeader(int runNumber) 
+    throw (IOException , std::exception) {
+
+    return readRunHeader( runNumber, EVENT::LCIO::READ_ONLY ) ;
+  }
+
+  EVENT::LCRunHeader * SIOReader::readRunHeader(int runNumber, int accessMode) 
     throw (IOException , std::exception) {
     
-    
-//     EventMap::iterator it = _evtMap.find( EVENTKEY( runNumber,evtNumber ) ) ;
-//     if( it != _evtMap.end() ) {
-//       int status = _stream->seek( it->second ) ;
-      
-//       if( status != SIO_STREAM_SUCCESS ) 
-// 	throw IOException( std::string( "[SIOReader::readEvent()] Can't seek stream to"
-// 					" requested position" ) ) ;
-//       return readNextEvent() ;
-//     } 
-//     else 
+    if( _readEventMap ) {
+      
+      EVENT::long64 pos = _raMgr.getPosition(  RunEvent( runNumber, -1 ) ) ; 
       
-//       return 0 ;
+      if( pos != RunEventMap::NPos ) {
+	
+	int status = _stream->seek( pos ) ;
+	
+	if( status != SIO_STREAM_SUCCESS ) 
+	  throw IOException( std::string( "[SIOReader::readRunHeader()] Can't seek stream to"
+					  " requested position" ) ) ;
+
+	return readNextRunHeader( accessMode ) ;
+
+      }  else {
+	
+	//       std::cout << " could not find run header " << runNumber << std::endl 
+	// 		<< _raMgr ;
+	
+	return 0 ;
+      }
+
+
+    } else {  // no event map ------------------
+
 
+      std::cout << " WARNING : LCReader::readRunHeader(run) called but not in direct access Mode  - " << std::endl 
+		<< " Too avoid this WARNING create the LCReader with: " << std::endl 
+		<< "       LCFactory::getInstance()->createLCReader( IO::LCReader::directAccess ) ; " << std::endl ;
+
+    }
+
+    return 0 ;
+  }
+
+
+  EVENT::LCEvent * SIOReader::readEvent(int runNumber, int evtNumber) 
+    throw (IOException , std::exception) {
+
+    return readEvent( runNumber, evtNumber , EVENT::LCIO::READ_ONLY ) ;
+  }
+
+  EVENT::LCEvent * SIOReader::readEvent(int runNumber, int evtNumber, int accessMode) 
+    throw (IOException , std::exception) {
+    
     if( _readEventMap ) {
       
- 
       EVENT::long64 pos = _raMgr.getPosition(  RunEvent( runNumber,evtNumber ) ) ; 
       
       if( pos != RunEventMap::NPos ) {
@@ -401,7 +435,7 @@
 	if( status != SIO_STREAM_SUCCESS ) 
 	  throw IOException( std::string( "[SIOReader::readEvent()] Can't seek stream to"
 					  " requested position" ) ) ;
-	return readNextEvent() ;
+	return readNextEvent( accessMode ) ;
       } 
       else {
 	

lcio/src/cpp/src/TESTS
test_randomaccess.cc 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- test_randomaccess.cc	7 Oct 2010 19:32:16 -0000	1.4
+++ test_randomaccess.cc	7 Dec 2010 14:23:10 -0000	1.5
@@ -9,7 +9,9 @@
 // #include "EVENT/LCIO.h"
 // #include "IO/LCWriter.h"
 // #include "IMPL/LCEventImpl.h" 
-// #include "IMPL/LCCollectionVec.h"
+
+
+#include "IMPL/LCRunHeaderImpl.h"
 
 #include "SIO/LCIORandomAccess.h"
 #include "SIO/LCIORandomAccessMgr.h"
@@ -140,6 +142,24 @@
       MYTEST( evt->getRunNumber() , 3 , " LCReader::readEvent( 3, 4  ) - run number is not 3" );
       MYTEST( evt->getEventNumber() , 4 , " LCReader::readEvent( 3, 4  ) - event number is not 4" );
 
+
+
+      // test direct access of run  headers
+      rHdr = lcReader->readRunHeader( 7 ) ;
+      MYTEST( rHdr->getRunNumber() , 7 , " LCReader::readRunHeader() - run number is not 7" );
+      rHdr = lcReader->readRunHeader( 3 ) ;
+      MYTEST( rHdr->getRunNumber() , 3 , " LCReader::readRunHeader() - run number is not 3" );
+
+      rHdr = lcReader->readRunHeader( 0 , EVENT::LCIO::UPDATE ) ;
+      //rHdr = lcReader->readRunHeader( 0 ) ;
+      IMPL::LCRunHeaderImpl* rhImpl = dynamic_cast< IMPL::LCRunHeaderImpl*> ( rHdr ) ;
+      bool notNull = rhImpl != 0 ;
+      MYTEST( notNull , true , " readRunHeader not of type IMPL::LCRunHeaderImpl " );
+
+      rhImpl->setRunNumber( 42 ) ;
+      MYTEST( rHdr->getRunNumber() , 42 , " LCReader::readRunHeader() - run number to changed to 42 in update mode " );
+ 
+
     }
     catch( Exception &e ){
       

lcio/src/java/hep/lcio/example
AnalysisJob.java 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- AnalysisJob.java	21 Oct 2005 13:53:21 -0000	1.6
+++ AnalysisJob.java	7 Dec 2010 14:23:10 -0000	1.7
@@ -26,6 +26,15 @@
       LCReader lcReader = LCFactory.getInstance().createLCReader();
       lcReader.open(args);
 
+   /**fg: ... test code for direct access to run header .... 
+      for(int i=9 ; i > -1 ; --i)
+      {
+         LCRunHeader runHdr = lcReader.readRunHeader(i);
+         if (runHdr == null)
+            break;
+         System.out.println("  Run : " + runHdr.getRunNumber() + " - " + runHdr.getDetectorName() + ":  " + runHdr.getDescription());
+      }
+    */
       for (;;)
       {
          LCRunHeader runHdr = lcReader.readNextRunHeader();

lcio/src/java/hep/lcio/implementation/sio
SIOLCRandomAccessReader.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- SIOLCRandomAccessReader.java	30 Jun 2010 00:10:48 -0000	1.3
+++ SIOLCRandomAccessReader.java	7 Dec 2010 14:23:10 -0000	1.4
@@ -89,16 +89,36 @@
             return super.readNextRunHeader(accessMode);
         }
     }
+    public LCRunHeader readRunHeader(int runNumber, int accessMode)
+    throws IOException {
+        if (randomAccess != null) {
+            long position = randomAccess.findRunHeader(runNumber) ;
+            if (position < 0) {
+                throw new IOException(String.format("Run: %d not found", runNumber));
+            }
+            SIORecord record = reader.readRecord(position);
+            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 !");
+//            }
 
-    //FIXME: What about accessMode?
-    public LCEvent readEvent(int runNumber, int evtNumber) throws IOException {
+            // FIX ME: need to set access mode here....
+            return new SIORunHeader(block.getData(), major, minor);
+        } else {
+            return super.readRunHeader(runNumber );
+        }
+    }
+
+    public LCEvent readEvent(int runNumber, int evtNumber, int accessMode) throws IOException {
         if (randomAccess != null) {
             long position = randomAccess.findEvent(runNumber, evtNumber);
             if (position < 0) {
                 throw new IOException(String.format("Run: %d Event: %d not found", runNumber, evtNumber));
             }
             SIORecord record = reader.readRecord(position);
-            SIOEvent event = new SIOEvent(record, LCIO.READ_ONLY);
+            SIOEvent event = new SIOEvent(record, accessMode );
             event.readData(reader.readRecord());
             return event;
         } else {
@@ -117,7 +137,9 @@
 
     private interface RandomAccessSupport {
 
-        long findNextRunHeader() throws IOException;
+    	long findNextRunHeader() throws IOException;
+    	
+    	long findRunHeader(int runNum ) throws IOException;
 
         void skipNEvents(int n) throws IOException;
 
@@ -157,6 +179,15 @@
             reader = fileBlocks.get(location).reader;
             return fileBlocks.get(location).findEvent(run, event);
         }
+
+		public long findRunHeader(int runNum) throws IOException {
+			
+            RunEvent re = new RunEvent(runNum, -1 );
+
+          int location = Collections.binarySearch(fileRandomAccessBlocks, re);
+          reader = fileBlocks.get(location).reader;
+          return fileBlocks.get(location).findRunHeader(runNum);
+		}
     }
 
     private static class FileRandomAccessSupport implements RandomAccessSupport {
@@ -173,7 +204,21 @@
             fileRandomAccessBlock = new RandomAccessBlock(record);
         }
 
-        public long findNextRunHeader() throws IOException {
+        public long findRunHeader(int runNum) throws IOException {
+            RunEvent re = new RunEvent( runNum, -1 );
+
+            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);
+		}
+
+		public long findNextRunHeader() throws IOException {
             List<RandomAccessBlock> iab = findIndexRandomAccessBlocks();
             int iabIndex = findIndexOfRandomAccessBlockContaining(reader.getNextRecordPosition());
             for (RandomAccessBlock rab : iab.subList(iabIndex, iab.size())) {

lcio/src/java/hep/lcio/implementation/sio
SIOLCReader.java 1.17 -> 1.18
diff -u -r1.17 -r1.18
--- SIOLCReader.java	22 Jun 2010 13:49:56 -0000	1.17
+++ SIOLCReader.java	7 Dec 2010 14:23:10 -0000	1.18
@@ -23,7 +23,7 @@
 /**
  *
  * @author Tony Johnson
- * @version $Id: SIOLCReader.java,v 1.17 2010/06/22 13:49:56 gaede Exp $
+ * @version $Id: SIOLCReader.java,v 1.18 2010/12/07 14:23:10 gaede Exp $
  */
 class SIOLCReader implements LCReader
 {
@@ -59,8 +59,26 @@
       reader = new SIOReader(filenames.get(currentFile));
    }
 
-   public LCEvent readEvent(int runNumber, int evtNumber) throws IOException
-   {
+
+
+   public LCRunHeader readRunHeader(int runNumber) throws IOException {
+	   return readRunHeader(runNumber, LCIO.READ_ONLY ) ;
+   }
+
+   public LCRunHeader readRunHeader(int runNumber, int accessMode)
+   		throws IOException {
+	   //fg: FIXME: reading dedicated run header not supported when not in direct access mode
+	   	return null ;
+   }
+   
+   public LCEvent readEvent(int runNumber, int evtNumber) throws IOException {
+	
+	   return readEvent(runNumber, evtNumber, LCIO.READ_ONLY );
+   }
+   
+   public LCEvent readEvent(int runNumber, int evtNumber, int accessMode)
+	 throws IOException {
+   
       try
       {
          for (;;)
@@ -69,7 +87,7 @@
             String name = record.getRecordName();
             if (!SIOFactory.eventHeaderRecordName.equals(name)) continue;
 
-            SIOEvent event = new SIOEvent(record,LCIO.READ_ONLY);
+            SIOEvent event = new SIOEvent(record, accessMode );
             if (event.getRunNumber() == runNumber && event.getEventNumber() == evtNumber)
             {
                event.readData(reader.readRecord());
@@ -80,12 +98,12 @@
       }
       catch (EOFException x)
       {
-	if( nextFile() ) {
-	    return readEvent( runNumber, evtNumber) ;
-	} 
-	return null;
+    	  if( nextFile() ) {
+    		  return readEvent( runNumber, evtNumber) ;
+	      } 
+	  return null;
       }
-   }
+    }
 
    public LCEvent readNextEvent(int accessMode) throws IOException
    {
@@ -256,4 +274,5 @@
       }
       else return false;
    }
+
 }
CVSspam 0.2.8