00001 #include "SIO/SIOClusterHandler.h"
00002
00003 #include "SIO/LCSIO.h"
00004 #include "IOIMPL/ParticleIDIOImpl.h"
00005
00006 #include "EVENT/LCIO.h"
00007 #include "IOIMPL/ClusterIOImpl.h"
00008 #include "IMPL/LCFlagImpl.h"
00009
00010 #include "SIO_functions.h"
00011 #include "SIO_block.h"
00012
00013 using namespace EVENT ;
00014 using namespace IMPL ;
00015 using namespace IOIMPL ;
00016
00017
00018 namespace SIO{
00019
00020 unsigned int SIOClusterHandler::read(SIO_stream* stream,
00021 LCObject** objP ){
00022 unsigned int status ;
00023
00024
00025
00026 ClusterIOImpl* cluster = new ClusterIOImpl ;
00027 *objP = cluster ;
00028
00029
00030 int type ;
00031 SIO_DATA( stream , &type , 1 ) ;
00032 cluster->setType( type ) ;
00033
00034 SIO_DATA( stream , &(cluster->_energy) , 1 ) ;
00035 SIO_DATA( stream , cluster->_position , 3 ) ;
00036
00037 float errpos[ NERRPOS ] ;
00038 SIO_DATA( stream , errpos , NERRPOS ) ;
00039 cluster->setPositionError( errpos ) ;
00040
00041 SIO_DATA( stream , &(cluster->_theta) , 1 ) ;
00042 SIO_DATA( stream , &(cluster->_phi) , 1 ) ;
00043
00044 float errdir[ NERRDIR ] ;
00045 SIO_DATA( stream , errdir , NERRDIR ) ;
00046 cluster->setDirectionError( errdir ) ;
00047
00048 int nShape ;
00049
00050 if( _vers > SIO_VERSION_ENCODE(1,2) ) {
00051 SIO_DATA( stream , &nShape , 1 ) ;
00052 } else {
00053 nShape = NSHAPE_OLD ;
00054 }
00055
00056 cluster->_shape.resize( nShape ) ;
00057
00058 SIO_DATA( stream , &(cluster->_shape[0]) ,nShape ) ;
00059
00060
00061 if( _vers > SIO_VERSION_ENCODE(1,2) ) {
00062
00063
00064
00065 int nPid ;
00066 SIO_DATA( stream , &nPid , 1 ) ;
00067 for(int i=0;i<nPid;i++){
00068
00069 ParticleIDIOImpl* pid = new ParticleIDIOImpl ;
00070
00071 SIO_DATA( stream , &(pid->_likelihood) , 1 ) ;
00072 SIO_DATA( stream , &(pid->_type) , 1 ) ;
00073 SIO_DATA( stream , &(pid->_pdg) , 1 ) ;
00074 SIO_DATA( stream , &(pid->_algorithmType) , 1 ) ;
00075
00076 int nPara ;
00077 SIO_DATA( stream , &nPara , 1 ) ;
00078 float aParameter ;
00079 for(int j=0;j<nPara;j++){
00080 SIO_DATA( stream , &aParameter , 1 ) ;
00081 pid->addParameter( aParameter ) ;
00082 }
00083 cluster->addParticleID( pid) ;
00084
00085 }
00086
00087 } else {
00088 float pType[3] ;
00089 SIO_DATA( stream , pType , 3 ) ;
00090
00091
00092
00093
00094 }
00095
00096
00097
00098 int nClusters ;
00099 SIO_DATA( stream, &nClusters , 1 ) ;
00100
00101
00102
00103
00104 cluster->_clusters.resize( nClusters ) ;
00105 for(int i=0;i<nClusters;i++){
00106 SIO_PNTR( stream , &(cluster->_clusters[i] ) ) ;
00107 }
00108
00109 if( LCFlagImpl(_flag).bitSet( LCIO::CLBIT_HITS ) ){
00110
00111 int nHits ;
00112 SIO_DATA( stream, &nHits , 1 ) ;
00113
00114 cluster->_hits.resize( nHits ) ;
00115 cluster->_weights.resize( nHits ) ;
00116
00117 for(int i=0;i<nHits;i++){
00118 SIO_PNTR( stream , &(cluster->_hits[i] ) ) ;
00119 SIO_DATA( stream , &(cluster->_weights[i] ) , 1 ) ;
00120 }
00121
00122 }
00123 int nEnergies ;
00124 SIO_DATA( stream, &nEnergies , 1 ) ;
00125 cluster->_subdetectorEnergies.resize( nEnergies ) ;
00126 for(int i=0;i<nEnergies;i++){
00127 SIO_DATA( stream, &(cluster->_subdetectorEnergies[i] ) , 1 ) ;
00128 }
00129
00130
00131 SIO_PTAG( stream , dynamic_cast<const Cluster*>(cluster) ) ;
00132 return ( SIO_BLOCK_SUCCESS ) ;
00133 }
00134
00135
00136 unsigned int SIOClusterHandler::write(SIO_stream* stream,
00137 const LCObject* obj ){
00138
00139 unsigned int status ;
00140
00141
00142
00143
00144 const Cluster* cluster = dynamic_cast<const Cluster*>(obj) ;
00145
00146
00147 LCSIO_WRITE( stream, cluster->getType() ) ;
00148 LCSIO_WRITE( stream, cluster->getEnergy() ) ;
00149 float* pos = const_cast<float*> ( cluster->getPosition() ) ;
00150 SIO_DATA( stream, pos , 3 ) ;
00151
00152 const FloatVec& errpos = cluster->getPositionError() ;
00153 for(unsigned int i=0;i<errpos.size();i++){
00154 LCSIO_WRITE( stream, errpos[i] ) ;
00155 }
00156 LCSIO_WRITE( stream, cluster->getITheta() ) ;
00157 LCSIO_WRITE( stream, cluster->getIPhi() ) ;
00158
00159 const FloatVec& errdir = cluster->getDirectionError() ;
00160 for(unsigned int i=0;i<errdir.size();i++){
00161 LCSIO_WRITE( stream, errdir[i] ) ;
00162 }
00163
00164 const FloatVec& shape = cluster->getShape() ;
00165 LCSIO_WRITE( stream, shape.size() ) ;
00166
00167 for(unsigned int i=0;i<shape.size();i++){
00168 LCSIO_WRITE( stream, shape[i] ) ;
00169 }
00170
00171
00172
00173
00174
00175
00176
00177 int nPid = cluster->getParticleIDs().size() ;
00178 SIO_DATA( stream , &nPid , 1 ) ;
00179 for(int i=0;i<nPid;i++){
00180 const ParticleID* pid = cluster->getParticleIDs()[i] ;
00181 LCSIO_WRITE( stream, pid->getLikelihood() ) ;
00182 LCSIO_WRITE( stream, pid->getType() ) ;
00183 LCSIO_WRITE( stream, pid->getPDG() ) ;
00184 LCSIO_WRITE( stream, pid->getAlgorithmType() ) ;
00185 int nPara = pid->getParameters().size() ;
00186 SIO_DATA( stream , &nPara , 1 ) ;
00187 for(int j=0;j<nPara;j++){
00188 LCSIO_WRITE( stream, pid->getParameters()[j] ) ;
00189 }
00190 }
00191
00192 const ClusterVec& clusters = cluster->getClusters() ;
00193 int nClusters = clusters.size() ;
00194
00195 SIO_DATA( stream, &nClusters , 1 ) ;
00196
00197 for(int i=0;i<nClusters;i++){
00198 SIO_PNTR( stream , &(clusters[i]) ) ;
00199 }
00200
00201 if( LCFlagImpl(_flag).bitSet( LCIO::CLBIT_HITS ) ){
00202
00203
00204 const CalorimeterHitVec& hits = cluster->getCalorimeterHits() ;
00205 const FloatVec& weights = cluster->getHitContributions() ;
00206 int nHits = hits.size() ;
00207 SIO_DATA( stream, &nHits , 1 ) ;
00208
00209 for(int i=0;i<nHits;i++){
00210 SIO_PNTR( stream , &(hits[i]) ) ;
00211 LCSIO_WRITE( stream , weights[i] ) ;
00212 }
00213
00214 }
00215
00216 const FloatVec& subdetectorEnergies = cluster->getSubdetectorEnergies() ;
00217 int nEnergies = subdetectorEnergies.size() ;
00218
00219 LCSIO_WRITE( stream, nEnergies ) ;
00220 for(int i=0;i<nEnergies;i++){
00221 LCSIO_WRITE( stream, subdetectorEnergies[i] ) ;
00222 }
00223
00224 SIO_PTAG( stream , cluster ) ;
00225
00226 return ( SIO_BLOCK_SUCCESS ) ;
00227
00228 }
00229
00230 }