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

Go to the documentation of this file.
00001 #include "SIO/SIOVertexHandler.h"
00002 
00003 #include <algorithm>
00004 #include "SIO/LCSIO.h"
00005 
00006 #include "EVENT/LCIO.h"
00007 #include "EVENT/Vertex.h"
00008 #include "IOIMPL/VertexIOImpl.h"
00009 #include "IMPL/LCFlagImpl.h"
00010 
00011 #include "SIO_functions.h"
00012 #include "SIO_block.h"
00013 #include "SIO/SIOLCParameters.h"
00014 
00015 //dbg
00016 #include <iostream>
00017 
00018 using namespace EVENT ;
00019 using namespace IMPL ;
00020 using namespace IOIMPL ;
00021 
00022 
00023 namespace SIO{
00024 
00025   SIOVertexHandler::~SIOVertexHandler(){ }
00026 
00027   unsigned int SIOVertexHandler::init( SIO_stream* stream,
00028                                        SIO_operation op,
00029                                        EVENT::LCCollection* col ,
00030                                        unsigned int vers ) {
00031                                                                                                                                                              
00032     unsigned int status ;
00033                                                                                                                                                              
00034                                                                                                                                                              
00035     if( op == SIO_OP_READ ) {
00036                                                                                                                                                              
00037                                                                                                                                                              
00038       SIO_DATA( stream ,  &_flag , 1  ) ;
00039                                                                                                                                                              
00040       if( vers > SIO_VERSION_ENCODE( 1, 1)   )
00041         SIOLCParameters::read( stream ,  col->parameters() , vers ) ;
00042       
00043       col->setFlag( _flag ) ;
00044       _vers = vers ;
00045  
00046       //get the parameters from the collection and initialize set/map with values
00047       imr.clear();
00048       //_set.clear();
00049       parameters.clear();
00050       col->getParameters().getStringVals("_lcio.VertexAlgorithmTypes",parameters);
00051       for(unsigned int i=0; i<parameters.size(); i++){
00052         //_set.insert(parameters[i]);
00053         imr[i]=parameters[i];
00054       }
00055     }
00056                                                                                                                                                              
00057     else if( op == SIO_OP_WRITE ) {
00058                                                                                                                                                              
00059                                                                                                                                                              
00060       _flag = col->getFlag() ;
00061                                                                                                                                                              
00062       LCSIO_WRITE( stream, _flag  ) ;
00063 /*      
00064       //add parameters for vertex algorithm types using FIFO algorithm
00065       parameters.clear();
00066       Vertex* v;
00067       v = dynamic_cast<Vertex*>( col->getElementAt( 0 ) ) ;
00068       parameters.push_back( v->getAlgorithmType() );
00069       bool found;
00070       for(int i=0; i<col->getNumberOfElements(); i++){
00071         found=0;
00072         v = dynamic_cast<Vertex*>( col->getElementAt( i ) ) ;
00073         for(unsigned int j=0; j<parameters.size(); j++){
00074           if( parameters[j] == v->getAlgorithmType() ){
00075             found=1;
00076             break;
00077           }
00078         }
00079         if(!found){ parameters.push_back( v->getAlgorithmType() ); }
00080       }
00081       col->parameters().setValues("_lcio.VertexAlgorithmTypes",parameters);
00082 
00083       //initialize map with parameter values
00084       imw.clear();
00085       for(unsigned int i=0; i<parameters.size(); i++)
00086         imw[parameters[i]]=i;
00087 */
00088       parameters.clear();
00089       _set.clear();
00090       Vertex* v;
00091       for(int i=0; i<col->getNumberOfElements(); i++){
00092         v = dynamic_cast<Vertex*>( col->getElementAt( i ) ) ;
00093         _set.insert(v->getAlgorithmType());
00094       }
00095       for(std::set<std::string>::iterator it=_set.begin(); it!=_set.end(); it++){
00096         parameters.push_back(*it);
00097       }
00098       //add parameters to collection
00099       col->parameters().setValues("_lcio.VertexAlgorithmTypes",parameters);
00100       
00101       SIOLCParameters::write( stream , col->getParameters() ) ;
00102                                                                                                                                                              
00103       _vers = vers ;  // not really needed !?
00104                                                                                                                                                              
00105     }
00106     return ( SIO_BLOCK_SUCCESS ) ;
00107   }
00108 
00109   
00110   unsigned int SIOVertexHandler::read(SIO_stream* stream, LCObject** objP){
00111 
00112     unsigned int status ; 
00113 
00114     // create a new object :
00115     VertexIOImpl* vtx  = new VertexIOImpl ;
00116     *objP = vtx ;
00117 
00118     //read data
00119     SIO_DATA( stream ,  &(vtx->_primary)  , 1 ) ;
00120     int algtype;
00121     SIO_DATA( stream ,  &algtype  , 1 ) ;
00122     vtx->setAlgorithmType(imr[algtype]);
00123     //std::set<std::string>::iterator it;
00124     //advance(it=_set.begin(),algtype);
00125     //vtx->setAlgorithmType(*it);
00126     
00127     //dbg
00128     //std::cout<<"Reading... (int)["<<algtype<<"] (string)["<<(*it)<<"]\n";
00129     //std::cout<<"Reading... (int)["<<algtype<<"] (string)["<<imr[algtype]<<"]\n";
00130       
00131     SIO_DATA( stream ,  &(vtx->_chi2)  , 1 ) ;
00132     SIO_DATA( stream ,  &(vtx->_probability)  , 1 ) ;
00133     SIO_DATA( stream ,  vtx->_vpos  , 3 ) ;
00134 
00135     //read covMatrix
00136     float cov[VTXCOVMATRIX] ;
00137     SIO_DATA( stream ,  cov  ,  VTXCOVMATRIX ) ;
00138     vtx->setCovMatrix( cov ) ;
00139 
00140     //read parameters
00141     int nPara  ;
00142     SIO_DATA( stream ,  &nPara  , 1 ) ;
00143     float aParameter ;
00144     for(int i=0; i<nPara; i++){
00145       SIO_DATA( stream ,  &aParameter  , 1 ) ;
00146       vtx->addParameter( aParameter ) ;
00147     }
00148 
00149     //read pointer to associated reconstructed particle
00150     SIO_PNTR( stream ,   &(vtx->_aParticle) ) ;
00151 
00152     // read the pointer tag 
00153     SIO_PTAG( stream , dynamic_cast<const Vertex*>(vtx) ) ;
00154     return ( SIO_BLOCK_SUCCESS ) ;
00155   }
00156     
00157     
00158   unsigned int SIOVertexHandler::write(SIO_stream* stream, const LCObject* obj){
00159     
00160     unsigned int status ; 
00161     
00162     // this is where we gave up type safety in order to
00163     // simplify the API and the implementation
00164     // by having a common collection of objects
00165     const Vertex* vtx = dynamic_cast<const Vertex*>(obj)  ;
00166 
00167     //write data
00168     LCSIO_WRITE( stream, vtx->isPrimary()  ) ;
00169     //LCSIO_WRITE( stream, imw[vtx->getAlgorithmType()]  ) ;
00170    
00171     LCSIO_WRITE( stream, static_cast<size_t> (distance( _set.begin(),_set.find( vtx->getAlgorithmType() )))) ;
00172     
00173     //dbg
00174     //std::cout<<"Writing... (string)["<<vtx->getAlgorithmType()<<"] (int)["<<distance( _set.begin(),_set.find( vtx->getAlgorithmType() ))<<"]\n";
00175     
00176     LCSIO_WRITE( stream, vtx->getChi2()  ) ;
00177     LCSIO_WRITE( stream, vtx->getProbability()  ) ;
00178 
00179     //write position of the vertex
00180     float* pos = const_cast<float*> ( vtx->getPosition() ) ; 
00181     SIO_DATA( stream,  pos , 3 ) ;
00182     
00183     //write covariance matrix
00184     const FloatVec& cov = vtx->getCovMatrix() ;
00185     for(unsigned int i=0; i<cov.size(); i++){
00186       LCSIO_WRITE( stream, cov[i]  ) ;
00187     }
00188 
00189     //write parameters
00190     int nPara = vtx->getParameters().size() ;
00191     SIO_DATA( stream ,  &nPara  , 1 ) ;
00192     for(int i=0; i<nPara; i++){
00193       LCSIO_WRITE( stream, vtx->getParameters()[i]  ) ;
00194     }
00195 
00196     //write pointer to associated reconstructed particle
00197     EVENT::ReconstructedParticle* recP = vtx->getAssociatedParticle() ;
00198     SIO_PNTR( stream , &recP  ) ;
00199         
00200     
00201     // write a ptag in order to be able to point to vertices
00202     SIO_PTAG( stream , vtx ) ;
00203 
00204     return ( SIO_BLOCK_SUCCESS ) ;
00205   }
00206   
00207 } // namespace

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