From 4005d0b53b389fd69a2b6626df9f605d16343368 Mon Sep 17 00:00:00 2001 From: hristov Date: Wed, 10 Jan 2007 17:53:29 +0000 Subject: [PATCH] Following our last OCDB design meeting I've modified the Grid CDB access classes, adding a dummy subVersion number in the file name. In this way one can copy a Grid folder locally and read it with the local CDB access. I've ensured backward compatibility: AliCDBGrid can read also files with the old name format. New files are nevertheless stored in the new format. Thus at some point we may think to remove the backward compatibility. I also send you an updated version of AliCDBManager, where I've added the "UnloadFromCache(const char* path)" method. This can be used to delete from the cache a single object, while ClearCache removes them all. It may be useful if we want to implement the idea of loading and unloading the calibration data during reconstruction... Alberto --- STEER/AliCDBGrid.cxx | 51 ++++++++++++++++++++++++------------ STEER/AliCDBGrid.h | 2 +- STEER/AliCDBManager.cxx | 57 +++++++++++++++++++++++++++++++++++------ STEER/AliCDBManager.h | 3 ++- 4 files changed, 87 insertions(+), 26 deletions(-) diff --git a/STEER/AliCDBGrid.cxx b/STEER/AliCDBGrid.cxx index 8b2c6664f26..e3e6f2b2944 100644 --- a/STEER/AliCDBGrid.cxx +++ b/STEER/AliCDBGrid.cxx @@ -101,7 +101,7 @@ AliCDBGrid::~AliCDBGrid() //_____________________________________________________________________________ Bool_t AliCDBGrid::FilenameToId(TString& filename, AliCDBId& id) { -// build AliCDBId from full path filename (fDBFolder/path/Run#x_#y_v#z.root) +// build AliCDBId from full path filename (fDBFolder/path/Run#x_#y_v#z_s0.root) if(filename.Contains(fDBFolder)){ filename = filename(fDBFolder.Length(),filename.Length()-fDBFolder.Length()); @@ -114,13 +114,26 @@ Bool_t AliCDBGrid::FilenameToId(TString& filename, AliCDBId& id) { filename=filename(idPath.Length()+1,filename.Length()-idPath.Length()); Ssiz_t mSize; - // valid filename: Run#firstRun_#lastRun_v#version.root - TRegexp keyPattern("^Run[0-9]+_[0-9]+_v[0-9]+.root$"); + // valid filename: Run#firstRun_#lastRun_v#version_s0.root + TRegexp keyPattern("^Run[0-9]+_[0-9]+_v[0-9]+_s0.root$"); keyPattern.Index(filename, &mSize); if (!mSize) { - AliDebug(2,Form("Bad filename <%s>.", filename.Data())); - return kFALSE; - } + + // TODO backward compatibility ... maybe remove later! + Ssiz_t oldmSize; + TRegexp oldKeyPattern("^Run[0-9]+_[0-9]+_v[0-9]+.root$"); + oldKeyPattern.Index(filename, &oldmSize); + if(!oldmSize) { + AliDebug(2,Form("Bad filename <%s>.", filename.Data())); + return kFALSE; + } else { + AliDebug(2,Form("Old filename format <%s>.", filename.Data())); + id.SetSubVersion(-11); // TODO trick to ensure backward compatibility + } + + } else { + id.SetSubVersion(-1); // TODO trick to ensure backward compatibility + } filename.Resize(filename.Length() - sizeof(".root") + 1); @@ -153,11 +166,14 @@ Bool_t AliCDBGrid::IdToFilename(const AliCDBId& id, TString& filename) const { return kFALSE; } - filename = Form("Run%d_%d_v%d.root", + filename = Form("Run%d_%d_v%d", id.GetFirstRun(), id.GetLastRun(), id.GetVersion()); + if (id.GetSubVersion() != -11) filename += "_s0"; // TODO to ensure backward compatibility + filename += ".root"; + filename.Prepend(fDBFolder + id.GetPath() + '/'); return kTRUE; @@ -173,7 +189,7 @@ Bool_t AliCDBGrid::PrepareId(AliCDBId& id) { TString dirName(fDBFolder); Bool_t dirExist=kFALSE; - + // go to the path; if directory does not exist, create it TObjArray *arrName=pathName.Tokenize("/"); for(int i=0;iGetEntries();i++){ @@ -209,9 +225,10 @@ Bool_t AliCDBGrid::PrepareId(AliCDBId& id) { } } - delete res; - + delete res; + id.SetVersion(lastVersion + 1); + id.SetSubVersion(0); TString lastStorage = id.GetLastStorage(); if(lastStorage.Contains(TString("new"), TString::kIgnoreCase) && id.GetVersion() > 1 ){ @@ -221,10 +238,10 @@ Bool_t AliCDBGrid::PrepareId(AliCDBId& id) { id.GetVersion()-1)); } - if(!lastRunRange.IsAnyRange() && !(lastRunRange.IsEqual(&id.GetAliCDBRunRange()))) + if(!lastRunRange.IsAnyRange() && !(lastRunRange.IsEqual(&id.GetAliCDBRunRange()))) AliWarning(Form("Run range modified w.r.t. previous version (Run%d_%d_v%d)", lastRunRange.GetFirstRun(), lastRunRange.GetLastRun(), id.GetVersion())); - + return kTRUE; } @@ -304,7 +321,7 @@ AliCDBEntry* AliCDBGrid::GetEntry(const AliCDBId& queryId) { MakeQueryFilter(selectedId.GetFirstRun(), selectedId.GetLastRun(), 0, filter); TString pattern = Form("%s/Run*", selectedId.GetPath().Data()); - if(selectedId.GetVersion() >= 0) pattern += Form("_v%d",selectedId.GetVersion()); + if(selectedId.GetVersion() >= 0) pattern += Form("_v%d*",selectedId.GetVersion()); pattern += ".root"; AliDebug(2,Form("pattern: %s", pattern.Data())); @@ -363,12 +380,14 @@ AliCDBEntry* AliCDBGrid::GetEntryFromFile(TString& filename, AliCDBId* dataId){ if(anEntry){ AliCDBId entryId = anEntry->GetId(); - dataId->SetSubVersion(entryId.GetSubVersion()); + Int_t tmpSubVersion = dataId->GetSubVersion(); + dataId->SetSubVersion(entryId.GetSubVersion()); // otherwise filename and id may mismatch if(!entryId.IsEqual(dataId)){ AliWarning(Form("Mismatch between file name and object's Id!")); AliWarning(Form("File name: %s", dataId->ToString().Data())); AliWarning(Form("Object's Id: %s", entryId.ToString().Data())); } + dataId->SetSubVersion(tmpSubVersion); } anEntry->SetLastStorage("grid"); @@ -522,7 +541,7 @@ Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry) { entry->SetVersion(id.GetVersion()); // write object (key name: "AliCDBEntry") - Bool_t result = (entry->Write("AliCDBEntry") != 0); + Bool_t result = (entry->Write("AliCDBEntry") != 0); if (!result) AliError(Form("Can't write entry to file <%s>!", filename.Data())); @@ -687,7 +706,7 @@ void AliCDBGrid::QueryValidFiles() MakeQueryFilter(fRun, fRun, fMetaDataFilter, filter); TString pattern = Form("%s/Run*", fPathFilter.GetPath().Data()); - if(fVersion >= 0) pattern += Form("_v%d", fVersion); + if(fVersion >= 0) pattern += Form("_v%d*", fVersion); pattern += ".root"; AliDebug(2,Form("pattern: %s", pattern.Data())); diff --git a/STEER/AliCDBGrid.h b/STEER/AliCDBGrid.h index c3ea257eaa2..9d0356881f1 100644 --- a/STEER/AliCDBGrid.h +++ b/STEER/AliCDBGrid.h @@ -114,7 +114,7 @@ private: TString fGridUrl; // Grid url "Host:port" TString fUser; // User TString fDBFolder; // path of the DB folder - TString fSE; // Storage Element + TString fSE; // Storage Element ClassDef(AliCDBGridParam, 0); }; diff --git a/STEER/AliCDBManager.cxx b/STEER/AliCDBManager.cxx index 141a7f8ab3d..1b33c45421b 100644 --- a/STEER/AliCDBManager.cxx +++ b/STEER/AliCDBManager.cxx @@ -138,7 +138,7 @@ Bool_t AliCDBManager::HasStorage(const char* dbString) const { if (factory->Validate(dbString)) { return kTRUE; - } + } } return kFALSE; @@ -307,7 +307,7 @@ void AliCDBManager::SetSpecificStorage(const char* calibType, AliCDBParam* param AliError("Please activate a default storage first!"); return; } - + AliCDBPath aPath(calibType); if(!aPath.IsValid()){ AliError(Form("Not a valid path: %s", calibType)); @@ -318,6 +318,8 @@ void AliCDBManager::SetSpecificStorage(const char* calibType, AliCDBParam* param if(fSpecificStorages.Contains(objCalibType)){ AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one", calibType)); + AliCDBParam *checkPar = dynamic_cast (fSpecificStorages.GetValue(calibType)); + if(checkPar) delete checkPar; delete fSpecificStorages.Remove(objCalibType); } GetStorage(param); @@ -346,10 +348,7 @@ AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) { // select storage valid for path from the list of specific storages AliCDBPath aPath(path); - if(!aPath.IsValid()){ - AliError(Form("Not a valid path: %s", path.Data())); - return NULL; - } + if(!aPath.IsValid()) return NULL; TIter iter(&fSpecificStorages); TObjString *aCalibType=0; @@ -582,7 +581,7 @@ Bool_t AliCDBManager::Put(AliCDBEntry* entry, DataType type){ AliCDBId id = entry->GetId(); AliCDBParam *aPar = SelectSpecificStorage(id.GetPath()); - AliCDBStorage *aStorage; + AliCDBStorage *aStorage=0; if(aPar) { aStorage=GetStorage(aPar); @@ -602,7 +601,11 @@ Bool_t AliCDBManager::Put(AliCDBEntry* entry, DataType type){ AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data())); - return aStorage->Put(entry, type); + Bool_t result = aStorage->Put(entry, type); + + if(fRun >= 0) QueryCDB(); + + return result; } @@ -672,6 +675,44 @@ void AliCDBManager::ClearCache(){ } +//_____________________________________________________________________________ +void AliCDBManager::UnloadFromCache(const char* path){ +// unload cached object + + AliCDBPath queryPath(path); + if(!queryPath.IsValid()) return; + + if(!queryPath.IsWildcard()) { // path is not wildcard, get it directly from the cache and unload it! + if(fEntryCache.Contains(path)){ + AliInfo(Form("Unloading object \"%s\" from cache", path)); + TObjString pathStr(path); + AliCDBEntry *entry = dynamic_cast (fEntryCache.GetValue(&pathStr)); + if(entry) delete entry; + delete fEntryCache.Remove(&pathStr); + } else { + AliError(Form("Cache does not contain object \"%s\"!", path)) + } + AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries())); + return; + } + + // path is wildcard: loop on the cache and unload all comprised objects! + TIter iter(fEntryCache.GetTable()); + TPair* pair = 0; + + while((pair = dynamic_cast (iter.Next()))){ + AliCDBPath entryPath = pair->Key()->GetName(); + if(queryPath.Comprises(entryPath)) { + AliInfo(Form("Unloading object \"%s\" from cache", entryPath.GetPath().Data())); + TObjString pathStr(entryPath.GetPath().Data()); + AliCDBEntry *entry = dynamic_cast (fEntryCache.GetValue(&pathStr)); + if(entry) delete entry; + delete fEntryCache.Remove(&pathStr); + } + } + AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries())); +} + //_____________________________________________________________________________ void AliCDBManager::DestroyActiveStorages() { // delete list of active storages diff --git a/STEER/AliCDBManager.h b/STEER/AliCDBManager.h index 4d339c4319e..6ce8efeb771 100644 --- a/STEER/AliCDBManager.h +++ b/STEER/AliCDBManager.h @@ -100,8 +100,9 @@ class AliCDBManager: public TObject { ~AliCDBManager(); void ClearCache(); + void UnloadFromCache(const char* path); - static AliCDBManager* Instance(); + static AliCDBManager* Instance(); private: -- 2.43.0