]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Added possibility to lock/unlock CDB manager. User is provided with a key everytime...
authoragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 31 Aug 2009 10:12:49 +0000 (10:12 +0000)
committeragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 31 Aug 2009 10:12:49 +0000 (10:12 +0000)
STEER/AliCDBManager.cxx
STEER/AliCDBManager.h

index 1f07502a0a76e246035cd06568d3bbba35395e8f..c63140c6ac19345e300469fe0b15bd5e0c8d7696 100644 (file)
@@ -129,7 +129,8 @@ AliCDBManager::AliCDBManager():
   fRaw(kFALSE),
   fStartRunLHCPeriod(-1),
   fEndRunLHCPeriod(-1),
-  fLHCPeriod("")
+  fLHCPeriod(""),
+  fKey(0)
 {
 // default constuctor
        fFactories.SetOwner(1);
@@ -1250,13 +1251,32 @@ Bool_t AliCDBManager::IsShortLived(const char* path)
 }
 
 //______________________________________________________________________________________________
-void AliCDBManager::SetLock(Bool_t lock){
-
-       if(fLock == kTRUE && lock == kFALSE) {
-               AliFatal("Lock is ON: cannot reset it!");
-       }
-       
-       fLock=lock;
+ULong_t AliCDBManager::SetLock(Bool_t lock, ULong_t key){
+  // To lock/unlock user must provide the key. A new key is provided after
+  // each successful lock. User should always backup the returned key and
+  // use it on next access.
+  if (fLock == lock) return 0;  // nothing to be done
+  if (lock) {
+    // User wants to lock - check his identity
+    if (fKey) {
+      // Lock has a user - check his key
+      if (fKey != key) {
+        AliFatal("Wrong key provided to lock CDB. Please remove CDB lock access from your code !");
+        return 0;
+      }  
+    }  
+    // Provide new key 
+    fKey = gSystem->Now();
+    fLock = kTRUE;
+    return fKey;
+  }
+  // User wants to unlock - check the provided key
+  if (key != fKey) {
+    AliFatal("Lock is ON: wrong key provided");
+    return 0;
+  }  
+  fLock = kFALSE;
+  return key;  
 }
 
 ///////////////////////////////////////////////////////////
index 379c493ca9094f0e8a47fc3147be3ceb4f6ba4db..c056586b379bee17fd3cf4868d0f0cfa74aff344 100644 (file)
@@ -97,7 +97,7 @@ class AliCDBManager: public TObject {
        void SetCacheFlag(Bool_t cacheFlag) {fCache=cacheFlag;}
        Bool_t GetCacheFlag() const {return fCache;}
        
-       void SetLock(Bool_t lockFlag=kTRUE);
+       ULong_t SetLock(Bool_t lockFlag=kTRUE, ULong_t key=0);
        Bool_t GetLock() const {return fLock;}
 
        void SetRaw(Bool_t rawFlag){fRaw=rawFlag;}
@@ -179,6 +179,9 @@ protected:
        Int_t fEndRunLHCPeriod;   // last run of the LHC period set
        TString fLHCPeriod;       // LHC period alien folder
 
+private:
+   ULong_t fKey;  //! Key for locking/unlocking
+
 
        ClassDef(AliCDBManager, 0);
 };