CMS 3D CMS Logo

Public Member Functions | Private Attributes

ora::STLContainerWriter Class Reference

#include <STLContainerStreamer.h>

Inheritance diagram for ora::STLContainerWriter:
ora::IRelationalWriter

List of all members.

Public Member Functions

IArrayHandlerarrayHandler ()
bool build (DataElement &offset, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
DataElementdataElement ()
MappingElementmapping ()
void setRecordId (const std::vector< int > &identity)
 STLContainerWriter (const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
 Constructor.
void write (int oid, const void *data)
 Writes a data element.
virtual ~STLContainerWriter ()

Private Attributes

std::auto_ptr< IArrayHandlerm_arrayHandler
bool m_associative
std::auto_ptr< IRelationalWriterm_dataWriter
MultiRecordInsertOperationm_insertOperation
std::auto_ptr< IRelationalWriterm_keyWriter
DataElement m_localElement
MappingElementm_mappingElement
Reflex::Type m_objectType
DataElementm_offset
std::vector< int > m_recordId
ContainerSchemam_schema

Detailed Description

Definition at line 21 of file STLContainerStreamer.h.


Constructor & Destructor Documentation

ora::STLContainerWriter::STLContainerWriter ( const Reflex::Type &  objectType,
MappingElement mapping,
ContainerSchema contSchema 
)

Constructor.

Definition at line 19 of file STLContainerStreamer.cc.

ora::STLContainerWriter::~STLContainerWriter ( ) [virtual]

Definition at line 35 of file STLContainerStreamer.cc.

                                          {
}

Member Function Documentation

ora::IArrayHandler * ora::STLContainerWriter::arrayHandler ( ) [inline]

Definition at line 151 of file STLContainerStreamer.h.

                                   {
  return m_arrayHandler.get();
}
bool ora::STLContainerWriter::build ( DataElement offset,
IRelationalData relationalData,
RelationalBuffer operationBuffer 
) [virtual]

Implements ora::IRelationalWriter.

Definition at line 38 of file STLContainerStreamer.cc.

References ora::ClassUtils::containerDataType(), ora::ClassUtils::containerKeyType(), ora::ClassUtils::containerValueType(), i, ora::ArrayHandlerFactory::newArrayHandler(), ora::RelationalBuffer::newMultiRecordInsert(), ora::RelationalStreamerFactory::newWriter(), evf::evtn::offset(), ora::ClassUtils::resolvedType(), AlCaHLTBitMon_QueryRunRegistry::string, and ora::throwException().

                                                                        {
  if( !m_objectType ){
    throwException( "Missing dictionary information for the type of the container \"" +
                    m_objectType.Name(Reflex::SCOPED|Reflex::FINAL) + "\"",
                    "STLContainerWriter::build" );
  }
  m_localElement.clear();
  m_recordId.clear();
  // allocate for the index...
  m_recordId.push_back(0);
    
  RelationalStreamerFactory streamerFactory( m_schema );
  
  // first open the insert on the extra table...
  m_insertOperation = &operationBuffer.newMultiRecordInsert( m_mappingElement.tableName() );
  const std::vector<std::string>& columns = m_mappingElement.columnNames();
  if( !columns.size() ){
    throwException( "Id columns not found in the mapping.",
                    "STLContainerWriter::build");    
  }
  for( size_t i=0; i<columns.size(); i++ ){
    m_insertOperation->addId( columns[ i ] );
  }

  m_offset = &offset;

  m_arrayHandler.reset( ArrayHandlerFactory::newArrayHandler( m_objectType ) );
  
  Reflex::Type valueType;
  if ( m_associative ){
    
    Reflex::Type keyType = ClassUtils::containerKeyType(m_objectType);
    Reflex::Type keyResolvedType = ClassUtils::resolvedType(keyType);
    if ( ! keyType || !keyResolvedType ) {
      throwException( "Missing dictionary information for the key type of the container \"" +
                      m_objectType.Name(Reflex::SCOPED) + "\"",
                      "STLContainerWriter::build" );
    }
    std::string keyName = keyType.Name();
    // Retrieve the relevant mapping element
    MappingElement::iterator iMe = m_mappingElement.find( keyName );
    if ( iMe == m_mappingElement.end() ) {
      throwException( "Item for \"" + keyName + "\" not found in the mapping element",
                      "STLContainerWriter::build" );
    }

    m_keyWriter.reset( streamerFactory.newWriter( keyResolvedType, iMe->second ) );
    m_keyWriter->build( m_localElement, *m_insertOperation, operationBuffer );
    valueType = ClassUtils::containerDataType(m_objectType);
  } else {
    valueType = ClassUtils::containerValueType(m_objectType);
  }

  Reflex::Type valueResolvedType = ClassUtils::resolvedType(valueType);
  // Check the component type
  if ( ! valueType || !valueResolvedType ) {
    throwException( "Missing dictionary information for the content type of the container \"" +
                    m_objectType.Name(Reflex::SCOPED) + "\"",
                    "STLContainerWriter::build" );
  }
  
  std::string valueName = valueType.Name();
  // Retrieve the relevant mapping element
  MappingElement::iterator iMe = m_mappingElement.find( valueName );
  if ( iMe == m_mappingElement.end() ) {
    throwException( "Item for \"" + valueName + "\" not found in the mapping element",
                    "STLContainerWriter::build" );
  }

  m_dataWriter.reset( streamerFactory.newWriter( valueResolvedType, iMe->second ) );
  m_dataWriter->build( m_localElement, *m_insertOperation, operationBuffer );
  //operationBuffer.addToExecutionBuffer( *m_insertOperation );
  return true;
}
ora::DataElement * ora::STLContainerWriter::dataElement ( ) [inline]

Definition at line 145 of file STLContainerStreamer.h.

                                  {
  return m_offset;
}
ora::MappingElement & ora::STLContainerWriter::mapping ( ) [inline]

Definition at line 139 of file STLContainerStreamer.h.

References m_mappingElement.

                              {
  return m_mappingElement;
}
void ora::STLContainerWriter::setRecordId ( const std::vector< int > &  identity) [virtual]

Implements ora::IRelationalWriter.

Definition at line 115 of file STLContainerStreamer.cc.

References i.

                                                                       {
  m_recordId.clear();
  for(size_t i=0;i<identity.size();i++) {
    m_recordId.push_back( identity[i] );
  }
  m_recordId.push_back( 0 );
}
void ora::STLContainerWriter::write ( int  oid,
const void *  data 
) [virtual]

Writes a data element.

Implements ora::IRelationalWriter.

Definition at line 123 of file STLContainerStreamer.cc.

References AlCaHLTBitMon_QueryRunRegistry::data, i, ora::InsertCache::processNextIteration(), and ora::throwException().

                                                            {

  if(!m_offset){
    throwException("The streamer has not been built.",
                   "STLContainerWriter::write");
  }

  const std::vector<std::string>& columns = m_mappingElement.columnNames();
  if( columns.size() != m_recordId.size()+1){
    throwException( "Object id elements provided are not matching with the mapped id columns.",
                    "STLContainerWriter::write");
  }

  const Reflex::Type& iteratorReturnType = m_arrayHandler->iteratorReturnType();
  // Retrieve the container type
  Reflex::Type keyType;
  if ( m_associative ) keyType = m_objectType.TemplateArgumentAt(0);
  Reflex::Member firstMember;
  Reflex::Member secondMember;
  if( keyType ){
    firstMember = iteratorReturnType.MemberByName( "first" );
    if ( ! firstMember ) {
      throwException( "Could not find the data member \"first\" for the class \"" +
                      iteratorReturnType.Name(Reflex::SCOPED) + "\"",
                      "STLContainerWriter::write" );
    }
    secondMember = iteratorReturnType.MemberByName( "second" );
    if ( ! secondMember ) {
      throwException( "Could not retrieve the data member \"second\" for the class \"" +
                      iteratorReturnType.Name(Reflex::SCOPED) + "\"",
                      "STLContainerWriter::write" );
    }
  }
  
  void* data = m_offset->address( inputData );
  
  // Use the iterator to loop over the elements of the container.
  size_t containerSize = m_arrayHandler->size( data  );
  
  if ( containerSize == 0 ) return;

  size_t startElementIndex = m_arrayHandler->startElementIndex( data );
  std::auto_ptr<IArrayIteratorHandler> iteratorHandler( m_arrayHandler->iterate( data ) );

  InsertCache& bulkInsert = m_insertOperation->setUp( containerSize-startElementIndex+1 );

  for ( size_t iIndex = startElementIndex; iIndex < containerSize; ++iIndex ) {

    m_recordId[m_recordId.size()-1] = iIndex;
    coral::AttributeList& dataBuff = m_insertOperation->data();

    dataBuff[ columns[0] ].data<int>() = oid;
    for( size_t i = 1;i < columns.size(); i++ ){
      dataBuff[ columns[i] ].data<int>() = m_recordId[i-1];
    }

    void* objectReference = iteratorHandler->object();
    void* componentData = objectReference;

    if ( keyType ) { // treat the key object first
      void* keyData = static_cast< char* >( objectReference ) + firstMember.Offset();
      m_keyWriter->setRecordId( m_recordId );
      m_keyWriter->write( oid, keyData );

      componentData = static_cast< char* >( objectReference ) + secondMember.Offset();
    }
    m_dataWriter->setRecordId( m_recordId );

    m_dataWriter->write( oid, componentData );
    bulkInsert.processNextIteration();
   
    // Increment the iterator
    iteratorHandler->increment();
  }

  // execute the insert...
  m_arrayHandler->finalize( const_cast<void*>( data ) );

}

Member Data Documentation

Definition at line 52 of file STLContainerStreamer.h.

Definition at line 49 of file STLContainerStreamer.h.

Definition at line 54 of file STLContainerStreamer.h.

Definition at line 51 of file STLContainerStreamer.h.

Definition at line 53 of file STLContainerStreamer.h.

Definition at line 46 of file STLContainerStreamer.h.

Definition at line 43 of file STLContainerStreamer.h.

Referenced by mapping().

Reflex::Type ora::STLContainerWriter::m_objectType [private]

Definition at line 42 of file STLContainerStreamer.h.

Definition at line 50 of file STLContainerStreamer.h.

std::vector<int> ora::STLContainerWriter::m_recordId [private]

Definition at line 45 of file STLContainerStreamer.h.

Definition at line 44 of file STLContainerStreamer.h.