00001
00002
00003
00004 #include "GaudiKernel/IDataProviderSvc.h"
00005 #include "GaudiKernel/IRegistry.h"
00006
00007 #include "DetDesc/ValidDataObject.h"
00008 #include "DetDesc/Condition.h"
00009
00010
00011 #include "UpdateManagerSvc.h"
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 UpdateManagerSvc::Item::~Item() {
00023 for (MembFuncList::const_iterator mi = memFuncs.begin();
00024 mi != memFuncs.end(); ++mi) {
00025 delete mi->mf;
00026 delete mi->items;
00027 }
00028
00029 for (UserPtrList::iterator pi = user_dest_ptrs.begin();
00030 pi != user_dest_ptrs.end(); ++pi){
00031 delete pi->first;
00032 }
00033 }
00034
00035
00036
00037 StatusCode UpdateManagerSvc::Item::update(IDataProviderSvc *dp,const Gaudi::Time &when, MsgStream *log){
00038 if (log){
00039 (*log) << MSG::DEBUG << "Updating (Item* " << this << ") " << ptr << " ---BEGIN---";
00040 if (!path.empty()) (*log) << " " << path;
00041 (*log) << endmsg;
00042 (*log) << MSG::VERBOSE << " initial validity: " << since << " -> " << until << endmsg;
00043 }
00044 if (updateLock) {
00045 if (log) (*log) << MSG::VERBOSE << "Update lock found: break loop" << endmsg;
00046 return StatusCode::SUCCESS;
00047 }
00048
00049 if (isValid(when)) {
00050 if (log) (*log) << MSG::VERBOSE << "Item valid, not need to update" << endmsg;
00051 return StatusCode::SUCCESS;
00052 }
00053
00054 updateLock = true;
00055 resetIOV();
00056 StatusCode sc;
00057
00058 if (ptr == NULL && vdo == NULL && !path.empty()) {
00059
00060 if (log) (*log) << MSG::DEBUG << "Retrieve object " << path << " from data provider" << endmsg;
00061
00062 DataObject *pObj;
00063 sc = dp->retrieveObject(path,pObj);
00064
00065 if (!sc.isSuccess()){
00066 if (log) (*log) << MSG::ERROR << "Retrieve from data provider failed!" << endmsg;
00067 return sc;
00068 }
00069
00070
00071 if ( override ) {
00072
00073
00074 ValidDataObject * vdo = dynamic_cast<ValidDataObject *>(pObj);
00075 if (vdo) {
00076 vdo->update(*override);
00077 Condition * cond = dynamic_cast<Condition *>(pObj);
00078 if (cond) {
00079 sc = cond->initialize();
00080 if ( !sc.isSuccess() ) {
00081 if (log) (*log) << MSG::ERROR
00082 << "Unable to initialize overridden condition at "
00083 << path << endmsg;
00084 return sc;
00085 }
00086 }
00087
00088 delete override;
00089
00090 override = NULL;
00091 } else {
00092
00093 sc = dp->unregisterObject(pObj);
00094 if ( !sc.isSuccess() ) {
00095 if (log) (*log) << MSG::ERROR << "Unable to unregister object at " << path << endmsg;
00096 return sc;
00097 }
00098
00099 pObj->release();
00100
00101 pObj = override;
00102 sc = dp->registerObject(path,pObj);
00103 if ( !sc.isSuccess() ) {
00104 if (log) (*log) << MSG::ERROR << "Unable to register override object to " << path << endmsg;
00105 return sc;
00106 }
00107
00108 }
00109 }
00110
00111
00112 sc = setPointers(pObj);
00113 if ( !sc.isSuccess() ) {
00114 if (log) (*log) << MSG::ERROR << "Failure setting the pointers for object at " << path << endmsg;
00115 return sc;
00116 }
00117
00118
00119 IOpaqueAddress *pAddr = pObj->registry()->address();
00120 if (pAddr != NULL) {
00121 if (pAddr->svcType() == CONDDB_StorageType) {
00122
00123 db_path = pAddr->par()[0];
00124 }
00125 }
00126 } else {
00127 if (vdo != NULL && !vdo->isValid(when)){
00128 if (log) (*log) << MSG::DEBUG << "Update object " << path << " from data provider" << endmsg;
00129 sc = vdo->update();
00130 if ( !sc.isSuccess() ) {
00131 if (log) (*log) << MSG::ERROR << "Update from data provider failed!" << endmsg;
00132 return sc;
00133 }
00134 }
00135 }
00136 if (vdo != NULL) {
00137
00138 since = vdo->validSince();
00139 until = vdo->validTill();
00140 }
00141
00142 if (log) (*log) << MSG::VERBOSE << "Enter dependencies update loop" << endmsg;
00143 for (MembFuncList::iterator mfIt = memFuncs.begin(); mfIt != memFuncs.end(); ++mfIt){
00144 if (!mfIt->isValid(when)) {
00145 size_t n = mfIt - memFuncs.begin();
00146 if (log) (*log) << MSG::VERBOSE << "Loop over dependencies of m.f. " << n << endmsg;
00147 mfIt->resetIOV();
00148 for (ItemList::iterator itemIt = mfIt->items->begin(); itemIt != mfIt->items->end(); ++itemIt){
00149 sc = (*itemIt)->update(dp,when,log);
00150 if (!sc.isSuccess()) return sc;
00151
00152 if (mfIt->since < (*itemIt)->since) mfIt->since = (*itemIt)->since;
00153 if (mfIt->until > (*itemIt)->until) mfIt->until = (*itemIt)->until;
00154 }
00155 if (log) (*log) << MSG::VERBOSE << "Call m.f. " << n << endmsg;
00156 sc = (*(mfIt->mf))();
00157 if (!sc.isSuccess()){
00158 if (log) (*log) << MSG::DEBUG << "m.f. " << n << " returned a failure" << endmsg;
00159 return sc;
00160 }
00161 }
00162
00163 if (since < mfIt->since) since = mfIt->since;
00164 if (until > mfIt->until) until = mfIt->until;
00165 }
00166 updateLock = false;
00167
00168
00169 if (log){
00170 (*log) << MSG::VERBOSE << " final validity: " << since << " -> " << until << endmsg;
00171 (*log) << MSG::DEBUG << "Updating (Item* " << this << ") " << ptr << " ---END---";
00172 if (!path.empty()) (*log) << " " << path;
00173 (*log) << endmsg;
00174 }
00175 sc = StatusCode::SUCCESS;
00176 return sc;
00177 }
00178
00179
00180
00181 BaseObjectMemberFunction * UpdateManagerSvc::Item::addChild(BaseObjectMemberFunction *thisMF, Item *child) {
00182 MembFuncList::iterator mfIt = find(thisMF);
00183 if (mfIt == memFuncs.end()) {
00184 mfIt = memFuncs.insert(mfIt,MembFunc(thisMF));
00185 } else {
00186 if (mfIt->mf != thisMF)
00187 delete thisMF;
00188 }
00189 if (std::find(mfIt->items->begin(),mfIt->items->end(),child) == mfIt->items->end()){
00190
00191 mfIt->items->push_back(child);
00192
00193
00194 if (mfIt->since < child->since) mfIt->since = child->since;
00195 if (mfIt->until > child->until) mfIt->until = child->until;
00196
00197
00198 if (std::find(children.begin(),children.end(),child) == children.end()){
00199 children.push_back(child);
00200 }
00201
00202
00203 if (since < mfIt->since) since = mfIt->since;
00204 if (until > mfIt->until) until = mfIt->until;
00205
00206 }
00207
00208 return mfIt->mf;
00209 }
00210
00211
00212
00213
00214 void UpdateManagerSvc::Item::purge(MsgStream *log) {
00215 if ( ! path.empty() ) {
00216 if (log) (*log) << MSG::DEBUG << "Purging " << path << endmsg;
00217
00218 const bool force = true;
00219 setPointers(NULL,force).ignore();
00220 } else {
00221 if (log) (*log) << MSG::DEBUG << "Purging object at " << ptr << endmsg;
00222 }
00223
00224
00225
00226
00227 since = 1;
00228 until = 0;
00229 }
00230