00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "BaBar/BaBar.hh"
00010
00011 #include "CdbBase/CdbCondition.hh"
00012
00013 #include "CdbBase/CdbDatabase.hh"
00014 #include "CdbBase/CdbView.hh"
00015 #include "CdbBase/CdbFolder.hh"
00016 #include "CdbBase/CdbObject.hh"
00017 #include "CdbBase/CdbRevision.hh"
00018 #include "CdbBase/CdbRevisionPolicy.hh"
00019 #include "CdbBase/CdbPathName.hh"
00020 #include "CdbBase/CdbObjectFactoryBase.hh"
00021 #include "CdbBase/CdbId.hh"
00022 #include "CdbBase/CdbCompositeName.hh"
00023
00024 #include "ErrLogger/ErrLog.hh"
00025 using std::endl;
00026
00027 CdbStatus
00028 CdbCondition::instance( CdbConditionPtr& theConditionPtr,
00029 const char* theFullPathName,
00030 const char* theViewName,
00031 const char* theDatabaseName,
00032 const char* theImplementationName,
00033 const char* theTechnologyName )
00034 {
00035 CdbStatus result = CdbStatus::Error;
00036
00037 theConditionPtr = 0;
00038
00039 do {
00040
00041
00042
00043 CdbPathName fullPathName( theFullPathName );
00044 if( ! fullPathName.isValid( ) ||
00045 ! fullPathName.isAbsolute( ) ||
00046 fullPathName.isRoot( )) {
00047
00048 ErrMsg(error) << "Invalid value of the condition's full path name passed to the procedure." << endl
00049 << " PASSED NAME: \"" << theFullPathName << "\"" << endl
00050 << "A non-empty non-'root' 'absolute' path name was expected." << endmsg;
00051 break;
00052 }
00053
00054
00055
00056 CdbFolderPtr folderPtr;
00057 if( CdbStatus::Success != CdbFolder::instance( folderPtr,
00058 fullPathName.beforeLast( ).toString( ).c_str( ),
00059 theViewName,
00060 theDatabaseName,
00061 theImplementationName,
00062 theTechnologyName )) break;
00063
00064
00065
00066 result = folderPtr->findCondition( theConditionPtr,
00067 fullPathName.last( ).toString( ).c_str( ));
00068
00069 } while( false );
00070
00071 return result;
00072 }
00073
00074 CdbStatus
00075 CdbCondition::instance( CdbConditionPtr& theConditionPtr,
00076 const char* theFullPathName,
00077 const CdbId& theViewId,
00078 const char* theDatabaseName,
00079 const char* theImplementationName,
00080 const char* theTechnologyName )
00081 {
00082 CdbStatus result = CdbStatus::Error;
00083
00084 theConditionPtr = 0;
00085
00086 do {
00087
00088
00089
00090 CdbPathName fullPathName( theFullPathName );
00091 if( ! fullPathName.isValid( ) ||
00092 ! fullPathName.isAbsolute( ) ||
00093 fullPathName.isRoot( )) {
00094
00095 ErrMsg(error) << "Invalid value of the condition's full path name passed to the procedure." << endl
00096 << " PASSED NAME: \"" << theFullPathName << "\"" << endl
00097 << "A non-empty non-'root' 'absolute' path name was expected." << endmsg;
00098 break;
00099 }
00100
00101
00102
00103 CdbFolderPtr folderPtr;
00104 if( CdbStatus::Success != CdbFolder::instance( folderPtr,
00105 fullPathName.beforeLast( ).toString( ).c_str( ),
00106 theViewId,
00107 theDatabaseName,
00108 theImplementationName,
00109 theTechnologyName )) break;
00110
00111
00112
00113 result = folderPtr->findCondition( theConditionPtr,
00114 fullPathName.last( ).toString( ).c_str( ));
00115
00116 } while( false );
00117
00118 return result;
00119 }
00120
00121 CdbStatus
00122 CdbCondition::instance( CdbConditionPtr& theConditionPtr,
00123 const CdbId& thePhysicalAddress,
00124 const char* theDatabaseName,
00125 const char* theImplementationName,
00126 const char* theTechnologyName )
00127 {
00128 CdbStatus result = CdbStatus::Error;
00129
00130 theConditionPtr = 0;
00131
00132 do {
00133
00134
00135
00136 CdbDatabasePtr databasePtr;
00137 if( CdbStatus::Success != CdbDatabase::instance( databasePtr,
00138 theDatabaseName,
00139 theImplementationName,
00140 theTechnologyName )) break;
00141
00142
00143
00144 result = databasePtr->findCondition( theConditionPtr,
00145 thePhysicalAddress );
00146
00147 } while( false );
00148
00149 return result;
00150 }
00151
00152 CdbStatus
00153 CdbCondition::instance( CdbConditionPtr& theConditionPtr,
00154 const CdbCompositeName& thePhysicalName,
00155 const char* theDatabaseName,
00156 const char* theImplementationName,
00157 const char* theTechnologyName )
00158 {
00159 CdbStatus result = CdbStatus::Error;
00160
00161 theConditionPtr = 0;
00162
00163 do {
00164
00165
00166
00167 CdbDatabasePtr databasePtr;
00168 if( CdbStatus::Success != CdbDatabase::instance( databasePtr,
00169 theDatabaseName,
00170 theImplementationName,
00171 theTechnologyName )) break;
00172
00173
00174
00175 result = databasePtr->findCondition( theConditionPtr,
00176 thePhysicalName );
00177
00178 } while( false );
00179
00180 return result;
00181 }
00182
00183 CdbStatus
00184 CdbCondition::instanceFromAny( CdbConditionPtr& theConditionPtr,
00185 const char* theConditionName,
00186 const char* theDatabaseName,
00187 const char* theImplementationName,
00188 const char* theTechnologyName )
00189 {
00190
00191
00192 CdbCompositeName physicalName( theConditionName );
00193 if( physicalName.isValid( )) {
00194
00195 CdbId physicalAddress;
00196 if( CdbId::translate( physicalAddress,
00197 physicalName )) {
00198
00199
00200
00201 return instance( theConditionPtr,
00202 physicalAddress,
00203 theDatabaseName,
00204 theImplementationName,
00205 theTechnologyName );
00206
00207 } else {
00208
00209
00210
00211 return instance( theConditionPtr,
00212 physicalName,
00213 theDatabaseName,
00214 theImplementationName,
00215 theTechnologyName );
00216 }
00217 }
00218
00219
00220
00221 return instance( theConditionPtr,
00222 theConditionName,
00223 theDatabaseName,
00224 theImplementationName,
00225 theTechnologyName );
00226 }
00227
00228 std::string
00229 CdbCondition::fullPathName( const CdbConditionPtr& theConditionPtr )
00230 {
00231 if( theConditionPtr.isNull( )) return std::string( "" );
00232
00233
00234
00235
00236 if( theConditionPtr->parent( ).isNull( )) return std::string( "" );
00237
00238
00239
00240 CdbPathName result( theConditionPtr->name( ));
00241
00242 CdbFolderPtr parentFolder = theConditionPtr->parent( );
00243 while( !parentFolder.isNull( )) {
00244 result = CdbPathName( parentFolder->name( )) + result;
00245 parentFolder = parentFolder->parentFolder( );
00246 }
00247 return result.toString( );
00248 }
00249
00250 CdbCondition::CdbCondition( const CdbFolderPtr& theFolderPtr,
00251 const CdbDatabasePtr& theDatabasePtr,
00252 const char* theName ) :
00253 _myParent (theFolderPtr),
00254 _myParentDatabase(theDatabasePtr),
00255 _myName (theName)
00256 {
00257 if( theDatabasePtr.isNull( )) ErrMsg(fatal) << "null database pointer passed to the constructor." << endmsg;
00258 if( 0 == theName ) ErrMsg(fatal) << "empty condition name string passed to the constructor." << endmsg;
00259 }
00260
00261 CdbCondition::CdbCondition( const CdbCondition& theCondition ) :
00262 _myParent (theCondition._myParent),
00263 _myParentDatabase(theCondition._myParentDatabase),
00264 _myName (theCondition._myName)
00265 { }
00266
00267 CdbCondition::~CdbCondition( )
00268 { }
00269
00270 CdbCondition&
00271 CdbCondition::operator=( const CdbCondition& theCondition )
00272 {
00273 if( this != &theCondition ) {
00274 _myParent = theCondition._myParent;
00275 _myParentDatabase = theCondition._myParentDatabase;
00276 _myName = theCondition._myName;
00277 }
00278 return *this;
00279 }
00280
00281 const CdbFolderPtr&
00282 CdbCondition::parent( ) const
00283 {
00284 return _myParent;
00285 }
00286
00287 const CdbDatabasePtr&
00288 CdbCondition::parentDatabase( ) const
00289 {
00290 return _myParentDatabase;
00291 }
00292
00293 const char*
00294 CdbCondition::name( ) const
00295 {
00296 return _myName.c_str( );
00297 }
00298
00299 CdbStatus
00300 CdbCondition::storeObject( CdbObjectFactoryBase& theObjectFactory,
00301 const BdbTime& theBegin,
00302 const BdbTime& theEnd )
00303 {
00304 CdbObjectPtr oPtr;
00305 return storeObject( theObjectFactory,
00306 theBegin,
00307 theEnd,
00308 oPtr );
00309 }
00310
00311 CdbStatus
00312 CdbCondition::storeAndTruncateObject( CdbObjectFactoryBase& theObjectFactory,
00313 const BdbTime& theStoreTime,
00314 const BdbTime& theTruncateTime )
00315 {
00316 CdbObjectPtr oPtr;
00317 return storeAndTruncateObject( theObjectFactory,
00318 theStoreTime,
00319 theTruncateTime,
00320 oPtr );
00321 }
00322
00323
00324
00325