00001 #ifndef CDB_NTUPLE_SIMPLE_IMPL_HH
00002 #define CDB_NTUPLE_SIMPLE_IMPL_HH
00003
00004
00005
00006
00007 #include "CdbBase/CdbItr.hh"
00008
00009 #include "CdbTable/CdbNTuple.hh"
00010
00011 #include <vector>
00012
00013
00014
00015
00016
00017
00018
00019 template < class T,
00020 unsigned int NCOL >
00021 class CdbNTupleSimpleImpl : public CdbNTuple<T,NCOL> {
00022
00023 friend class CdbNTupleFactory<T,NCOL>;
00024
00025 protected:
00026
00027
00028
00029
00030
00031 CdbNTupleSimpleImpl( );
00032
00033
00034
00035
00036
00037 CdbNTupleSimpleImpl( const std::string& theName,
00038 const std::string& theDescription );
00039
00040
00041
00042
00043
00044 CdbNTupleSimpleImpl( const std::vector<std::string>& theCollumnNames,
00045 const std::string& theName,
00046 const std::string& theDescription );
00047
00048
00049
00050
00051
00052 CdbNTupleSimpleImpl( const CdbNTupleSimpleImpl<T,NCOL>& theOther );
00053
00054
00055
00056
00057
00058 CdbNTupleSimpleImpl<T,NCOL>& operator=( const CdbNTupleSimpleImpl<T,NCOL>& theOther );
00059
00060
00061
00062
00063 virtual ~CdbNTupleSimpleImpl( );
00064
00065 public:
00066
00067
00068
00069
00070
00071 virtual CdbNTuple<T,NCOL>* clone( ) const;
00072
00073
00074
00075
00076
00077 virtual unsigned int rows( ) const;
00078
00079
00080
00081
00082
00083 virtual CdbStatus set_rows( unsigned int theNewSize );
00084
00085
00086
00087
00088
00089 virtual CdbStatus set_rows( unsigned int theNewSize,
00090 const T& thePrototype );
00091
00092
00093
00094
00095
00096 virtual CdbStatus append_row( const std::vector<T>& theRow );
00097
00098
00099
00100
00101
00102 virtual CdbStatus insert_row( const std::vector<T>& theRow,
00103 unsigned int theRowNumber );
00104
00105
00106
00107
00108
00109 virtual CdbStatus replace_row( const std::vector<T>& theRow,
00110 unsigned int theRowNumber );
00111
00112
00113
00114
00115
00116 virtual CdbStatus get_row( std::vector<T>& theRow,
00117 unsigned int theRowNumber ) const;
00118
00119
00120
00121
00122
00123 virtual CdbStatus get_column( std::vector<T>& theColumn,
00124 unsigned int theColumnNumber ) const;
00125
00126
00127
00128
00129
00130 virtual CdbStatus get_column( std::vector<T>& theColumn,
00131 const std::string& theColumnName ) const;
00132
00133
00134
00135
00136
00137 virtual CdbStatus get_element( T& theValue,
00138 unsigned int theRowNumber,
00139 unsigned int theColumnNumber ) const;
00140
00141
00142
00143
00144
00145 virtual CdbStatus get_element( T& theValue,
00146 unsigned int theRowNumber,
00147 const std::string& theColumnName ) const;
00148
00149
00150
00151
00152
00153 virtual CdbStatus set_element( const T& theValue,
00154 unsigned int theRowNumber,
00155 unsigned int theColumnNumber );
00156
00157
00158
00159
00160
00161 virtual CdbStatus set_element( const T& theValue,
00162 unsigned int theRowNumber,
00163 const std::string& theColumnName );
00164
00165
00166
00167
00168
00169 virtual CdbStatus find_row( CdbItr<unsigned int>& theIterator,
00170 unsigned int theColumnNumber,
00171 const T& theValue ) const;
00172
00173
00174
00175
00176
00177 virtual CdbStatus find_row( CdbItr<unsigned int>& theIterator,
00178 const std::string& theColumnName,
00179 const T& theValue ) const;
00180
00181
00182
00183
00184
00185 virtual CdbStatus sort( const CdbNTupleIsLessComparator<T,NCOL>* theComparatorPtr );
00186
00187 public:
00188
00189
00190
00191
00192
00193
00194 struct Row {
00195
00196
00197
00198 Row( )
00199 { };
00200
00201 Row( const T& thePrototypeElement )
00202 {
00203 for( unsigned int i = 0; i < NCOL; ++i ) element[i] = thePrototypeElement;
00204 }
00205
00206 Row( const std::vector<T>& theRow )
00207 {
00208 const unsigned int num = theRow.size( );
00209 const unsigned int num2copy = ( num < NCOL ? num : NCOL );
00210
00211 for( unsigned int i = 0; i < num2copy; ++i ) element[i] = theRow[i];
00212 }
00213
00214 Row( const std::vector<T>& theRow,
00215 const T& thePrototypeElement )
00216 {
00217 const unsigned int num = theRow.size( );
00218 const unsigned int num2copy = ( num < NCOL ? num : NCOL );
00219
00220 for( unsigned int i = 0; i < num2copy; ++i ) element[i] = theRow[i];
00221 for( unsigned int i = num2copy; i < NCOL; ++i ) element[i] = thePrototypeElement;
00222 }
00223
00224 Row( const Row& theOther )
00225 {
00226 for( unsigned int i = 0; i < NCOL; ++i ) element[i] = theOther.element[i];
00227 }
00228
00229
00230
00231 ~Row( )
00232 { };
00233
00234
00235
00236 Row& operator=( const Row& theOther )
00237 {
00238 if( &theOther != this )
00239 for( unsigned int i = 0; i < NCOL; ++i ) element[i] = theOther.element[i];
00240
00241 return *this;
00242 }
00243
00244
00245
00246 void toVector( std::vector<T>& theRow ) const
00247 {
00248 theRow.clear( );
00249 for( unsigned int i = 0; i < NCOL; ++i ) theRow.push_back( element[i] );
00250 }
00251
00252
00253
00254 T element[NCOL];
00255 };
00256
00257 private:
00258
00259
00260
00261 std::vector< Row > _data;
00262 };
00263
00264 #ifdef BABAR_COMP_INST
00265 #include "CdbTable/CdbNTupleSimpleImpl.cc"
00266 #endif // BABAR_COMP_INST
00267
00268 #endif // CDB_NTUPLE_SIMPLE_IMPL_HH
00269