/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/lcio/src/cpp/src/SIO/SIOReconstructedParticleHandler.cc

Go to the documentation of this file.
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     // create a new object :
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       //     SIO_DATA( stream ,  recP->_momentum  , 3 ) ;
00039       recP->setMomentum( momentum ) ;
00040       
00041       float energy ;
00042       SIO_DATA( stream , &energy , 1  ) ;
00043       recP->setEnergy( energy )  ;
00044 //       SIO_DATA( stream ,  &(recP->_energy)  , 1 ) ;
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 //       SIO_DATA( stream ,  &(recP->_mass)  , 1 ) ;
00054 
00055       SIO_DATA( stream ,  &(recP->_charge)  , 1 ) ;
00056       
00057       SIO_DATA( stream ,  recP->_reference  , 3 ) ;
00058       
00059       // read PIDs
00060       int nPid ;
00061       
00062       SIO_DATA( stream ,  &nPid  , 1 ) ;
00063       for(int i=0;i<nPid;i++){
00064         // create new Pid objects
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       // read reconstructed particles
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       // read tracks
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       // read clusters
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         //read pointers to start/end vertices
00117         SIO_PNTR( stream ,   &(recP->_sv) ) ;
00118         //SIO_PNTR( stream ,   &(recP->_ev) ) ;
00119       }
00120       
00121       
00122     } else {   // old version (1.0-1.2 keep for a while - no official release !! )
00123 
00124       int typeFlag ;
00125       SIO_DATA( stream ,  &typeFlag , 1  ) ;
00126       recP->setType( 0x0000ffff & typeFlag ) ;
00127 //       recP->setPrimary( (1<<31) &  typeFlag ) ;
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       // read PIDs
00143       int nPid ;
00144       SIO_DATA( stream ,  &nPid  , 1 ) ;
00145       for(int i=0;i<nPid;i++){
00146         // create new Pid objects
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       // read reconstructed particles
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       // read tracks
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       // read clusters
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       // read MCParticles
00203       int nMCP ;
00204       SIO_DATA( stream, &nMCP , 1  ) ;
00205 
00206       SIO_DATA( stream ,  &dummyWeights  , nMCP ) ;
00207       SIO_DATA( stream ,  &dummyWeights  , nMCP ) ;
00208       
00209 //       for(int i=0;i<nMCP;i++){
00210 //      recP->_mcParticles.push_back( 0 ) ;
00211 //      recP->_mcParticleWeights.push_back( 0 ) ;
00212 //       }
00213 //       for(int i=0;i<nMCP;i++){
00214 //      SIO_PNTR( stream , &(recP->_mcParticles[i] ) ) ;
00215 //      SIO_PNTR( stream , &(recP->_mcParticleWeights[i] ) ) ;
00216 //       }
00217       
00218     } // --- end old version 1.0-1.2
00219       
00220     // read the pointer tag 
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     // this is where we gave up type safety in order to
00232     // simplify the API and the implementation
00233     // by having a common collection of objects
00234     const ReconstructedParticle* recP = dynamic_cast<const ReconstructedParticle*>(obj)  ;
00235 
00236 
00237 //     // bit 31 is primary flag 
00238 //     // lower 16 bits are type 
00239 //     std::bitset<32> typeFlag =   recP->getType() ; 
00240 //     if( recP->isPrimary() ) typeFlag[31] = 1 ;
00241 //     LCSIO_WRITE( stream, (int) typeFlag.to_ulong()  ) ;
00242 
00243 
00244     LCSIO_WRITE( stream, recP->getType()  ) ;
00245 
00246 //     float* mom = const_cast<float*> ( recP->getMomentum() ) ; 
00247 //     SIO_DATA( stream,  mom , 3 ) ;
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     // write Pids
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     // write reconstructed particles
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 //       LCSIO_WRITE( stream, recP->getParticleWeights()[i]  ) ;
00296     }
00297     
00298     // write tracks
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 //       LCSIO_WRITE( stream, recP->getTrackWeights()[i]  ) ;
00305     }
00306 
00307     // write clusters
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 //       LCSIO_WRITE( stream, recP->getClusterWeights()[i]  ) ;
00314     }
00315 
00316 //     // write MCParticles
00317 //     int nMCP = recP->getMCParticles().size() ;
00318 //     SIO_DATA( stream, &nMCP , 1  ) ;
00319 
00320 //     for(int i=0;i<nMCP;i++){
00321 //       SIO_PNTR( stream , &(recP->getMCParticles()[i]) ) ;
00322 //       LCSIO_WRITE( stream, recP->getMCParticleWeights()[i]  ) ;
00323 //     }
00324 
00325     // write pointers to start/end vertices
00326     EVENT::Vertex* sv = recP->getStartVertex() ;
00327     SIO_PNTR( stream , &sv  ) ;
00328     //EVENT::Vertex* ev = recP->getEndVertex() ;
00329     //SIO_PNTR( stream , &ev  ) ;
00330 
00331 
00332     // write a ptag in order to be able to point to recPs
00333     SIO_PTAG( stream , recP ) ;
00334 
00335     return ( SIO_BLOCK_SUCCESS ) ;
00336     
00337   }
00338   
00339 } // namespace

Generated on Mon Jan 7 13:15:21 2013 for MicromegasFramework by  doxygen 1.4.7