* about the suitability of this software for any purpose. It is *
* provided "as is" without express or implied warranty. *
**************************************************************************/
+//-------------------------------------------------------------------------
+// Implementation of AliCDBManager and AliCDBParam classe
+// Author: Alberto Colla
+// e-mail: Alberto.Colla@cern.ch
+//-------------------------------------------------------------------------
#include "AliCDBManager.h"
#include "AliCDBStorage.h"
#include "AliCDBDump.h"
#include "AliCDBLocal.h"
#include "AliCDBGrid.h"
+#include "AliCDBEntry.h"
+#include "AliCDBMetaData.h"
#include <TObjString.h>
#include <TSystem.h>
// delete ALCDBManager instance and active storages
if (fgInstance) {
+ //fgInstance->Delete();
delete fgInstance;
fgInstance = 0x0;
}
//_____________________________________________________________________________
AliCDBManager::AliCDBManager():
fDefaultStorage(NULL),
- fDrainStorage(NULL)
+ fDrainStorage(NULL),
+ fCache(kTRUE),
+ fRun(0)
{
// default constuctor
- fFactories.SetOwner();
+ fFactories.SetOwner(1);
+ fEntryCache.SetOwner(1);
}
//_____________________________________________________________________________
AliCDBManager::~AliCDBManager() {
// destructor
+ ClearCache();
DestroyActiveStorages();
+ fDrainStorage = 0x0;
+ fDefaultStorage = 0x0;
}
//_____________________________________________________________________________
}
//_____________________________________________________________________________
-Bool_t AliCDBManager::HasStorage(const char* dbString) {
+Bool_t AliCDBManager::HasStorage(const char* dbString) const {
// check if dbString is a URI valid for one of the registered factories
TIter iter(&fFactories);
}
//_____________________________________________________________________________
-AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) {
+AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
// create AliCDBParam object from URI string
TIter iter(&fFactories);
return fDrainStorage->Put(entry);
}
-//_____________________________________________________________________________
-void AliCDBManager::RemoveDrain() {
-// remove drain storage
-
- fDrainStorage=0;
-}
-
//_____________________________________________________________________________
void AliCDBManager::SetDefaultStorage(const char* dbString) {
// sets default storage from URI string
- if(fDefaultStorage) fDefaultStorage = 0;
fDefaultStorage = GetStorage(dbString);
}
void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
// set default storage from AliCDBParam object
- if(fDefaultStorage) fDefaultStorage = 0;
fDrainStorage = GetStorage(param);
}
void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
// set default storage from another active storage
- if(fDefaultStorage) fDefaultStorage = 0;
fDefaultStorage = storage;
}
//_____________________________________________________________________________
-void AliCDBManager::RemoveDefaultStorage() {
-// remove default storage
+void AliCDBManager::SetSpecificStorage(const char* detName, const char* dbString) {
+// sets storage specific for detector (works with AliCDBManager::Get(...))
+
+ AliCDBParam *aPar = CreateParameter(dbString);
+ if(!aPar) return;
+ SetSpecificStorage(detName, aPar);
+ delete aPar;
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::SetSpecificStorage(const char* detName, AliCDBParam* param) {
+// sets storage specific for detector (works with AliCDBManager::Get(...))
+
+ if(!fDefaultStorage) {
+ AliError("Please activate a default storage first!");
+ return;
+ }
+
+ TObjString *objDetName = new TObjString(detName);
+ AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(objDetName);
+ if(checkPar){
+ AliWarning(Form("%s storage already activated! It will be replaced by the new one",objDetName->String().Data()));
+ fSpecificStorages.Remove(objDetName);
+ delete checkPar;
+ }
+ GetStorage(param);
+ fSpecificStorages.Add(objDetName, param->CloneParam());
+}
+
+//_____________________________________________________________________________
+AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* detName) {
+// get storage specific for detector
+
+ AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(detName);
+ if(!checkPar){
+ AliError(Form("%s storage not found!",detName));
+ return NULL;
+ } else {
+ return GetStorage(checkPar);
+ }
+
+}
+
+//_____________________________________________________________________________
+AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber,
+ Int_t version, Int_t subVersion) {
+// get an AliCDBEntry object from the database
+
+ return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
+}
+
+//_____________________________________________________________________________
+AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path,
+ const AliCDBRunRange& runRange, Int_t version,
+ Int_t subVersion) {
+// get an AliCDBEntry object from the database!
+
+ return Get(AliCDBId(path, runRange, version, subVersion));
+}
+
+//_____________________________________________________________________________
+AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) {
+// get an AliCDBEntry object from the database
+
+ if(!fDefaultStorage) {
+ AliError("No storage set!");
+ return NULL;
+ }
+
+ // check if query's path and runRange are valid
+ // query is invalid also if version is not specified and subversion is!
+ if (!query.IsValid()) {
+ AliError(Form("Invalid query: %s", query.ToString().Data()));
+ return NULL;
+ }
+
+ // query is not specified if path contains wildcard or runrange = [-1,-1]
+ if (!query.IsSpecified()) {
+ AliError(Form("Unspecified query: %s",
+ query.ToString().Data()));
+ return NULL;
+ }
+
+ TObjString objStrLev0(query.GetLevel0());
+ AliCDBParam *aPar = (AliCDBParam*) fSpecificStorages.GetValue(&objStrLev0);
+ AliCDBStorage *aStorage;
+
+ if(aPar) {
+ aStorage=GetStorage(aPar);
+ TString str = aPar->GetURI();
+ AliDebug(2,Form("Looking into storage: %s",str.Data()));
+
+ } else {
+ aStorage=GetDefaultStorage();
+ AliDebug(2,"Looking into default storage");
+ }
+
+ return aStorage->Get(query);
+}
+
+//_____________________________________________________________________________
+TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber,
+ Int_t version, Int_t subVersion) {
+// get multiple AliCDBEntry objects from the database
+
+ return GetAll(AliCDBId(path, runNumber, runNumber, version,
+ subVersion));
+}
+
+//_____________________________________________________________________________
+TList* AliCDBManager::GetAll(const AliCDBPath& path,
+ const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
+// get multiple AliCDBEntry objects from the database
+
+ return GetAll(AliCDBId(path, runRange, version, subVersion));
+}
+
+//_____________________________________________________________________________
+TList* AliCDBManager::GetAll(const AliCDBId& query) {
+// get multiple AliCDBEntry objects from the database
+
+ if(!fDefaultStorage) {
+ AliError("No storage set!");
+ return NULL;
+ }
+
+ if (!query.IsValid()) {
+ AliError(Form("Invalid query: %s", query.ToString().Data()));
+ return NULL;
+ }
+
+ if(query.GetPath().BeginsWith('*')){
+ AliError("Query too generic in this context!");
+ return NULL;
+ }
+
+ if (query.IsAnyRange()) {
+ AliError(Form("Unspecified run or runrange: %s",
+ query.ToString().Data()));
+ return NULL;
+ }
+
+ TObjString objStrLev0(query.GetLevel0());
+ AliCDBParam *aPar = (AliCDBParam*) fSpecificStorages.GetValue(&objStrLev0);
+ AliCDBStorage *aStorage;
+
+ if(aPar) {
+ aStorage=GetStorage(aPar);
+ TString str = aPar->GetURI();
+ AliDebug(2,Form("Looking into storage: %s",str.Data()));
+
+ } else {
+ aStorage=GetDefaultStorage();
+ AliDebug(2,"Looking into default storage");
+ }
+
+ TList *result = aStorage->GetAll(query);
+
+ return result;
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBManager::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData){
+// store an AliCDBEntry object into the database
+
+ AliCDBEntry anEntry(object, id, metaData);
+ return Put(&anEntry);
+
+}
+
+
+//_____________________________________________________________________________
+Bool_t AliCDBManager::Put(AliCDBEntry* entry){
+// store an AliCDBEntry object into the database
+
+ if(!fDefaultStorage) {
+ AliError("No storage set!");
+ return kFALSE;
+ }
+
+ if (!entry){
+ AliError("No entry!");
+ return kFALSE;
+ }
+
+ if (!entry->GetId().IsValid()) {
+ AliError(Form("Invalid entry ID: %s",
+ entry->GetId().ToString().Data()));
+ return kFALSE;
+ }
+
+ if (!entry->GetId().IsSpecified()) {
+ AliError(Form("Unspecified entry ID: %s",
+ entry->GetId().ToString().Data()));
+ return kFALSE;
+ }
+
+ AliCDBId id = entry->GetId();
+ TObjString objStrLev0(id.GetLevel0());
+ AliCDBParam *aPar = (AliCDBParam*) fSpecificStorages.GetValue(&objStrLev0);
+ AliCDBStorage *aStorage;
+
+ if(aPar) {
+ aStorage=GetStorage(aPar);
+ TString str = aPar->GetURI();
+ AliDebug(2,Form("Storing object into storage: %s",str.Data()));
+
+ } else {
+ aStorage=GetDefaultStorage();
+ AliDebug(2,"Storing object into default storage");
+ }
+
+ return aStorage->Put(entry);
+
+
+}
+
+//_____________________________________________________________________________
+AliCDBEntry* AliCDBManager::Get(const char* path)
+{
+// get an AliCDBEntry object from the database, using fRun as run number
+
+ if (fRun < 0)
+ {
+ AliError("Run number not set! Use AliCDBManager::SetRun.");
+ return 0;
+ }
+
+ AliCDBEntry *entry;
+
+ // first look into map of cached objects
+ entry = (AliCDBEntry*) fEntryCache.GetValue(path);
+ if(entry) return entry;
+
+ // Entry is not in cache -> retrieve it from CDB and cache it!!
+ entry = Get(path, fRun);
+ if (!entry) return 0;
+
+ if(fCache) CacheEntry(path, entry);
+
+ return entry;
+
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry)
+{
+// cache AliCDBEntry. Cache is valid until run number is changed.
+
+ AliDebug(2,Form("Filling cache with entry %s",path));
+ fEntryCache.Add(new TObjString(path), entry);
+ AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries()));
+
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::SetRun(Long64_t run)
+{
+//
+// Sets current run number.
+// When the run number changes the caching is cleared.
+//
+
+ if (fRun == run)
+ return;
+
+ fRun = run;
+ ClearCache();
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::ClearCache(){
+// clear AliCDBEntry cache
+
+ AliDebug(2,Form("Clearing cache!"));
+ fEntryCache.DeleteAll();
+ AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries()));
- fDefaultStorage = 0;
}
//_____________________________________________________________________________
// delete list of active storages
fActiveStorages.DeleteAll();
+ fSpecificStorages.DeleteAll();
}
//_____________________________________________________________________________
void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
-// destroys active storage (not implemented)
+// destroys active storage
+
+/*
+ TIter iter(fActiveStorages.GetTable());
+ TPair* aPair;
+ while ((aPair = (TPair*) iter.Next())) {
+ if(storage == (AliCDBStorage*) aPair->Value())
+ delete fActiveStorages.Remove(aPair->Key());
+ storage->Delete(); storage=0x0;
+ }
+*/
}