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

CdbBdbSConditionAtFolderP.cc

Go to the documentation of this file.
00001 // File and Version Information:
00002 //      $Id: CdbBdbSConditionAtFolderP.cc,v 1.8 2004/08/06 05:54:24 bartoldu Exp $
00003 
00004 /// The implementation for the CdbBdbSConditionAtFolderP class
00005 /**
00006   * @see CdbBdbSConditionAtFolderP
00007   */
00008 
00009 #include "BaBar/BaBar.hh"
00010 
00011 #include "CdbBdbShared/CdbBdbSConditionAtFolderP.hh"
00012 #include "CdbBdbShared/CdbBdbSFolderP.hh"
00013 #include "CdbBdbShared/CdbBdbSViewP.hh"
00014 
00015 #include <iostream>
00016 #include <assert.h>
00017 using std::endl;
00018 using std::ostream;
00019 
00020 CdbBdbSConditionAtFolderP::CdbBdbSConditionAtFolderP( const char*                             theName,
00021                                                       const char*                             theDescription,
00022                                                       const BdbTime&                          theCreationTime,
00023                                                       const CdbBdbSId&                        theId,
00024                                                       const BdbRef(CdbBdbSFolderP)&           theParentFolderRef,
00025                                                       const BdbRef(CdbBdbSConfigCollectionP)& theConfigRef ) :
00026     _name(theName),
00027     _description(theDescription),
00028     _created(theCreationTime),
00029     _id(theId),
00030     _parentFolderRef(theParentFolderRef),
00031     _configRef(theConfigRef)
00032 {
00033     assert( 0 != theName );
00034     assert( 0 != theDescription );
00035     assert(( BdbTime::minusInfinity != theCreationTime ) && ( BdbTime::plusInfinity != theCreationTime ));
00036     assert( ! BdbIsNull(theParentFolderRef));
00037 }
00038 
00039 CdbBdbSConditionAtFolderP::~CdbBdbSConditionAtFolderP( ) 
00040 {
00041     if( ! BdbIsNull(_configRef)) BdbDelete(_configRef);
00042 }
00043 
00044 ooString(32)
00045 CdbBdbSConditionAtFolderP::name( ) const
00046 {
00047     return _name.head( );
00048 }
00049 
00050 ooString(32)
00051 CdbBdbSConditionAtFolderP::description( ) const
00052 {
00053     return _description;
00054 }
00055 
00056 BdbTime
00057 CdbBdbSConditionAtFolderP::created( ) const
00058 {
00059     return _created;
00060 }
00061 
00062 CdbBdbSId
00063 CdbBdbSConditionAtFolderP::id( ) const
00064 {
00065     return _id;
00066 }
00067 
00068 BdbRef(CdbBdbSFolderP)
00069 CdbBdbSConditionAtFolderP::parentFolder( ) const
00070 {
00071     return _parentFolderRef;
00072 }
00073 
00074 BdbRef(CdbBdbSConfigCollectionP)
00075 CdbBdbSConditionAtFolderP::config( ) const
00076 {
00077     return _configRef;
00078 }
00079 
00080 CdbStatus
00081 CdbBdbSConditionAtFolderP::find( const BdbTime&         theTime,
00082                                  CdbBdbSConfigInterval& theConfigInterval ) const
00083 {
00084     CdbStatus result = CdbStatus::NotFound;
00085     do {
00086 
00087       // Evaluate the parameters
00088 
00089         BdbHandle(CdbBdbSViewP) vH;
00090         vH = _parentFolderRef->parentView( );
00091 
00092         BdbTime minTime = vH->minValidity( );
00093         BdbTime maxTime = vH->maxValidity( );
00094 
00095         if(( theTime < minTime ) || ( theTime >= maxTime )) break;
00096 
00097       // Try local first
00098 
00099         if( ! BdbIsNull(_configRef)) {
00100 
00101             result = _configRef->find( theTime, theConfigInterval );
00102             if( CdbStatus::Success != result ) break;
00103 
00104           // Make adjustments to the validity interval
00105 
00106             if( theConfigInterval.begin < minTime ) theConfigInterval.begin = minTime;
00107             if( theConfigInterval.end   > maxTime ) theConfigInterval.end   = maxTime;
00108 
00109             break;
00110         }
00111 
00112       // Try default configuration
00113 
00114         BdbRef(CdbBdbSConfigCollectionP) defaultConfigRef = vH->defaultConfig( );
00115         if( ! BdbIsNull(defaultConfigRef)) {
00116 
00117             result = defaultConfigRef->find( theTime, theConfigInterval );
00118             if( CdbStatus::Success != result ) break;
00119 
00120           // Make adjustments to the validity interval
00121 
00122             if( theConfigInterval.begin < minTime ) theConfigInterval.begin = minTime;
00123             if( theConfigInterval.end   > maxTime ) theConfigInterval.end   = maxTime;
00124 
00125             break;
00126         }
00127 
00128     } while( false );
00129 
00130     return result;
00131 }
00132 
00133 CdbStatus
00134 CdbBdbSConditionAtFolderP::setConfig( const BdbRef(CdbBdbSConfigCollectionP)& theConfigRef,
00135                                       bool                                    dontDestroyConfigObject )
00136 {
00137     ooUpdate( );
00138 
00139     CdbStatus result = CdbStatus::Error;
00140     do {
00141 
00142       // Replace and delete (if any) the previously known configuration
00143       // with the new one.
00144       //
00145       // NOTE: If the passed reference is the same than the one we have then
00146       //       we don't remove existing one to avoid dangling references.
00147       //       Known reference might be passed if a client has updated configuration
00148       //       and explictly wants this configuration to present.
00149 
00150         if( ! BdbIsNull(_configRef)) {
00151             if( theConfigRef != _configRef ) {
00152                 if( ! dontDestroyConfigObject ) {
00153                     BdbDelete(_configRef);
00154                 }
00155             }
00156         }
00157         _configRef = theConfigRef;
00158 
00159       // Done
00160 
00161         result = CdbStatus::Success;
00162 
00163     } while( false );
00164 
00165     return result;
00166 }
00167 
00168 void
00169 CdbBdbSConditionAtFolderP::dump( ostream& o ) const
00170 {
00171     o << "         NAME: \"" << _name.head( ) << "\"" << endl
00172       << "  DESCRIPTION: \"" << _description.head( ) << "\"" << endl
00173       << "      CREATED: " << _created << endl
00174       << "           ID: " << _id << endl
00175       << "PARENT FOLDER: " << _parentFolderRef.sprint( ) << endl
00176       << "CONFIGURATION: " << _configRef.sprint( ) << endl;
00177 }
00178 
00179 /////////////////
00180 // End Of File //
00181 /////////////////

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