00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "BaBar/BaBar.hh"
00010
00011 #include "CdbBdbShared/CdbBdbSConfigCollectionP.hh"
00012 #include "CdbBdbShared/CdbBdbSSimpleConfigIterator.hh"
00013
00014 #include <assert.h>
00015 using std::cout;
00016 using std::endl;
00017 using std::ostream;
00018
00019 CdbBdbSConfigCollectionP::CdbBdbSConfigCollectionP( ) :
00020 _complexConfigRef(0)
00021 { }
00022
00023 CdbBdbSConfigCollectionP::CdbBdbSConfigCollectionP( const CdbBdbSConfigElement& theConfig ) :
00024 _simpleConfig(theConfig),
00025 _complexConfigRef(0)
00026 { }
00027
00028 CdbBdbSConfigCollectionP::CdbBdbSConfigCollectionP( const CdbBdbSConfigInterval& theConfigInterval ) :
00029 _complexConfigRef(0)
00030 {
00031 BdbTime begin = theConfigInterval.begin;
00032 BdbTime end = theConfigInterval.end;
00033
00034
00035
00036 if(( BdbTime::minusInfinity == begin ) && ( BdbTime::plusInfinity == end )) {
00037 _simpleConfig = theConfigInterval.value;
00038 } else {
00039
00040 _complexConfigRef = new( ooThis( )) CdbBdbSTimeLineP< CdbBdbSConfigElement >( );
00041
00042 if( CdbStatus::Success != _complexConfigRef->insert( theConfigInterval )) {
00043 cout << "CdbBdbSConfigCollectionP::CdbBdbSConfigCollectionP() - FATAL ERROR IN THE CONSTRUCTOR" << endl
00044 << " Failed to insert an original configuration element into the TimeLine" << endl
00045 << " for the following range of the validity dimension" << endl
00046 << " BEGIN: " << begin << endl
00047 << " END: " << end << endl;
00048
00049 BdbDelete(_complexConfigRef);
00050
00051 assert( 0 );
00052 }
00053 }
00054 }
00055
00056 CdbBdbSConfigCollectionP::~CdbBdbSConfigCollectionP( )
00057 {
00058 if( ! BdbIsNull(_complexConfigRef)) {
00059 BdbDelete( _complexConfigRef );
00060 _complexConfigRef = 0;
00061 }
00062 }
00063
00064 void
00065 CdbBdbSConfigCollectionP::reset( )
00066 {
00067 ooUpdate( );
00068
00069 _simpleConfig = CdbBdbSConfigElement( );
00070
00071 if( ! BdbIsNull(_complexConfigRef)) {
00072 BdbDelete(_complexConfigRef);
00073 _complexConfigRef = 0;
00074 }
00075 }
00076
00077 CdbStatus
00078 CdbBdbSConfigCollectionP::insert( const CdbBdbSConfigElement& theInitialConfig,
00079 const BdbTime& theBeginTime,
00080 const BdbTime& theEndTime )
00081 {
00082 return insert( CdbBdbSConfigInterval( theInitialConfig,
00083 theBeginTime,
00084 theEndTime ));
00085 }
00086
00087 CdbStatus
00088 CdbBdbSConfigCollectionP::insert( const CdbBdbSConfigInterval& theConfigInterval )
00089 {
00090 const char* errorMsg = "CdbBdbSConfigCollectionP::insert() -- ERROR";
00091
00092 ooUpdate( );
00093
00094 CdbStatus result = CdbStatus::Error;
00095 do {
00096
00097
00098
00099 BdbTime begin = theConfigInterval.begin;
00100 BdbTime end = theConfigInterval.end;
00101
00102 if( begin >= end ) {
00103 cout << errorMsg << endl
00104 << " Invaid validity range for the configuration. " << endl;
00105 break;
00106 }
00107
00108
00109
00110
00111 if(( BdbTime::minusInfinity == begin ) && ( BdbTime::plusInfinity == end )) {
00112
00113 _simpleConfig = theConfigInterval.value;
00114
00115 if( ! BdbIsNull(_complexConfigRef)) {
00116 BdbDelete(_complexConfigRef);
00117 _complexConfigRef = 0;
00118 }
00119
00120 } else {
00121
00122
00123
00124 if( BdbIsNull(_complexConfigRef)) {
00125
00126
00127
00128
00129
00130
00131
00132 _complexConfigRef = new( ooThis( )) CdbBdbSTimeLineP< CdbBdbSConfigElement >( _simpleConfig );
00133 }
00134 if( CdbStatus::Success != _complexConfigRef->insert( theConfigInterval )) {
00135 cout << errorMsg << endl
00136 << " Failed to insert a configuration element into the TimeLine" << endl
00137 << " for the following range of the validity dimension" << endl
00138 << " BEGIN: " << begin << endl
00139 << " END: " << end << endl;
00140 break;
00141 }
00142 }
00143
00144
00145
00146 result = CdbStatus::Success;
00147
00148 } while( false );
00149
00150 return result;
00151 }
00152
00153 CdbStatus
00154 CdbBdbSConfigCollectionP::find( const BdbTime& theTime,
00155 CdbBdbSConfigInterval& theConfigInterval ) const
00156 {
00157 CdbStatus result = CdbStatus::Error;
00158 do {
00159 if( ! BdbIsNull(_complexConfigRef)) {
00160 if( ! _complexConfigRef->find( theConfigInterval,
00161 theTime )) {
00162 result = CdbStatus::NotFound;
00163 break;
00164 }
00165 } else {
00166 theConfigInterval = CdbBdbSConfigInterval( _simpleConfig,
00167 BdbTime::minusInfinity,
00168 BdbTime::plusInfinity );
00169 }
00170
00171
00172
00173 result = CdbStatus::Success;
00174
00175 } while( false );
00176
00177 return result;
00178 }
00179
00180 CdbBdbSConfigCollectionP::IteratorOfIntervals
00181 CdbBdbSConfigCollectionP::iterator( ) const
00182 {
00183 if( !BdbIsNull(_complexConfigRef)) {
00184 return _complexConfigRef->iterator( );
00185 }
00186
00187
00188
00189
00190 return IteratorOfIntervals( new CdbBdbSSimpleConfigIterator( _simpleConfig ));
00191 }
00192
00193 CdbStatus
00194 CdbBdbSConfigCollectionP::clone( BdbRef(CdbBdbSConfigCollectionP)& theRef,
00195 const BdbRefAny& theHint ) const
00196 {
00197 const char* errorMsg = "CdbBdbSConfigCollectionP::clone() -- ERROR";
00198
00199
00200
00201 BdbRefAny hint = theHint;
00202 if( BdbIsNull(hint)) hint = ooThis( );
00203
00204
00205
00206 BdbHandle(CdbBdbSConfigCollectionP) configH;
00207 {
00208
00209
00210 configH = new( hint ) CdbBdbSConfigCollectionP( _simpleConfig );
00211
00212
00213
00214
00215 if( ! BdbIsNull(_complexConfigRef)) {
00216
00217 BdbRef( CdbBdbSTimeLineP< CdbBdbSConfigElement > ) complexConfigRef;
00218
00219 CdbStatus status = _complexConfigRef->clone( complexConfigRef,
00220 theHint );
00221 if( CdbStatus::Success != status ) {
00222 cout << errorMsg << endl
00223 << " Failed to clone the TimeLine object due to: " << status << endl;
00224
00225 BdbDelete(configH);
00226
00227 return status;
00228 }
00229 configH->_complexConfigRef = complexConfigRef;
00230 }
00231 }
00232 theRef = configH;
00233
00234 return CdbStatus::Success;
00235 }
00236
00237 bool
00238 CdbBdbSConfigCollectionP::isEqual( const BdbRef(CdbBdbSConfigCollectionP)& theRef ) const
00239 {
00240 assert( !BdbIsNull(theRef));
00241
00242 if( BdbIsNull(_complexConfigRef)) {
00243 if( !BdbIsNull(theRef->_complexConfigRef)) {
00244 return false;
00245 } else {
00246 return ( _simpleConfig == theRef->_simpleConfig );
00247 }
00248 } else {
00249 if( BdbIsNull(theRef->_complexConfigRef)) {
00250 return false;
00251 } else {
00252
00253 IteratorOfIntervals currentItr = iterator( );
00254 IteratorOfIntervals inputItr = theRef->iterator( );
00255
00256 while( currentItr.next( )) {
00257 if( !inputItr.next( )) {
00258 return false;
00259 } else {
00260
00261 const CdbBdbSConfigInterval currentIVal = currentItr.value( );
00262 const CdbBdbSConfigInterval inputIVal = inputItr.value( );
00263
00264 if(( currentIVal.begin != inputIVal.begin ) ||
00265 ( currentIVal.end != inputIVal.end ) ||
00266 ( currentIVal.value != inputIVal.value )) return false;
00267 }
00268 }
00269 if( inputItr.next( )) return false;
00270 }
00271 }
00272
00273 return true;
00274 }
00275
00276
00277 void
00278 CdbBdbSConfigCollectionP::dump( ostream& o ) const
00279 {
00280 o << "=== Condition Cofiguration Collection ===" << endl
00281 << endl;
00282
00283 if( BdbIsNull(_complexConfigRef)) {
00284
00285 o << "[ -Infinity , +Infinity )" << endl
00286 << " -> " << _simpleConfig << endl
00287 << endl;
00288
00289 } else {
00290
00291 CdbBdbSTimeLineP< CdbBdbSConfigElement >::IteratorOfIntervals itr
00292 = _complexConfigRef->iterator( );
00293
00294 while( itr.next( ))
00295 o << itr.value( ) << endl
00296 << endl;
00297 }
00298 o << "=== End Of The Collection ===" << endl;
00299 }
00300
00301
00302
00303