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

CdbRooRoViewCollectionR.cc

Go to the documentation of this file.
00001 // File and Version Information:
00002 //      $Id: CdbRooRoViewCollectionR.cc,v 1.5 2004/12/08 17:36:47 gapon Exp $
00003 
00004 /// The implementation file for the CdbRooRoViewCollectionR class
00005 /**
00006   * @see CdbRooRoViewCollectionR
00007   */
00008 
00009 #include "BaBar/BaBar.hh"
00010 
00011 #include "CdbRooReadonly/CdbRooRoViewCollectionR.hh"
00012 
00013 #include <iostream>
00014 #include <assert.h>
00015 using std::cout;
00016 using std::cerr;
00017 using std::endl;
00018 
00019 CdbRooRoViewCollectionR::CdbRooRoViewCollectionR( ) :
00020     CdbRooRoNameIdCollectionR< CdbRooRoViewR > ( ),
00021     _newestId(0xFFFF)
00022 { }
00023 
00024 CdbRooRoViewCollectionR::~CdbRooRoViewCollectionR( ) 
00025 { }
00026 
00027 CdbStatus
00028 CdbRooRoViewCollectionR::add( const CdbRooRoViewR& theRef )
00029 {
00030     const char* errorStr = "CdbRooRoViewCollectionR::add() -- FATAL ERROR";
00031 
00032     CdbStatus result = CdbStatus::Error;
00033 
00034   // Update the "newest" element if the passed one qualifies for this criteria.
00035   //
00036   // NOTE: The update of the "newest" is revertable in case if something wrong
00037   //       happens during the insertion into the collection.
00038 
00039     UShort_t oldNewestId = _newestId;
00040 
00041     if( 0 == size( )) {
00042         _newestId = theRef.id( );
00043     } else {
00044 
00045         CdbRooRoViewR view;
00046         if( CdbStatus::Success != ( result = find( _newestId,
00047                                                    view ))) {
00048             cerr << errorStr << endl
00049                  << "    Inconsistent data structures." << endl;
00050 
00051             return result;
00052         }
00053         if( theRef.created( ) > view.created( )) {
00054             _newestId = theRef.id( );
00055         }
00056     }
00057 
00058   // Do the rest at the base class's method.
00059 
00060     if( CdbStatus::Success != ( result = CdbRooRoNameIdCollectionR< CdbRooRoViewR >::add( theRef ))) {
00061 
00062         cerr << errorStr << endl
00063              << "    Failed to add new view with ID = " << theRef.id( ) << endl;
00064 
00065         _newestId = oldNewestId;
00066 
00067         return result;
00068     }
00069     return CdbStatus::Success;
00070 }
00071 
00072 CdbStatus
00073 CdbRooRoViewCollectionR::newest( CdbRooRoViewR& theRef )
00074 {
00075     if( 0 == size( )) return CdbStatus::NotFound;
00076     return find( _newestId,
00077                  theRef );
00078 }
00079 
00080 CdbStatus
00081 CdbRooRoViewCollectionR::newest( CdbCPtr< CdbRooRoViewR >& thePtr )
00082 {
00083     if( 0 == size( )) return CdbStatus::NotFound;
00084     return find( _newestId,
00085                  thePtr );
00086 }
00087 
00088 /////////////////
00089 // End Of File //
00090 /////////////////

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