00001 #include "SIO/SIORandomAccessHandler.h"
00002
00003 #include "SIO/LCIORandomAccess.h"
00004 #include "SIO/LCSIO.h"
00005 #include "SIO_functions.h"
00006
00007 #include "EVENT/LCIO.h"
00008
00009 #include <iostream>
00010
00011
00012 namespace SIO {
00013
00014
00015 SIORandomAccessHandler::SIORandomAccessHandler(const std::string& name, LCIORandomAccessMgr* raMgr) :
00016 SIO_block( name.c_str() ),
00017 _raMgr( raMgr ) {
00018
00019 }
00020
00021
00022 SIORandomAccessHandler::~SIORandomAccessHandler(){ }
00023
00024
00025 unsigned int SIORandomAccessHandler::xfer( SIO_stream* stream, SIO_operation op,
00026 unsigned int versionID){
00027
00028 LCSIO::checkVersion(versionID) ;
00029
00030 unsigned int status ;
00031
00032
00033 if( op == SIO_OP_READ ){
00034
00035 LCIORandomAccess* ra = new LCIORandomAccess ;
00036
00037 SIO_DATA( stream , &(ra->_minRunEvt.RunNum) , 1 ) ;
00038 SIO_DATA( stream , &(ra->_minRunEvt.EvtNum) , 1 ) ;
00039
00040 SIO_DATA( stream , &( ra->_maxRunEvt.RunNum) , 1 ) ;
00041 SIO_DATA( stream , &( ra->_maxRunEvt.EvtNum) , 1 ) ;
00042
00043 SIO_DATA( stream , &( ra->_nRunHeaders) , 1 ) ;
00044 SIO_DATA( stream , &( ra->_nEvents) , 1 ) ;
00045 SIO_DATA( stream , &( ra->_recordsAreInOrder) , 1 ) ;
00046
00047 SIO_DATA( stream , &( ra->_indexLocation) , 1 ) ;
00048 SIO_DATA( stream , &( ra->_prevLocation) , 1 ) ;
00049 SIO_DATA( stream , &( ra->_nextLocation) , 1 ) ;
00050 SIO_DATA( stream , &( ra->_firstRecordLocation) , 1 ) ;
00051
00052
00053
00054 int recSize ;
00055 SIO_DATA( stream , &recSize , 1 ) ;
00056
00057
00058 _raMgr->addLCIORandomAccess( ra ) ;
00059
00060 } else if( op == SIO_OP_WRITE ){
00061
00062
00063 LCIORandomAccess* ra = const_cast<LCIORandomAccess*> ( _raMgr->lastLCIORandomAccess() ) ;
00064
00065
00066 SIO_DATA( stream , &(ra->_minRunEvt.RunNum) , 1 ) ;
00067 SIO_DATA( stream , &(ra->_minRunEvt.EvtNum) , 1 ) ;
00068
00069 SIO_DATA( stream , &( ra->_maxRunEvt.RunNum) , 1 ) ;
00070 SIO_DATA( stream , &( ra->_maxRunEvt.EvtNum) , 1 ) ;
00071
00072 SIO_DATA( stream , &( ra->_nRunHeaders) , 1 ) ;
00073 SIO_DATA( stream , &( ra->_nEvents) , 1 ) ;
00074 SIO_DATA( stream , &( ra->_recordsAreInOrder) , 1 ) ;
00075
00076 SIO_DATA( stream , &( ra->_indexLocation) , 1 ) ;
00077 SIO_DATA( stream , &( ra->_prevLocation) , 1 ) ;
00078 SIO_DATA( stream , &( ra->_nextLocation) , 1 ) ;
00079 SIO_DATA( stream , &( ra->_firstRecordLocation) , 1 ) ;
00080
00081
00082
00083 int recSize = ( 0xabcd0000 | LCSIO_RANDOMACCESS_SIZE ) ;
00084 SIO_DATA( stream , &recSize , 1 ) ;
00085
00086 }
00087
00088
00089 return ( SIO_BLOCK_SUCCESS ) ;
00090 }
00091
00092 unsigned int SIORandomAccessHandler::version(){
00093
00094 int version = SIO_VERSION_ENCODE( EVENT::LCIO::MAJORVERSION, EVENT::LCIO::MINORVERSION ) ;
00095 return version ;
00096
00097 }
00098
00099 }