]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliCDBManager.cxx
Fixed compilation
[u/mrichter/AliRoot.git] / STEER / AliCDBManager.cxx
index 8879bdaf39c2e1aa97716b08ba6e4bddbf6ecd43..bc3f46ea1eda9544664caf478e5a2ec63f5f4fe8 100644 (file)
 #include "AliCDBLocal.h"
 #include "AliCDBGrid.h"
 #include "AliCDBEntry.h"
-#include "AliCDBMetaData.h"
 #include "AliCDBHandler.h"
 
 #include <TObjString.h>
-#include <TSystem.h>
 #include <TSAXParser.h>
 #include <TFile.h>
 #include <TUUID.h>
+#include <TGrid.h>
 
 ClassImp(AliCDBParam)
 
@@ -94,6 +93,7 @@ void AliCDBManager::InitFromCache(TMap *entryCache, Int_t run) {
   }
   // fEntry is the new owner of the cache
   fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
+  entryCache->SetOwnerKeyValue(kFALSE,kFALSE);
   AliInfo(Form("%d cache entries have been loaded",fEntryCache.GetEntries()));
 }
 
@@ -128,14 +128,15 @@ AliCDBManager::AliCDBManager():
   fRaw(kFALSE),
   fStartRunLHCPeriod(-1),
   fEndRunLHCPeriod(-1),
-  fLHCPeriod("")
+  fLHCPeriod(""),
+  fKey(0)
 {
 // default constuctor
        fFactories.SetOwner(1);
        fActiveStorages.SetOwner(1);
        fSpecificStorages.SetOwner(1);
        fEntryCache.SetName("CDBEntryCache");
-       fEntryCache.SetOwner(1);
+       fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
 
        fStorageMap = new TMap();
        fStorageMap->SetOwner(1);
@@ -327,11 +328,22 @@ Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
 void AliCDBManager::SetDefaultStorage(const char* dbString) {
 // sets default storage from URI string
        
-       AliInfo(Form("Setting Default storage to: %s",dbString));
-
        // checking whether we are in the raw case
        TString dbStringTemp(dbString);
-       if (dbStringTemp == "raw://") fRaw = kTRUE;
+       if (dbStringTemp == "raw://")
+       {
+               fRaw = kTRUE;
+               AliInfo("Setting the run-number will set the corresponding OCDB for raw data reconstruction.");
+               AliInfo("Connecting to the grid...");
+               if(!gGrid) {
+                       TGrid::Connect("alien://","");
+                       if(!gGrid) {
+                               AliError("Connection to alien failed!");
+                               return;
+                       }
+               }
+               return;
+       }
 
        AliCDBStorage* bckStorage = fDefaultStorage;
        
@@ -445,6 +457,13 @@ void AliCDBManager::SetDefaultStorageFromRun(Int_t run) {
        }       
 
        // retrieve XML file from alien
+       if(!gGrid) {
+           TGrid::Connect("alien://","");
+           if(!gGrid) {
+               AliError("Connection to alien failed!");
+               return;
+           }
+       }
        TUUID uuid;
        TString rndname = "/tmp/";
        rndname += "OCDBFolderXML.";
@@ -486,6 +505,9 @@ void AliCDBManager::UnsetDefaultStorage() {
                AliWarning("Clearing cache!");
                ClearCache();
        }
+
+       fRun = fStartRunLHCPeriod = fEndRunLHCPeriod = -1;
+       fRaw = kFALSE;
        
        fDefaultStorage = 0x0;
 }
@@ -510,7 +532,7 @@ void AliCDBManager::SetSpecificStorage(const char* calibType, AliCDBParam* param
 // calibType must be a valid CDB path! (3 level folder structure)
 
 
-       if(!fDefaultStorage) {
+       if(!fDefaultStorage && !fRaw) {
                AliError("Please activate a default storage first!");
                return;
        }
@@ -625,10 +647,10 @@ AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) {
                 return NULL;
        }
 
-       if(fLock && query.GetFirstRun() != fRun)
+       if(fLock && !(fRun >= query.GetFirstRun() && fRun <= query.GetLastRun())) 
                AliFatal("Lock is ON: cannot use different run number than the internal one!");
        
-       if(fCache && query.GetFirstRun() != fRun)
+       if(fCache && !(fRun >= query.GetFirstRun() && fRun <= query.GetLastRun())) 
                AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
 
        AliCDBEntry *entry=0;
@@ -909,7 +931,7 @@ TList* AliCDBManager::GetAll(const AliCDBId& query) {
 }
 
 //_____________________________________________________________________________
-Bool_t AliCDBManager::Put(TObject* object, AliCDBId& id,  AliCDBMetaData* metaData, DataType type){
+Bool_t AliCDBManager::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData, const DataType type){
 // store an AliCDBEntry object into the database
 
        if (object==0x0) {
@@ -1041,7 +1063,7 @@ void AliCDBManager::SetRun(Int_t run)
 // Sets current run number.
 // When the run number changes the caching is cleared.
        
-       if (fRun == run)
+       if(fRun == run)
                return;
   
        if(fLock && fRun >= 0) {
@@ -1049,13 +1071,14 @@ void AliCDBManager::SetRun(Int_t run)
        }       
                
        fRun = run;
-       if (fRaw){
+       if(fRaw){
                // here the LHCPeriod xml file is parsed; the string containing the correct period is returned; the default storage is set
                if (fStartRunLHCPeriod <= run && fEndRunLHCPeriod >= run){
                        AliInfo("LHCPeriod alien folder for current run already in memory");
-               }
-               else {
+               }else{
                        SetDefaultStorageFromRun(run);
+                       if(fEntryCache.GetEntries()!=0) ClearCache();
+                       return;
                }
        }
        ClearCache();
@@ -1089,6 +1112,11 @@ void AliCDBManager::ClearCache(){
 void AliCDBManager::UnloadFromCache(const char* path){
 // unload cached object
 
+       if(!fActiveStorages.GetEntries()) {
+               AliDebug(2, Form("No active storages. Object \"%s\" is not unloaded from cache", path));
+               return;
+       }
+
        AliCDBPath queryPath(path);
        if(!queryPath.IsValid()) return;
 
@@ -1096,8 +1124,6 @@ void AliCDBManager::UnloadFromCache(const char* path){
                if(fEntryCache.Contains(path)){
                        AliDebug(2, Form("Unloading object \"%s\" from cache", path));
                        TObjString pathStr(path);
-                       AliCDBEntry *entry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(&pathStr));
-                       if(entry && !fEntryCache.IsOwnerValue()) delete entry;
                        delete fEntryCache.Remove(&pathStr);
                } else {
                        AliError(Form("Cache does not contain object \"%s\"!", path))
@@ -1115,8 +1141,6 @@ void AliCDBManager::UnloadFromCache(const char* path){
                if(queryPath.Comprises(entryPath)) {
                        AliDebug(2, Form("Unloading object \"%s\" from cache", entryPath.GetPath().Data()));
                        TObjString pathStr(entryPath.GetPath().Data());
-                       AliCDBEntry *entry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(&pathStr));
-                       if(entry && !fEntryCache.IsOwnerValue()) delete entry;
                        delete fEntryCache.Remove(&pathStr);
                }
        }
@@ -1253,13 +1277,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;  
 }
 
 ///////////////////////////////////////////////////////////