//_____________________________________________________________________________
-AliCDBId AliCDBDump::GetId(const AliCDBId& query) {
+Bool_t AliCDBDump::GetId(const AliCDBId& query, AliCDBId& result) {
// look for filename matching query (called by GetEntry)
- AliCDBId result(query.GetAliCDBPath(), -1, -1, -1, -1);
AliCDBRunRange aRunRange; // the runRange got from filename
Int_t aVersion, aSubVersion; // the version and subVersion got from filename
AliError(Form("More than one object valid for run %d, version %d_%d!",
query.GetFirstRun(), aVersion, aSubVersion));
result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
- return result;
+ return kFALSE;
}
}
AliError(Form("More than one object valid for run %d, version %d_%d!",
query.GetFirstRun(), aVersion, aSubVersion));
result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
- return result;
+ return kFALSE;
}
if( result.GetSubVersion() < aSubVersion) {
AliError(Form("More than one object valid for run %d, version %d_%d!",
query.GetFirstRun(), aVersion, aSubVersion));
result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
- return result;
+ return kFALSE;
}
result.SetVersion(aVersion);
result.SetSubVersion(aSubVersion);
}
}
- return result;
+ return kTRUE;
}
//_____________________________________________________________________________
-AliCDBEntry* AliCDBDump::GetEntry(const AliCDBId& query) {
+AliCDBEntry* AliCDBDump::GetEntry(const AliCDBId& queryId) {
// get AliCDBEntry from the database
TDirectory::TContext context(gDirectory, fFile);
return NULL;
}
- if (!gDirectory->cd(query.GetPath())) {
+ if (!gDirectory->cd(queryId.GetPath())) {
return NULL;
}
- AliCDBId dataId;
+ AliCDBId dataId(queryId.GetAliCDBPath(), -1, -1, -1, -1);
+ Bool_t result;
// look for a filename matching query requests (path, runRange, version, subVersion)
- if (!query.HasVersion()) {
+ if (!queryId.HasVersion()) {
// if version is not specified, first check the selection criteria list
- dataId = GetId(GetSelection(query));
+ AliCDBId selectedId(queryId);
+ GetSelection(&selectedId);
+ result = GetId(selectedId, dataId);
} else {
- dataId = GetId(query);
+ result = GetId(queryId, dataId);
}
- if (!dataId.IsSpecified()) {
+ if (!result || !dataId.IsSpecified()) {
return NULL;
}
Bool_t PrepareId(AliCDBId& id);
- AliCDBId GetId(const AliCDBId& query);
+ Bool_t GetId(const AliCDBId& query, AliCDBId& result);
void GetEntriesForLevel0(const AliCDBId& query, TList* result);
}
//_____________________________________________________________________________
-AliCDBId AliCDBGrid::GetId(const AliCDBId& query) {
+Bool_t AliCDBGrid::GetId(const AliCDBId& query, AliCDBId& result) {
// look for filename matching query (called by GetEntry)
TString initDir(gGrid->Pwd(0));
- AliCDBId result(query.GetAliCDBPath(), -1, -1, -1, -1);
-
TString dirName(fDBFolder);
dirName += query.GetPath(); // dirName = fDBFolder/idPath
if (!gGrid->Cd(dirName,0)) {
AliError(Form("Directory <%s> not found", (query.GetPath()).Data()));
AliError(Form("in DB folder %s", fDBFolder.Data()));
- return result;
+ return kFALSE;
}
TGridResult *res = gGrid->Ls(dirName);
if(result.GetVersion() == aVersion) {
AliError(Form("More than one object valid for run %d, version %d!",
query.GetFirstRun(), aVersion));
- result.SetRunRange(-1,-1); result.SetVersion(-1);
- return result;
+ return kFALSE;
}
result.SetVersion(aVersion);
result.SetFirstRun(aRunRange.GetFirstRun());
if(result.GetVersion() == aVersion){
AliError(Form("More than one object valid for run %d, version %d!",
query.GetFirstRun(), aVersion));
- result.SetRunRange(-1,-1); result.SetVersion(-1);
- return result;
+ return kFALSE;
}
result.SetVersion(aVersion);
result.SetFirstRun(aRunRange.GetFirstRun());
gGrid->Cd(initDir.Data(),0);
- return result;
+ return kTRUE;
}
//_____________________________________________________________________________
AliCDBEntry* AliCDBGrid::GetEntry(const AliCDBId& queryId) {
// get AliCDBEntry from the database
- AliCDBId dataId;
+ AliCDBId dataId(queryId.GetAliCDBPath(), -1, -1, -1, -1);
+ Bool_t result;
// look for a filename matching query requests (path, runRange, version, subVersion)
if (!queryId.HasVersion()) {
// if version is not specified, first check the selection criteria list
- dataId = GetId(GetSelection(queryId));
+ AliCDBId selectedId(queryId);
+ GetSelection(&selectedId);
+ result = GetId(selectedId,dataId);
} else {
- dataId = GetId(queryId);
+ result = GetId(queryId,dataId);
}
- if (!dataId.IsSpecified()) return NULL;
+ if (!result || !dataId.IsSpecified()) return NULL;
TString filename;
if (!IdToFilename(dataId.GetAliCDBRunRange(), dataId.GetVersion(),filename)) {
Bool_t IdToFilename(const AliCDBRunRange& runRange, Int_t version, TString& filename);
Bool_t PrepareId(AliCDBId& id);
- AliCDBId GetId(const AliCDBId& query);
+ Bool_t GetId(const AliCDBId& query, AliCDBId& result);
void GetEntriesForLevel0(const char* level0, const AliCDBId& query, TList* result);
//_____________________________________________________________________________
Bool_t AliCDBLocal::FilenameToId(const char* filename, AliCDBRunRange& runRange,
+ Int_t& version, Int_t& subVersion) {
// build AliCDBId from filename numbers
- Int_t& version, Int_t& subVersion) {
Ssiz_t mSize;
}
//_____________________________________________________________________________
-AliCDBId AliCDBLocal::GetId(const AliCDBId& query) {
+Bool_t AliCDBLocal::GetId(const AliCDBId& query, AliCDBId& result) {
// look for filename matching query (called by GetEntry)
- AliCDBId result(query.GetAliCDBPath(), -1, -1, -1, -1);
-
TString dirName;
dirName += fBaseDirectory;
dirName += '/';
if (!dirPtr) {
AliError(Form("Directory <%s> not found", (query.GetPath()).Data()));
AliError(Form("in DB folder %s", fBaseDirectory.Data()));
- return result;
+ return kFALSE;
}
const char* filename;
&& result.GetSubVersion() == aSubVersion){
AliError(Form("More than one object valid for run %d, version %d_%d!",
query.GetFirstRun(), aVersion, aSubVersion));
- result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
- return result;
+ gSystem->FreeDirectory(dirPtr);
+ return kFALSE;
}
}
if(result.GetSubVersion() == aSubVersion){
AliError(Form("More than one object valid for run %d, version %d_%d!",
query.GetFirstRun(), aVersion, aSubVersion));
- result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
- return result;
+ gSystem->FreeDirectory(dirPtr);
+ return kFALSE;
}
if( result.GetSubVersion() < aSubVersion) {
if(result.GetVersion() == aVersion && result.GetSubVersion() == aSubVersion){
AliError(Form("More than one object valid for run %d, version %d_%d!",
query.GetFirstRun(), aVersion, aSubVersion));
- result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
- return result;
+ gSystem->FreeDirectory(dirPtr);
+ return kFALSE;
}
result.SetVersion(aVersion);
result.SetSubVersion(aSubVersion);
gSystem->FreeDirectory(dirPtr);
- return result;
+ return kTRUE;
}
//_____________________________________________________________________________
AliCDBEntry* AliCDBLocal::GetEntry(const AliCDBId& queryId) {
// get AliCDBEntry from the database
- AliCDBId dataId;
-
+ AliCDBId dataId(queryId.GetAliCDBPath(), -1, -1, -1, -1);
+ Bool_t result;
+
// look for a filename matching query requests (path, runRange, version, subVersion)
if (!queryId.HasVersion()) {
// if version is not specified, first check the selection criteria list
- dataId = GetId(GetSelection(queryId));
+ AliCDBId selectedId(queryId);
+ GetSelection(&selectedId);
+ result = GetId(selectedId, dataId);
} else {
- dataId = GetId(queryId);
+ result = GetId(queryId, dataId);
}
- if (!dataId.IsSpecified()) return NULL;
+ if (!result || !dataId.IsSpecified()) return NULL;
TString filename;
if (!IdToFilename(dataId.GetAliCDBRunRange(), dataId.GetVersion(),
Int_t subVersion, TString& filename);
Bool_t PrepareId(AliCDBId& id);
- AliCDBId GetId(const AliCDBId& query);
+ Bool_t GetId(const AliCDBId& query, AliCDBId& result);
void GetEntriesForLevel0(const char* level0, const AliCDBId& query, TList* result);
void GetEntriesForLevel1(const char* level0, const char* Level1,
// 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;
//_____________________________________________________________________________
AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* detName) {
// get storage specific for detector
- TObjString objDetName(detName);
- AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(&objDetName);
+
+ AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(detName);
if(!checkPar){
- AliError(Form("%s storage not found!",objDetName.String().Data()));
+ AliError(Form("%s storage not found!",detName));
return NULL;
} else {
return GetStorage(checkPar);
}
+//_____________________________________________________________________________
+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()));
+
+}
+
//_____________________________________________________________________________
void AliCDBManager::DestroyActiveStorages() {
// delete list of active storages
Bool_t Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData);
Bool_t Put(AliCDBEntry* entry);
+
+ void SetCacheFlag(Bool_t cacheFlag) {fCache=cacheFlag;}
+ Bool_t GetCacheFlag() {return fCache;}
+
+ void SetRun(Long64_t run);
+ Long64_t GetRun() {return fRun;}
+
+ AliCDBEntry* Get(const char* path);
void DestroyActiveStorages();
void DestroyActiveStorage(AliCDBStorage* storage);
AliCDBStorage* GetActiveStorage(const AliCDBParam* param);
void PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage);
+
+ void ClearCache();
+ void CacheEntry(const char* path, AliCDBEntry* entry);
+
void Init();
TList fFactories; //! list of registered storage factories
TMap fActiveStorages; //! list of active storages
TMap fSpecificStorages; //! list of detector-specific storages
+
AliCDBStorage *fDefaultStorage; //! pointer to default storage
AliCDBStorage *fDrainStorage; //! pointer to drain storage
+ TMap fEntryCache; //! cache of the retrieved objects
+
+ Bool_t fCache; //! The cache flag
+ Long64_t fRun; //! The run number
+
ClassDef(AliCDBManager, 0);
};
}
//_____________________________________________________________________________
-AliCDBId AliCDBStorage::GetSelection(const AliCDBId& id) {
+void AliCDBStorage::GetSelection(/*const*/ AliCDBId* id) {
// return required version and subversion from the list of selection criteria
TIter iter(&fSelections);
// loop on the list of selection criteria
while ((aSelection = (AliCDBId*) iter.Next())) {
// check if selection element contains id's path and run (range)
- if (aSelection->Comprises(id)) {
+ if (aSelection->Comprises(*id)) {
AliDebug(2,Form("Using selection criterion: %s ", aSelection->ToString().Data()));
// return required version and subversion
- return AliCDBId(id.GetAliCDBPath(),
- id.GetAliCDBRunRange(),
- aSelection->GetVersion(),
- aSelection->GetSubVersion());
+
+ id->SetVersion(aSelection->GetVersion());
+ id->SetSubVersion(aSelection->GetSubVersion());
+ return;
}
}
// no valid element is found in the list of selection criteria -> return
AliDebug(2,"Looking for objects with most recent version");
- return AliCDBId(id.GetAliCDBPath(), id.GetAliCDBRunRange());
+ return;
}
//_____________________________________________________________________________
protected:
virtual ~AliCDBStorage();
- AliCDBId GetSelection(const AliCDBId& id);
+ void GetSelection(/*const*/ AliCDBId* id);
virtual AliCDBEntry* GetEntry(const AliCDBId& query) = 0;
virtual TList* GetEntries(const AliCDBId& query) = 0;
virtual Bool_t PutEntry(AliCDBEntry* entry) = 0;