00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "BaBar/BaBar.hh"
00010
00011 #if !defined(OO_DDL_TRANSLATION)
00012 #include "CdbBdbTable/CdbBdbNTupleSimpleImplP.hh"
00013 #endif // OO_DDL_TRANSLATION
00014
00015 #include <iostream>
00016 #include <assert.h>
00017 using std::cout;
00018 using std::endl;
00019
00020 template< class E >
00021 CdbBdbNTupleSimpleImplP<E>::CdbBdbNTupleSimpleImplP( d_ULong theNumberOfColumns,
00022 const std::string& theName,
00023 const std::string& theDescription,
00024 const std::vector<std::string>& theColumnNames ) :
00025 CdbBdbNTupleP<E>( theNumberOfColumns,
00026 theName,
00027 theDescription,
00028 theColumnNames ),
00029 _rows(0),
00030 _dataRef(0)
00031 {
00032 _dataRef = new( ooThis( )) CdbBdbSPagedVarrayP<E>( );
00033 if( BdbIsNull(_dataRef)) {
00034 cout << "CdbBdbNTupleSimpleImplP<E>::CdbBdbNTupleSimpleImplP() -- FATAL ERROR IN THE CONSTRUCTOR." << endl
00035 << " Failed to create an instance of the paged v-array object to store elements" << endl
00036 << " of the n-tuple." << endl;
00037 assert(0);
00038 }
00039 }
00040
00041 template< class E >
00042 CdbBdbNTupleSimpleImplP<E>::~CdbBdbNTupleSimpleImplP( )
00043 {
00044 BdbDelete(_dataRef);
00045 _dataRef = 0;
00046 }
00047
00048 template< class E >
00049 d_ULong
00050 CdbBdbNTupleSimpleImplP<E>::rows( ) const
00051 {
00052 return _rows;
00053 }
00054
00055 template< class E >
00056 CdbStatus
00057 CdbBdbNTupleSimpleImplP<E>::get_row( std::vector<E>& theRow,
00058 const d_ULong theNumber ) const
00059 {
00060 if( theNumber >= _rows ) return CdbStatus::NotFound;
00061
00062 d_ULong nColumns = columns( );
00063 d_ULong first = nColumns * theNumber;
00064
00065
00066
00067 if( _dataRef->size( ) < first + nColumns ) {
00068 cout << "CdbBdbNTupleSimpleImplP<E>::get_row() -- ERROR." << endl
00069 << " An inconsistency in the internal data structures of the current" << endl
00070 << " object " << ooThis( ).sprint( ) << " detected." << endl
00071 << " It may happen due to a transient memory corruption or a corrupted" << endl
00072 << " persistent store." << endl;
00073 return CdbStatus::Error;
00074 }
00075
00076
00077
00078 theRow.clear( );
00079 for( d_ULong i = 0; i < nColumns; ++i )
00080 theRow.push_back( _dataRef->elementAt( first + i ));
00081
00082 return CdbStatus::Success;
00083 }
00084
00085 template< class E >
00086 CdbStatus
00087 CdbBdbNTupleSimpleImplP<E>::append_row( const std::vector<E>& theRow )
00088 {
00089 ooUpdate( );
00090 if( columns( ) != theRow.size( )) return CdbStatus::IllegalParameters;
00091
00092 d_ULong nColumns = columns( );
00093 d_ULong first = nColumns * _rows;
00094
00095
00096
00097 d_ULong capacity = _dataRef->size( );
00098
00099 if( capacity < first ) {
00100 cout << "CdbBdbNTupleSimpleImplP<E>::append_row() -- ERROR." << endl
00101 << " An inconsistency in the internal data structures of the current" << endl
00102 << " object " << ooThis( ).sprint( ) << " detected." << endl
00103 << " It may happen due to a transient memory corruption or a corrupted" << endl
00104 << " persistent store." << endl;
00105 return CdbStatus::Error;
00106 }
00107
00108
00109
00110
00111 d_ULong nFree = capacity - first;
00112 if( nFree < nColumns ) {
00113 d_ULong nToAdd = ( capacity > ( nColumns - nFree ) ? capacity : ( nColumns - nFree ));
00114 if( BdbcSuccess != _dataRef->resize( capacity + nToAdd )) return CdbStatus::Error;
00115 }
00116
00117
00118
00119
00120 for( d_ULong i = 0; i < nColumns; ++i )
00121 _dataRef->setElementAt( first + i, theRow[i] );
00122
00123 ++_rows;
00124
00125 return CdbStatus::Success;
00126 }
00127
00128 template< class E >
00129 CdbStatus
00130 CdbBdbNTupleSimpleImplP<E>::repack( )
00131 {
00132 ooUpdate( );
00133 return ( BdbcSuccess == _dataRef->resize( columns( ) * _rows ) ? CdbStatus::Success : CdbStatus::Error );
00134 }
00135
00136
00137
00138