From a6f592406c51bb4e609c9fca6c0a27f3c52b1ee7 Mon Sep 17 00:00:00 2001 From: agheata Date: Mon, 31 Aug 2009 10:12:49 +0000 Subject: [PATCH] Added possibility to lock/unlock CDB manager. User is provided with a key everytime it locks. The key has to be used in the SetLock() method whenever the state of the lock need to be changed. (A.G.) --- STEER/AliCDBManager.cxx | 36 ++++++++++++++++++++++++++++-------- STEER/AliCDBManager.h | 5 ++++- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/STEER/AliCDBManager.cxx b/STEER/AliCDBManager.cxx index 1f07502a0a7..c63140c6ac1 100644 --- a/STEER/AliCDBManager.cxx +++ b/STEER/AliCDBManager.cxx @@ -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; } /////////////////////////////////////////////////////////// diff --git a/STEER/AliCDBManager.h b/STEER/AliCDBManager.h index 379c493ca90..c056586b379 100644 --- a/STEER/AliCDBManager.h +++ b/STEER/AliCDBManager.h @@ -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); }; -- 2.43.0