00001 #include "SIO/SIOEventHandler.h"
00002 #include "SIO/LCSIO.h"
00003
00004 #include "EVENT/LCEvent.h"
00005 #include "EVENT/LCIO.h"
00006 #include "IOIMPL/LCEventIOImpl.h"
00007 #include "IOIMPL/LCCollectionIOVec.h"
00008
00009 #include "LCIOSTLTypes.h"
00010 #include "SIO/SIOLCParameters.h"
00011
00012 #include "SIO_functions.h"
00013 #include <sstream>
00014 #include <iostream>
00015
00016 #define SUBSETPOSTFIX "_References"
00017
00018 using namespace EVENT ;
00019 using namespace IOIMPL ;
00020
00021 namespace SIO {
00022
00023
00024 SIOEventHandler::SIOEventHandler(const std::string& name) :
00025 SIO_block( name.c_str() ),
00026 _evtP(0) {
00027 }
00028
00029 SIOEventHandler::SIOEventHandler(const std::string& name, LCEventIOImpl** anEvtP) :
00030 SIO_block( name.c_str() ),
00031 _evtP( anEvtP ) {
00032
00033 *_evtP = 0 ;
00034 }
00035
00036
00037 SIOEventHandler::~SIOEventHandler(){
00038
00039 }
00040
00041
00042 void SIOEventHandler::setEvent(const LCEvent* evt ){
00043 _evt = evt ;
00044 }
00045 void SIOEventHandler::setEventPtr(IOIMPL::LCEventIOImpl** evtP ){
00046 _evtP = evtP ;
00047 }
00048
00049
00050 unsigned int SIOEventHandler::xfer( SIO_stream* stream, SIO_operation op,
00051 unsigned int versionID){
00052
00053 unsigned int status ;
00054
00055
00056 if( op == SIO_OP_READ ){
00057
00058 LCSIO::checkVersion(versionID) ;
00059
00060
00061
00062 if (*_evtP ) {
00063
00064 delete *_evtP ;
00065 }
00066 *_evtP = new LCEventIOImpl ;
00067
00068
00069 SIO_DATA( stream , &(*_evtP)->_runNumber , 1 ) ;
00070 SIO_DATA( stream , &(*_evtP)->_eventNumber , 1 ) ;
00071 SIO_DATA( stream , &(*_evtP)->_timeStamp , 1 ) ;
00072
00073 char* detName ;
00074 LCSIO_READ( stream, &detName ) ;
00075 (*_evtP)->setDetectorName( detName ) ;
00076
00077
00078
00079
00080 int nCol ;
00081 SIO_DATA( stream , &nCol , 1 ) ;
00082 for( int i=0; i<nCol ; i++ ){
00083 char* dummy ;
00084 LCSIO_READ( stream, &dummy ) ;
00085 std::string colName( dummy ) ;
00086 char* type ;
00087
00088 LCSIO_READ( stream, &type ) ;
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 std::string colType( type ) ;
00099
00100 std::string::size_type idx ;
00101 if( ( idx = colType.rfind( SUBSETPOSTFIX ) ) != std::string::npos ){
00102 colType = std::string( colType , 0 , idx ) ;
00103 }
00104
00105 try {
00106
00107 (*_evtP)->addCollection( new LCCollectionIOVec( colType ) , colName) ;
00108
00109 }
00110 catch( EventException ){ return LCIO::ERROR ; }
00111
00112 }
00113
00114
00115 if( versionID > SIO_VERSION_ENCODE( 1, 1) )
00116 SIOLCParameters::read( stream , (*_evtP)->parameters() , versionID) ;
00117
00118
00119 } else if( op == SIO_OP_WRITE ){
00120
00121 if( _evt ){
00122 LCSIO_WRITE( stream, _evt->getRunNumber() ) ;
00123 LCSIO_WRITE( stream, _evt->getEventNumber() ) ;
00124 LCSIO_WRITE( stream, _evt->getTimeStamp() ) ;
00125 LCSIO_WRITE( stream, _evt->getDetectorName() ) ;
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 const StringVec* colNames = _evt->getCollectionNames() ;
00143
00144
00145 int nCol = colNames->size() ;
00146
00147 for(unsigned int i=0 ; i < colNames->size() ; i++ ) {
00148 if( _evt->getCollection( (*colNames)[i] )->isTransient() ) nCol-- ;
00149 }
00150
00151 SIO_DATA( stream, &nCol, 1 ) ;
00152
00153
00154 for(unsigned int i=0 ; i < colNames->size() ; i++ ) {
00155 const LCCollection* col = _evt->getCollection( (*colNames)[i] ) ;
00156 if( ! col->isTransient() ){
00157 LCSIO_WRITE( stream, (*colNames)[i] ) ;
00158
00159 std::string colType( col->getTypeName() ) ;
00160
00161 if( col->isSubset() )
00162 colType += SUBSETPOSTFIX ;
00163
00164 LCSIO_WRITE( stream, colType ) ;
00165 }
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 if( version() > SIO_VERSION_ENCODE( 1, 1) )
00178 SIOLCParameters::write( stream , _evt->getParameters() ) ;
00179
00180 } else {
00181 return 0 ;
00182 }
00183 }
00184
00185
00186 return ( SIO_BLOCK_SUCCESS ) ;
00187 }
00188
00189 unsigned int SIOEventHandler::version(){
00190
00191 int version = SIO_VERSION_ENCODE( LCIO::MAJORVERSION, LCIO::MINORVERSION ) ;
00192 return version ;
00193
00194 }
00195
00196 }