00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "BaBar/BaBar.hh"
00010
00011 #include "CdbBdbTable/CdbBdbNTupleBaseP.hh"
00012
00013 #include <assert.h>
00014
00015 namespace {
00016
00017
00018
00019
00020
00021
00022
00023 void packColumnNames( ooVArray(d_Char)& theInternalArray,
00024 const std::vector<std::string>& theColumnNames )
00025 {
00026 d_ULong nColumns = theColumnNames.size( );
00027 assert( 0 != nColumns );
00028
00029
00030
00031
00032 d_ULong nTotalCharacters = 0;
00033 for( d_ULong column = 0; column < nColumns; ++column )
00034 nTotalCharacters += 1 + theColumnNames[column].size( );
00035
00036 theInternalArray.resize( nTotalCharacters );
00037
00038
00039
00040
00041 d_ULong next = 0;
00042 for( d_ULong column = 0; column < nColumns; ++column ) {
00043
00044 d_ULong nCharacters = theColumnNames[column].size( );
00045 for( d_ULong c = 0; c < nCharacters; ++c ) {
00046 theInternalArray[next++] = theColumnNames[column][c];
00047 }
00048 theInternalArray[next++] = '\0';
00049 }
00050 assert( next == nTotalCharacters );
00051 }
00052
00053
00054
00055
00056
00057
00058 void extractColumnNames( std::vector<std::string>& theColumnNames,
00059 const ooVArray(d_Char)& theInternalArray )
00060 {
00061 assert( 0 != theInternalArray.size( ));
00062
00063
00064
00065 theColumnNames.resize( 0 );
00066
00067
00068
00069
00070
00071 std::string currentColumn = "";
00072
00073 d_ULong nTotalCharacters = theInternalArray.size( );
00074 for( d_ULong c = 0; c < nTotalCharacters; ++c ) {
00075
00076 d_Char currentChar = theInternalArray[c];
00077 if( '\0' == currentChar ) {
00078
00079 theColumnNames.push_back( currentColumn );
00080
00081 currentColumn = "";
00082
00083 } else {
00084 currentColumn += currentChar;
00085 }
00086 }
00087 assert( 0 != theColumnNames.size( ));
00088 }
00089 };
00090
00091 CdbBdbNTupleBaseP::CdbBdbNTupleBaseP( d_ULong theNumberOfColumns,
00092 const std::string& theName,
00093 const std::string& theDescription,
00094 const std::vector<std::string>& theColumnNames ) :
00095 _columns(theNumberOfColumns),
00096 _name(theName.c_str( )),
00097 _description(theDescription.c_str( ))
00098 {
00099 assert( 0 != _columns );
00100 assert( _columns == theColumnNames.size( ));
00101
00102 ::packColumnNames( _columnNames, theColumnNames );
00103 }
00104
00105 CdbBdbNTupleBaseP::~CdbBdbNTupleBaseP( )
00106 { }
00107
00108
00109 d_ULong
00110 CdbBdbNTupleBaseP::columns( ) const
00111 {
00112 return _columns;
00113 }
00114
00115 std::string
00116 CdbBdbNTupleBaseP::name( ) const
00117 {
00118 return std::string( _name.head( ));
00119 }
00120
00121 std::string
00122 CdbBdbNTupleBaseP::description( ) const
00123 {
00124 return std::string( _description.head( ));
00125 }
00126
00127 void
00128 CdbBdbNTupleBaseP::column_names( std::vector<std::string>& theColumnNames ) const
00129 {
00130 ::extractColumnNames( theColumnNames, _columnNames );
00131 }
00132
00133
00134
00135