| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

UpdateManagerSvc_Item.cpp

Go to the documentation of this file.
00001 // $Id: UpdateManagerSvc_Item.cpp,v 1.5 2009/02/16 14:22:56 cattanem Exp $
00002 // Include files 
00003 
00004 #include "GaudiKernel/IDataProviderSvc.h"
00005 #include "GaudiKernel/IRegistry.h"
00006 
00007 #include "DetDesc/ValidDataObject.h"
00008 #include "DetDesc/Condition.h"
00009 
00010 // local
00011 #include "UpdateManagerSvc.h"
00012 
00013 //-----------------------------------------------------------------------------
00014 // Implementation file for class : UpdateManagerSvc::Item
00015 //
00016 // 2006-10-23 : Marco Clemencic
00017 //-----------------------------------------------------------------------------
00018 
00019 //=============================================================================
00020 // Destructor
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   // I'm the owner of the list of user's pointer setters: delete them!
00029   for (UserPtrList::iterator pi = user_dest_ptrs.begin();
00030        pi != user_dest_ptrs.end(); ++pi){
00031     delete pi->first;
00032   }
00033 }
00034 //=============================================================================
00035 // Main method. Used to update the object and all the used ones.
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   // check validity
00049   if (isValid(when)) {
00050     if (log) (*log) << MSG::VERBOSE << "Item valid, not need to update" << endmsg;
00051     return StatusCode::SUCCESS;
00052   }
00053   // prepare for update
00054   updateLock = true;
00055   resetIOV();
00056   StatusCode sc;
00057   // start real update
00058   if (ptr == NULL && vdo == NULL && !path.empty()) { // I do not have a VDO ptr (or a void*) but a path: load it
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     // Check if the requested condition is in the override list.
00071     if ( override ) {
00072       // yes, it is!
00073       // First I check if I can update in place the object
00074       ValidDataObject * vdo = dynamic_cast<ValidDataObject *>(pObj);
00075       if (vdo) { // Good, we can update in place
00076         vdo->update(*override);
00077         Condition * cond = dynamic_cast<Condition *>(pObj);
00078         if (cond) { // A condition needs to be initialized too
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         // to avoid memory leaks, I have to delete the overriding object
00088         delete override;
00089         //override->release();
00090         override = NULL;
00091       } else { // I cannot update the object, so I replace it.
00092         //   let's unregister the original object
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         //   and delete it
00099         pObj->release();
00100         //   Now I can register the user specified one
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         // I do not need to delete the overriding object because now it belongs to the T.S.
00108       }
00109     }
00110     
00111     // Set also internal pointers
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     // try to get the path to CondDB folder
00119     IOpaqueAddress *pAddr = pObj->registry()->address();
00120     if (pAddr != NULL) {
00121       if (pAddr->svcType() == CONDDB_StorageType) {
00122         // it comes from the cond db, so I can find its path
00123         db_path = pAddr->par()[0];
00124       }
00125     }
00126   } else {
00127     if (vdo != NULL && !vdo->isValid(when)){ // I have a VDO ptr and the object is not valid
00128       if (log) (*log) << MSG::DEBUG << "Update object " << path << " from data provider" << endmsg;
00129       sc = vdo->update(); // only if I didn't load it
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) { // it is a valid data object and should be up-to-date: align validity
00137     // no check because it shouldn't be necessary
00138     since = vdo->validSince();
00139     until = vdo->validTill();
00140   }
00141   // object internal data are up-to-date, now check what it depends on
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)) { // only if one the children of the member function need an update
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         // child item updated, update mf's IOV
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     // update the overall validity even if the M.F. was not called
00163     if (since < mfIt->since) since = mfIt->since;
00164     if (until > mfIt->until) until = mfIt->until;
00165   }
00166   updateLock = false;
00167   //std::cout << "UMS:      final validity: " << since << " -> " << until << std::endl;
00168   //std::cout << "UMS: Updating (Item* " << this << ") " << ptr << " ---END---" << std::endl;
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 // Adds a child item to the given member function
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     // it is a new child (not in current m.f. list)
00191     mfIt->items->push_back(child);
00192 
00193     // intersect M.F. validity with the new child
00194     if (mfIt->since < child->since) mfIt->since = child->since;
00195     if (mfIt->until > child->until) mfIt->until = child->until;
00196 
00197     // add the new child to the list of childs if not already included
00198     if (std::find(children.begin(),children.end(),child) == children.end()){
00199       children.push_back(child);
00200     }
00201     
00202     // intersect the item validity with the one of the member function
00203     if (since < mfIt->since) since = mfIt->since;
00204     if (until > mfIt->until) until = mfIt->until;
00205 
00206   }
00207   // return the real pointer since thisMF can be deleted
00208   return mfIt->mf;
00209 }
00210   
00211 //=============================================================================
00212 // Clean up the tree
00213 //=============================================================================
00214 void UpdateManagerSvc::Item::purge(MsgStream *log) {
00215   if ( ! path.empty() ) {
00216     if (log) (*log) << MSG::DEBUG << "Purging " << path << endmsg;
00217     // Clean up pointers
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   // I'm not sure I need this
00225   // invalidate();
00226   // or just this
00227   since = 1;
00228   until = 0;
00229 }
00230 //=============================================================================
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:02:42 2011 for DetDescSvc by doxygen 1.4.7