00001 #include "SIO/SIOSimCalHitHandler.h"
00002
00003 #include "SIO/LCSIO.h"
00004
00005 #include "EVENT/LCIO.h"
00006 #include "EVENT/MCParticle.h"
00007 #include "EVENT/SimCalorimeterHit.h"
00008 #include "IOIMPL/SimCalorimeterHitIOImpl.h"
00009 #include "IMPL/LCFlagImpl.h"
00010
00011 #include "SIO_functions.h"
00012 #include "SIO_block.h"
00013
00014
00015 using namespace EVENT ;
00016 using namespace IMPL ;
00017 using namespace IOIMPL ;
00018
00019
00020 namespace SIO{
00021
00022 unsigned int SIOSimCalHitHandler::read(SIO_stream* stream,
00023 LCObject** objP){
00024 unsigned int status ;
00025
00026
00027 SimCalorimeterHitIOImpl* hit = new SimCalorimeterHitIOImpl ;
00028 *objP = hit ;
00029
00030 SIO_DATA( stream , &(hit->_cellID0) , 1 ) ;
00031
00032
00033 if( LCFlagImpl(_flag).bitSet( LCIO::CHBIT_ID1 ) ||
00034
00035 ( SIO_VERSION_MAJOR(_vers)==0 && SIO_VERSION_MINOR(_vers)==8) ){
00036
00037 SIO_DATA( stream , &(hit->_cellID1) , 1 ) ;
00038
00039 }
00040 SIO_DATA( stream , &(hit->_energy) , 1 ) ;
00041
00042 if( LCFlagImpl(_flag).bitSet( LCIO::CHBIT_LONG ) ){
00043 SIO_DATA( stream , hit->_position , 3 ) ;
00044 }
00045
00046
00047 int nCon ;
00048 SIO_DATA( stream , &nCon , 1 ) ;
00049
00050 for(int i=0; i< nCon ; i++){
00051
00052 MCParticleCont* mcCon = new MCParticleCont ;
00053 SIO_PNTR( stream , &(mcCon->Particle) ) ;
00054 SIO_DATA( stream , &(mcCon->Energy) , 1 ) ;
00055 SIO_DATA( stream , &(mcCon->Time) , 1 ) ;
00056 if( LCFlagImpl(_flag).bitSet( LCIO::CHBIT_PDG ) )
00057 SIO_DATA( stream , &(mcCon->PDG) , 1 ) ;
00058
00059 hit->_vec.push_back( mcCon );
00060 }
00061
00062
00063
00064 if( _vers > SIO_VERSION_ENCODE( 1, 0) ){
00065 SIO_PTAG( stream , dynamic_cast<const SimCalorimeterHit*>(hit) ) ;
00066 }
00067
00068 return ( SIO_BLOCK_SUCCESS ) ;
00069
00070 }
00071
00072
00073 unsigned int SIOSimCalHitHandler::write(SIO_stream* stream,
00074 const LCObject* obj){
00075
00076 unsigned int status ;
00077
00078 const SimCalorimeterHit* hit = dynamic_cast<const SimCalorimeterHit*>(obj) ;
00079
00080 LCSIO_WRITE( stream, hit->getCellID0() ) ;
00081 if( LCFlagImpl(_flag).bitSet( LCIO::CHBIT_ID1 ) ){
00082 LCSIO_WRITE( stream, hit->getCellID1() ) ;
00083 }
00084 LCSIO_WRITE( stream, hit->getEnergy() ) ;
00085
00086
00087
00088 if( LCFlagImpl(_flag).bitSet( LCIO::CHBIT_LONG ) ){
00089 float* pos = const_cast<float*> ( hit->getPosition() ) ;
00090 SIO_DATA( stream, pos , 3 ) ;
00091 }
00092
00093 int nMC = hit->getNMCContributions() ;
00094 SIO_DATA( stream, &nMC , 1 ) ;
00095
00096 for(int i=0; i<nMC ;i++){
00097
00098 const MCParticle* part = hit->getParticleCont(i) ;
00099 SIO_PNTR( stream , &part ) ;
00100
00101 LCSIO_WRITE( stream, hit->getEnergyCont(i) ) ;
00102 LCSIO_WRITE( stream, hit->getTimeCont(i) ) ;
00103 if( LCFlagImpl(_flag).bitSet( LCIO::CHBIT_PDG ) )
00104 LCSIO_WRITE( stream, hit->getPDGCont(i) ) ;
00105
00106 }
00107
00108
00109 SIO_PTAG( stream , hit ) ;
00110
00111 return ( SIO_BLOCK_SUCCESS ) ;
00112
00113 }
00114
00115 }