Commit in lcio/src/cpp on random_access_io_branch
include/SIO/LCIORandomAccessMgr.h+9-31.1.2.5 -> 1.1.2.6
src/SIO/LCIORandomAccessMgr.cc+106-211.1.2.5 -> 1.1.2.6
       /SIOWriter.cc+31.36.8.3 -> 1.36.8.4
src/TESTS/test_randomaccess.cc+4-41.1.2.5 -> 1.1.2.6
+122-28
4 modified files
 - added a 'file record' at the end of each file (needed for JAVA)   
    ( previous file records are not overwritten so far)

lcio/src/cpp/include/SIO
LCIORandomAccessMgr.h 1.1.2.5 -> 1.1.2.6
diff -u -r1.1.2.5 -r1.1.2.6
--- LCIORandomAccessMgr.h	1 May 2010 11:12:41 -0000	1.1.2.5
+++ LCIORandomAccessMgr.h	26 May 2010 10:22:21 -0000	1.1.2.6
@@ -32,7 +32,7 @@
  *   
  *
  * @author gaede
- * @version $Id: LCIORandomAccessMgr.h,v 1.1.2.5 2010/05/01 11:12:41 gaede Exp $
+ * @version $Id: LCIORandomAccessMgr.h,v 1.1.2.6 2010/05/26 10:22:21 gaede Exp $
  */
 
   class LCIORandomAccessMgr {
@@ -81,7 +81,7 @@
     LCIORandomAccess* createFromEventMap() ;
 
     /** Add a new LCIORandomAccess object to the list */
-    void addLCIORandomAccess( LCIORandomAccess* ra ) { _list.push_back( ra ) ;  }
+    void addLCIORandomAccess( LCIORandomAccess* ra ) ;
     
     /** Read the LCIORandomAccess record at the specified position */
     bool readLCIORandomAccessAt( SIO_stream* stream , long64 pos) ;
@@ -98,6 +98,10 @@
     /** Helper for reading the next LCIOIndex record (need preceeding call to LCSIO::seek() ) */
     bool readLCIOIndex( SIO_stream* stream ) ;
    
+
+    /** Create file record from all LCIORandomAccess records */
+    void createFileRecord() ;
+
     /**Pointer to the last LCIORandomAccess in the list */
     const LCIORandomAccess* lastLCIORandomAccess() {
       return (_list.empty() ?  0 : _list.back() )  ; 
@@ -108,7 +112,9 @@
     
     // ----- list of LCIORandomAccess objects 
     std::list< LCIORandomAccess* > _list ;
-    
+
+    LCIORandomAccess* _fileRecord ;
+
   }; // class
   
   

lcio/src/cpp/src/SIO
LCIORandomAccessMgr.cc 1.1.2.5 -> 1.1.2.6
diff -u -r1.1.2.5 -r1.1.2.6
--- LCIORandomAccessMgr.cc	1 May 2010 11:12:41 -0000	1.1.2.5
+++ LCIORandomAccessMgr.cc	26 May 2010 10:22:21 -0000	1.1.2.6
@@ -20,7 +20,7 @@
 namespace SIO{
 
 
-  LCIORandomAccessMgr::LCIORandomAccessMgr() {
+  LCIORandomAccessMgr::LCIORandomAccessMgr() : _fileRecord(0) {
   }
 
   LCIORandomAccessMgr::~LCIORandomAccessMgr() {
@@ -31,17 +31,18 @@
       delete *i ; 
     }
 
+    if( _fileRecord != 0 ) 
+      delete _fileRecord ;
   }
 
-
   LCIORandomAccess* LCIORandomAccessMgr::createFromEventMap() {
 
     LCIORandomAccess* ra = new LCIORandomAccess  ;
     
     ra->_minRunEvt =   _runEvtMap.minRunEvent() ;
     ra->_maxRunEvt =   _runEvtMap.maxRunEvent() ;
-    ra->_nRunHeaders = _runEvtMap.getNumberOfEventRecords() ;
-    ra->_nEvents =     _runEvtMap.getNumberOfRunRecords() ;
+    ra->_nRunHeaders = _runEvtMap.getNumberOfRunRecords() ;
+    ra->_nEvents =     _runEvtMap.getNumberOfEventRecords() ;
     
     ra->_recordsAreInOrder =  true ;  //  ???? how is this defined ????  
     ra->_indexLocation = 0 ;
@@ -51,16 +52,61 @@
 
     return ra ;
   }
- 
-//   bool LCIORandomAccessMgr::readLastLCIORandomAccess( SIO_stream* stream ) {
-//     // go to the end and see if the last record is of type LCIORandomAccess 
-//     const int LCIORandomAccess_Size = 132  ; //FIXME - define globally or store at end of file ....
 
-//     LCSIO::seekStream( stream,  -LCIORandomAccess_Size ) ;
 
-//     return readLCIORandomAccess( stream ) ;
-//   }
 
+  void LCIORandomAccessMgr::createFileRecord(){
+
+    if( _fileRecord == 0 ) {
+
+      _fileRecord = new LCIORandomAccess ;
+      
+      _fileRecord->_minRunEvt = RunEvent( 2147483647L, 2147483647L ) ; // 2**31-1  - largest 32 bit signed 
+      _fileRecord->_maxRunEvt = 0 ;
+      _fileRecord->_nRunHeaders = 0 ;
+      _fileRecord->_nEvents = 0 ;
+      _fileRecord->_recordsAreInOrder = 1 ;  
+      _fileRecord->_indexLocation = 0 ; // defines file record
+      _fileRecord->_prevLocation = 9223372036854775807LL ; // 2**63-1  - largest 64 bit signed 
+      _fileRecord->_nextLocation = 0 ;
+      _fileRecord->_firstRecordLocation = 0 ;
+      
+    } 
+    
+    
+    for( std::list<LCIORandomAccess* >::const_iterator i = _list.begin() ; i != _list.end() ; ++i ){
+      LCIORandomAccess* ra = *i ; 
+      
+	_fileRecord->_minRunEvt = ( ra->_minRunEvt < _fileRecord->_minRunEvt ?  ra->_minRunEvt : _fileRecord->_minRunEvt  ) ;
+	_fileRecord->_maxRunEvt = ( ra->_maxRunEvt > _fileRecord->_maxRunEvt ?  ra->_maxRunEvt : _fileRecord->_maxRunEvt  ) ;
+	_fileRecord->_nRunHeaders += ra->_nRunHeaders ;
+	_fileRecord->_nEvents += ra->_nEvents ;
+	_fileRecord->_recordsAreInOrder = ( _fileRecord->_recordsAreInOrder * ra->_recordsAreInOrder  ) ; // should be 0 if any record is 0  
+	_fileRecord->_indexLocation = 0 ; // defines file record
+
+	if( ra->_nextLocation > _fileRecord->_nextLocation )
+	  _fileRecord->_nextLocation  =  ra->_nextLocation ;
+	
+	if( 0 < ra->_prevLocation  &&  ra->_prevLocation < _fileRecord->_prevLocation )
+	  _fileRecord->_prevLocation  =  ra->_prevLocation ;
+	
+	
+	//  _fileRecord->_firstRecordLocation = 0 ;
+	    
+    }
+	  
+  }
+
+  void  LCIORandomAccessMgr::addLCIORandomAccess( LCIORandomAccess* ra ) { 
+    
+    _list.push_back( ra ) ; 
+    
+    //       _list.sort() ;
+    //       for( std::list<LCIORandomAccess* >::const_iterator i = _list.begin() ; i != _list.end() ; ++i ){
+// 	std::cout << "++++++++++++++++++++++++++++++++++++++ "  << **i ; 
+//       }
+
+    }
 
 
   bool LCIORandomAccessMgr::readLCIORandomAccessAt( SIO_stream* stream , long64 pos) {
@@ -94,11 +140,13 @@
 			   + *stream->getName() ) ;
       }
       
-//       std::cout << " ... no LCIORandomAccess record found - old file ??? " << std::endl ;
+      // std::cout << " ... no LCIORandomAccess record found - old file ??? " << std::endl ;
       
       return false ;
     }
     
+    //    std::cout << " ...  LCIORandomAccess record found - return true ;-) " << std::endl ;
+
     return true ;
   }
 
@@ -142,26 +190,41 @@
 
 
   void LCIORandomAccessMgr::initAppend( SIO_stream* stream ) {
-
-    // check if the last record is LCIORandomAccess
+    
+    // check if the last record is LCIORandomAccess  (the file record )
     if( ! readLCIORandomAccessAt( stream , -LCSIO_RANDOMACCESS_SIZE) )  {
-
-      // else:
+      
       recreateEventMap( stream ) ; 
+      
       return ;
     }
+    
+    // store the file record separately 
+    _fileRecord = _list.back() ;
+    _list.pop_back()  ;
+
+    // no read first LCIORandomAccess record 
+    readLCIORandomAccessAt( stream ,   _fileRecord->_nextLocation    ) ; // start of last LCIORandomAccessRecord	
   }
 
+
   bool LCIORandomAccessMgr::getEventMap( SIO_stream* stream ) {
 
-    // check if the last record is LCIORandomAccess
+    // check if the last record is LCIORandomAccess ( the file record )
     if( ! readLCIORandomAccessAt( stream , -LCSIO_RANDOMACCESS_SIZE) )  {
 
-      // else:
       return recreateEventMap( stream ) ; 
     }
 
-    //read all remaining LCIORandomAccess records
+    // store the file record separately 
+    _fileRecord = _list.back() ;
+    _list.pop_back()  ;
+
+    // no read first LCIORandomAccess record 
+    readLCIORandomAccessAt( stream ,   _fileRecord->_nextLocation    ) ; // start of last LCIORandomAccessRecord	
+
+
+    // and then read all remaining LCIORandomAccess records
 
     const LCIORandomAccess* ra = lastLCIORandomAccess() ;
 
@@ -311,7 +374,8 @@
     ra->setIndexLocation( stream->lastRecordStart() ) ;
 
     //FIXME: mis-use getFirstRecordLocation for now - should become an attribute : "thisLocation"
-    ra->setFirstRecordLocation(  stream->currentPosition()  ) ;
+    long64 thisPos = stream->currentPosition() ;
+    ra->setFirstRecordLocation(  thisPos  ) ;
 
     const LCIORandomAccess* lRa  = lastLCIORandomAccess() ;
 
@@ -335,8 +399,29 @@
     
 
 
-  }
+    //--------  now we write the file record at the end -------------------------------------
+
+    createFileRecord() ;
 
+    if( thisPos > _fileRecord->_nextLocation )
+      _fileRecord->_nextLocation  =  thisPos ;
+    
+    if( _fileRecord->_prevLocation > thisPos )
+      _fileRecord->_prevLocation  =  thisPos ;
+
+    addLCIORandomAccess( _fileRecord ) ; 
+    
+    status =  stream->write( LCSIO_ACCESSRECORDNAME    ) ;
+    
+    if( !(status & 1)  )
+      throw IOException( std::string( "[LCIORandomAccessMgr::writeRandomAccessRecords] couldn't write LCIORandomAccess file record to stream: "
+				      +  *stream->getName() ) ) ;
+    
+    
+    _list.pop_back()  ;
+
+  }
+  
 
 
   //---------------------------------------------

lcio/src/cpp/src/SIO
SIOWriter.cc 1.36.8.3 -> 1.36.8.4
diff -u -r1.36.8.3 -r1.36.8.4
--- SIOWriter.cc	1 May 2010 11:12:41 -0000	1.36.8.3
+++ SIOWriter.cc	26 May 2010 10:22:21 -0000	1.36.8.4
@@ -160,6 +160,9 @@
 	// --- open the file in append mode 	
 	status  = _stream->open( sioFilename.c_str() , SIO_MODE_WRITE_APPEND ) ; 
 
+	// the file record will be overwritten with the next record ...
+	//	LCSIO::seekStream( _stream, -LCSIO_RANDOMACCESS_SIZE ) ; 
+
 	break ;
       }
 

lcio/src/cpp/src/TESTS
test_randomaccess.cc 1.1.2.5 -> 1.1.2.6
diff -u -r1.1.2.5 -r1.1.2.6
--- test_randomaccess.cc	1 May 2010 11:12:41 -0000	1.1.2.5
+++ test_randomaccess.cc	26 May 2010 10:22:21 -0000	1.1.2.6
@@ -109,7 +109,8 @@
     }
 
 
-    MYTEST.LOG( "  -------------------------------------    test random access in file simjob.slcio - file must exist ...."  ) ;
+    MYTEST.LOG( "  -------------------------------------    test random access in file simjob.slcio - file must exist in : "  ) ;
+    std::system("pwd") ;
 
     // 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 ...
@@ -120,9 +121,8 @@
     //    LCReader* lcReader = LCFactory::getInstance()->createLCReader( ) ;
 
     try{
-      
-      //      std::system("pwd") ;
-      lcReader->open( "simjob.slcio" ) ;
+
+       lcReader->open( "simjob.slcio" ) ;
       
       LCEvent* evt = lcReader->readEvent( 3 , 4 ) ;
 
CVSspam 0.2.8