Print

Print


Commit in lcio on random_access_io_branch
bin/runRecJob.sh+2-11.3 -> 1.3.10.1
src/cpp/CMakeLists.txt+16-61.22.4.3 -> 1.22.4.4
src/cpp/include/SIO/LCIORandomAccess.h+22-201.1.2.5 -> 1.1.2.6
                   /LCIORandomAccessMgr.h+58-171.1.2.4 -> 1.1.2.5
                   /RunEventMap.h+3-11.1.2.4 -> 1.1.2.5
                   /SIOWriter.h-61.17.10.2 -> 1.17.10.3
src/cpp/src/SIO/LCIORandomAccess.cc+21-221.1.2.4 -> 1.1.2.5
               /LCIORandomAccessMgr.cc+205-81.1.2.4 -> 1.1.2.5
               /SIOReader.cc+88-1811.54.4.5 -> 1.54.4.6
               /SIOWriter.cc+10-821.36.8.2 -> 1.36.8.3
src/cpp/src/TESTS/test_randomaccess.cc+29-301.1.2.4 -> 1.1.2.5
+454-374
11 modified files
first complete version of direct access for C++ ; added some minimal tests
append mode works; cleanup and documentation ;
refactoring: moved most code from SIOReader/Writer to LCIORandomAccessMgr
TODO: iterate on record contents and record position (end vs. start (java))

lcio/bin
runRecJob.sh 1.3 -> 1.3.10.1
diff -u -r1.3 -r1.3.10.1
--- runRecJob.sh	8 Nov 2007 17:37:29 -0000	1.3
+++ runRecJob.sh	1 May 2010 11:12:40 -0000	1.3.10.1
@@ -1,7 +1,8 @@
 #!/bin/sh
 
 LOCALCLASSPATH=$LCIO/lib/lcio.jar:$LCIO/tools/sio.jar
-LOCALCLASSPATH=$LOCALCLASSPATH:$LCIO/tools/freehep-sio-2.0.jar:$LCIO/tools/freehep-xdr-2.0.3.jar
+#LOCALCLASSPATH=$LOCALCLASSPATH:$LCIO/tools/freehep-sio-2.0.jar:$LCIO/tools/freehep-xdr-2.0.3.jar
+LOCALCLASSPATH=$LOCALCLASSPATH:$LCIO/tools/freehep-sio-2.1-SNAPSHOT.jar:$LCIO/tools/freehep-xdr-2.0.4-SNAPSHOT.jar
 
 # OS specific support for Cygwin 
 cygwin=false;

lcio/src/cpp
CMakeLists.txt 1.22.4.3 -> 1.22.4.4
diff -u -r1.22.4.3 -r1.22.4.4
--- CMakeLists.txt	22 Apr 2010 16:34:09 -0000	1.22.4.3
+++ CMakeLists.txt	1 May 2010 11:12:40 -0000	1.22.4.4
@@ -188,6 +188,7 @@
 ADD_LCIO_BIN( dumpevent ) 
 ADD_LCIO_BIN( copyfix ) 
 ADD_LCIO_BIN( stdhepjob ) 
+ADD_LCIO_BIN( addRandomAccess ) 
 
 
 IF( BUILD_LCIO_EXAMPLES )
@@ -236,11 +237,6 @@
 #===================================================================
 
 
-ADD_LCIO_CTEST( test_example ) 
-ADD_LCIO_CTEST( test_calohit )
-ADD_LCIO_CTEST( test_randomaccess) 
-
-
 #------------- install the library and the (public) header files -------
 
 INSTALL( TARGETS lib_LCIO DESTINATION lib PERMISSIONS
@@ -260,14 +256,23 @@
   PATTERN "*CPPFORT*" EXCLUDE
   PATTERN "*CVS*" EXCLUDE)
 
-
 #------------- ctest stuff (call with ctest or 'make test') ------------
 
 ADD_TEST( t_simjob "${EXECUTABLE_OUTPUT_PATH}/simjob" )
+
+ADD_LCIO_CTEST( test_example ) 
+ADD_LCIO_CTEST( test_calohit )
+ADD_LCIO_CTEST( test_randomaccess) 
+
+
+ADD_TEST( t_dumpevent "${EXECUTABLE_OUTPUT_PATH}/dumpevent" simjob.slcio 4 5 )
+#ADD_TEST( t_randomaccessrecords "${PROJECT_SOURCE_DIR}/bin/runSIODump.sh" -v 1 ${PROJECT_SOURCE_DIR}/doc/lcio.xml simjob.slcio | grep RandomAccess )
 ADD_TEST( t_anajob_sim "${EXECUTABLE_OUTPUT_PATH}/anajob" simjob.slcio )
 ADD_TEST( t_recjob "${EXECUTABLE_OUTPUT_PATH}/recjob" simjob.slcio recjob.slcio )
 ADD_TEST( t_anajob_rec "${EXECUTABLE_OUTPUT_PATH}/anajob" recjob.slcio )
 
+
+
 SET_TESTS_PROPERTIES( t_simjob PROPERTIES PASS_REGULAR_EXPRESSION
     "created  10 runs with  100 events" )
 SET_TESTS_PROPERTIES( t_anajob_sim PROPERTIES PASS_REGULAR_EXPRESSION
@@ -276,6 +281,11 @@
     "added collection: 'SomeClusters' and 'SomeTracks' to   100 events and added one extra MCParticle to each event." )
 SET_TESTS_PROPERTIES( t_anajob_rec PROPERTIES PASS_REGULAR_EXPRESSION
     "100 events read from files:" )
+SET_TESTS_PROPERTIES( t_dumpevent PROPERTIES PASS_REGULAR_EXPRESSION
+    "Event  : 5 - run:  4" )
+
+#SET_TESTS_PROPERTIES( t_randomaccessrecords PROPERTIES PASS_REGULAR_EXPRESSION
+#    "Event  : 5 - run:  4" )
 
 IF( BUILD_F77_TESTJOBS )
     ADD_TEST( t_simjob_F "${EXECUTABLE_OUTPUT_PATH}/simjob_F" )

lcio/src/cpp/include/SIO
LCIORandomAccess.h 1.1.2.5 -> 1.1.2.6
diff -u -r1.1.2.5 -r1.1.2.6
--- LCIORandomAccess.h	30 Apr 2010 21:30:52 -0000	1.1.2.5
+++ LCIORandomAccess.h	1 May 2010 11:12:41 -0000	1.1.2.6
@@ -9,25 +9,26 @@
 
 typedef EVENT::long64 long64 ;
 
-struct RunEvent{
-  RunEvent(): RunNum( 0 ), EvtNum( 0 ) {}
-  RunEvent(int run, int evt): RunNum( run ), EvtNum( evt ) {}
-  RunEvent(long64 runEvt): RunNum( (runEvt >> 32 ) & 0xffffffff  ), EvtNum( runEvt &  0xffffffff ) {}
-  int RunNum ;
-  int EvtNum ;
-
-  operator long64() const {  return  ( long64( RunNum ) << 32  |  ( long64(EvtNum) & 0xffffffff )  ) ; } 
-  //bool operator < ( const RunEvent& other) {  return ( RunNum <= other.RunNum && EvtNum < other.EvtNum ) ; } 
-};
-
-std::ostream & operator<<(std::ostream& os, const RunEvent& re ) ;
-
-bool operator < ( const RunEvent& r0, const RunEvent& other)  ;
-
-
-
 namespace SIO{ // IO or IMPL ?
 
+  /** Helper struct that stores run and event positions in the file. The operator<() defines a lexicographical ordering
+   *  in RunNum and EvtNum where all run records (EvtNum=-1) are orderd first. 
+   */
+  struct RunEvent{
+    RunEvent(): RunNum( 0 ), EvtNum( 0 ) {}
+    RunEvent(int run, int evt): RunNum( run ), EvtNum( evt ) {}
+    RunEvent(long64 runEvt): RunNum( (runEvt >> 32 ) & 0xffffffff  ), EvtNum( runEvt &  0xffffffff ) {}
+    int RunNum ;
+    int EvtNum ;
+    
+    operator long64() const {  return  ( long64( RunNum ) << 32  |  ( long64(EvtNum) & 0xffffffff )  ) ; } 
+  };
+  
+  std::ostream & operator<<(std::ostream& os, const RunEvent& re ) ;
+  
+  bool operator < ( const RunEvent& r0, const RunEvent& other)  ;
+  
+
   class SIORandomAccessHandler ;
   class LCIORandomAccess ;
   class LCIORandomAccessMgr ;
@@ -40,7 +41,7 @@
 /**  Implementation class for LCIORandomAccess records.
  *
  * @author gaede
- * @version $Id: LCIORandomAccess.h,v 1.1.2.5 2010/04/30 21:30:52 gaede Exp $
+ * @version $Id: LCIORandomAccess.h,v 1.1.2.6 2010/05/01 11:12:41 gaede Exp $
  */
 //  class LCIORandomAccess : public EVENT LCObject {
   class LCIORandomAccess {
@@ -56,12 +57,13 @@
     
     long64 getIndexLocation() const  { return _indexLocation ; }
     long64 getPrevLocation()  const  { return _prevLocation ; }
-    long64 getNextLocation()  const  { return _nextLocation ; }
+    //   long64 getNextLocation()  const  { return _nextLocation ; }
     long64 getFirstRecordLocation() const  { return _firstRecordLocation ; }
 
 
     void setIndexLocation(long64 il)       { _indexLocation = il ; }
-    void setPreviousLocation(long64 pl)    {  _prevLocation = pl ; }
+    void setPreviousLocation(long64 pl)    { _prevLocation = pl ; }
+    //    void setNextLocation(long64 nl)        { _nextLocation = nl ; }
     void setFirstRecordLocation(long64 fl) { _firstRecordLocation = fl ; }
 
   protected:

lcio/src/cpp/include/SIO
LCIORandomAccessMgr.h 1.1.2.4 -> 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- LCIORandomAccessMgr.h	30 Apr 2010 21:30:52 -0000	1.1.2.4
+++ LCIORandomAccessMgr.h	1 May 2010 11:12:41 -0000	1.1.2.5
@@ -10,7 +10,7 @@
 
 class SIO_stream ;
 
-namespace SIO{ // IO or IMPL ?
+namespace SIO { 
 
   class LCIORandomAccessMgr ;
   class SIOIndexHandler ;
@@ -18,10 +18,21 @@
    
   std::ostream & operator<<(std::ostream& os, const LCIORandomAccessMgr& ra ) ;
 
-/**  Manager class for LCIORandomAccess objects and direct access
+/**  Manager class for LCIO direct access. Provides the functionality for reading and writing the LCIORandomAccess and 
+ *   LCIOIndex records as needed by SIOReader and SIOWriter. 
+ *   Direct Access is implemented through appending LCIOIndex and LCIORandomAccess and records to the end of the LCIO file.
+ *   The LCIOIndex records hold the locations of the RunHeader and EventHeader in the file and are referenced by corresponding
+ *   LCIORandomAccess records. The last record in the file will always be an LCIORandomAccess record - and previous records can
+ *   be found through pointers to the previous record (simply linked list). LCIORandomAccess are always stored uncompressed.
+ *   When reading a file with direct access mode a RunEvent map is created by reading all LCIORandomAccess and LCIOIndex records 
+ *   or - for old files - is recreated from all RunHeader and EventHeader records in the file. If an old file is opened in APPEND 
+ *   mode the corresponding records are created and written at the end on close() @see writeRandomAccessRecords().
+ *   @TODO: currently the last LCIORandomAccess record is found by seeking a fixed size from the end - need to store the actual 
+ *          length as last word in the file for future changes of the records length
+ *   
  *
  * @author gaede
- * @version $Id: LCIORandomAccessMgr.h,v 1.1.2.4 2010/04/30 21:30:52 gaede Exp $
+ * @version $Id: LCIORandomAccessMgr.h,v 1.1.2.5 2010/05/01 11:12:41 gaede Exp $
  */
 
   class LCIORandomAccessMgr {
@@ -36,40 +47,70 @@
     
     virtual ~LCIORandomAccessMgr() ;
  
-    //    void addRunEventMap( const RunEventMap& reMap)  {  _runEvtMap.insert( reMap.begin() , reMap.end()  ) ; }
-    
-    RunEventMap& map() {  return _runEvtMap ;  } 
+    /** Return the position of the specified Event record or Run record respectively (if EventNum == -1 ).
+     *  Returns RunEventMap::NPos if no record found.
+     */
+    long64 getPosition(const RunEvent& re ) {
+      return _runEvtMap.getPosition( re  ) ;
+    }
+
+     /** Add a new entry to the event map - if the RunEvent already exists the new position will be stored.
+     */
+    void add(const RunEvent& re, long64 pos ) {
+      _runEvtMap.add( re , pos ) ;
+    }
+
+    /** Get the run and event header map from the stream - either by reading the random access records or by recreating
+     * it for olf files.
+     */
+    bool getEventMap(SIO_stream* s) ;
+    
+    /** Initialize random access for append mode: read last LCIORandomAccess record if it exists - 
+     *  recreate the RunEvent map from the file if not (old files).
+     */
+    void initAppend( SIO_stream* s) ;
+
+
+    /** Write the current random access records LCIOIndex and LCIORandomAccess to the stream.
+     */
+    void writeRandomAccessRecords(SIO_stream* stream) ;
 
-    LCIORandomAccess* createFromEventMap() ;
+  protected:
     
-    const LCIORandomAccess* lastLCIORandomAccess() {
-
-      return (_list.empty() ?  0 : _list.back() )  ; 
-    } 
+    /** Prepare an LCIORandomAccess object from the current contents of RunEventMap (all file locations set to 0). */
+    LCIORandomAccess* createFromEventMap() ;
 
+    /** Add a new LCIORandomAccess object to the list */
     void addLCIORandomAccess( LCIORandomAccess* ra ) { _list.push_back( ra ) ;  }
     
-
-    //    bool readLastLCIORandomAccess( SIO_stream* stream ) ;
-
+    /** Read the LCIORandomAccess record at the specified position */
     bool readLCIORandomAccessAt( SIO_stream* stream , long64 pos) ;
 
+    /** Read the LCIOIndex record at the specified position */
     bool readLCIOIndexAt( SIO_stream* stream , long64 pos) ;
 
-  protected:
+   /** Fill the RunEventMap from the event and run header records in the file */
+     bool recreateEventMap(SIO_stream*) ;
 
+    /** Helper for reading the next LCIORandomAccess record (need preceeding call to LCSIO::seek() ) */
     bool readLCIORandomAccess( SIO_stream* stream ) ;
 
+    /** Helper for reading the next LCIOIndex record (need preceeding call to LCSIO::seek() ) */
     bool readLCIOIndex( SIO_stream* stream ) ;
    
+    /**Pointer to the last LCIORandomAccess in the list */
+    const LCIORandomAccess* lastLCIORandomAccess() {
+      return (_list.empty() ?  0 : _list.back() )  ; 
+    } 
+
+    // ----- map with RunHeader and EventHeader record positions
     RunEventMap _runEvtMap ;
     
+    // ----- list of LCIORandomAccess objects 
     std::list< LCIORandomAccess* > _list ;
     
   }; // class
   
   
-  
-  
 } // namespace 
 #endif 

lcio/src/cpp/include/SIO
RunEventMap.h 1.1.2.4 -> 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- RunEventMap.h	30 Apr 2010 21:30:52 -0000	1.1.2.4
+++ RunEventMap.h	1 May 2010 11:12:41 -0000	1.1.2.5
@@ -6,14 +6,16 @@
 #include "LCIORandomAccess.h"
 
 namespace SIO {
+
   class RunEventMap ; 
+
   std::ostream & operator<<(std::ostream& os, const RunEventMap& rm ) ;
 
 
 /** Map that holds positions of Run and Event records.
  * 
  * @author gaede
- * @version $Id: RunEventMap.h,v 1.1.2.4 2010/04/30 21:30:52 gaede Exp $
+ * @version $Id: RunEventMap.h,v 1.1.2.5 2010/05/01 11:12:41 gaede Exp $
  */
   class RunEventMap {
 

lcio/src/cpp/include/SIO
SIOWriter.h 1.17.10.2 -> 1.17.10.3
diff -u -r1.17.10.2 -r1.17.10.3
--- SIOWriter.h	30 Apr 2010 21:30:52 -0000	1.17.10.2
+++ SIOWriter.h	1 May 2010 11:12:41 -0000	1.17.10.3
@@ -103,12 +103,6 @@
     virtual void flush() throw (IO::IOException, std::exception) ;
 
 
-    /** Write random access records: LCIOIndex and LCIORandomAccess.
-     *
-     *@throws IOException
-     */
-    void writeRandomAccessRecords() throw (IO::IOException, std::exception) ;
-
   protected:
 
     /** Sets up the handlers for writing the current event.

lcio/src/cpp/src/SIO
LCIORandomAccess.cc 1.1.2.4 -> 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- LCIORandomAccess.cc	30 Apr 2010 21:30:52 -0000	1.1.2.4
+++ LCIORandomAccess.cc	1 May 2010 11:12:41 -0000	1.1.2.5
@@ -1,31 +1,30 @@
 #include "SIO/LCIORandomAccess.h"
 
 
-bool operator < ( const RunEvent& r0, const RunEvent& other) { 
+namespace SIO{
+
   
-  //std::cout << r0 << " < " << other << " : [" 
-  //<<  ( r0.RunNum == other.RunNum ?  r0.EvtNum < other.EvtNum  :  r0.RunNum < other.RunNum )  << "]" << std::endl;
+  bool operator < ( const RunEvent& r0, const RunEvent& other) { 
+    
+    //std::cout << r0 << " < " << other << " : [" 
+    //<<  ( r0.RunNum == other.RunNum ?  r0.EvtNum < other.EvtNum  :  r0.RunNum < other.RunNum )  << "]" << std::endl;
+    
+    if( r0.EvtNum < 0 ) { // sort run records (evtNu == -1 ) first 
+      
+      return ( other.EvtNum < 0 ?  r0.RunNum < other.RunNum : true ) ;
+    }
+    else if( other.EvtNum < 0 ) return false ;
+    
+    return ( r0.RunNum == other.RunNum ?  r0.EvtNum < other.EvtNum  :  r0.RunNum < other.RunNum ) ; 
+  } 
   
-  if( r0.EvtNum < 0 ) { // sort run records (evtNu == -1 ) first 
-
-    return ( other.EvtNum < 0 ?  r0.RunNum < other.RunNum : true ) ;
+  std::ostream & operator<<(std::ostream& os, const RunEvent& re ) {
+    
+    os << " run: " << re.RunNum << " - evt: " << re.EvtNum ;
+    
+    return os ;
   }
-  else if( other.EvtNum < 0 ) return false ;
-
-  return ( r0.RunNum == other.RunNum ?  r0.EvtNum < other.EvtNum  :  r0.RunNum < other.RunNum ) ; 
-} 
-
-std::ostream & operator<<(std::ostream& os, const RunEvent& re ) {
-
-  os << " run: " << re.RunNum << " - evt: " << re.EvtNum ;
-
-  return os ;
-}
-
-namespace SIO{
-
-
-
+  
   bool operator<(const LCIORandomAccess ra0, const LCIORandomAccess& other) {  
     
     return ra0._maxRunEvt < other._minRunEvt ;

lcio/src/cpp/src/SIO
LCIORandomAccessMgr.cc 1.1.2.4 -> 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- LCIORandomAccessMgr.cc	30 Apr 2010 21:30:52 -0000	1.1.2.4
+++ LCIORandomAccessMgr.cc	1 May 2010 11:12:41 -0000	1.1.2.5
@@ -3,6 +3,11 @@
 #include "SIO/LCSIO.h"
 #include "SIO/SIORandomAccessHandler.h"
 #include "SIO/SIOIndexHandler.h"
+#include "SIO/SIOEventHandler.h"
+#include "SIO/SIORunHeaderHandler.h"
+
+#include "IOIMPL/LCEventIOImpl.h"
+#include "IOIMPL/LCRunHeaderIOImpl.h"
 
 #include "SIO_stream.h"
 #include "SIO_blockManager.h"
@@ -89,7 +94,7 @@
 			   + *stream->getName() ) ;
       }
       
-      std::cout << " ... no LCIORandomAccess record found - old file ??? " << std::endl ;
+//       std::cout << " ... no LCIORandomAccess record found - old file ??? " << std::endl ;
       
       return false ;
     }
@@ -136,25 +141,217 @@
   }
 
 
+  void LCIORandomAccessMgr::initAppend( SIO_stream* stream ) {
+
+    // check if the last record is LCIORandomAccess
+    if( ! readLCIORandomAccessAt( stream , -LCSIO_RANDOMACCESS_SIZE) )  {
 
+      // else:
+      recreateEventMap( stream ) ; 
+      return ;
+    }
+  }
 
+  bool LCIORandomAccessMgr::getEventMap( SIO_stream* stream ) {
 
+    // check if the last record is LCIORandomAccess
+    if( ! readLCIORandomAccessAt( stream , -LCSIO_RANDOMACCESS_SIZE) )  {
 
-  std::ostream& operator<<(std::ostream& os, const LCIORandomAccessMgr& ra ){
+      // else:
+      return recreateEventMap( stream ) ; 
+    }
+
+    //read all remaining LCIORandomAccess records
+
+    const LCIORandomAccess* ra = lastLCIORandomAccess() ;
+
+    EVENT::long64 raPos = ra->getPrevLocation() ;
+
+    EVENT::long64 indexPos = ra->getIndexLocation() ;
     
-    os << " LCIORandomAccessMgr:  ----------------------- " << std::endl   ;
+    readLCIOIndexAt( stream , indexPos ) ;
 
-    for( std::list<LCIORandomAccess* >::const_iterator i = ra._list.begin() ; i != ra._list.end() ; ++i ){
+    while( raPos != 0 ){
 
-      os << **i ; 
+      if( readLCIORandomAccessAt( stream , raPos) ){
+
+	ra = lastLCIORandomAccess() ;
+
+	raPos = ra->getPrevLocation() ;	
+
+	//	std::cout << " read ra at " << ra << " : " << *ra << "  - prevPos : " << raPos << std::endl ;
+
+	EVENT::long64 indexPos = ra->getIndexLocation() ;
+
+	readLCIOIndexAt( stream , indexPos ) ;
+
+      }else{
+	throw IOException( std::string( "[LCIORandomAccessMgr::ReadEventMap()] Could not read previous LCIORandomAccess record" ) ) ;
+      }      
     }
 
-    os  <<  ra._runEvtMap   << std::endl ;
+    return true ;
 
-    return os ;
+    //    std::cout << " ... LCIORandomAccess read from stream : "<< *ra << std::endl ;
   }
 
-}
+  bool LCIORandomAccessMgr::recreateEventMap( SIO_stream* stream ) {
 
+//      std::cout << " LCIORandomAccessMgr::getEventMap() recreating event map for direct access ..." 
+// 	       << std::endl ;
 
+    LCSIO::seekStream( stream, 0 ) ;// go to start of file
+    
+    
+    SIO_record* dummyRecord ; 
+    IOIMPL::LCEventIOImpl* evtPtr ;
+    IOIMPL::LCRunHeaderIOImpl* runPtr ;
+    
+    SIORunHeaderHandler runHandler( LCSIO_RUNBLOCKNAME, &runPtr ) ;
+    SIOEventHandler eventHandler( LCSIO_HEADERBLOCKNAME, &evtPtr ) ;
+    
+    SIO_blockManager::remove(  LCSIO_HEADERBLOCKNAME ) ;
+    SIO_blockManager::add( &eventHandler ) ;
+    SIO_blockManager::remove(  LCSIO_RUNBLOCKNAME ) ;
+    SIO_blockManager::add( &runHandler ) ;
+    
+    { // -- scope for unpacking evt and run headers  --------
+      SIORecords::Unpack hdrUnp( SIORecords::Unpack::Header + SIORecords::Unpack::Run ) ;
+      
+      while( true ){
+	
+	
+	//----	  readRecord() ;
+	// read the next record from the stream
+	if( stream->getState()== SIO_STATE_OPEN ){
+	  
+	  unsigned int status =  stream->read( &dummyRecord ) ;
+	  
+	  if( ! (status & 1)  ){
+	    
+	    if( status & SIO_STREAM_EOF ){
+	      break ;
+	    }
+	    
+	    throw IOException( std::string(" io error on stream: ") + *stream->getName() ) ;
+	  }
+	} else {
+	  throw IOException( std::string(" stream not open: ")+ *stream->getName() ) ;
+	}
+	
+	//--
+	int runNum = -1 ;
+	int evtNum = -1 ;
+	
+	if( ! strcmp( dummyRecord->getName()->c_str() , LCSIO_HEADERRECORDNAME )){
+	  
+	  runNum = evtPtr->getRunNumber() ;
+	  evtNum = evtPtr->getEventNumber() ;
+	}
+	if( ! strcmp( dummyRecord->getName()->c_str() , LCSIO_RUNRECORDNAME )){
+	  
+	  runNum = runPtr->getRunNumber() ;
+	}
+	
+	_runEvtMap.add(   RunEvent( runNum , evtNum ) ,  stream->lastRecordStart() ) ;
+	
+	
+	//  	EVENT::long64 key  = (EVENT::long64( runNum ) << 32 ) | evtNum ;
+	//  	std::cout << "  " <<  key << " - " << stream->lastRecordStart()  
+	//  		  << " evt: " << evtNum << std::endl ;
+	
+      } // while
+      
+      
+      LCSIO::seekStream( stream, 0 ) ;// go to start of file
+      
+    }// -- end of scope for unpacking evt header --
+    
+    //     std::cout << " LCIORandomAccessMgr::getEventMap() : done " << std::endl ;
+    
+    return true ;
+  }
+  
+  void LCIORandomAccessMgr::writeRandomAccessRecords(SIO_stream* stream) {
+    
+    if( _runEvtMap.empty() ) { 
+      return ;       // nothing to write          
+    }
+    //-------------------------------------
+
+    SIO_record* accessRecord = LCSIO::records()[ SIORecords::Access ] ;
+    SIO_record* indexRecord  = LCSIO::records()[ SIORecords::Index ] ;
+    
+    SIORandomAccessHandler raHandler (  LCSIO_ACCESSRECORDNAME, this ) ;
+    SIOIndexHandler idxHandler(  LCSIO_INDEXRECORDNAME,   this ) ;
+    
+    accessRecord->connect( &raHandler ) ;
+    indexRecord->connect( &idxHandler ) ;
+    
+    
+    if( stream->getState() != SIO_STATE_OPEN ){
+      throw IOException( std::string( "[LCIORandomAccessMgr::writeRandomAccessRecords] stream not opened: "
+				      +  *stream->getName() ) ) ;
+    }
+
+    //    LCSIO::records().setCompress( _compressionLevel != 0 ) ; 
+    
+    // write LCIOIndex record
+    unsigned int status =  stream->write( LCSIO_INDEXRECORDNAME    ) ;
+    
+    if( !(status & 1)  )
+      throw IOException( std::string( "[LCIORandomAccessMgr::writeRandomAccessRecords] couldn't write LCIOIndex to stream: "
+				      +  *stream->getName() ) ) ;
 
+
+
+    // create the LCIORandomAccess object ( linked list of records ) 
+    LCIORandomAccess* ra = createFromEventMap() ;
+    
+    ra->setIndexLocation( stream->lastRecordStart() ) ;
+
+    //FIXME: mis-use getFirstRecordLocation for now - should become an attribute : "thisLocation"
+    ra->setFirstRecordLocation(  stream->currentPosition()  ) ;
+
+    const LCIORandomAccess* lRa  = lastLCIORandomAccess() ;
+
+    EVENT::long64 prevPos = (  lRa ? lRa->getFirstRecordLocation()  : 0 ) ;
+
+    //    std::cout << " setting previous location : " << prevPos << "  from last ra : " << lRa << std::endl ;  
+
+    ra->setPreviousLocation(  prevPos ) ;
+
+
+    // the last LCIORandomAccess object will be written to the file by the SIORandomAccessHandler
+    addLCIORandomAccess( ra ) ; 
+    
+    
+    // write LCAccess record
+    status =  stream->write( LCSIO_ACCESSRECORDNAME    ) ;
+    
+    if( !(status & 1)  )
+      throw IOException( std::string( "[LCIORandomAccessMgr::writeRandomAccessRecords] couldn't write LCIORandomAccess to stream: "
+				      +  *stream->getName() ) ) ;
+    
+
+
+  }
+
+
+
+  //---------------------------------------------
+
+  std::ostream& operator<<(std::ostream& os, const LCIORandomAccessMgr& ra ){
+    
+    os << " LCIORandomAccessMgr:  ----------------------- " << std::endl   ;
+    
+    for( std::list<LCIORandomAccess* >::const_iterator i = ra._list.begin() ; i != ra._list.end() ; ++i ){
+      
+      os << **i ; 
+    }
+    
+    os  <<  ra._runEvtMap   << std::endl ;
+    
+    return os ;
+  }
+}

lcio/src/cpp/src/SIO
SIOReader.cc 1.54.4.5 -> 1.54.4.6
diff -u -r1.54.4.5 -r1.54.4.6
--- SIOReader.cc	30 Apr 2010 21:41:39 -0000	1.54.4.5
+++ SIOReader.cc	1 May 2010 11:12:41 -0000	1.54.4.6
@@ -40,7 +40,7 @@
 
 typedef EVENT::long64 long64 ;
 
-#define EVENTKEY(RN,EN)  ( EVENT::long64( RN ) << 32 ) | EN 
+//#define EVENTKEY(RN,EN)  ( EVENT::long64( RN ) << 32 ) | EN 
  
 namespace SIO {
 
@@ -166,112 +166,10 @@
   
   void SIOReader::getEventMap() {
 
-    // check if the last record is LCIORandomAccess
-    if( ! _raMgr.readLCIORandomAccessAt( _stream , -LCSIO_RANDOMACCESS_SIZE) )  {
-
-      // else:
-      return recreateEventMap() ; 
-    }
-
-    //read all remaining LCIORandomAccess records
-
-    const LCIORandomAccess* ra = _raMgr.lastLCIORandomAccess() ;
-
-    EVENT::long64 raPos = ra->getPrevLocation() ;
-
-    EVENT::long64 indexPos = ra->getIndexLocation() ;
-    
-    _raMgr.readLCIOIndexAt( _stream , indexPos ) ;
-
-    while( raPos != 0 ){
-
-      if( _raMgr.readLCIORandomAccessAt( _stream , raPos) ){
-
-	ra = _raMgr.lastLCIORandomAccess() ;
-
-	raPos = ra->getPrevLocation() ;	
-
-	//	std::cout << " read ra at " << ra << " : " << *ra << "  - prevPos : " << raPos << std::endl ;
-
-	EVENT::long64 indexPos = ra->getIndexLocation() ;
-
-	_raMgr.readLCIOIndexAt( _stream , indexPos ) ;
-
-      }else{
-	throw IOException( std::string( "[SIOReader::getEventMap()] Could not read previous LCIORandomAccess record" ) ) ;
-      }      
-    }
-
-    //    std::cout << " ... LCIORandomAccess read from stream : "<< *ra << std::endl ;
-
-
-    //std::cout << " ... LCIORandomAccessMgr: "<< _raMgr << std::endl ;
-    
-
+    _raMgr.getEventMap( _stream ) ;
   }
 
   //-------------------------------------------------------------------------------------------
-  void SIOReader::recreateEventMap() {
-
-     std::cout << " SIOReader::getEventMap() recreating event map for direct access ..." 
-	       << std::endl ;
-
-     int status = _stream->seek( 0 ) ; // go to start of file
-
-     if( status != SIO_STREAM_SUCCESS ) 
-       throw IOException( std::string( "[SIOReader::getEventMap()] Can't seek stream to 0 ") ) ;
-    
-    { // -- scope for unpacking evt header --------
-      //      SIOUnpack hdrUnp( SIOUnpack::EVENTHDR ) ;
-      SIORecords::Unpack hdrUnp( SIORecords::Unpack::Header ) ;
-
-      while( true ){
-	
-	SIO_blockManager::remove(  LCSIO_HEADERBLOCKNAME ) ;
-	SIO_blockManager::add( _evtHandler ) ;
-
-	//----	  readRecord() ;
-	// read the next record from the stream
-	if( _stream->getState()== SIO_STATE_OPEN ){
-      
-	  unsigned int status =  _stream->read( &_dummyRecord ) ;
-	  
-	  if( ! (status & 1)  ){
-
-	    if( status & SIO_STREAM_EOF ){
-	      break ;
-	    }
-	    
-	    throw IOException( std::string(" io error on stream: ") + *_stream->getName() ) ;
-	  }
-	} else {
-	  throw IOException( std::string(" stream not open: ")+ *_stream->getName() ) ;
-	}
-	
-	//--
-	int runNum = (*_evtP)->getRunNumber() ;
-	int evtNum = (*_evtP)->getEventNumber() ;
-	
-	//        _evtMap[  EVENTKEY( runNum , evtNum ) ] = _stream->lastRecordStart() ;
-
-	_raMgr.map().add(   RunEvent( runNum , evtNum ) ,  _stream->lastRecordStart() ) ;
-
-
-//  	EVENT::long64 key  = (EVENT::long64( runNum ) << 32 ) | evtNum ;
-//  	std::cout << "  " <<  key << " - " << _stream->lastRecordStart()  
-//  		  << " evt: " << evtNum << std::endl ;
-	
-      } // while
-
-      _stream->seek(0) ; // go to start - FIXME - should we store the current 
-
-      if( status != SIO_STREAM_SUCCESS ) 
-	throw IOException( std::string( "[SIOReader::getEventMap()] Can't seek stream to 0" ) ) ;
-
-    }// -- end of scope for unpacking evt header --
-
-//    std::cout << " SIOReader::getEventMap() : done " << std::endl ;
-  }
 
   void SIOReader::readRecord() throw (IOException , EndOfDataException , std::exception) {
 
@@ -491,93 +389,102 @@
       
 //       return 0 ;
 
-    EVENT::long64 pos = _raMgr.map().getPosition(  EVENTKEY( runNumber,evtNumber ) ) ; 
-
-    if( pos != RunEventMap::NPos ) {
+    if( _readEventMap ) {
       
-      int status = _stream->seek( pos ) ;
-      
-      if( status != SIO_STREAM_SUCCESS ) 
-	throw IOException( std::string( "[SIOReader::readEvent()] Can't seek stream to"
-					" requested position" ) ) ;
-      return readNextEvent() ;
-    } 
-    else 
+ 
+      EVENT::long64 pos = _raMgr.getPosition(  RunEvent( runNumber,evtNumber ) ) ; 
       
-      return 0 ;
-    
-    
+      if( pos != RunEventMap::NPos ) {
+	
+	int status = _stream->seek( pos ) ;
+	
+	if( status != SIO_STREAM_SUCCESS ) 
+	  throw IOException( std::string( "[SIOReader::readEvent()] Can't seek stream to"
+					  " requested position" ) ) ;
+	return readNextEvent() ;
+      } 
+      else {
+	
+	//       std::cout << " could not find event " << runNumber <<  "," << evtNumber << std::endl 
+	// 		<< _raMgr ;
+	
+	return 0 ;
+      }
 
 
+    } else {  // no event map ------------------
 
 
+      std::cout << " WARNING : LCReader::readEvent(run,evt) called but not in direct access Mode  - " << std::endl 
+		<< " use fast skip mechanism instead ..." << std::endl 
+		<< " Too avoid this WARNING create the LCReader with: " << std::endl 
+		<< "       LCFactory::getInstance()->createLCReader( IO::LCReader::directAccess ) ; " << std::endl ;
+
+      // ---- OLD code with fast skip -----------
+       
+      bool runFound = false ;
+      bool evtFound = false ;
+      // check current run - if any
+      if( *_runP != 0 ){
+	if( (*_runP)->getRunNumber() == runNumber ) runFound = true ;
+      }
+      // skip through run headers until run found or EOF
+      while (!runFound ) {
+	if( readNextRunHeader() == 0 ) break ; 
+	runFound = ( (*_runP)->getRunNumber() == runNumber ) ;
+      }
+      if( !runFound ){
+	//       std::stringstream message ;
+	//       message << " run not found: " << runNumber << std::ends ;
+	//       throw NotAvailableException( message.str()  ) ;
+	return 0 ;
+      }
+      { // -- scope for unpacking evt header --------
+	//      SIORecordUnpack hdrUnp( SIOWriter::_hdrRecord ) ;
+	SIORecords::Unpack hdrUnp( SIORecords::Unpack::Header ) ;
 
+	while( !evtFound ){
+	  
+	  try{ 
+	    readRecord() ;
+	  }
+	  catch(EndOfDataException){
+	    return 0 ;
+	  }
+	  
+	  evtFound = ( (*_evtP)->getEventNumber() == evtNumber ) ;
+	}
+      }// -- end of scope for unpacking evt header --
+      
+      if( !evtFound ) return 0 ;
+      
+      { // now read the event record
+	SIORecords::Unpack evtUnp( SIORecords::Unpack::Event ) ;
 
-    /* ---- OLD code with fast skip -----------
-       
-       bool runFound = false ;
-       bool evtFound = false ;
-       // check current run - if any
-       if( *_runP != 0 ){
-       if( (*_runP)->getRunNumber() == runNumber ) runFound = true ;
-       }
-       // skip through run headers until run found or EOF
-       while (!runFound ) {
-       if( readNextRunHeader() == 0 ) break ; 
-       runFound = ( (*_runP)->getRunNumber() == runNumber ) ;
-       }
-       if( !runFound ){
-       //       std::stringstream message ;
-       //       message << " run not found: " << runNumber << std::ends ;
-       //       throw NotAvailableException( message.str()  ) ;
-       return 0 ;
-       }
-       { // -- scope for unpacking evt header --------
-       //      SIORecordUnpack hdrUnp( SIOWriter::_hdrRecord ) ;
-       SIOUnpack hdrUnp( SIOUnpack::EVENTHDR ) ;
-       
-       while( !evtFound ){
-       
-       try{ 
-       readRecord() ;
-       }
-       catch(EndOfDataException){
-       return 0 ;
-       }
-       
-       evtFound = ( (*_evtP)->getEventNumber() == evtNumber ) ;
-       }
-       }// -- end of scope for unpacking evt header --
-       
-       if( !evtFound ) return 0 ;
-       
-       { // now read the event record
-       //      SIORecordUnpack evtUnp( SIOWriter::_evtRecord ) ;
-       SIOUnpack evtUnp( SIOUnpack::EVENT ) ;
-       
-       try{ 
-       readRecord() ;
-       }
-       catch(EndOfDataException){
-       return 0 ;
-       }
-       
-       // set the proper acces mode before returning the event
-       // FIXME : need update mode as well
-       // (*_evtP)->setAccessMode( accessMode ) ;
-       (*_evtP)->setAccessMode( LCIO::READ_ONLY ) ;
-       
-       //       // restore the daughter relations from the parent relations
-       //       SIOParticleHandler::restoreParentDaughterRelations( *_evtP ) ;
-       postProcessEvent() ;
-       
-       return *_evtP ;      
-       }
-       
-    */
+	try{ 
+	  readRecord() ;
+	}
+	catch(EndOfDataException){
+	  return 0 ;
+	}
+	
+	// set the proper acces mode before returning the event
+	// FIXME : need update mode as well
+	// (*_evtP)->setAccessMode( accessMode ) ;
+	(*_evtP)->setAccessMode( LCIO::READ_ONLY ) ;
+	
+	//       // restore the daughter relations from the parent relations
+	//       SIOParticleHandler::restoreParentDaughterRelations( *_evtP ) ;
+	postProcessEvent() ;
+	
+	return *_evtP ;      
+      }
+     
+
+    } //----------   end fast skip --------------------------------------------------   
+   
   }
   
-  
   void SIOReader::close() throw (IOException, std::exception ){
   
     int status  =  SIO_streamManager::remove( _stream ) ;

lcio/src/cpp/src/SIO
SIOWriter.cc 1.36.8.2 -> 1.36.8.3
diff -u -r1.36.8.2 -r1.36.8.3
--- SIOWriter.cc	30 Apr 2010 21:30:52 -0000	1.36.8.2
+++ SIOWriter.cc	1 May 2010 11:12:41 -0000	1.36.8.3
@@ -153,13 +153,8 @@
 	  throw IOException( std::string( "[SIOWriter::open()] Can't open stream for reading TOC: "
 					  + sioFilename ) ) ;
 
-	bool haveTOC = _raMgr.readLCIORandomAccessAt( _stream , -LCSIO_RANDOMACCESS_SIZE ) ;
+	_raMgr.initAppend( _stream ) ;
 
-	if( ! haveTOC ){
-
-	  //TODO: recreateTOC in append mode for older files ...... 
-
-	}
 	_stream->close() ;
 
 	// --- open the file in append mode 	
@@ -198,10 +193,10 @@
       
 
       // store position for random access records
-      _raMgr.map().add( RunEvent(  hdr->getRunNumber(), -1 ) , _stream->lastRecordStart() ) ;
+      _raMgr.add( RunEvent(  hdr->getRunNumber(), -1 ) , _stream->lastRecordStart() ) ;
 
-      std::cout << " writeRunHeader " << hdr->getRunNumber()   << " at position : " << _stream->lastRecordStart()  
-		<< std::endl ;
+//       std::cout << " writeRunHeader " << hdr->getRunNumber()   << " at position : " << _stream->lastRecordStart()  
+// 		<< std::endl ;
 
       if( !(status & 1)  )
 	throw IOException( std::string( "[SIOWriter::writeRunHeader] couldn't write run header to stream: "
@@ -287,11 +282,11 @@
       // write LCEventHeader record
       status =  _stream->write( LCSIO_HEADERRECORDNAME    ) ;
 
-      _raMgr.map().add( RunEvent(  evt->getRunNumber(), evt->getEventNumber()  ) , _stream->lastRecordStart() ) ;
+      _raMgr.add( RunEvent(  evt->getRunNumber(), evt->getEventNumber()  ) , _stream->lastRecordStart() ) ;
 
-      std::cout << " writeEventHeader " << evt->getRunNumber() << " - " << evt->getEventNumber()    
- 		<< " at position : " << _stream->lastRecordStart()  
- 		<< std::endl ;      
+//       std::cout << " writeEventHeader " << evt->getRunNumber() << " - " << evt->getEventNumber()    
+//  		<< " at position : " << _stream->lastRecordStart()  
+//  		<< std::endl ;      
 
       if( ! (status & 1) )
 	throw IOException(  std::string("[SIOWriter::writeEvent] couldn't write event header to stream: "
@@ -312,78 +307,11 @@
     
   }
 
-  void SIOWriter::writeRandomAccessRecords() throw (IOException, std::exception) {
-    
-    if( _raMgr.map().empty() ) { 
-      return ;       // nothing to write          
-    }
-    //-------------------------------------
-
-    SIO_record* accessRecord = LCSIO::records()[ SIORecords::Access ] ;
-    SIO_record* indexRecord  = LCSIO::records()[ SIORecords::Index ] ;
-    
-    SIORandomAccessHandler raHandler (  LCSIO_ACCESSRECORDNAME,  &_raMgr ) ;
-    SIOIndexHandler idxHandler(  LCSIO_INDEXRECORDNAME,   &_raMgr ) ;
-    
-    accessRecord->connect( &raHandler ) ;
-    indexRecord->connect( &idxHandler ) ;
-    
-    
-    if( _stream->getState() != SIO_STATE_OPEN ){
-      throw IOException( std::string( "[SIOWriter::writeRandomAccessRecords] stream not opened: "
-				      +  *_stream->getName() ) ) ;
-    }
-
-    LCSIO::records().setCompress( _compressionLevel != 0 ) ; 
-    
-    // write LCIOIndex record
-    unsigned int status =  _stream->write( LCSIO_INDEXRECORDNAME    ) ;
-    
-    if( !(status & 1)  )
-      throw IOException( std::string( "[SIOWriter::writeRandomAccessRecords] couldn't write LCIOIndex to stream: "
-				      +  *_stream->getName() ) ) ;
-
-
-
-    // create the LCIORandomAccess object ( linked list of records ) 
-    LCIORandomAccess* ra = _raMgr.createFromEventMap() ;
-    
-    ra->setIndexLocation( _stream->lastRecordStart() ) ;
-
-    //FIXME: mis-use getFirstRecordLocation for now - should become an attribute : "thisLocation"
-    ra->setFirstRecordLocation(  _stream->currentPosition()  ) ;
-
-    const LCIORandomAccess* lRa  = _raMgr.lastLCIORandomAccess() ;
-
-    EVENT::long64 prevPos = (  lRa ? lRa->getFirstRecordLocation()  : 0 ) ;
-
-
-    std::cout << " setting previous location : " << prevPos << "  from last ra : " << lRa << std::endl ;  
-
-    ra->setPreviousLocation(  prevPos ) ;
-
-
-
-    // the last LCIORandomAccess object will be written to the file by the SIORandomAccessHandler
-    _raMgr.addLCIORandomAccess( ra ) ; 
-    
-    
-    // write LCAccess record
-    status =  _stream->write( LCSIO_ACCESSRECORDNAME    ) ;
-    
-    if( !(status & 1)  )
-      throw IOException( std::string( "[SIOWriter::writeRandomAccessRecords] couldn't write LCIORandomAccess to stream: "
-				      +  *_stream->getName() ) ) ;
-    
-
-
-  }
-
 
   void SIOWriter::close() throw (IOException, std::exception) {
   
-
-    writeRandomAccessRecords() ;
+    
+    _raMgr.writeRandomAccessRecords( _stream ) ;
 
 
     const std::string* streamName  = _stream->getName() ;

lcio/src/cpp/src/TESTS
test_randomaccess.cc 1.1.2.4 -> 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- test_randomaccess.cc	30 Apr 2010 21:30:52 -0000	1.1.2.4
+++ test_randomaccess.cc	1 May 2010 11:12:41 -0000	1.1.2.5
@@ -4,6 +4,7 @@
 
 #include "tutil.h"
 #include "lcio.h"
+#include <cstdlib>
 
 // #include "EVENT/LCIO.h"
 // #include "IO/LCWriter.h"
@@ -14,6 +15,7 @@
 #include "SIO/LCIORandomAccessMgr.h"
 #include "SIO/RunEventMap.h"
 
+#include "UTIL/LCTOOLS.h"
 
 #include <iostream>
 #include <set>
@@ -100,46 +102,43 @@
 
 
 
+    //if( true ){
+    if( false ){
+        // force test program to fail in this way:
+        MYTEST.FAILED( "oops, something went wrong..." );
+    }
 
 
-    MYTEST.LOG( "  ---------TO DO !!!!!! ---------------------   testing class LCIORandomAccess"  ) ;
-
-    MYTEST( true , true , " LCIORandomAccess " )  ;
-
-
-
-    MYTEST.LOG( "  ---------TO DO !!!!!! ---------------------   testing class LCIORandomAccessMgr"  ) ;
-
-    LCIORandomAccessMgr raMgr ;
+    MYTEST.LOG( "  -------------------------------------    test random access in file simjob.slcio - file must exist ...."  ) ;
 
-    //    raMgr.addRunEventMap( map ) ;
-    
+    // simjob.slcio has written 100 events in 10 runs, closing and re-opening the file after every run 
+    //  this tests writing the random access records in append mode ...
+    //  here we make just one simple test of reading a given event
 
-    MYTEST( true , true , " LCIORandomAccessMgr" )  ;
-  
+    LCReader* lcReader = LCFactory::getInstance()->createLCReader( IO::LCReader::directAccess ) ;
 
+    //    LCReader* lcReader = LCFactory::getInstance()->createLCReader( ) ;
 
+    try{
+      
+      //      std::system("pwd") ;
+      lcReader->open( "simjob.slcio" ) ;
+      
+      LCEvent* evt = lcReader->readEvent( 3 , 4 ) ;
 
-    //MYTEST( true , true , " LCIORandomAccess " )  ;
+      MYTEST( evt !=0  , true  , " LCReader::readEvent( 3 , 4  ) - evt is NULL" );
+      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" );
 
-    //if( true ){
-    if( false ){
-        // force test program to fail in this way:
-        MYTEST.FAILED( "oops, something went wrong..." );
+    }
+    catch( Exception &e ){
+      
+      MYTEST.FAILED( e.what() );
     }
 
-    // example with a try&catch fail condition:
-    //
-    ///////////////////////////////////////////////////////////////////////
-    //LCReader* lcReader = LCFactory::getInstance()->createLCReader() ;
-    //try{
-    //    lcReader->open( "blub.slcio" ) ;
-    //}
-    //catch( Exception &e ){
-    //    MYTEST.FAILED( e.what() );
-    //}
-    //lcReader->close();
-    //delete lcReader;
+    lcReader->close();
+    
+    delete lcReader;
     ///////////////////////////////////////////////////////////////////////
 
     return 0;
CVSspam 0.2.8