#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)
}
// 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()));
}
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);
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;
}
// 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.";
AliWarning("Clearing cache!");
ClearCache();
}
+
+ fRun = fStartRunLHCPeriod = fEndRunLHCPeriod = -1;
+ fRaw = kFALSE;
fDefaultStorage = 0x0;
}
// calibType must be a valid CDB path! (3 level folder structure)
- if(!fDefaultStorage) {
+ if(!fDefaultStorage && !fRaw) {
AliError("Please activate a default storage first!");
return;
}
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;
}
//_____________________________________________________________________________
-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) {
return kFALSE;
}
- if (entry->GetObject()==0x0){
- AliError("No valid object in CDB entry!");
+ if (!entry){
+ AliError("No entry!");
return kFALSE;
}
- if (!entry){
- AliError("No entry!");
+ if (entry->GetObject()==0x0){
+ AliError("No valid object in CDB entry!");
return kFALSE;
}
// Sets current run number.
// When the run number changes the caching is cleared.
- if (fRun == run)
+ if(fRun == run)
return;
if(fLock && fRun >= 0) {
}
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();
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;
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))
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);
}
}
}
//______________________________________________________________________________________________
-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;
}
///////////////////////////////////////////////////////////