CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/CondCore/ORA/src/PrimitiveStreamer.cc

Go to the documentation of this file.
00001 #include "CondCore/ORA/interface/Exception.h"
00002 #include "PrimitiveStreamer.h"
00003 #include "DataElement.h"
00004 #include "MappingElement.h"
00005 #include "RelationalOperation.h"
00006 #include "ClassUtils.h"
00007 // externals
00008 #include "CoralBase/Attribute.h"
00009 
00010 
00011 ora::PrimitiveStreamerBase::PrimitiveStreamerBase( const Reflex::Type& objectType,
00012                                                    MappingElement& mapping ):
00013   m_objectType( objectType ),
00014   m_columnName(""),
00015   m_dataElement( 0 ),
00016   m_relationalData( 0 ){
00017   
00018   if( mapping.columnNames().size() ){
00019     m_columnName = mapping.columnNames()[0];
00020   }
00021 }
00022 
00023 ora::PrimitiveStreamerBase::~PrimitiveStreamerBase(){
00024 }
00025 
00026 bool ora::PrimitiveStreamerBase::buildDataElement(DataElement& dataElement,
00027                                                   IRelationalData& relationalData){
00028     
00029   if( m_columnName.empty() ){
00030     throwException( "Column name not found ",
00031                     "PrimitiveStreamerBase::buildDataElement");
00032   }
00033   
00034   m_dataElement = &dataElement;
00035   const std::type_info* attrType = &m_objectType.TypeInfo();
00036   if(m_objectType.IsEnum()) attrType = &typeid(int);
00037   if(ClassUtils::isTypeString( m_objectType )) attrType = &typeid(std::string);
00038   relationalData.addData( m_columnName, *attrType );
00039   m_relationalData = &relationalData;
00040   return true;
00041 }
00042 
00043 void ora::PrimitiveStreamerBase::bindDataForUpdate( const void* data ){
00044   if( ! m_dataElement ){
00045     throwException( "The streamer has not been built.",
00046                     "PrimitiveStreamerBase::bindDataForUpdate");
00047   }
00048   void* dataElementAddress = m_dataElement->address( data );
00049   coral::Attribute& relDataElement = m_relationalData->data()[ m_columnName ];
00050   relDataElement.setValueFromAddress( dataElementAddress );
00051   if(!relDataElement.isValidData()){
00052     throwException("Data provided for column \""+
00053                    relDataElement.specification().name()+
00054                    "\" is not valid for RDBMS storage.",
00055                    "PrimitiveStreamerBase::bindDataForUpdate");
00056   }  
00057 }
00058 
00059 void ora::PrimitiveStreamerBase::bindDataForRead( void* data ){
00060   if( ! m_dataElement ){
00061     throwException( "The streamer has not been built.",
00062                     "PrimitiveStreamerBase::bindDataForRead");
00063   }
00064   void* dataElementAddress = m_dataElement->address( data );
00065   coral::Attribute& relDataElement = m_relationalData->data()[ m_columnName ];
00066   relDataElement.copyValueToAddress( dataElementAddress );
00067 }
00068 
00069 
00070 ora::PrimitiveWriter::PrimitiveWriter( const Reflex::Type& objectType,
00071                                        MappingElement& mapping ):
00072   PrimitiveStreamerBase( objectType, mapping ){
00073 }
00074 
00075 ora::PrimitiveWriter::~PrimitiveWriter(){
00076 }
00077 
00078 bool ora::PrimitiveWriter::build(DataElement& dataElement,
00079                                  IRelationalData& relationalData,
00080                                  RelationalBuffer&){
00081   return buildDataElement( dataElement, relationalData );
00082 }
00083 
00084 void ora::PrimitiveWriter::setRecordId( const std::vector<int>& ){
00085 }
00086 
00087 void ora::PrimitiveWriter::write( int, const void* data ){
00088   bindDataForUpdate( data );  
00089 }
00090 
00091 ora::PrimitiveUpdater::PrimitiveUpdater( const Reflex::Type& objectType,
00092                                          MappingElement& mapping ):
00093   PrimitiveStreamerBase( objectType, mapping ){
00094 }
00095 
00096 ora::PrimitiveUpdater::~PrimitiveUpdater(){
00097 }
00098 
00099 bool ora::PrimitiveUpdater::build(DataElement& dataElement,
00100                                   IRelationalData& relationalData,
00101                                   RelationalBuffer&){
00102   return buildDataElement( dataElement, relationalData );  
00103 }
00104 
00105 void ora::PrimitiveUpdater::setRecordId( const std::vector<int>& ){
00106 }
00107 
00108 void ora::PrimitiveUpdater::update( int,
00109                                     const void* data ){
00110   bindDataForUpdate( data );  
00111 }
00112 
00113 ora::PrimitiveReader::PrimitiveReader( const Reflex::Type& objectType,
00114                                        MappingElement& mapping ):
00115   PrimitiveStreamerBase( objectType, mapping ){
00116 }
00117 
00118 ora::PrimitiveReader::~PrimitiveReader(){
00119 }
00120 
00121 bool ora::PrimitiveReader::build(DataElement& dataElement,
00122                                  IRelationalData& relationalData){
00123   return buildDataElement( dataElement, relationalData );  
00124 }
00125 
00126 void ora::PrimitiveReader::select( int ){
00127 }
00128 
00129 void ora::PrimitiveReader::setRecordId( const std::vector<int>& ){
00130 }
00131 
00132 void ora::PrimitiveReader::read( void* data ){
00133   bindDataForRead( data );
00134 }
00135 
00136 void ora::PrimitiveReader::clear(){
00137 }
00138 
00139 
00140 ora::PrimitiveStreamer::PrimitiveStreamer( const Reflex::Type& objectType,
00141                                            MappingElement& mapping ):
00142   m_objectType( objectType ),
00143   m_mapping( mapping ){
00144 }
00145 
00146 ora::PrimitiveStreamer::~PrimitiveStreamer(){
00147 }
00148 
00149 ora::IRelationalWriter* ora::PrimitiveStreamer::newWriter(){
00150   return new PrimitiveWriter( m_objectType, m_mapping );
00151 }
00152 
00153 ora::IRelationalUpdater* ora::PrimitiveStreamer::newUpdater(){
00154   return new PrimitiveUpdater( m_objectType, m_mapping );
00155 }
00156 
00157 ora::IRelationalReader* ora::PrimitiveStreamer::newReader(){
00158   return new PrimitiveReader( m_objectType, m_mapping );
00159 }