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

Go to the documentation of this file.
00001 #include "SIO/SIOLCGenericObjectHandler.h"
00002 
00003 #include "SIO/LCSIO.h"
00004 
00005 #include "EVENT/LCIO.h"
00006 #include "EVENT/MCParticle.h"
00007 #include "EVENT/LCGenericObject.h"
00008 #include "IOIMPL/LCGenericObjectIOImpl.h"
00009 #include "IMPL/LCFlagImpl.h"
00010 
00011 #include "SIO_functions.h"
00012 #include "SIO_block.h"
00013 #include "SIO/SIOLCParameters.h"
00014 
00015 using namespace EVENT ;
00016 using namespace IMPL ;
00017 using namespace IOIMPL ;
00018 
00019 
00020 namespace SIO{
00021     
00022   unsigned int  SIOLCGenericObjectHandler::init( SIO_stream* stream, 
00023                                         SIO_operation op,
00024                                         LCCollection* col, 
00025                                         unsigned int vers ) {
00026     unsigned int status ; 
00027 
00028     if( op == SIO_OP_READ ) {
00029 
00030 
00031       SIO_DATA( stream ,  &_flag , 1  ) ;
00032       if( vers > SIO_VERSION_ENCODE( 1, 1)   ) 
00033         SIOLCParameters::read( stream ,  col->parameters() , vers ) ;
00034       
00035       col->setFlag( _flag ) ;
00036       _vers = vers ;
00037       
00038       _isFixedSize  =  LCFlagImpl(_flag).bitSet( LCIO::GOBIT_FIXED ) ;
00039       
00040       if( _isFixedSize ) { // need to read the size variables once
00041         
00042         SIO_DATA( stream , &_nInt  , 1  ) ;
00043         SIO_DATA( stream , &_nFloat  , 1  ) ;
00044         SIO_DATA( stream , &_nDouble  , 1  ) ;
00045       }
00046       
00047 
00048     } else if( op == SIO_OP_WRITE ) {
00049       
00050 
00051       _isFixedSize = true ;
00052       // need to check whether we have fixed size objects only
00053       unsigned int nObj = col->getNumberOfElements() ;
00054       for( unsigned int i=0 ; i < nObj ; i++ ){
00055         LCGenericObject* obj  =  dynamic_cast< LCGenericObject* >( col->getElementAt( i ) ) ; 
00056         if( !  obj->isFixedSize() ){ 
00057           _isFixedSize = false ;
00058           break ;
00059         }
00060       }
00061       LCFlagImpl flag( col->getFlag() ) ;
00062       
00063       LCGenericObject* gObj  =  0 ;
00064       if( col->getNumberOfElements() > 0 ) 
00065           gObj = dynamic_cast< LCGenericObject* >( col->getElementAt( 0 ) ) ; 
00066 
00067       // if the collection doesn't have the TypeName/DataDescription parameters set,
00068       //  we use the ones from the first object
00069       if(  col->parameters().getStringVal( "TypeName" ).size() ==  0 && gObj != 0 )
00070         col->parameters().setValue( "TypeName", gObj->getTypeName() ) ;
00071       
00072       if( _isFixedSize ) {
00073         
00074         flag.setBit( LCIO::GOBIT_FIXED ) ;
00075         
00076         if(  col->parameters().getStringVal( "DataDescription" ).size() ==  0 && gObj != 0 )
00077           col->parameters().setValue( "DataDescription", gObj->getDataDescription() ) ;
00078       }
00079       
00080       
00081 
00082       _flag = flag.getFlag() ;
00083       
00084       LCSIO_WRITE( stream, _flag  ) ;
00085       SIOLCParameters::write( stream , col->getParameters() ) ;
00086       
00087       if( _isFixedSize ) { // need to write the size variables once
00088 
00089           if( gObj != 0 ){
00090               _nInt = gObj->getNInt() ;
00091               _nFloat = gObj->getNFloat() ;
00092               _nDouble = gObj->getNDouble() ;
00093           } else {
00094               _nInt = 0 ;
00095               _nFloat = 0 ;
00096               _nDouble = 0 ;
00097           }
00098 
00099           SIO_DATA( stream , &_nInt  , 1  ) ;
00100           SIO_DATA( stream , &_nFloat  , 1  ) ;
00101           SIO_DATA( stream , &_nDouble  , 1  ) ;
00102           
00103         //      cout << " >>>>>>>  written nInt, nFloat, nDouble : " << _nInt << ", " << _nFloat << ", " << _nDouble  
00104         // << " for type " << col->getTypeName() << endl ;
00105       }
00106       
00107     }
00108     return ( SIO_BLOCK_SUCCESS ) ;
00109   }
00110   
00111 
00112   unsigned int SIOLCGenericObjectHandler::read(SIO_stream* stream, 
00113                                                LCObject** objP ){
00114     unsigned int status ; 
00115 
00116     LCGenericObjectIOImpl* obj  = new LCGenericObjectIOImpl ;   
00117     *objP = obj ;
00118     
00119     obj->_isFixedSize = _isFixedSize ;
00120     
00121     if( ! _isFixedSize ){ 
00122       
00123       SIO_DATA( stream ,  &_nInt , 1  ) ;
00124       SIO_DATA( stream ,  &_nFloat , 1  ) ;
00125       SIO_DATA( stream ,  &_nDouble , 1  ) ;
00126     } 
00127     
00128     
00129     obj->_intVec.resize( _nInt )  ; 
00130     obj->_floatVec.resize( _nFloat ) ; 
00131     obj->_doubleVec.resize( _nDouble ) ;
00132     
00133     // the 2003 C++ standard guarantes that vector uses  contigous memory ...
00134     SIO_DATA( stream , &(obj->_intVec[0])  , _nInt  ) ;      
00135     SIO_DATA( stream , &(obj->_floatVec[0])  , _nFloat  ) ;      
00136     SIO_DATA( stream , &(obj->_doubleVec[0])  , _nDouble  ) ;      
00137     
00138     SIO_PTAG( stream , obj  ) ;
00139     
00140     return ( SIO_BLOCK_SUCCESS ) ;
00141   }
00142   
00143   
00144   unsigned int SIOLCGenericObjectHandler::write(SIO_stream* stream, 
00145                                                 const LCObject* obj){
00146     
00147     unsigned int status ; 
00148     
00149     const LCGenericObject* gObj = dynamic_cast<const LCGenericObject*>(obj)  ;
00150     
00151     if( ! _isFixedSize ){ 
00152 
00153       _nInt = gObj->getNInt() ;
00154       _nFloat = gObj->getNFloat() ;
00155       _nDouble = gObj->getNDouble() ;
00156 
00157       LCSIO_WRITE( stream , _nInt  ) ;
00158       LCSIO_WRITE( stream , _nFloat ) ;
00159       LCSIO_WRITE( stream ,  _nDouble ) ;
00160 
00161     } 
00162     for( int i=0 ; i< _nInt ; i++){
00163       LCSIO_WRITE( stream , gObj->getIntVal( i ) ) ;
00164     }
00165     for( int i=0 ; i< _nFloat ; i++){
00166       LCSIO_WRITE( stream , gObj->getFloatVal( i ) ) ;
00167     }
00168     for( int i=0 ; i< _nDouble ; i++){
00169       //      LCSIO_WRITE( stream , gObj->getDoubleVal( i ) ) ;
00170       double dVal =  gObj->getDoubleVal( i ) ;
00171       SIO_DATA( stream , &dVal  , 1  ) ;
00172     }
00173 
00174     SIO_PTAG( stream , gObj  ) ;
00175 
00176     return ( SIO_BLOCK_SUCCESS ) ;
00177   }
00178   
00179 } // namespace

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