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

CdbNTupleAlgorithms.hh

Go to the documentation of this file.
00001 #ifndef CDB_NTUPLE_ALGORITHMS_HH
00002 #define CDB_NTUPLE_ALGORITHMS_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbNTupleAlgorithms.hh,v 1.4 2004/03/16 19:22:42 gapon Exp $
00006 
00007 #include "CdbBase/CdbCPtr.hh"
00008 #include "CdbTable/CdbNTuple.hh"
00009 
00010 // Forward declaration for the comparator interface used by the CdbNTupleSort
00011 // algorithm.
00012 
00013 template < class T, unsigned int NCOL > class CdbNTupleIsLessComparator;
00014 
00015 /**
00016   * DESCRIPTION:
00017   *
00018   *   This file contains declarations for a collection of algorithms
00019   *   dealing with n-tuple-es.
00020   *
00021   * DESIGN NOTES:
00022   *
00023   *   Strictly speaking we should have defined these algorithms as:
00024   *
00025   *     template < class T,
00026   *                unsigned int NCOL >
00027   *     CdbStatus
00028   *     CdbNTupleMerge(       CdbCPtr<CdbNTuple<T,NCOL> >& theOutputPtr,
00029   *                     const CdbCPtr<CdbNTuple<T,NCOL> >& thePrototypePtr,
00030   *                     const CdbCPtr<CdbNTuple<T,NCOL> >& theExtraPtr );
00031   *
00032   *     template < class T,
00033   *                unsigned int NCOL >
00034   *     CdbStatus
00035   *     CdbNTupleAppend(       CdbCPtr<CdbNTuple<T,NCOL> >& theOutputPtr,
00036   *                      const CdbCPtr<CdbNTuple<T,NCOL> >& theInputPtr );
00037   *
00038   *     template < class T,
00039   *                unsigned int NCOL >
00040   *     CdbStatus
00041   *     CdbNTupleCopy(       CdbCPtr<CdbNTuple<T,NCOL> >& theOutputPtr,
00042   *                    const CdbCPtr<CdbNTuple<T,NCOL> >& theInputPtr );
00043   *
00044   *   Unfortunatelly this trick does not work for those n-tuples are subclasses
00045   *   of CdbNTuple and which are passed directly (w/o downcasting) to this function.
00046   *
00047   *   The solution was to have less strict interfaces which expects smart pointers
00048   *   onto n-tuple-like objects, meaning that the corresponding classes should exhibit
00049   *   enough interface to perform the current action.
00050   *
00051   *   Another advantage of this approach is that these algorithm would be perfectly
00052   *   functional for any other classes which may not derive from CdbNTuple.
00053   *
00054   *   Things are even more complicated for the "glue" algorithm, which should have
00055   *   been defined as:
00056   *
00057   *     template < class T,
00058   *                unsigned int NCOL_LEFT,
00059   *                unsigned int NCOL_RIGHT >
00060   *     CdbStatus
00061   *     CdbNTupleGlue(       CdbCPtr<CdbNTuple< T, NCOL_LEFT + NCOL_RIGHT > >& theOutputPtr,
00062   *                    const CdbCPtr<CdbNTuple< T, NCOL_LEFT > >&              theLeftPtr,
00063   *                    const CdbCPtr<CdbNTuple< T, NCOL_RIGHT > >&             theRightPtr,
00064   *                    const bool                                              allowRenamingOfColumnsFlag = true );
00065   *
00066   *   See the documentation on the algorithm below for more explanation why.
00067   */
00068 
00069 /// A "merge of rows" algorithm for n-tuples of the same type
00070 /**
00071   * This algorithm will produce a _NEW_ "output" tuple with rows copied from
00072   * both input tables.
00073   *
00074   * The metadata of the "output" tuple will be copied from the "prototype" one.
00075   *
00076   * The order of rows won't change. All rows from the "prototype" tuple will
00077   * be copied first. Then all rows found in the "extra" tuple will be appended
00078   * by the end of the "ouput" tuple.
00079   *
00080   * MEMORY MODEL NOTES:
00081   *
00082   *   Note, that the parameters of these algorithms are _counted_smart_pointers_
00083   *   onto the actual tuples. Therefore, to avoid confusions in case when two or
00084   *   more parameters of the algorithm will point onto the same instance
00085   *   of a tuple, remember that:
00086   *
00087   *   (1) The "output" pointer will always be initialized with a _newely_ created
00088   *       tuple. Any initial tuple pointed by the "output" pointer won't be affected
00089   *       by the algorithm.
00090   *
00091   *       IMPORTANT: The actual type of the "output" tuple will be the same as
00092   *                  the one of the "protorype" tuple.
00093   *
00094   *   (2) The algorithm won't attempt to check if both "prototype" and "extra"
00095   *       pointers point onto the same tuple. If this is going to be the case
00096   *       then the resulting tuple will have a double set of rows.
00097   *
00098   *   (3) The "output" pointer may not be a valid (not pointing to any tuple)
00099   *       pointer when calling this algorithm.
00100   *
00101   *   (4) Both "prototype" and "extra" pointers must be valid pointers.
00102   *
00103   *   (5) If the algorithm will fail for some reason then the "output"
00104   *       pointer won't change.
00105   *
00106   * @see class CdbNTuple
00107   * @see class CdbCPtr
00108   */
00109 template < class NTUPLE >
00110 CdbStatus
00111 CdbNTupleMerge(       CdbCPtr<NTUPLE>& theOutputPtr,
00112                 const CdbCPtr<NTUPLE>& thePrototypePtr,
00113                 const CdbCPtr<NTUPLE>& theExtraPtr );
00114 
00115 /// An "append of rows" algorithm for n-tuples of the same type
00116 /**
00117   * This algorithm will append all rows from the "input" tuple by
00118   * the "output" one.
00119   *
00120   * The metadata of the "output" tuple won't be affected.
00121   *
00122   * The order of rows won't change. All the original rows of the "output" tuple
00123   * won't be affected. All rows found in the "input" tuple will be appended
00124   * by the end of the "ouput" tuple.
00125   *
00126   * MEMORY MODEL NOTES:
00127   *
00128   *   Note, that the parameters of these algorithms are _counted_smart_pointers_
00129   *   onto the actual tuples. Therefore, to avoid confusions in case when two or
00130   *   more parameters of the algorithm will point onto the same instance
00131   *   of a tuple, remember that:
00132   *
00133   *   (1) Upon the completion of the algorithm, the "output" pointer will
00134   *       always be pointing onto the same tuple.
00135   *
00136   *   (2) If both "output" and "input" pointers point onto the same tuple then
00137   *       the resulting tuple will contain a duble set of rows after the completion
00138   *       of the algorithm.
00139   *
00140   *   (3) Both "output" and "input" pointers must be valid pointers.
00141   *
00142   *   (5) If the algorithm will fail for some reason then the "output"
00143   *       tuple may stay in the unpredicted state!!!. IN this case also
00144   *       keep in mind the rule (2) above.
00145   *
00146   * @see class CdbNTuple
00147   * @see class CdbCPtr
00148   */
00149 template < class NTUPLE >
00150 CdbStatus
00151 CdbNTupleAppend(       CdbCPtr<NTUPLE>& theOutputPtr,
00152                  const CdbCPtr<NTUPLE>& theInputPtr );
00153 
00154 /// A "copy" algorithm for n-tuples of the same type
00155 /**
00156   * will produce a _NEW_ "output" tuple with an exact copy of the "input" one.
00157   *
00158   * The metadata of the "output" tuple will be replaced with the one taken
00159   * from the input
00160   *
00161   * The order of rows won't change. All the original rows of the "output" tuple
00162   * won't be affected. All rows found in the "input" tuple will be appended
00163   * by the end of the "ouput" tuple.
00164   *
00165   * MEMORY MODEL NOTES:
00166   *
00167   *   Note, that the parameters of these algorithms are _counted_smart_pointers_
00168   *   onto the actual tuples. Therefore, to avoid confusions in case when two or
00169   *   more parameters of the algorithm will point onto the same instance
00170   *   of a tuple, remember that:
00171   *
00172   *   (1) The "output" pointer will always be initialized with a _newely_ created
00173   *       tuple. Any initial tuple pointed by the "output" pointer won't be affected
00174   *       by the algorithm.
00175   *
00176   *       IMPORTANT: The actual type of the "output" tuple will be the same as
00177   *                  the one of the "input" tuple.
00178   *
00179   *   (2) The "output" pointer may not be a valid (not pointing to any tuple)
00180   *       pointer when calling this algorithm.
00181   *
00182   *   (3) The "input" pointer must be a valid pointer.
00183   *
00184   *   (4) If the algorithm will fail for some reason then the "output"
00185   *       pointer won't change.
00186   *
00187   * @see class CdbNTuple
00188   * @see class CdbCPtr
00189   */
00190 template < class NTUPLE >
00191 CdbStatus
00192 CdbNTupleCopy(       CdbCPtr<NTUPLE>& theOutputPtr,
00193                const CdbCPtr<NTUPLE>& theInputPtr );
00194 
00195 /// A "glue of columns" algorithm for n-tuples of the same type elements
00196 /**
00197   * This algorithm will produce a _NEW_ "output" tuple, with a sum of columns
00198   * from both input tuples. The data from rows will be copied accordingly.
00199   *
00200   * The metadata of the "output" tuple will be copied from the "left" one.
00201   *
00202   * The algorithm will also make a best attempt to preserve the names of columns.
00203   * An optional parameter "allowRenamingOfColumnsFlag" of the algorithm would
00204   * control a resolution of potential conflicts. Here are the rules:
00205   *
00206   *   - if there is no conflict then all names from both tuples will be copied
00207   *     into the output tuple.
00208   *
00209   *   - in case of a conflict and if the flag is set to "false" then the algorithm
00210   *     will fail and return the "CdbStatus::ConflictOfParameters" error status.
00211   *
00212   *   - in case of a conflict and if the flag is set to "true" then the algorithm
00213   *     will preserve al names from the "left" tuple, it will also preserve
00214   *     all non-conflicting names from the "right" tuple, and it will replace
00215   *     all conflicting names from the "right" tuple with default names (see
00216   *     the description of the CdbNTupleBase class for details).
00217   *
00218   * The order of rows won't change. The rows with the same numbers from both
00219   * tuples will be "glued" into the corresponding rows of the "output" tuple.
00220   * Missing elements of a shortest tuple will be replaced using defaul constructor
00221   * of the elements type.
00222   *
00223   * MEMORY MODEL NOTES:
00224   *
00225   *   Note, that the parameters of these algorithms are _counted_smart_pointers_
00226   *   onto the actual tuples. Therefore, to avoid confusions in case when two or
00227   *   more parameters of the algorithm will point onto the same instance
00228   *   of a tuple, remember that:
00229   *
00230   *   (1) The "output" pointer will always be initialized with a _newely_ created
00231   *       tuple. Any initial tuple pointed by the "output" pointer won't be affected
00232   *       by the algorithm.
00233   *
00234   *       IMPORTANT: The actual type of the "output" tuple is implementation
00235   *                  (of the algorithm) specific.
00236   *
00237   *   (2) The algorithm won't attempt to check if both "left" and "right"
00238   *       pointers point onto the same tuple. If this is going to be the case
00239   *       then the resulting tuple will have a double set of columns.
00240   *
00241   *   (3) The "output" pointer may not be a valid (not pointing to any tuple)
00242   *       pointer when calling this algorithm.
00243   *
00244   *   (4) Both "left" and "right" pointers must be valid pointers.
00245   *
00246   *   (5) If the algorithm will fail for some reason then the "output"
00247   *       pointer won't change.
00248   *
00249   *
00250   * IMPLEMENTATION NOTE:
00251   *
00252   *   Due to a lack of full support for any expressions with non-class template parameters
00253   *   of template functions _and_ template methods in:
00254   *
00255   *     "Sun WorkShop 6 update 1 C++ 5.2 Patch 109508-03 2001/04/07"
00256   *
00257   *   this algorithm can't be made available through a normal template function
00258   *   with a signature like:
00259   *
00260   *     template < class T,
00261   *                unsigned int NCOL_LEFT,
00262   *                unsigned int NCOL_RIGHT >
00263   *     CdbStatus
00264   *     CdbNTupleGlue(       CdbCPtr<CdbNTuple< T, NCOL_LEFT + NCOL_RIGHT > >& theOutputPtr,
00265   *                    const CdbCPtr<CdbNTuple< T, NCOL_LEFT > >&              theLeftPtr,
00266   *                    const CdbCPtr<CdbNTuple< T, NCOL_RIGHT > >&             theRightPtr,
00267   *                    const bool                                              allowRenamingOfColumnsFlag = true );
00268   *
00269   *   One unfortunate problem of this solution is its weakness (compared to the original idea of
00270   *   the template function) in the compilation time type checking of arguments. The problem
00271   *   is that there is no simple way to check that the output tuple has the same width as
00272   *   a sum of both input tuples' widths. That's why this implementation will return
00273   *   a special error value to indicate this problem:
00274   *
00275   *     CdbStatus::ConflictOfParameters
00276   *
00277   * @see class CdbNTuple
00278   * @see class CdbCPtr
00279   */
00280 template < class NTUPLE_OUT,
00281            class NTUPLE_LEFT,
00282            class NTUPLE_RIGHT >
00283 CdbStatus
00284 CdbNTupleGlue(       CdbCPtr<NTUPLE_OUT>&   theOutputPtr,
00285                const CdbCPtr<NTUPLE_LEFT>&  theLeftPtr,
00286                const CdbCPtr<NTUPLE_RIGHT>& theRightPtr,
00287                const bool                   allowRenamingOfColumnsFlag = true );
00288 
00289 #ifdef     BABAR_COMP_INST
00290 #include "CdbTable/CdbNTupleAlgorithms.cc"
00291 #endif  // BABAR_COMP_INST
00292 
00293 #endif // CDB_NTUPLE_ALGORITHMS_HH
00294 

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