Bdb packages | Design docs | Source docs | Guidelines | Recent releases

Search | Site Map .

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

/BdbScribeTest/tstManyToOne.cc

Go to the documentation of this file.
00001 #if !defined(TSTMANYTOONE_CC)
00002 #define TSTMANYTOONE_CC
00003 //--------------------------------------------------------------------------
00004 // File and Version Information:
00005 //      $Id: tstManyToOne.cc,v 1.5 2001/04/23 23:54:22 patton Exp $
00006 //
00007 // Description:
00008 //      Class TstManyToOne
00009 //
00010 // Environment:
00011 //      Software developed for the BaBar Detector at the SLAC B-Factory.
00012 //
00013 // Author List:
00014 //      Simon Patton            Originator
00015 //
00016 // Copyright Information:
00017 //      Copyright (C) 1999      LBNL
00018 //
00019 //------------------------------------------------------------------------
00020 
00021 //-------------
00022 // C Headers --
00023 //-------------
00024 extern "C" {
00025            }
00026 
00027 //---------------
00028 // C++ Headers --
00029 //---------------
00030 #include <iostream.h>
00031 #include <stdlib.h>
00032 #include <stdio.h>
00033 
00034 //----------------
00035 // BaBar Header --
00036 //----------------
00037 #include "BaBar/BaBar.hh"
00038 #include "BdbUtil/Bdb.hh"
00039 
00040 //-------------------------------
00041 // Collaborating Class Headers --
00042 //-------------------------------
00043 #include "BdbScribeTest/BdbScribeChkCompositeP_001.hh"
00044 #include "BdbScribeTest/BdbScribeChkCompositeP_000.hh"
00045 #include "BdbScribeTest/BdbScribeChkClass.hh"
00046 #include "BdbScribeTest/BdbScribeChkPlaceMgr.hh"
00047 #include "BdbScribes/BdbCompositeScribe.hh"
00048 #include "BdbScribes/BdbConversionManager.hh"
00049 #include "BdbEvent/BdbEventT.hh"
00050 #include "BdbEvent/BdbEvent.hh"
00051 #include "BdbTrees/BdbHeaderKeysMgr.hh"
00052 #include "ProxyDict/IfdStrKey.hh"
00053 #include "AbsEvent/getTmpAList.hh"
00054 #include "AbsEvent/AbsEvent.hh"
00055 #include "ErrLogger/ErrLog.hh"
00056 
00057 //------------------------------------
00058 // Collaborating Class Declarations --
00059 //------------------------------------
00060 
00061 //-----------------------------------------------------------------------
00062 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00063 //-----------------------------------------------------------------------
00064 
00065 //
00066 // Trivial FD operations
00067 //
00068 
00069 ooHandle( ooFDObj ) fdH ;
00070 ooHandle( ooDBObj ) dbH ;
00071 
00072 d_Boolean fd_begin()
00073 {
00074    const char* kDbName( "BdbScribeTest" ) ;
00075 
00076    if ( oocError == fdH.open( 0 ,
00077                               oocUpdate ,
00078                               oocFalse ) ) {
00079       return ( false ) ;
00080    }
00081 
00082    if ( ! dbH.exist( fdH ,
00083                      kDbName ) ) {
00084       dbH = new(fdH)ooDBObj( kDbName ) ;
00085    }
00086 
00087    return( !false ) ;
00088 }
00089 
00090 int main()
00091 {
00092    ooInit() ;
00093    ooCheckVTablePointer() ;
00094 
00095    ooTrans gTransaction ;
00096 
00097    // Start a federation transaction
00098    gTransaction.start() ;
00099 
00100    if ( ! fd_begin() ) {
00101       ErrMsg( fatal ) << "Failed to open Federated Database."
00102                       << endmsg ;
00103       exit( -1 ) ;
00104    }
00105 
00106    // Create transient and persistent events.
00107    AbsEvent* transEvent( new AbsEvent ) ;
00108    BdbHandle( BdbEvent ) persEvent ;
00109    persEvent = new ( dbH ) BdbEvent ;
00110 //   BdbEventT eventT( persEvent ) ;
00111 
00112    BdbHandle( BdbHeaderKeysMgr ) keysManager ;
00113    keysManager = new( dbH )BdbHeaderKeysMgr() ;
00114    BdbEventT eventT( persEvent ,
00115                      keysManager ) ;
00116 
00117    // Create a placement manager
00118    BdbRefAny hint( dbH ) ;
00119    BdbAbsPlacementManager* placementManager( new BdbScribeChkPlaceMgr( "tst" ,
00120                                                                        "one" ,
00121                                                                        hint ) ) ;
00122 
00123    // Create a transient representation of objects and place then
00124    //   in the transient event.
00125    BdbScribeChkClass* objectOne( new BdbScribeChkClass( 0 ,
00126                                                         10 ,
00127                                                         1.0 ) ) ;
00128    BdbScribeChkClass* objectTwo( new BdbScribeChkClass( objectOne ,
00129                                                         20 ,
00130                                                         2.0 ) ) ;
00131    objectOne->setAssociation( objectTwo ) ;
00132 
00133    IfdStrKey key( "ObjectList" ) ;
00134    HepAList< BdbScribeChkClass>* list( 0 ) ;
00135    getTmpAList( transEvent ,
00136                 list ,
00137                 key ) ;
00138    list->append( objectOne ) ;
00139    list->append( objectTwo ) ;
00140 
00141    ErrMsg( routine ) << "Objects to be output to the Federation:"
00142                      << endmsg ;
00143    const size_t finished = list->length() ;
00144    for( size_t outIndex( 0 ) ;
00145         finished != outIndex ;
00146         ++outIndex ) {
00147       ErrMsg( routine ) << (*(*list)[ outIndex ])
00148                         << endmsg ;
00149    }
00150 
00151    // Create a conversion manager.
00152    size_t highestInputCount( 0 ) ;
00153    size_t highestOutputCount( 0 ) ;
00154    size_t* inputHigh( &highestInputCount ) ;
00155    size_t* outputHigh( &highestOutputCount ) ;
00156    BdbConversionManager* manager( new BdbConversionManager( inputHigh ,
00157                                                             outputHigh ) ) ;
00158 
00159    // Create an register for output with the conversion manager
00160    //   a Scribe which can convert the transient representation
00161    //   into a persistent one.
00162    BdbGenericScribe* scribe( new BdbCompositeScribe< BdbScribeChkClass , BdbScribeChkCompositeP_000 >( key ,
00163                                                                                                        "tst" ,
00164                                                                                                        "one" ) ) ;
00165    manager->addScribeForOutput( *scribe ) ;
00166 
00167    // Use the conversion manager to output the transient
00168    //   representation.
00169    manager->convertToPersistent( *transEvent ,
00170                                  *placementManager ,
00171                                  eventT ) ;
00172 
00173    // Commit transaction and start a new one.
00174    gTransaction.commit() ;
00175    gTransaction.start() ;
00176    if ( ! fd_begin() ) {
00177       ErrMsg( fatal ) << "Failed to open Federated Database."
00178                       << endmsg ;
00179       exit( -1 ) ;
00180    }
00181 
00182    // Delete transient event and create a new one.
00183    delete transEvent ;
00184    transEvent = new AbsEvent ;
00185 
00186 
00187    // Delete conversion manager and create a new one.
00188    delete manager ;
00189    manager = new BdbConversionManager( inputHigh ,
00190                                        outputHigh ) ;
00191 
00192    // Delete old scribe and then create and register for input with the
00193    //   conversion manager a Scribe which can convert the most recent
00194    //   persistent representation into a transient one.
00195    delete scribe ;
00196    scribe = new BdbCompositeScribe< BdbScribeChkClass , BdbScribeChkCompositeP_001 >( key ,
00197                                                                                       "tst" ,
00198                                                                                       "one" ) ;
00199    manager->addScribeForInput( *scribe ) ;
00200 
00201    // Use the conversion manager to input the transient representation.
00202    manager->convertToTransient( eventT ,
00203                                 *transEvent ) ;
00204 
00205    // Commit the transaction.
00206    gTransaction.commit() ;
00207 
00208    // Check that the transient representation have been correctly restore.
00209    getTmpAList( transEvent ,
00210                 list ,
00211                 key ) ;
00212    ErrMsg( routine ) << "Results of input from the Federation:"
00213                      << endmsg ;
00214    for( size_t inIndex( 0 ) ;
00215         finished != inIndex ;
00216         ++inIndex ) {
00217       ErrMsg( routine ) << (*(*list)[ inIndex ])
00218                         << endmsg ;
00219    }
00220          
00221    // clean up
00222    delete scribe ;
00223    delete manager ;
00224    // "objectOne"& "objectTwo" cleaned up by AbsEvent
00225    delete placementManager ;
00226    // "persEvent" cleaned up by Objy
00227    delete transEvent ;
00228 
00229    // Write out summary of ConversionManager
00230    ErrMsg( routine ) << "The highest input count was "
00231                      << highestInputCount
00232                      << endmsg ;
00233    ErrMsg( routine ) << "The highest output count was "
00234                      << highestOutputCount
00235                      << endmsg ;
00236 
00237    return ( 0 ) ;
00238 }
00239 
00240 #endif // TSTMANYTOONE_CC

 


BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us

Page Owner: Jacek Becla
Last Update: October 04, 2002