00001 #include "SIO/SIORunHeaderHandler.h"
00002 #include "SIO/SIOLCParameters.h"
00003 #include "SIO/LCSIO.h"
00004
00005 #include "EVENT/LCRunHeader.h"
00006 #include "EVENT/LCIO.h"
00007
00008 #include "SIO_functions.h"
00009
00010 #include <iostream>
00011
00012
00013 using namespace EVENT ;
00014 using namespace IOIMPL ;
00015
00016 namespace SIO {
00017
00018
00019 SIORunHeaderHandler::SIORunHeaderHandler(const std::string& name) :
00020 SIO_block( name.c_str() ),
00021 _rhP(0) {
00022 }
00023
00024 SIORunHeaderHandler::SIORunHeaderHandler(const std::string& name, IOIMPL::LCRunHeaderIOImpl** aRhP) :
00025 SIO_block( name.c_str() ),
00026 _rhP( aRhP ) {
00027
00028 *_rhP = 0 ;
00029 }
00030
00031
00032 SIORunHeaderHandler::~SIORunHeaderHandler(){
00033
00034 }
00035
00036
00037 void SIORunHeaderHandler::setRunHeader(const LCRunHeader* rh ){
00038 _hdr = rh ;
00039 }
00040 void SIORunHeaderHandler::setRunHeaderPtr( LCRunHeaderIOImpl** hdrP ) {
00041 _rhP= hdrP ;
00042 }
00043
00044
00045 unsigned int SIORunHeaderHandler::xfer( SIO_stream* stream, SIO_operation op,
00046 unsigned int versionID){
00047
00048 LCSIO::checkVersion(versionID) ;
00049
00050 unsigned int status ;
00051
00052 if( op == SIO_OP_READ ){
00053
00054 if(!_rhP) return LCIO::ERROR ;
00055
00056
00057
00058 if (*_rhP != 0 ) delete *_rhP ;
00059 *_rhP = new IOIMPL::LCRunHeaderIOImpl ;
00060
00061
00062
00063 int rnTmp ;
00064 SIO_DATA( stream , &rnTmp , 1 ) ;
00065 (*_rhP)->setRunNumber( rnTmp );
00066
00067 char* detNameTmp ;
00068 LCSIO_READ( stream, &detNameTmp ) ;
00069 (*_rhP)->setDetectorName( detNameTmp ) ;
00070
00071 char* descTmp ;
00072 LCSIO_READ( stream, &descTmp ) ;
00073 (*_rhP)->setDescription( descTmp ) ;
00074
00075
00076 int nSDN ;
00077 SIO_DATA( stream , &nSDN , 1 ) ;
00078 for( int i=0; i<nSDN ; i++ ){
00079
00080 char* sdnTmp ;
00081 LCSIO_READ( stream, &sdnTmp ) ;
00082
00083 (*_rhP)->addActiveSubdetector( sdnTmp ) ;
00084 }
00085
00086
00087 if( versionID > SIO_VERSION_ENCODE( 1, 1) )
00088 SIOLCParameters::read( stream , (*_rhP)->parameters() , versionID) ;
00089
00090 } else if( op == SIO_OP_WRITE ){
00091
00092 if( _hdr ){
00093
00094 LCSIO_WRITE( stream, _hdr->getRunNumber() ) ;
00095 LCSIO_WRITE( stream, _hdr->getDetectorName() ) ;
00096 LCSIO_WRITE( stream, _hdr->getDescription() ) ;
00097
00098
00099 const std::vector<std::string>* strVec = _hdr->getActiveSubdetectors() ;
00100
00101 int nSDN = strVec->size() ;
00102 SIO_DATA( stream, &nSDN, 1 ) ;
00103
00104 for( std::vector<std::string>::const_iterator name = strVec->begin() ; name != strVec->end() ; name++){
00105 LCSIO_WRITE( stream, *name ) ;
00106 }
00107
00108
00109 if( version() > SIO_VERSION_ENCODE( 1, 1) )
00110 SIOLCParameters::write( stream , _hdr->getParameters() ) ;
00111
00112
00113
00114 } else {
00115 std::cout << " SIORunHeaderHandler::xfer : run header pointer not set ! " << std::endl ;
00116 return LCIO::ERROR ;
00117 }
00118 }
00119
00120
00121 return ( SIO_BLOCK_SUCCESS ) ;
00122 }
00123
00124 unsigned int SIORunHeaderHandler::version(){
00125
00126 int version = SIO_VERSION_ENCODE( LCIO::MAJORVERSION, LCIO::MINORVERSION ) ;
00127 return version ;
00128
00129 }
00130
00131 }