CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/CondCore/ORA/src/PVectorHandler.cc

Go to the documentation of this file.
00001 #include "CondCore/ORA/interface/Exception.h"
00002 #include "PVectorHandler.h"
00003 #include "ClassUtils.h"
00004 // externals
00005 #include "RVersion.h"
00006 
00007 ora::PVectorIteratorHandler::PVectorIteratorHandler( const Reflex::Environ<long>& collEnv,
00008                                                      Reflex::CollFuncTable& collProxy,
00009                                                      const Reflex::Type& iteratorReturnType,
00010                                                      size_t startElement):
00011   m_returnType(iteratorReturnType),
00012   m_collEnv(collEnv),
00013   m_collProxy(collProxy),
00014   m_currentElement(0),
00015   m_startElement(startElement){
00016   // retrieve the first element
00017   m_currentElement = m_collProxy.first_func(&m_collEnv);
00018 
00019   if(startElement){
00020     size_t i = 0;
00021     while(i<startElement){
00022       increment();
00023       i++;
00024     }
00025   }
00026 }
00027 
00028 ora::PVectorIteratorHandler::~PVectorIteratorHandler(){
00029 }
00030 
00031 void
00032 ora::PVectorIteratorHandler::increment(){
00033   // this is requiredd! It sets the number of memory slots (of size sizeof(Class)) to be used for the step
00034   m_collEnv.fIdx = 1;
00035   m_currentElement = m_collProxy.next_func(&m_collEnv);
00036 }
00037 
00038 void*
00039 ora::PVectorIteratorHandler::object(){
00040   return m_currentElement;
00041 }
00042 
00043 Reflex::Type&
00044 ora::PVectorIteratorHandler::returnType(){
00045   return m_returnType;
00046 }
00047 
00048 ora::PVectorHandler::PVectorHandler( const Reflex::Type& dictionary ):
00049   m_type( dictionary ),
00050   m_iteratorReturnType(),
00051   m_isAssociative( false ),
00052   m_collEnv(),
00053   m_collProxy(),
00054   m_persistentSizeAttributeOffset(0),
00055   m_vecAttributeOffset(0)
00056 {
00057   Reflex::Member privateVectorAttribute = m_type.DataMemberByName("m_vec");
00058   if(privateVectorAttribute){
00059     m_vecAttributeOffset = privateVectorAttribute.Offset();
00060     Reflex::Member method = privateVectorAttribute.TypeOf().MemberByName("createCollFuncTable");
00061     if(method){
00062       Reflex::CollFuncTable* collProxyPtr;
00063       method.Invoke(collProxyPtr);
00064       m_collProxy.reset( collProxyPtr );
00065     }
00066     if(! m_collProxy.get() ){
00067       throwException( "Cannot find \"createCollFuncTable\" function for type \""+m_type.Name(Reflex::SCOPED)+"\"",
00068                       "PVectorHandler::PVectorHandler");
00069     }
00070   }
00071 
00072   Reflex::Member persistentSizeAttribute = m_type.DataMemberByName("m_persistentSize");
00073   if( persistentSizeAttribute ){
00074     m_persistentSizeAttributeOffset = persistentSizeAttribute.Offset();
00075   }
00076 
00077   // find the iterator return type as the member type_value of the containers
00078   Reflex::Type valueType = ClassUtils::containerValueType( m_type );
00079   m_iteratorReturnType = ClassUtils::resolvedType( valueType );
00080 }
00081 
00082 ora::PVectorHandler::~PVectorHandler(){
00083 }
00084 
00085 size_t
00086 ora::PVectorHandler::size( const void* address ){
00087   m_collEnv.fObject = static_cast<char*>(const_cast<void*>(address))+m_vecAttributeOffset;
00088   size_t transientSize = *(static_cast<size_t*>(m_collProxy->size_func(&m_collEnv)));
00089   return transientSize;
00090 }
00091 
00092 size_t
00093 ora::PVectorHandler::startElementIndex( const void* address ){
00094   void* persistentSizeAddress = static_cast<char*>(const_cast<void*>(address))+m_persistentSizeAttributeOffset;
00095   size_t persistentSize = *static_cast<size_t*>(persistentSizeAddress);
00096   size_t transientSize = *(static_cast<size_t*>(m_collProxy->size_func(&m_collEnv)));
00097   size_t startElement = 0;
00098   if(persistentSize < transientSize) startElement = persistentSize;
00099   return startElement;
00100 }
00101 
00102 size_t ora::PVectorHandler::persistentSize( const void* address ){
00103   void* persistentSizeAddress = static_cast<char*>(const_cast<void*>(address))+m_persistentSizeAttributeOffset;
00104   size_t persistentSize = *static_cast<size_t*>(persistentSizeAddress);
00105   return persistentSize;
00106 }
00107 
00108 ora::IArrayIteratorHandler*
00109 ora::PVectorHandler::iterate( const void* address ){
00110   if ( ! m_iteratorReturnType ) {
00111     throwException( "Missing the dictionary information for the value_type member of the container \"" +
00112                     m_type.Name(Reflex::SCOPED|Reflex::FINAL) + "\"",
00113                     "PVectorHandler" );
00114   }
00115   m_collEnv.fObject = static_cast<char*>(const_cast<void*>(address))+m_vecAttributeOffset;
00116   return new PVectorIteratorHandler( m_collEnv,*m_collProxy,m_iteratorReturnType,startElementIndex(address) );
00117 }
00118 
00119 void
00120 ora::PVectorHandler::appendNewElement( void* address, void* data ){
00121   void* dest_address = static_cast<char*>(address)+m_vecAttributeOffset;
00122 #if ROOT_VERSION_CODE < ROOT_VERSION(5,28,0)
00123   m_collEnv.fObject = dest_address;
00124   m_collEnv.fSize = 1;
00125   m_collEnv.fStart = data;
00126   m_collProxy->feed_func(&m_collEnv);
00127 #else
00128   m_collProxy->feed_func(data,dest_address,1);
00129 #endif
00130 }
00131 
00132 void
00133 ora::PVectorHandler::clear( const void* address ){
00134   m_collEnv.fObject = static_cast<char*>(const_cast<void*>(address))+m_vecAttributeOffset;
00135   m_collProxy->clear_func(&m_collEnv);
00136 }
00137 
00138 Reflex::Type&
00139 ora::PVectorHandler::iteratorReturnType() {
00140   return m_iteratorReturnType;
00141 }
00142 
00143 void ora::PVectorHandler::finalize( void* address ){
00144   size_t transSize = size( address );
00145   void* persistentSizeAttributeAddress = static_cast<char*>(address)+m_persistentSizeAttributeOffset;
00146   *static_cast<size_t*>(persistentSizeAttributeAddress) = transSize;
00147 }
00148 
00149                         
00150                         
00151