00001 #include "SIO/SIOReconstructedParticleHandler.h"
00002
00003 #include "SIO/LCSIO.h"
00004
00005 #include "EVENT/LCIO.h"
00006 #include "IOIMPL/ReconstructedParticleIOImpl.h"
00007 #include "IOIMPL/ParticleIDIOImpl.h"
00008 #include "IMPL/LCFlagImpl.h"
00009
00010 #include "SIO_functions.h"
00011 #include "SIO_block.h"
00012 #include <bitset>
00013
00014
00015 using namespace EVENT ;
00016 using namespace IMPL ;
00017 using namespace IOIMPL ;
00018
00019
00020 namespace SIO{
00021
00022 unsigned int SIOReconstructedParticleHandler::read(SIO_stream* stream,
00023 LCObject** objP){
00024 unsigned int status ;
00025
00026
00027
00028 ReconstructedParticleIOImpl* recP = new ReconstructedParticleIOImpl ;
00029 *objP = recP ;
00030
00031 if( _vers > SIO_VERSION_ENCODE( 1, 2) ) {
00032
00033
00034 SIO_DATA( stream , &(recP->_type) , 1 ) ;
00035
00036 float momentum[3] ;
00037 SIO_DATA( stream , momentum , 3 ) ;
00038
00039 recP->setMomentum( momentum ) ;
00040
00041 float energy ;
00042 SIO_DATA( stream , &energy , 1 ) ;
00043 recP->setEnergy( energy ) ;
00044
00045
00046 float errpos[ NCOVARIANCE ] ;
00047 SIO_DATA( stream , errpos , NCOVARIANCE ) ;
00048 recP->setCovMatrix( errpos ) ;
00049
00050 float mass ;
00051 SIO_DATA( stream , &mass , 1 ) ;
00052 recP->setMass( mass ) ;
00053
00054
00055 SIO_DATA( stream , &(recP->_charge) , 1 ) ;
00056
00057 SIO_DATA( stream , recP->_reference , 3 ) ;
00058
00059
00060 int nPid ;
00061
00062 SIO_DATA( stream , &nPid , 1 ) ;
00063 for(int i=0;i<nPid;i++){
00064
00065 ParticleIDIOImpl* pid = new ParticleIDIOImpl ;
00066
00067 SIO_DATA( stream , &(pid->_likelihood) , 1 ) ;
00068 SIO_DATA( stream , &(pid->_type) , 1 ) ;
00069 SIO_DATA( stream , &(pid->_pdg) , 1 ) ;
00070 SIO_DATA( stream , &(pid->_algorithmType) , 1 ) ;
00071
00072 int nPara ;
00073 SIO_DATA( stream , &nPara , 1 ) ;
00074 float aParameter ;
00075 for(int j=0;j<nPara;j++){
00076 SIO_DATA( stream , &aParameter , 1 ) ;
00077 pid->addParameter( aParameter ) ;
00078 }
00079 SIO_PTAG( stream , pid ) ;
00080
00081 recP->addParticleID( pid) ;
00082 }
00083
00084 SIO_PNTR( stream , &(recP->_pidUsed) ) ;
00085 SIO_DATA( stream , &(recP->_goodnessOfPID) , 1 ) ;
00086
00087
00088 int nRecP ;
00089 SIO_DATA( stream, &nRecP , 1 ) ;
00090
00091 recP->_particles.resize( nRecP ) ;
00092 for(int i=0;i<nRecP;i++){
00093 SIO_PNTR( stream , &(recP->_particles[i] ) ) ;
00094 }
00095
00096
00097 int nTrk ;
00098 SIO_DATA( stream, &nTrk , 1 ) ;
00099
00100 recP->_tracks.resize( nTrk ) ;
00101 for(int i=0;i<nTrk;i++){
00102 SIO_PNTR( stream , &(recP->_tracks[i] ) ) ;
00103 }
00104
00105
00106 int nClu ;
00107 SIO_DATA( stream, &nClu , 1 ) ;
00108
00109 recP->_clusters.resize( nClu ) ;
00110 for(int i=0;i<nClu;i++){
00111 SIO_PNTR( stream , &(recP->_clusters[i] ) ) ;
00112 }
00113
00114 if( _vers > SIO_VERSION_ENCODE( 1,7 ) ) {
00115
00116
00117 SIO_PNTR( stream , &(recP->_sv) ) ;
00118
00119 }
00120
00121
00122 } else {
00123
00124 int typeFlag ;
00125 SIO_DATA( stream , &typeFlag , 1 ) ;
00126 recP->setType( 0x0000ffff & typeFlag ) ;
00127
00128
00129 SIO_DATA( stream , recP->_momentum , 3 ) ;
00130
00131 SIO_DATA( stream , &(recP->_energy) , 1 ) ;
00132
00133 float errpos[ NCOVARIANCE ] ;
00134 SIO_DATA( stream , errpos , NCOVARIANCE ) ;
00135 recP->setCovMatrix( errpos ) ;
00136
00137 SIO_DATA( stream , &(recP->_mass) , 1 ) ;
00138 SIO_DATA( stream , &(recP->_charge) , 1 ) ;
00139
00140 SIO_DATA( stream , recP->_reference , 3 ) ;
00141
00142
00143 int nPid ;
00144 SIO_DATA( stream , &nPid , 1 ) ;
00145 for(int i=0;i<nPid;i++){
00146
00147 ParticleIDIOImpl* pid = new ParticleIDIOImpl ;
00148
00149 SIO_DATA( stream , &(pid->_likelihood) , 1 ) ;
00150 SIO_DATA( stream , &(pid->_type) , 1 ) ;
00151 SIO_DATA( stream , &(pid->_algorithmType) , 1 ) ;
00152
00153 int nPara ;
00154 SIO_DATA( stream , &nPara , 1 ) ;
00155 float aParameter ;
00156 for(int j=0;j<nPara;j++){
00157 SIO_DATA( stream , &aParameter , 1 ) ;
00158 pid->addParameter( aParameter ) ;
00159 }
00160 recP->addParticleID( pid) ;
00161 }
00162
00163 recP->_pidUsed = 0 ;
00164
00165
00166 int nRecP ;
00167 SIO_DATA( stream, &nRecP , 1 ) ;
00168
00169 for(int i=0;i<nRecP;i++){
00170 recP->_particles.push_back( 0 ) ;
00171 }
00172 float dummyWeights ;
00173 for(int i=0;i<nRecP;i++){
00174 SIO_PNTR( stream , &(recP->_particles[i] ) ) ;
00175 SIO_DATA( stream , &dummyWeights , 1 ) ;
00176 }
00177
00178
00179 int nTrk ;
00180 SIO_DATA( stream, &nTrk , 1 ) ;
00181
00182 for(int i=0;i<nTrk;i++){
00183 recP->_tracks.push_back( 0 ) ;
00184 }
00185 for(int i=0;i<nTrk;i++){
00186 SIO_PNTR( stream , &(recP->_tracks[i] ) ) ;
00187 SIO_DATA( stream , &dummyWeights , 1 ) ;
00188 }
00189
00190
00191 int nClu ;
00192 SIO_DATA( stream, &nClu , 1 ) ;
00193
00194 for(int i=0;i<nClu;i++){
00195 recP->_clusters.push_back( 0 ) ;
00196 }
00197 for(int i=0;i<nClu;i++){
00198 SIO_PNTR( stream , &(recP->_clusters[i] ) ) ;
00199 SIO_DATA( stream , &dummyWeights , 1 ) ;
00200 }
00201
00202
00203 int nMCP ;
00204 SIO_DATA( stream, &nMCP , 1 ) ;
00205
00206 SIO_DATA( stream , &dummyWeights , nMCP ) ;
00207 SIO_DATA( stream , &dummyWeights , nMCP ) ;
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 }
00219
00220
00221 SIO_PTAG( stream , dynamic_cast<const ReconstructedParticle*>(recP) ) ;
00222 return ( SIO_BLOCK_SUCCESS ) ;
00223 }
00224
00225
00226 unsigned int SIOReconstructedParticleHandler::write(SIO_stream* stream,
00227 const LCObject* obj){
00228
00229 unsigned int status ;
00230
00231
00232
00233
00234 const ReconstructedParticle* recP = dynamic_cast<const ReconstructedParticle*>(obj) ;
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 LCSIO_WRITE( stream, recP->getType() ) ;
00245
00246
00247
00248 LCSIO_WRITE( stream, (float) recP->getMomentum()[0] ) ;
00249 LCSIO_WRITE( stream, (float) recP->getMomentum()[1] ) ;
00250 LCSIO_WRITE( stream, (float) recP->getMomentum()[2] ) ;
00251
00252
00253 LCSIO_WRITE( stream, (float) recP->getEnergy() ) ;
00254
00255 const FloatVec& cov = recP->getCovMatrix() ;
00256 for(unsigned int i=0;i<cov.size();i++){
00257 LCSIO_WRITE( stream, cov[i] ) ;
00258 }
00259 LCSIO_WRITE( stream, (float) recP->getMass() ) ;
00260 LCSIO_WRITE( stream, recP->getCharge() ) ;
00261
00262 float* ref = const_cast<float*> ( recP->getReferencePoint() ) ;
00263 SIO_DATA( stream, ref , 3 ) ;
00264
00265
00266
00267 int nPid = recP->getParticleIDs().size() ;
00268 SIO_DATA( stream , &nPid , 1 ) ;
00269
00270 for(int i=0;i<nPid;i++){
00271 const ParticleID* pid = recP->getParticleIDs()[i] ;
00272 LCSIO_WRITE( stream, pid->getLikelihood() ) ;
00273 LCSIO_WRITE( stream, pid->getType() ) ;
00274 LCSIO_WRITE( stream, pid->getPDG() ) ;
00275 LCSIO_WRITE( stream, pid->getAlgorithmType() ) ;
00276
00277 int nPara = pid->getParameters().size() ;
00278 SIO_DATA( stream , &nPara , 1 ) ;
00279 for(int j=0;j<nPara;j++){
00280 LCSIO_WRITE( stream, pid->getParameters()[j] ) ;
00281 }
00282 SIO_PTAG( stream , pid ) ;
00283 }
00284
00285 EVENT::ParticleID* pidUsed = recP->getParticleIDUsed() ;
00286 SIO_PNTR( stream , &pidUsed ) ;
00287 LCSIO_WRITE( stream, recP->getGoodnessOfPID() ) ;
00288
00289
00290 int nReconstructedParticles= recP->getParticles().size() ;
00291 SIO_DATA( stream, &nReconstructedParticles , 1 ) ;
00292
00293 for(int i=0;i<nReconstructedParticles;i++){
00294 SIO_PNTR( stream , &(recP->getParticles()[i]) ) ;
00295
00296 }
00297
00298
00299 int nTrk = recP->getTracks().size() ;
00300 SIO_DATA( stream, &nTrk , 1 ) ;
00301
00302 for(int i=0;i<nTrk;i++){
00303 SIO_PNTR( stream , &(recP->getTracks()[i]) ) ;
00304
00305 }
00306
00307
00308 int nClu = recP->getClusters().size() ;
00309 SIO_DATA( stream, &nClu , 1 ) ;
00310
00311 for(int i=0;i<nClu;i++){
00312 SIO_PNTR( stream , &(recP->getClusters()[i]) ) ;
00313
00314 }
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326 EVENT::Vertex* sv = recP->getStartVertex() ;
00327 SIO_PNTR( stream , &sv ) ;
00328
00329
00330
00331
00332
00333 SIO_PTAG( stream , recP ) ;
00334
00335 return ( SIO_BLOCK_SUCCESS ) ;
00336
00337 }
00338
00339 }