Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

CdbBdbNTupleBaseP.cc

Go to the documentation of this file.
00001 // File and Version Information:
00002 //      $Id: CdbBdbNTupleBaseP.cc,v 1.2 2004/03/24 07:17:05 gapon Exp $
00003 
00004 /// The implementation file for the CdbBdbNTupleBaseP class
00005 /**
00006   * @see CdbBdbNTupleBaseP
00007   */
00008 
00009 #include "BaBar/BaBar.hh"
00010 
00011 #include "CdbBdbTable/CdbBdbNTupleBaseP.hh"
00012 
00013 #include <assert.h>
00014 
00015 namespace {
00016 
00017   /// Pack columns from specified vector into internal representation
00018   /**
00019     * The packing algorithm is meant to be used to pack an input vector of strings
00020     * just once to be repacked later on as a whole. The method of packing
00021     * is not meant to be used for random access to the packaed names.
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       // To avoid ineffcient extending of the output array do resize it once
00030       // to accomodate strings along with the terminator symbols '\0';
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       // Copy input strings into the output array and add the terminator symbol
00039       // at the end of each output string.
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 );     // just a double check
00051     }
00052 
00053   /// Extract the column names from the internal array into a vector of strings
00054   /**
00055     * The size of the output vector will be equal to the number of
00056     * passed found columns.
00057     */
00058     void extractColumnNames( std::vector<std::string>& theColumnNames,
00059                              const ooVArray(d_Char)&   theInternalArray )
00060     {
00061         assert( 0 != theInternalArray.size( ));
00062 
00063       // Reset the output vector
00064 
00065         theColumnNames.resize( 0 );
00066 
00067       // Find null ternminated ('\0') strings in the input array and put them into
00068       // the output one.
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 // End Of File //
00135 /////////////////

Generated on Mon Dec 5 18:21:59 2005 for CDB by doxygen1.3-rc3