00001 // File and Version Information: 00002 // $Id: CdbRooRoConfigCollectionR.cc,v 1.3 2004/11/19 14:33:00 gapon Exp $ 00003 00004 /// The implementation file for the CdbRooRoConfigCollectionR class 00005 /** 00006 * @see CdbRooRoConfigCollectionR 00007 */ 00008 00009 #include "BaBar/BaBar.hh" 00010 00011 #include "CdbRooReadonly/CdbRooRoConfigCollectionR.hh" 00012 00013 #include <assert.h> 00014 using std::cout; 00015 using std::endl; 00016 00017 CdbRooRoConfigCollectionR::CdbRooRoConfigCollectionR( ) 00018 { } 00019 00020 CdbRooRoConfigCollectionR::CdbRooRoConfigCollectionR( const CdbRooRoConfigElementR& thelConfigElement ) 00021 { 00022 if( CdbStatus::Success != _config.insert( CdbRooRoConfigInterval( thelConfigElement, 00023 BdbTime::minusInfinity, 00024 BdbTime::plusInfinity ))) { 00025 00026 cout << "CdbRooRoConfigCollectionR::CdbRooRoConfigCollectionR(element) - FATAL ERROR IN THE CONSTRUCTOR" << endl 00027 << " Failed to insert an initial configuration interval into the TimeLine." << endl; 00028 assert( 0 ); 00029 } 00030 } 00031 00032 CdbRooRoConfigCollectionR::CdbRooRoConfigCollectionR( const CdbRooRoConfigInterval& theConfigInterval ) 00033 { 00034 if( CdbStatus::Success != _config.insert( theConfigInterval )) { 00035 cout << "CdbRooRoConfigCollectionR::CdbRooRoConfigCollectionR(interval) - FATAL ERROR IN THE CONSTRUCTOR" << endl 00036 << " Failed to insert an initial configuration interval into the TimeLine." << endl; 00037 assert( 0 ); 00038 } 00039 } 00040 00041 CdbRooRoConfigCollectionR::~CdbRooRoConfigCollectionR( ) 00042 { } 00043 00044 void 00045 CdbRooRoConfigCollectionR::reset( ) 00046 { 00047 _config = CdbRooRoTimeLineR< CdbRooRoConfigElementR >( ); 00048 } 00049 00050 CdbStatus 00051 CdbRooRoConfigCollectionR::insert( const CdbRooRoConfigElementR& theConfigElement, 00052 const BdbTime& theBeginTime, 00053 const BdbTime& theEndTime ) 00054 { 00055 return insert( CdbRooRoConfigInterval( theConfigElement, 00056 theBeginTime, 00057 theEndTime )); 00058 } 00059 00060 CdbStatus 00061 CdbRooRoConfigCollectionR::insert( const CdbRooRoConfigInterval& theConfigInterval ) 00062 { 00063 const char* errorMsg = "CdbRooRoConfigCollectionR::insert() -- ERROR"; 00064 00065 CdbStatus result = CdbStatus::Error; 00066 do { 00067 00068 // Verify parameters. 00069 00070 BdbTime begin = theConfigInterval.begin( ); 00071 BdbTime end = theConfigInterval.end ( ); 00072 00073 if( begin >= end ) { 00074 cout << errorMsg << endl 00075 << " Invaid validity range for the configuration. " << endl; 00076 break; 00077 } 00078 if( CdbStatus::Success != _config.insert( theConfigInterval )) { 00079 cout << errorMsg << endl 00080 << " Failed to insert a configuration element into the TimeLine" << endl 00081 << " for the following range of the validity dimension" << endl 00082 << " BEGIN: " << CdbTimeUtils::time2string( begin ) << endl 00083 << " END: " << CdbTimeUtils::time2string( end ) << endl; 00084 break; 00085 } 00086 00087 // Done. 00088 00089 result = CdbStatus::Success; 00090 00091 } while( false ); 00092 00093 return result; 00094 } 00095 00096 CdbStatus 00097 CdbRooRoConfigCollectionR::find( const BdbTime& theTime, 00098 CdbRooRoConfigInterval& theConfigInterval ) const 00099 { 00100 return ( _config.find( theConfigInterval, theTime ) ? CdbStatus::Success : CdbStatus::NotFound ); 00101 } 00102 00103 CdbRooRoConfigCollectionR::IteratorOfIntervals 00104 CdbRooRoConfigCollectionR::iterator( ) const 00105 { 00106 return _config.iterator( ); 00107 } 00108 00109 bool 00110 CdbRooRoConfigCollectionR::isEqual( const CdbRooRoConfigCollectionR& theRef ) const 00111 { 00112 IteratorOfIntervals currentItr = iterator( ); 00113 IteratorOfIntervals inputItr = theRef.iterator( ); 00114 00115 while( currentItr.next( )) { 00116 if( !inputItr.next( )) { 00117 return false; 00118 } else { 00119 00120 const CdbRooRoConfigInterval currentIVal = currentItr.value( ); 00121 const CdbRooRoConfigInterval inputIVal = inputItr.value( ); 00122 00123 if(( currentIVal.begin( ) != inputIVal.begin( )) || 00124 ( currentIVal.end ( ) != inputIVal.end ( )) || 00125 ( currentIVal.value( ) != inputIVal.value( ))) return false; 00126 } 00127 } 00128 if( inputItr.next( )) return false; 00129 00130 return true; 00131 } 00132 00133 void 00134 CdbRooRoConfigCollectionR::dump( std::ostream& o, 00135 const std::string& theIndent ) const 00136 { 00137 CdbRooRoTimeLineR< CdbRooRoConfigElementR >::IteratorOfIntervals itr = _config.iterator( ); 00138 while( itr.next( )) o << theIndent << itr.value( ) << endl; 00139 } 00140 00141 ///////////////// 00142 // End Of File // 00143 /////////////////
1.3-rc3