5 modified files
lcio/doc
diff -u -r1.58 -r1.59
--- versions.readme 19 Sep 2007 06:57:16 -0000 1.58
+++ versions.readme 16 Oct 2007 16:22:45 -0000 1.59
@@ -3,6 +3,15 @@
---------------------------------------------------------------
=====================
+v01-08-05 --- in preparation
+=====================
+ no changes in file format and API
+
+ - experimental code for direct access (C++)
+ (LCReader builds event map at open())
+ - readEvent( rNum , evtNum ) uses direct access
+
+=====================
v01-08-04
=====================
bug fix release
lcio/sio/include
diff -u -r1.4 -r1.5
--- SIO_stream.h 9 Dec 2005 19:01:47 -0000 1.4
+++ SIO_stream.h 16 Oct 2007 16:22:45 -0000 1.5
@@ -1,5 +1,5 @@
// ----------------------------------------------------------------------------
-// CVS $Id: SIO_stream.h,v 1.4 2005/12/09 19:01:47 jeremy Exp $
+// CVS $Id: SIO_stream.h,v 1.5 2007/10/16 16:22:45 gaede Exp $
// ----------------------------------------------------------------------------
// => Controller for a single SIO stream.
// ----------------------------------------------------------------------------
@@ -50,6 +50,10 @@
unsigned int write( const char* );
unsigned int write( SIO_record* );
+ // return the start of the last record read; -1 if not sucessfull
+ SIO_64BITINT lastRecordStart() { return recPos ; }
+ unsigned int seek(SIO_64BITINT pos) ;
+
private:
SIO_stream( const char *, unsigned int, SIO_verbosity );
~SIO_stream();
@@ -81,6 +85,9 @@
SIO_stream_state state; // Stream state
SIO_verbosity verbosity; // Reporting level
+ SIO_64BITINT recPos ; // start Position of last record read
+
+
friend class SIO_streamManager; // Access to constructor/destructor
friend class SIO_record; // Access to buffer
friend class SIO_functions; // Access to buffer and pointer maps
lcio/sio/src
diff -u -r1.3 -r1.4
--- SIO_stream.cc 11 May 2005 00:40:45 -0000 1.3
+++ SIO_stream.cc 16 Oct 2007 16:22:45 -0000 1.4
@@ -1,5 +1,5 @@
// ----------------------------------------------------------------------------
-// CVS $Id: SIO_stream.cc,v 1.3 2005/05/11 00:40:45 tonyj Exp $
+// CVS $Id: SIO_stream.cc,v 1.4 2007/10/16 16:22:45 gaede Exp $
// ----------------------------------------------------------------------------
// => Controller for a single SIO stream.
// ----------------------------------------------------------------------------
@@ -544,6 +544,48 @@
return( SIO_STREAM_SUCCESS );
}
+
+
+//
+//fg: add method to position the file pointer
+//
+unsigned int SIO_stream::seek(SIO_64BITINT pos) {
+
+ unsigned int status;
+
+ //
+ // This must be a readable stream!
+ //
+ if( mode != SIO_MODE_READ ) {
+
+ if( verbosity >= SIO_ERRORS ) {
+
+ std::cout << "SIO: [" << name << "//] "
+ << "Cannot seek (stream is write only)"
+ << std::endl;
+ }
+ return( SIO_STREAM_WRITEONLY );
+ }
+
+ status = fseek( handle, pos , SEEK_SET ) ;
+
+ if( status != 0 ) {
+
+ state = SIO_STATE_ERROR;
+
+ if( verbosity >= SIO_ERRORS ) {
+
+ std::cout << "SIO: [" << name << "/] "
+ << "Failed seeking position" << pos
+ << std::endl;
+ }
+ return( SIO_STREAM_EOF );
+ }
+
+ return( SIO_STREAM_SUCCESS );
+}
+
+
// ----------------------------------------------------------------------------
// Read the next record.
// ----------------------------------------------------------------------------
@@ -578,6 +620,9 @@
//
*record = NULL;
+ recPos = -1 ;
+ SIO_64BITINT recStart = -1 ;
+
//
// The stream must be open!
//
@@ -612,6 +657,9 @@
requested = false;
while( requested == false )
{
+
+ recStart = std::ftell( handle ) ;
+
//
// Initialize the buffer and read the first eight bytes. A read failure
// at this point is treated as an end-of-file (even if there are a few
@@ -933,7 +981,11 @@
<< "Unpacking error"
<< std::endl;
}
+ } else {
+ // save position of record start // can be queried with lastRecordStart()
+ recPos = recStart ;
}
+
}
//
lcio/src/cpp/include/SIO
diff -u -r1.24 -r1.25
--- SIOReader.h 21 Oct 2005 13:53:19 -0000 1.24
+++ SIOReader.h 16 Oct 2007 16:22:45 -0000 1.25
@@ -3,12 +3,14 @@
#include <string>
#include <set>
+#include <map>
#include "IO/LCReader.h"
#include "IO/LCEventListener.h"
#include "IO/LCRunListener.h"
#include "IOIMPL/LCEventIOImpl.h"
#include "IOIMPL/LCRunHeaderIOImpl.h"
+#include "LCIOTypes.h"
class SIO_record ;
class SIO_stream ;
@@ -22,10 +24,12 @@
/** Concrete implementation of LCWriter using SIO.
*
* @author gaede
- * @version $Id: SIOReader.h,v 1.24 2005/10/21 13:53:19 gaede Exp $
+ * @version $Id: SIOReader.h,v 1.25 2007/10/16 16:22:45 gaede Exp $
*/
class SIOReader : public IO::LCReader {
+ typedef std::map< EVENT::long64 , EVENT::long64 > EventMap ;
+
public:
/** Default constructor.
@@ -148,6 +152,7 @@
void postProcessEvent() ;
+ void getEventMap() ;
protected:
@@ -173,6 +178,7 @@
const std::vector<std::string>* _myFilenames ;
unsigned int _currentFileIndex ;
+ EventMap _evtMap ;
}; // class
} // namespace
lcio/src/cpp/src/SIO
diff -u -r1.48 -r1.49
--- SIOReader.cc 13 Aug 2007 10:35:00 -0000 1.48
+++ SIOReader.cc 16 Oct 2007 16:22:45 -0000 1.49
@@ -33,6 +33,8 @@
using namespace IOIMPL ;
using namespace IMPL ;
+#define EVENTKEY(RN,EN) ( EVENT::long64( RN ) << 32 ) | EN
+
namespace SIO {
// small helper class to activate the unpack mode of the
@@ -182,8 +184,69 @@
// eh = new SIOEventHandler( LCSIO::HEADERBLOCKNAME, _evtP ) ;
// else
// eh->setEventPtr( _evtP ) ;
+
+ getEventMap() ;
+
}
+
+ void SIOReader::getEventMap() {
+
+
+ int status = _stream->seek(0) ; // go to start - FIXME - should we store the current position ?
+
+ if( status != SIO_STREAM_SUCCESS )
+ throw IOException( std::string( "[SIOReader::getEventMap()] Can't seek stream to 0" ) ) ;
+
+ std::cout << " SIOReader::getEventMap() recreating event for direct access ..."
+ << std::endl ;
+
+ { // -- scope for unpacking evt header --------
+ SIOUnpack hdrUnp( SIOUnpack::EVENTHDR ) ;
+
+ 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() ;
+
+// 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) {
@@ -395,7 +458,7 @@
// // restore the daughter relations from the parent relations
// SIOParticleHandler::restoreParentDaughterRelations( *_evtP ) ;
- postProcessEvent() ;
+ postProcessEvent() ;
return *_evtP ;
}
@@ -420,7 +483,7 @@
}
}
- // now we need to also read the next record which suposedly nis an event record
+ // now we need to also read the next record which suposedly is an event record
// in order to prevent readStream from reading this event (the last to be skipped)
SIOUnpack evtUnp( SIOUnpack::EVENT ) ;
@@ -436,6 +499,26 @@
EVENT::LCEvent * SIOReader::readEvent(int runNumber, int evtNumber)
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
+
+ return 0 ;
+
+
+ /* ---- OLD code with fast skip -----------
+
bool runFound = false ;
bool evtFound = false ;
// check current run - if any
@@ -495,6 +578,7 @@
return *_evtP ;
}
+ */
}
CVSspam 0.2.8