From 620321242adc863f8edba964e55ab8ee5475abbd Mon Sep 17 00:00:00 2001 From: hristov Date: Mon, 4 Sep 2006 10:24:27 +0000 Subject: [PATCH] Implementation of Grid CDB access using the Grid metadata tables. The objects are now tagged during storage and their retrieval is done throught a query to the file catalog using the tags information. Alberto --- STEER/AliCDBDump.cxx | 15 +- STEER/AliCDBDump.h | 1 + STEER/AliCDBEntry.cxx | 1 + STEER/AliCDBGrid.cxx | 654 ++++++++++++++++++++++++++------------- STEER/AliCDBGrid.h | 24 +- STEER/AliCDBId.cxx | 7 +- STEER/AliCDBLocal.cxx | 43 ++- STEER/AliCDBLocal.h | 2 + STEER/AliCDBManager.cxx | 99 ++++-- STEER/AliCDBManager.h | 6 +- STEER/AliCDBMetaData.cxx | 33 +- STEER/AliCDBStorage.cxx | 96 +++++- STEER/AliCDBStorage.h | 27 +- 13 files changed, 711 insertions(+), 297 deletions(-) diff --git a/STEER/AliCDBDump.cxx b/STEER/AliCDBDump.cxx index df5c9fe4614..6e221d5d47e 100644 --- a/STEER/AliCDBDump.cxx +++ b/STEER/AliCDBDump.cxx @@ -46,6 +46,9 @@ fFile(NULL), fReadOnly(readOnly) { AliDebug(2,Form("File <%s> opened",dbFile)); if(fReadOnly) AliDebug(2,Form("in read-only mode")); } + + fType="dump"; + fBaseFolder = dbFile; } //_____________________________________________________________________________ @@ -600,6 +603,14 @@ Bool_t AliCDBDump::Contains(const char* path) const{ } +//_____________________________________________________________________________ +void AliCDBDump::QueryValidFiles() +{ +// blabla + +} + + ///////////////////////////////////////////////////////////////////////////////////////////////// // // // AliCDBDump factory // @@ -670,7 +681,9 @@ AliCDBStorage* AliCDBDumpFactory::Create(const AliCDBParam* param) { ClassImp(AliCDBDumpParam) //_____________________________________________________________________________ -AliCDBDumpParam::AliCDBDumpParam() { +AliCDBDumpParam::AliCDBDumpParam(): +fDBPath(), fReadOnly(kFALSE) +{ // default constructor } diff --git a/STEER/AliCDBDump.h b/STEER/AliCDBDump.h index 832b70e13ee..86fac8b13d5 100644 --- a/STEER/AliCDBDump.h +++ b/STEER/AliCDBDump.h @@ -49,6 +49,7 @@ private: Bool_t PrepareId(AliCDBId& id); Bool_t GetId(const AliCDBId& query, AliCDBId& result); + virtual void QueryValidFiles(); void GetEntriesForLevel0(const AliCDBId& query, TList* result); void GetEntriesForLevel1(const AliCDBId& query, TList* result); diff --git a/STEER/AliCDBEntry.cxx b/STEER/AliCDBEntry.cxx index e305983170c..f90ec74e193 100644 --- a/STEER/AliCDBEntry.cxx +++ b/STEER/AliCDBEntry.cxx @@ -29,6 +29,7 @@ ClassImp(AliCDBEntry) //_____________________________________________________________________________ AliCDBEntry::AliCDBEntry(): fObject(NULL), +fId(), fMetaData(NULL), fIsOwner(kFALSE){ // default constructor diff --git a/STEER/AliCDBGrid.cxx b/STEER/AliCDBGrid.cxx index dafdd7990c1..fc8fd411111 100644 --- a/STEER/AliCDBGrid.cxx +++ b/STEER/AliCDBGrid.cxx @@ -52,7 +52,7 @@ fSE(se) if (!gGrid || fGridUrl != gGrid->GridUrl() || (( fUser != "" ) && ( fUser != gGrid->GetUser() )) ) { // connection to the Grid - AliInfo("Connection to the Grid!!!!"); + AliInfo("Connection to the Grid..."); if(gGrid){ AliInfo(Form("gGrid = %x; fGridUrl = %s; gGrid->GridUrl() = %s",gGrid,fGridUrl.Data(), gGrid->GridUrl())); AliInfo(Form("fUser = %s; gGrid->GetUser() = %s",fUser.Data(), gGrid->GetUser())); @@ -84,6 +84,9 @@ fSE(se) while(fDBFolder.EndsWith("/")) fDBFolder.Remove(fDBFolder.Last('/')); fDBFolder+="/"; + fType="alien"; + fBaseFolder = fDBFolder; + // return to the initial directory gGrid->Cd(initDir.Data(),0); } @@ -92,35 +95,43 @@ fSE(se) AliCDBGrid::~AliCDBGrid() { // destructor + delete gGrid; gGrid=0; } //_____________________________________________________________________________ -Bool_t AliCDBGrid::FilenameToId(const char* filename, AliCDBRunRange& runRange, - Int_t& gridVersion) { -// build AliCDBId from filename numbers +Bool_t AliCDBGrid::FilenameToId(TString& filename, AliCDBId& id) { +// build AliCDBId from full path filename (fDBFolder/path/Run#x_#y_v#z.root) + + if(filename.Contains(fDBFolder)){ + filename = filename(fDBFolder.Length(),filename.Length()-fDBFolder.Length()); + } + + TString idPath = filename(0,filename.Last('/')); + id.SetPath(idPath); + if(!id.IsValid()) return kFALSE; + + 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$"); keyPattern.Index(filename, &mSize); if (!mSize) { - AliDebug(2,Form("Bad filename <%s>.", filename)); + AliDebug(2,Form("Bad filename <%s>.", filename.Data())); return kFALSE; } - TString idString(filename); - idString.Resize(idString.Length() - sizeof(".root") + 1); + filename.Resize(filename.Length() - sizeof(".root") + 1); - TObjArray* strArray = (TObjArray*) idString.Tokenize("_"); + TObjArray* strArray = (TObjArray*) filename.Tokenize("_"); TString firstRunString(((TObjString*) strArray->At(0))->GetString()); - runRange.SetFirstRun(atoi(firstRunString.Data() + 3)); - runRange.SetLastRun(atoi(((TObjString*) strArray->At(1))->GetString())); - + id.SetFirstRun(atoi(firstRunString.Data() + 3)); + id.SetLastRun(atoi(((TObjString*) strArray->At(1))->GetString())); + TString verString(((TObjString*) strArray->At(2))->GetString()); - gridVersion = atoi(verString.Data() + 1); + id.SetVersion(atoi(verString.Data() + 1)); delete strArray; @@ -128,28 +139,26 @@ Bool_t AliCDBGrid::FilenameToId(const char* filename, AliCDBRunRange& runRange, } //_____________________________________________________________________________ -Bool_t AliCDBGrid::IdToFilename(const AliCDBRunRange& runRange, Int_t gridVersion, - TString& filename) { -// build file name from AliCDBId data (run range, version) +Bool_t AliCDBGrid::IdToFilename(const AliCDBId& id, TString& filename) { +// build file name from AliCDBId (path, run range, version) and fDBFolder - if (!runRange.IsValid()) { - AliDebug(2,Form("Invalid run range <%d, %d>.", - runRange.GetFirstRun(), runRange.GetLastRun())); + if (!id.GetAliCDBRunRange().IsValid()) { + AliDebug(2,Form("Invalid run range <%d, %d>.", + id.GetFirstRun(), id.GetLastRun())); return kFALSE; } - if (gridVersion < 0) { - AliDebug(2,Form("Invalid version <%d>.", gridVersion)); + if (id.GetVersion() < 0) { + AliDebug(2,Form("Invalid version <%d>.", id.GetVersion())); return kFALSE; } - - filename += "Run"; - filename += runRange.GetFirstRun(); - filename += "_"; - filename += runRange.GetLastRun(); - filename += "_v"; - filename += gridVersion; - filename += ".root"; + + filename = Form("Run%d_%d_v%d.root", + id.GetFirstRun(), + id.GetLastRun(), + id.GetVersion()); + + filename.Prepend(fDBFolder + id.GetPath() + '/'); return kTRUE; } @@ -183,21 +192,20 @@ Bool_t AliCDBGrid::PrepareId(AliCDBId& id) { delete arrName; gGrid->Cd(initDir,0); - const char* filename; - AliCDBRunRange aRunRange; // the runRange got from filename + TString filename; + AliCDBId anId; // the id got from filename AliCDBRunRange lastRunRange(-1,-1); // highest runRange found - Int_t aVersion; // the version got from filename Int_t lastVersion=0; // highest version found TGridResult *res = gGrid->Ls(dirName); //loop on the files in the directory, look for highest version for(int i=0; i < res->GetEntries(); i++){ - filename=res->GetFileName(i); - if (!FilenameToId(filename, aRunRange, aVersion)) continue; - if (aRunRange.Overlaps(id.GetAliCDBRunRange()) && aVersion > lastVersion) { - lastVersion = aVersion; - lastRunRange = aRunRange; + filename=res->GetFileNamePath(i); + if (!FilenameToId(filename, anId)) continue; + if (anId.GetAliCDBRunRange().Overlaps(id.GetAliCDBRunRange()) && anId.GetVersion() > lastVersion) { + lastVersion = anId.GetVersion(); + lastRunRange = anId.GetAliCDBRunRange(); } } @@ -221,93 +229,148 @@ Bool_t AliCDBGrid::PrepareId(AliCDBId& id) { } //_____________________________________________________________________________ -Bool_t AliCDBGrid::GetId(const AliCDBId& query, AliCDBId& result) { -// look for filename matching query (called by GetEntry) +AliCDBId* AliCDBGrid::GetId(const TList& validFileIds, const AliCDBId& query) { +// look for the Id that matches query's requests (highest or exact version) - TString initDir(gGrid->Pwd(0)); + if(validFileIds.GetEntries() < 1) { + return NULL; + } else if (validFileIds.GetEntries() == 1) { + return dynamic_cast (validFileIds.At(0)); + } - TString dirName(fDBFolder); - dirName += query.GetPath(); // dirName = fDBFolder/idPath + TIter iter(&validFileIds); - if (!gGrid->Cd(dirName,0)) { - AliDebug(2,Form("Directory <%s> not found", (query.GetPath()).Data())); - AliDebug(2,Form("in DB folder %s", fDBFolder.Data())); - return kFALSE; - } - - TGridResult *res = gGrid->Ls(dirName); + AliCDBId *anIdPtr=0; + AliCDBId* result=0; - const char* filename; - AliCDBRunRange aRunRange; // the runRange got from filename - Int_t aVersion; // the version got from filename - - for(int i=0; i < res->GetEntries(); i++){ - filename=res->GetFileName(i); - if (!FilenameToId(filename, aRunRange, aVersion)) continue; - // aRunRange and aVersion filled from filename - - if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue; - // aRunRange contains requested run! + while((anIdPtr = dynamic_cast (iter.Next()))){ + + if(anIdPtr->GetPath() != query.GetPath()) continue; + + //if(!CheckVersion(query, anIdPtr, result)) return NULL; if (!query.HasVersion()){ // look for highest version - if(result.GetVersion() > aVersion) continue; - if(result.GetVersion() == aVersion) { - AliDebug(2,Form("More than one object valid for run %d, version %d!", - query.GetFirstRun(), aVersion)); - return kFALSE; + if(result && result->GetVersion() > anIdPtr->GetVersion()) continue; + if(result && result->GetVersion() == anIdPtr->GetVersion()) { + AliDebug(2,Form("More than one object valid for run %d, version %d!", + query.GetFirstRun(), anIdPtr->GetVersion())); + return NULL; } - result.SetVersion(aVersion); - result.SetFirstRun(aRunRange.GetFirstRun()); - result.SetLastRun(aRunRange.GetLastRun()); - + result = anIdPtr; } else { // look for specified version - if(query.GetVersion() != aVersion) continue; - if(result.GetVersion() == aVersion){ - AliDebug(2,Form("More than one object valid for run %d, version %d!", - query.GetFirstRun(), aVersion)); - return kFALSE; + if(query.GetVersion() != anIdPtr->GetVersion()) continue; + if(result && result->GetVersion() == anIdPtr->GetVersion()){ + AliDebug(2,Form("More than one object valid for run %d, version %d!", + query.GetFirstRun(), anIdPtr->GetVersion())); + return NULL; } - result.SetVersion(aVersion); - result.SetFirstRun(aRunRange.GetFirstRun()); - result.SetLastRun(aRunRange.GetLastRun()); + result = anIdPtr; } - } // end loop on filenames - delete res; - - gGrid->Cd(initDir.Data(),0); - + + } + + + return result; +} + +/* TODO remove +//_____________________________________________________________________________ +Bool_t AliCDBGrid::CheckVersion(const AliCDBId& query, AliCDBId* idToCheck, AliCDBId* result){ +// Check if idToCheck has the "right" requested version and return it in result + + if (!result) { + result = idToCheck; + AliInfo(Form("all'inizio: result = %s", result->ToString().Data())); + return kTRUE; + } + + AliInfo(Form("result = %s", result->ToString().Data())); + + if (!query.HasVersion()){ // look for highest version + if(result->GetVersion() > idToCheck->GetVersion()) return kTRUE; + if(result->GetVersion() == idToCheck->GetVersion()) { + AliDebug(2,Form("More than one object valid for run %d, version %d!", + query.GetFirstRun(), idToCheck->GetVersion())); + return kFALSE; + } + + } else { // look for specified version + if(query.GetVersion() != idToCheck->GetVersion()) return kTRUE; + if(result->GetVersion() == idToCheck->GetVersion()){ + AliDebug(2,Form("More than one object valid for run %d, version %d!", + query.GetFirstRun(), idToCheck->GetVersion())); + return kFALSE; + } + } + result = idToCheck; + AliInfo(Form("alla fine: result = %s", result->ToString().Data())); return kTRUE; } +*/ //_____________________________________________________________________________ AliCDBEntry* AliCDBGrid::GetEntry(const AliCDBId& queryId) { // get AliCDBEntry from the database - 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()) { + AliCDBId* dataId=0; + + AliCDBId selectedId(queryId); + if (!selectedId.HasVersion()) { // if version is not specified, first check the selection criteria list - AliCDBId selectedId(queryId); GetSelection(&selectedId); - result = GetId(selectedId,dataId); + } + + TList validFileIds; + validFileIds.SetOwner(1); + + // look for file matching query requests (path, runRange, version) + if(selectedId.GetFirstRun() == fRun && + fPathFilter.Comprises(selectedId.GetAliCDBPath()) && fVersion < 0){ + // look into list of valid files previously loaded with AliCDBStorage::FillValidFileIds() + AliDebug(2, Form("List of files valid for run %d and for path %s was loaded. Looking there!", + selectedId.GetFirstRun(), selectedId.GetPath().Data())); + dataId = GetId(fValidFileIds, selectedId); + } else { - result = GetId(queryId,dataId); + // List of files valid for reqested run was not loaded. Looking directly into CDB + AliDebug(2, Form("List of files valid for run %d and for path %s was not loaded. Looking directly into CDB!", + selectedId.GetFirstRun(), selectedId.GetPath().Data())); + + TString filter; + MakeQueryFilter(selectedId.GetFirstRun(), selectedId.GetLastRun(), + selectedId.GetAliCDBPath(), selectedId.GetVersion(), 0, filter); + + TGridResult *res = gGrid->Query(fDBFolder, "Run*.root", filter, ""); + AliCDBId validFileId; + for(int i=0; iGetEntries(); i++){ + TString filename = res->GetKey(i, "lfn"); + if(FilenameToId(filename, validFileId)) + validFileIds.AddLast(validFileId.Clone()); + } + delete res; + dataId = GetId(validFileIds, selectedId); } - if (!result || !dataId.IsSpecified()) return NULL; + if (!dataId) return NULL; TString filename; - if (!IdToFilename(dataId.GetAliCDBRunRange(), dataId.GetVersion(),filename)) { + if (!IdToFilename(*dataId, filename)) { AliDebug(2,Form("Bad data ID encountered! Subnormal error!")); return NULL; } - filename.Prepend("/alien" + fDBFolder + queryId.GetPath() + '/'); - filename += "?se="; filename += fSE.Data(); + AliCDBEntry* anEntry = GetEntryFromFile(filename, dataId); + + return anEntry; +} + +//_____________________________________________________________________________ +AliCDBEntry* AliCDBGrid::GetEntryFromFile(TString& filename, const AliCDBId* dataId){ +// Get AliCBEntry object from file "filename" AliDebug(2,Form("Opening file: %s",filename.Data())); + + filename.Prepend("/alien"); TFile *file = TFile::Open(filename); if (!file) { AliDebug(2,Form("Can't open file <%s>!", filename.Data())); @@ -317,172 +380,276 @@ AliCDBEntry* AliCDBGrid::GetEntry(const AliCDBId& queryId) { // get the only AliCDBEntry object from the file // the object in the file is an AliCDBEntry entry named "AliCDBEntry" - TObject* anObject = file->Get("AliCDBEntry"); - - if (!anObject) { - AliDebug(2,Form("Bad storage data: NULL entry object!")); - return NULL; - } + AliCDBEntry* anEntry = dynamic_cast (file->Get("AliCDBEntry")); - if (AliCDBEntry::Class() != anObject->IsA()) { - AliDebug(2,Form("Bad storage data: Invalid entry object!")); + if (!anEntry) { + AliDebug(2,Form("Bad storage data: file does not contain an AliCDBEntry object!")); + file->Close(); return NULL; } - AliCDBId entryId = ((AliCDBEntry* ) anObject)->GetId(); - // The object's Id is not reset during storage // If object's Id runRange or version do not match with filename, // it means that someone renamed file by hand. In this case a warning msg is issued. - - ((AliCDBEntry*) anObject)->SetLastStorage("grid"); - - if(!((entryId.GetAliCDBRunRange()).IsEqual(&dataId.GetAliCDBRunRange())) || - entryId.GetVersion() != dataId.GetVersion()){ - AliWarning(Form("Either RunRange or gridVersion in the object's metadata do noth match with fileName numbers:")); - AliWarning(Form("someone renamed file by hand!")); + + if(anEntry){ + AliCDBId entryId = anEntry->GetId(); + if(!((entryId.GetAliCDBRunRange()).IsEqual(&(dataId->GetAliCDBRunRange()))) || + entryId.GetVersion() != dataId->GetVersion()){ + AliWarning(Form("Either RunRange or gridVersion in the object's metadata")); + AliWarning(Form("do noth match with fileName numbers:")); + AliWarning(Form("someone renamed file by hand!")); + } } + anEntry->SetLastStorage("grid"); + // close file, return retieved entry file->Close(); delete file; file=0; - return (AliCDBEntry*) anObject; + + return anEntry; } //_____________________________________________________________________________ -void AliCDBGrid::GetEntriesForLevel0(const char* level0, - const AliCDBId& queryId, TList* result) { +TList* AliCDBGrid::GetEntries(const AliCDBId& queryId) { // multiple request (AliCDBStorage::GetAll) - TString level0Dir=fDBFolder; - level0Dir += level0; + TList* result = new TList(); + result->SetOwner(); - if (!gGrid->Cd(level0Dir,0)) { - AliDebug(2,Form("Level0 directory <%s> not found", level0Dir.Data())); - return; - } + TList validFileIds; + validFileIds.SetOwner(1); - TGridResult *res = gGrid->Ls(level0Dir); - TString level1; - for(int i=0; i < res->GetEntries(); i++){ - level1=res->GetFileName(i); - if (queryId.GetAliCDBPath().Level1Comprises(level1)) - GetEntriesForLevel1(level0, level1, queryId, result); - } - delete res; -} + Bool_t alreadyLoaded = kFALSE; -//_____________________________________________________________________________ -void AliCDBGrid::GetEntriesForLevel1(const char* level0, const char* level1, - const AliCDBId& queryId, TList* result) { -// multiple request (AliCDBStorage::GetAll) + // look for file matching query requests (path, runRange) + if(queryId.GetFirstRun() == fRun && + fPathFilter.Comprises(queryId.GetAliCDBPath()) && fVersion < 0){ + // look into list of valid files previously loaded with AliCDBStorage::FillValidFileIds() + AliDebug(2,Form("List of files valid for run %d and for path %s was loaded. Looking there!", + queryId.GetFirstRun(), queryId.GetPath().Data())); - TString level1Dir=fDBFolder; - level1Dir += level0; - level1Dir += '/'; - level1Dir += level1; + alreadyLoaded = kTRUE; - if (!gGrid->Cd(level1Dir,0)) { - AliDebug(2,Form("Level1 directory <%s> not found", level1Dir.Data())); - return; + } else { + // List of files valid for reqested run was not loaded. Looking directly into CDB + AliDebug(2,Form("List of files valid for run %d and for path %s was not loaded. Looking directly into CDB!", + queryId.GetFirstRun(), queryId.GetPath().Data())); + + TString filter; + MakeQueryFilter(queryId.GetFirstRun(), queryId.GetLastRun(), + queryId.GetAliCDBPath(), queryId.GetVersion(), 0, filter); + + TGridResult *res = gGrid->Query(fDBFolder, "Run*.root", filter, ""); + AliCDBId validFileId; + for(int i=0; iGetEntries(); i++){ + TString filename = res->GetKey(i, "lfn"); + if(FilenameToId(filename, validFileId)) + validFileIds.AddLast(validFileId.Clone()); + } + delete res; } - TGridResult *res = gGrid->Ls(level1Dir); - TString level2; - for(int i=0; i < res->GetEntries(); i++){ - level2=res->GetFileName(i); - if (queryId.GetAliCDBPath().Level2Comprises(level2)){ - AliCDBPath entryPath(level0, level1, level2); - AliCDBId entryId(entryPath, - queryId.GetAliCDBRunRange(), - queryId.GetVersion(), - queryId.GetSubVersion()); - - AliCDBEntry* anEntry = GetEntry(entryId); - if (anEntry) result->Add(anEntry); + TIter *iter=0; + if(alreadyLoaded){ + iter = new TIter(&fValidFileIds); + } else { + iter = new TIter(&validFileIds); + } + TList selectedIds; + selectedIds.SetOwner(1); + + // loop on list of valid Ids to select the right version to get. + // According to query and to the selection criteria list, version can be the highest or exact + AliCDBPath pathCopy; + AliCDBId* anIdPtr=0; + AliCDBId* dataId=0; + AliCDBPath queryPath = queryId.GetAliCDBPath(); + while((anIdPtr = dynamic_cast (iter->Next()))){ + AliCDBPath thisCDBPath = anIdPtr->GetAliCDBPath(); + if(!(queryPath.Comprises(thisCDBPath)) || pathCopy.GetPath() == thisCDBPath.GetPath()) continue; + pathCopy = thisCDBPath; + + // check the selection criteria list for this query + AliCDBId thisId(*anIdPtr); + thisId.SetVersion(queryId.GetVersion()); + if(!thisId.HasVersion()) GetSelection(&thisId); + + if(alreadyLoaded){ + dataId = GetId(fValidFileIds, thisId); + } else { + dataId = GetId(validFileIds, thisId); } + if(dataId) selectedIds.Add(dataId->Clone()); } - delete res; -} -//_____________________________________________________________________________ -TList* AliCDBGrid::GetEntries(const AliCDBId& queryId) { -// multiple request (AliCDBStorage::GetAll) + delete iter; iter=0; - TList* result = new TList(); - result->SetOwner(); + // selectedIds contains the Ids of the files matching all requests of query! + // All the objects are now ready to be retrieved + iter = new TIter(&selectedIds); + while((anIdPtr = dynamic_cast (iter->Next()))){ + TString filename; + if (!IdToFilename(*anIdPtr, filename)) { + AliDebug(2,Form("Bad data ID encountered! Subnormal error!")); + continue; + } - TString initDir(gGrid->Pwd(0)); + AliCDBEntry* anEntry = GetEntryFromFile(filename, anIdPtr); - TGridResult *res = gGrid->Ls(fDBFolder); - TString level0; + if(anEntry) result->Add(anEntry); - for(int i=0; i < res->GetEntries(); i++){ - level0=res->GetFileName(i); - if (queryId.GetAliCDBPath().Level0Comprises(level0)) - GetEntriesForLevel0(level0, queryId, result); - } - delete res; - - gGrid->Cd(initDir.Data(),0); - return result; + } + delete iter; iter=0; + + return result; } //_____________________________________________________________________________ Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry) { // put an AliCDBEntry object into the database - + AliCDBId& id = entry->GetId(); // set version for the entry to be stored - if (!PrepareId(id)) return kFALSE; + if (!PrepareId(id)) return kFALSE; // build filename from entry's id TString filename; - if (!IdToFilename(id.GetAliCDBRunRange(), id.GetVersion(), filename)) { + if (!IdToFilename(id, filename)) { AliError("Bad ID encountered! Subnormal error!"); return kFALSE; - } + } + + TString folderToTag = Form("%s%s", + fDBFolder.Data(), + id.GetPath().Data()); + + // add CDB and CDB_MD tag to folder + // TODO how to check that folder has already tags? + Bool_t tagCDB = AddTag(folderToTag,"CDB"); + Bool_t tagCDBmd = AddTag(folderToTag,"CDB_MD"); - filename.Prepend("/alien" + fDBFolder + id.GetPath() + '/'); - TString filenameCopy(filename); - filename += "?se="; filename += fSE.Data(); - TDirectory* saveDir = gDirectory; + // specify SE to filename + TString fullFilename = Form("/alien%s?se=%s", filename.Data(), fSE.Data()); + // open file - TFile *file = TFile::Open(filename,"CREATE"); + TFile *file = TFile::Open(fullFilename,"CREATE"); if(!file || !file->IsWritable()){ - AliError(Form("Can't open file <%s>!", filename.Data())); + AliError(Form("Can't open file <%s>!", filename.Data())); if(file && !file->IsWritable()) file->Close(); delete file; file=0; return kFALSE; } - - file->cd(); + + file->cd(); entry->SetVersion(id.GetVersion()); // write object (key name: "AliCDBEntry") Bool_t result = (entry->Write("AliCDBEntry") != 0); - if (!result) AliError(Form("Can't write entry to file <%s>!",filename.Data())); + if (!result) AliError(Form("Can't write entry to file <%s>!", filename.Data())); if (saveDir) saveDir->cd(); else gROOT->cd(); file->Close(); delete file; file=0; if(result) { - AliInfo(Form("CDB object stored into file %s",filenameCopy.Data())); + AliInfo(Form("CDB object stored into file %s", filename.Data())); AliInfo(Form("using S.E. %s", fSE.Data())); + + if(tagCDB) TagFileId(filename, &id); + if(tagCDBmd) TagFileMetaData(filename, entry->GetMetaData()); } - + + return result; +} +//_____________________________________________________________________________ +Bool_t AliCDBGrid::AddTag(TString& folderToTag, const char* tagname){ +// add "tagname" tag (CDB or CDB_MD) to folder where object will be stored + + Bool_t result = kTRUE; + AliDebug(2, Form("adding %s tag to folder %s", tagname, folderToTag.Data())); + TString addTag = Form("addTag %s %s", folderToTag.Data(), tagname); + TGridResult *gridres = gGrid->Command(addTag.Data()); + const char* resCode = gridres->GetKey(0,"__result__"); // '1' if success + if(resCode[0] != '1') { + AliError(Form("Couldn't add %s tags to folder %s !", + tagname, folderToTag.Data())); + result = kFALSE; + } + delete gridres; return result; } +//_____________________________________________________________________________ +void AliCDBGrid::TagFileId(TString& filename, const AliCDBId* id){ +// tag stored object in CDB table using object Id's parameters + + TString addTagValue_1 = Form("addTagValue %s CDB ", filename.Data()); + TString addTagValue_2 = Form("first_run=%d last_run=%d version=%d ", + id->GetFirstRun(), + id->GetLastRun(), + id->GetVersion()); + TString addTagValue_3 = Form("path_level_0=\"%s\" path_level_1=\"%s\" path_level_2=\"%s\"", + id->GetLevel0().Data(), + id->GetLevel1().Data(), + id->GetLevel2().Data()); + TString addTagValue = Form("%s%s%s", + addTagValue_1.Data(), + addTagValue_2.Data(), + addTagValue_3.Data()); + + AliDebug(2, Form("Tagging file. Tag command: %s", addTagValue.Data())); + TGridResult* res = gGrid->Command(addTagValue.Data()); + const char* resCode = res->GetKey(0,"__result__"); // '1' if success + if(resCode[0] != '1') { + AliWarning(Form("Couldn't add CDB tag value to file %s !", + filename.Data())); + } else { + AliInfo("Object successfully tagged."); + } + delete res; + + +} + +//_____________________________________________________________________________ +void AliCDBGrid::TagFileMetaData(TString& filename, const AliCDBMetaData* md){ +// tag stored object in CDB table using object Id's parameters + + TString addTagValue_1 = Form("addTagValue %s CDB_MD ", filename.Data()); + TString addTagValue_2 = Form("object_classname=\"%s\" responsible=\"%s\" beam_period=%d ", + md->GetObjectClassName(), + md->GetResponsible(), + md->GetBeamPeriod()); + TString addTagValue_3 = Form("aliroot_version=\"%s\" comment=\"%s\"", + md->GetAliRootVersion(), + md->GetComment()); + TString addTagValue = Form("%s%s%s", + addTagValue_1.Data(), + addTagValue_2.Data(), + addTagValue_3.Data()); + + AliDebug(2, Form("Tagging file. Tag command: %s", addTagValue.Data())); + TGridResult* res = gGrid->Command(addTagValue.Data()); + const char* resCode = res->GetKey(0,"__result__"); // '1' if success + if(resCode[0] != '1') { + AliWarning(Form("Couldn't add CDB_MD tag value to file %s !", + filename.Data())); + } else { + AliInfo("Object successfully tagged."); + } + +} + //_____________________________________________________________________________ TList* AliCDBGrid::GetIdListFromFile(const char* fileName){ TString turl(fileName); turl.Prepend("/alien" + fDBFolder); - turl += "?se="; turl += fSE.Data(); + turl += "?se="; turl += fSE.Data(); TFile *file = TFile::Open(turl); if (!file) { AliError(Form("Can't open selection file <%s>!", turl.Data())); @@ -493,7 +660,7 @@ TList* AliCDBGrid::GetIdListFromFile(const char* fileName){ list->SetOwner(); int i=0; TString keycycle; - + AliCDBId *id; while(1){ i++; @@ -524,6 +691,72 @@ Bool_t AliCDBGrid::Contains(const char* path) const{ return result; } +//_____________________________________________________________________________ +void AliCDBGrid::QueryValidFiles() +{ +// Query the CDB for files valid for AliCDBStorage::fRun +// fills list fValidFileIds with AliCDBId objects created from file name + + TString filter; + MakeQueryFilter(fRun, fRun, fPathFilter, fVersion, fMetaDataFilter, filter); + + TGridResult *res = gGrid->Query(fDBFolder, "Run*.root", filter, ""); + AliCDBId validFileId; + for(int i=0; iGetEntries(); i++){ + TString filename = res->GetKey(i, "lfn"); + AliDebug(2,Form("Found valid file: %s", filename.Data())); + Bool_t result = FilenameToId(filename, validFileId); + if(result) { + fValidFileIds.AddLast(validFileId.Clone()); + } + } + delete res; + +} + +//_____________________________________________________________________________ +void AliCDBGrid::MakeQueryFilter(Long64_t firstRun, Long64_t lastRun, + const AliCDBPath& pathFilter, Int_t version, + const AliCDBMetaData* md, TString& result) const +{ +// create filter for file query + + result = Form("CDB:first_run<=%ld and CDB:last_run>=%ld", (long) firstRun, (long) lastRun); + + if(version >= 0) { + result += Form(" and CDB:version=%d", version); + } + if(pathFilter.GetLevel0() != "*") { + result += Form(" and CDB:path_level_0=\"%s\"", pathFilter.GetLevel0().Data()); + } + if(pathFilter.GetLevel1() != "*") { + result += Form(" and CDB:path_level_1=\"%s\"", pathFilter.GetLevel1().Data()); + } + if(pathFilter.GetLevel2() != "*") { + result += Form(" and CDB:path_level_2=\"%s\"", pathFilter.GetLevel2().Data()); + } + + if(md){ + if(md->GetObjectClassName()[0] != '\0') { + result += Form(" and CDB_MD:object_classname=\"%s\"", md->GetObjectClassName()); + } + if(md->GetResponsible()[0] != '\0') { + result += Form(" and CDB_MD:responsible=\"%s\"", md->GetResponsible()); + } + if(md->GetBeamPeriod() != 0) { + result += Form(" and CDB_MD:beam_period=%d", md->GetBeamPeriod()); + } + if(md->GetAliRootVersion()[0] != '\0') { + result += Form(" and CDB_MD:aliroot_version=\"%s\"", md->GetAliRootVersion()); + } + if(md->GetComment()[0] != '\0') { + result += Form(" and CDB_MD:comment=\"%s\"", md->GetComment()); + } + } + AliDebug(2, Form("filter: %s",result.Data())); + +} + ///////////////////////////////////////////////////////////////////////////////////////////////// // // // AliCDBGrid factory // @@ -562,7 +795,7 @@ AliCDBParam* AliCDBGridFactory::CreateParameter(const char* gridString) { TObjArray *arr = buffer.Tokenize('?'); TIter iter(arr); - TObjString *str; + TObjString *str = 0; while((str = (TObjString*) iter.Next())){ TString entry(str->String()); @@ -603,24 +836,25 @@ AliCDBParam* AliCDBGridFactory::CreateParameter(const char* gridString) { AliDebug(2, Form("dbFolder: %s",dbFolder.Data())); AliDebug(2, Form("s.e.: %s",se.Data())); - return new AliCDBGridParam(gridUrl, user, dbFolder, se); + return new AliCDBGridParam(gridUrl.Data(), user.Data(), dbFolder.Data(), se.Data()); } //_____________________________________________________________________________ AliCDBStorage* AliCDBGridFactory::Create(const AliCDBParam* param) { // create AliCDBGrid storage instance from parameters + AliCDBGrid *grid = 0; if (AliCDBGridParam::Class() == param->IsA()) { - + const AliCDBGridParam* gridParam = (const AliCDBGridParam*) param; - AliCDBGrid *grid = new AliCDBGrid(gridParam->GridUrl(), - gridParam->GetUser(), gridParam->GetDBFolder(), - gridParam->GetSE()); + grid = new AliCDBGrid(gridParam->GridUrl().Data(), + gridParam->GetUser().Data(), + gridParam->GetDBFolder().Data(), + gridParam->GetSE().Data()); - if(gGrid) return grid; } - return NULL; + return grid; } ///////////////////////////////////////////////////////////////////////////////////////////////// @@ -632,16 +866,23 @@ AliCDBStorage* AliCDBGridFactory::Create(const AliCDBParam* param) { ClassImp(AliCDBGridParam) //_____________________________________________________________________________ -AliCDBGridParam::AliCDBGridParam() { +AliCDBGridParam::AliCDBGridParam(): + AliCDBParam(), + fGridUrl(), + fUser(), + fDBFolder(), + fSE() + { // default constructor } //_____________________________________________________________________________ AliCDBGridParam::AliCDBGridParam(const char* gridUrl, - const char* user, + const char* user, const char* dbFolder, const char* se): + AliCDBParam(), fGridUrl(gridUrl), fUser(user), fDBFolder(dbFolder), @@ -651,13 +892,11 @@ AliCDBGridParam::AliCDBGridParam(const char* gridUrl, SetType("alien"); - TString uri; - uri+=fGridUrl; uri+="?"; - uri+="User="; uri+=fUser; uri+="?"; - uri+="DBFolder="; uri+=fDBFolder; uri+="?"; - uri+="SE="; uri+=fSE; - - SetURI(uri); + TString uri = Form("%s?User=%s?DBFolder=%s?SE=%s", + fGridUrl.Data(), fUser.Data(), + fDBFolder.Data(), fSE.Data()); + + SetURI(uri.Data()); } //_____________________________________________________________________________ @@ -670,7 +909,8 @@ AliCDBGridParam::~AliCDBGridParam() { AliCDBParam* AliCDBGridParam::CloneParam() const { // clone parameter - return new AliCDBGridParam(fGridUrl, fUser, fDBFolder, fSE); + return new AliCDBGridParam(fGridUrl.Data(), fUser.Data(), + fDBFolder.Data(), fSE.Data()); } //_____________________________________________________________________________ diff --git a/STEER/AliCDBGrid.h b/STEER/AliCDBGrid.h index 044e328f792..e41124bcd88 100644 --- a/STEER/AliCDBGrid.h +++ b/STEER/AliCDBGrid.h @@ -13,6 +13,7 @@ #include "AliCDBStorage.h" #include "AliCDBManager.h" +#include "AliCDBMetaData.h" class AliCDBGrid: public AliCDBStorage { friend class AliCDBGridFactory; @@ -39,21 +40,28 @@ private: AliCDBGrid(const AliCDBGrid& db); AliCDBGrid& operator = (const AliCDBGrid& db); - Bool_t FilenameToId(const char* filename, AliCDBRunRange& runRange, Int_t& version); - Bool_t IdToFilename(const AliCDBRunRange& runRange, Int_t version, TString& filename); + Bool_t FilenameToId(TString& filename, AliCDBId& id); + Bool_t IdToFilename(const AliCDBId& id, TString& filename); Bool_t PrepareId(AliCDBId& id); - Bool_t GetId(const AliCDBId& query, AliCDBId& result); + AliCDBId* GetId(const TList& validFileIds, const AliCDBId& query); + AliCDBEntry* GetEntryFromFile(TString& filename, const AliCDBId* dataId); + Bool_t AddTag(TString& foldername, const char* tagname); + void TagFileId(TString& filename, const AliCDBId* id); + void TagFileMetaData(TString& filename, const AliCDBMetaData* md); - void GetEntriesForLevel0(const char* level0, const AliCDBId& query, TList* result); - void GetEntriesForLevel1(const char* level0, const char* level1, - const AliCDBId& query, TList* result); +// Bool_t CheckVersion(const AliCDBId& query, AliCDBId* idToCheck, AliCDBId* result); + + void MakeQueryFilter(Long64_t firstRun, Long64_t lastRun, const AliCDBPath& pathFilter, Int_t version, + const AliCDBMetaData* md, TString& result) const; + + virtual void QueryValidFiles(); TString fGridUrl; // Grid Url ("alien://aliendb4.cern.ch:9000") TString fUser; // User TString fDBFolder; // path of the DB folder - TString fSE; // Storage Element + TString fSE; // Storage Element ClassDef(AliCDBGrid, 0) // access class to a DataBase in an AliEn storage }; @@ -87,7 +95,7 @@ class AliCDBGridParam: public AliCDBParam { public: AliCDBGridParam(); - AliCDBGridParam(const char* gridUrl, const char* user, + AliCDBGridParam(const char* gridUrl, const char* user, const char* dbFolder, const char* se); virtual ~AliCDBGridParam(); diff --git a/STEER/AliCDBId.cxx b/STEER/AliCDBId.cxx index f1523537f9c..0f00a334f03 100644 --- a/STEER/AliCDBId.cxx +++ b/STEER/AliCDBId.cxx @@ -107,8 +107,9 @@ TString AliCDBId::ToString() const { result += GetLastRun(); result += "]; version v"; result += GetVersion(); - result += "_s"; - result += GetSubVersion(); - + if(GetSubVersion()>0){ + result += "_s"; + result += GetSubVersion(); + } return result; } diff --git a/STEER/AliCDBLocal.cxx b/STEER/AliCDBLocal.cxx index b0575127798..a11dd2b4572 100644 --- a/STEER/AliCDBLocal.cxx +++ b/STEER/AliCDBLocal.cxx @@ -49,6 +49,8 @@ fBaseDirectory(baseDir) AliDebug(2,Form("Folder <%s> found",fBaseDirectory.Data())); gSystem->FreeDirectory(dir); } + fType="local"; + fBaseFolder = fBaseDirectory; } //_____________________________________________________________________________ @@ -409,24 +411,20 @@ AliCDBEntry* AliCDBLocal::GetEntry(const AliCDBId& queryId) { // get the only AliCDBEntry object from the file // the object in the file is an AliCDBEntry entry named "AliCDBEntry" - TObject* anObject = file.Get("AliCDBEntry"); - if (!anObject) { - AliDebug(2,Form("Bad storage data: NULL entry object!")); + AliCDBEntry* anEntry = dynamic_cast (file.Get("AliCDBEntry")); + if (!anEntry) { + AliDebug(2,Form("Bad storage data: No AliCDBEntry in file!")); + file.Close(); return NULL; } - if (AliCDBEntry::Class() != anObject->IsA()) { - AliDebug(2,Form("Bad storage data: Invalid entry object!")); - return NULL; - } - - AliCDBId entryId = ((AliCDBEntry* ) anObject)->GetId(); + AliCDBId entryId = anEntry->GetId(); // The object's Id are not reset during storage // If object's Id runRange or version do not match with filename, // it means that someone renamed file by hand. In this case a warning msg is issued. - - ((AliCDBEntry*) anObject)-> SetLastStorage("local"); + + anEntry-> SetLastStorage("local"); if(!((entryId.GetAliCDBRunRange()).IsEqual(& dataId.GetAliCDBRunRange())) || (entryId.GetVersion() != dataId.GetVersion()) || (entryId.GetSubVersion() != dataId.GetSubVersion())){ @@ -436,7 +434,7 @@ AliCDBEntry* AliCDBLocal::GetEntry(const AliCDBId& queryId) { // close file, return retieved entry file.Close(); - return (AliCDBEntry*) anObject; + return anEntry; } //_____________________________________________________________________________ @@ -500,7 +498,7 @@ void AliCDBLocal::GetEntriesForLevel1(const char* level0, const char* level1, } if (queryId.GetAliCDBPath().Level2Comprises(level2)) { - + AliCDBPath entryPath(level0, level1, level2); AliCDBId entryId(entryPath, queryId.GetAliCDBRunRange(), queryId.GetVersion(), queryId.GetSubVersion()); @@ -558,7 +556,7 @@ Bool_t AliCDBLocal::PutEntry(AliCDBEntry* entry) { // build filename from entry's id - TString filename; + TString filename=""; if (!IdToFilename(id.GetAliCDBRunRange(), id.GetVersion(), id.GetSubVersion(), filename)) { @@ -640,6 +638,13 @@ Bool_t AliCDBLocal::Contains(const char* path) const{ return result; } +//_____________________________________________________________________________ +void AliCDBLocal::QueryValidFiles() +{ +// blabla + +} + ///////////////////////////////////////////////////////////////////////////////////////////////// // // // AliCDBLocal factory // @@ -700,15 +705,19 @@ AliCDBStorage* AliCDBLocalFactory::Create(const AliCDBParam* param) { ClassImp(AliCDBLocalParam) //_____________________________________________________________________________ -AliCDBLocalParam::AliCDBLocalParam() { +AliCDBLocalParam::AliCDBLocalParam(): + AliCDBParam(), + fDBPath() + { // default constructor } //_____________________________________________________________________________ AliCDBLocalParam::AliCDBLocalParam(const char* dbPath): -fDBPath(dbPath) -{ + AliCDBParam(), + fDBPath(dbPath) +{ // constructor SetType("local"); diff --git a/STEER/AliCDBLocal.h b/STEER/AliCDBLocal.h index 6969e9012e9..ce904bb77d1 100644 --- a/STEER/AliCDBLocal.h +++ b/STEER/AliCDBLocal.h @@ -43,6 +43,8 @@ private: Bool_t PrepareId(AliCDBId& id); Bool_t GetId(const AliCDBId& query, AliCDBId& result); + virtual void QueryValidFiles(); + void GetEntriesForLevel0(const char* level0, const AliCDBId& query, TList* result); void GetEntriesForLevel1(const char* level0, const char* Level1, const AliCDBId& query, TList* result); diff --git a/STEER/AliCDBManager.cxx b/STEER/AliCDBManager.cxx index b85be745554..8abdccfbbce 100644 --- a/STEER/AliCDBManager.cxx +++ b/STEER/AliCDBManager.cxx @@ -80,7 +80,9 @@ AliCDBManager::AliCDBManager(): { // default constuctor fFactories.SetOwner(1); - fEntryCache.SetOwner(1); + fActiveStorages.SetOwner(1); + fSpecificStorages.SetOwner(1); + fEntryCache.SetOwner(1); } //_____________________________________________________________________________ @@ -88,17 +90,11 @@ AliCDBManager::~AliCDBManager() { // destructor ClearCache(); DestroyActiveStorages(); + fFactories.Delete(); fDrainStorage = 0x0; fDefaultStorage = 0x0; } -//_____________________________________________________________________________ -AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) { -// get a storage object from the list of active storages - - return (AliCDBStorage*) fActiveStorages.GetValue(param); -} - //_____________________________________________________________________________ void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){ // put a storage object into the list of active storages @@ -122,7 +118,7 @@ Bool_t AliCDBManager::HasStorage(const char* dbString) const { TIter iter(&fFactories); - AliCDBStorageFactory* factory; + AliCDBStorageFactory* factory=0; while ((factory = (AliCDBStorageFactory*) iter.Next())) { if (factory->Validate(dbString)) { @@ -139,13 +135,10 @@ AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const { TIter iter(&fFactories); - AliCDBStorageFactory* factory; + AliCDBStorageFactory* factory=0; while ((factory = (AliCDBStorageFactory*) iter.Next())) { - AliCDBParam* param = factory->CreateParameter(dbString); - if (param) { - return param; - } + if(param) return param; } return NULL; @@ -163,7 +156,6 @@ AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) { AliCDBStorage* aStorage = GetStorage(param); delete param; - return aStorage; } @@ -180,7 +172,7 @@ AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) { TIter iter(&fFactories); - AliCDBStorageFactory* factory; + AliCDBStorageFactory* factory=0; // loop on the list of registered factories while ((factory = (AliCDBStorageFactory*) iter.Next())) { @@ -197,14 +189,22 @@ AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) { return NULL; } +//_____________________________________________________________________________ +AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) { +// get a storage object from the list of active storages + + return dynamic_cast (fActiveStorages.GetValue(param)); +} + //_____________________________________________________________________________ TList* AliCDBManager::GetActiveStorages() { // return list of active storages +// user has responsibility to delete returned object TList* result = new TList(); TIter iter(fActiveStorages.GetTable()); - TPair* aPair; + TPair* aPair=0; while ((aPair = (TPair*) iter.Next())) { result->Add(aPair->Value()); } @@ -286,11 +286,17 @@ void AliCDBManager::SetSpecificStorage(const char* calibType, AliCDBParam* param return; } - TObjString *objCalibType = new TObjString(calibType); + AliCDBPath aPath(calibType); + if(!aPath.IsValid()){ + AliError(Form("Not a valid path: %s", calibType)); + return; + } + + TObjString *objCalibType = new TObjString(aPath.GetPath()); if(fSpecificStorages.Contains(objCalibType)){ - AliWarning(Form("%s storage already activated! It will be replaced by the new one", + AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one", calibType)); - fSpecificStorages.Remove(objCalibType); + fSpecificStorages.Remove(objCalibType); } GetStorage(param); fSpecificStorages.Add(objCalibType, param->CloneParam()); @@ -314,11 +320,18 @@ AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) { 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; + } + TIter iter(&fSpecificStorages); - TObjString *aCalibType; + TObjString *aCalibType=0; AliCDBParam* aPar=0; while((aCalibType = (TObjString*) iter.Next())){ - if(path.Contains(aCalibType->String(), TString::kIgnoreCase)) { + AliCDBPath calibTypePath(aCalibType->GetName()); + if(calibTypePath.Comprises(aPath)) { aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType); break; } @@ -382,18 +395,18 @@ AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) { AliCDBEntry *entry=0; // first look into map of cached objects - if(query.GetFirstRun() == fRun) + if(fCache && query.GetFirstRun() == fRun) entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath()); if(entry) { - AliDebug(2,Form("Object %s retrieved from cache !!",query.GetPath().Data())); + AliInfo(Form("Object %s retrieved from cache !!",query.GetPath().Data())); return entry; } // Entry is not in cache -> retrieve it from CDB and cache it!! AliCDBStorage *aStorage=0; AliCDBParam *aPar=SelectSpecificStorage(query.GetPath()); - + if(aPar) { aStorage=GetStorage(aPar); TString str = aPar->GetURI(); @@ -417,7 +430,7 @@ AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) { } //_____________________________________________________________________________ -TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber, +TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber, Int_t version, Int_t subVersion) { // get multiple AliCDBEntry objects from the database @@ -576,7 +589,7 @@ void AliCDBManager::Print(Option_t* /*option*/) const if(fSpecificStorages.GetEntries()>0) { AliInfo("*** Specific Storages: ***"); TIter iter(fSpecificStorages.GetTable()); - TPair *aPair; + TPair *aPair=0; while((aPair = (TPair*) iter.Next())){ output = Form("Key: %s - Storage: %s", ((TObjString*) aPair->Key())->GetName(), @@ -605,6 +618,7 @@ void AliCDBManager::SetRun(Long64_t run) fRun = run; ClearCache(); + QueryCDB(); } //_____________________________________________________________________________ @@ -641,13 +655,42 @@ void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) { } +//_____________________________________________________________________________ +void AliCDBManager::QueryCDB() { +// query default and specific storages for files valid for fRun. Every storage loads the Ids into its list. + + if (fRun < 0){ + AliError("Run number not yet set! Use AliCDBManager::SetRun."); + return; + } + + AliInfo(Form("Querying default and specific storages for files valid for run %ld", (long) fRun)); + fDefaultStorage->QueryCDB(fRun); + + TIter iter(&fSpecificStorages); + TObjString *aCalibType=0; + AliCDBParam* aPar=0; + while((aCalibType = dynamic_cast (iter.Next()))){ + aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType); + if(aPar) { + AliDebug(2,Form("Qerying specific storage %s",aCalibType->GetName())); + GetStorage(aPar)->QueryCDB(fRun,aCalibType->GetName()); + + } + } + +} + + /////////////////////////////////////////////////////////// // AliCDBManager Parameter class // // interface to specific AliCDBParameter class // // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) // /////////////////////////////////////////////////////////// -AliCDBParam::AliCDBParam() { +AliCDBParam::AliCDBParam(): +fType(), fURI() +{ // constructor } diff --git a/STEER/AliCDBManager.h b/STEER/AliCDBManager.h index 9b82188babd..8767e69be66 100644 --- a/STEER/AliCDBManager.h +++ b/STEER/AliCDBManager.h @@ -62,13 +62,13 @@ class AliCDBManager: public TObject { void UnsetDrain(){fDrainStorage = 0x0;} AliCDBEntry* Get(const AliCDBId& query); - AliCDBEntry* Get(const AliCDBPath& path, Int_t runNumber=-1, + AliCDBEntry* Get(const AliCDBPath& path, Int_t runNumber=-1, Int_t version = -1, Int_t subVersion = -1); AliCDBEntry* Get(const AliCDBPath& path, const AliCDBRunRange& runRange, Int_t version = -1, Int_t subVersion = -1); TList* GetAll(const AliCDBId& query); - TList* GetAll(const AliCDBPath& path, Int_t runNumber=-1, + TList* GetAll(const AliCDBPath& path, Int_t runNumber=-1, Int_t version = -1, Int_t subVersion = -1); TList* GetAll(const AliCDBPath& path, const AliCDBRunRange& runRange, Int_t version = -1, Int_t subVersion = -1); @@ -87,6 +87,8 @@ class AliCDBManager: public TObject { void DestroyActiveStorages(); void DestroyActiveStorage(AliCDBStorage* storage); + void QueryCDB(); + void Print(Option_t* option="") const; static void Destroy(); diff --git a/STEER/AliCDBMetaData.cxx b/STEER/AliCDBMetaData.cxx index cdb325d931f..c33f1b7b505 100644 --- a/STEER/AliCDBMetaData.cxx +++ b/STEER/AliCDBMetaData.cxx @@ -81,18 +81,25 @@ Bool_t AliCDBMetaData::RemoveProperty(const char* property) { void AliCDBMetaData::PrintMetaData() { // print the object's metaData - AliInfo("**** Object's MetaData set ****"); - AliInfo(Form(" Object's class name: %s", fObjectClassName.Data())); - AliInfo(Form(" Responsible: %s", fResponsible.Data())); - AliInfo(Form(" Beam period: %d", fBeamPeriod)); - AliInfo(Form(" AliRoot version: %s", fAliRootVersion.Data())); - AliInfo(Form(" Comment: %s", fComment.Data())); - AliInfo(" Properties key names:"); - - TIter iter(fProperties.GetTable()); - TPair* aPair; - while ((aPair = (TPair*) iter.Next())) { - AliInfo(Form(" %s",((TObjString* )aPair->Key())->String().Data())); + TString message; + if(fObjectClassName != "") + message += Form("\tObject's class name: %s\n", fObjectClassName.Data()); + if(fResponsible != "") + message += Form("\tResponsible: %s\n", fResponsible.Data()); + if(fBeamPeriod != 0) + message += Form("\tBeam period: %d\n", fBeamPeriod); + if(fAliRootVersion != "") + message += Form("\tAliRoot version: %s\n", fAliRootVersion.Data()); + if(fComment != "") + message += Form("\tComment: %s\n", fComment.Data()); + if(fProperties.GetEntries() > 0){ + message += "\tProperties key names:"; + + TIter iter(fProperties.GetTable()); + TPair* aPair; + while ((aPair = (TPair*) iter.Next())) { + message += Form("\t\t%s\n", ((TObjString* ) aPair->Key())->String().Data()); + } } - + AliInfo(Form("**** Object's MetaData set **** \n%s", message.Data())); } diff --git a/STEER/AliCDBStorage.cxx b/STEER/AliCDBStorage.cxx index 2af734d621b..a82c176d25c 100644 --- a/STEER/AliCDBStorage.cxx +++ b/STEER/AliCDBStorage.cxx @@ -24,9 +24,20 @@ ClassImp(AliCDBStorage) //_____________________________________________________________________________ -AliCDBStorage::AliCDBStorage() { +AliCDBStorage::AliCDBStorage(): +fValidFileIds(), +fRun(-1), +fPathFilter(), +fVersion(-1), +fMetaDataFilter(0), +fSelections(), +fURI(), +fType(), +fBaseFolder() +{ // constructor + fValidFileIds.SetOwner(1); fSelections.SetOwner(1); } @@ -34,6 +45,10 @@ AliCDBStorage::AliCDBStorage() { AliCDBStorage::~AliCDBStorage() { // destructor + RemoveAllSelections(); + fValidFileIds.Clear(); + delete fMetaDataFilter; + } //_____________________________________________________________________________ @@ -108,7 +123,7 @@ void AliCDBStorage::AddSelection(const AliCDBId& selection) { } //_____________________________________________________________________________ -void AliCDBStorage::AddSelection(const AliCDBPath& path, +void AliCDBStorage::AddSelection(const AliCDBPath& path, const AliCDBRunRange& runRange, Int_t version, Int_t subVersion){ // add a selection criterion @@ -157,14 +172,14 @@ void AliCDBStorage::RemoveSelection(const AliCDBPath& path, void AliCDBStorage::RemoveSelection(int position){ // remove a selection criterion from its position in the list - fSelections.RemoveAt(position); + delete fSelections.RemoveAt(position); } //_____________________________________________________________________________ void AliCDBStorage::RemoveAllSelections(){ // remove all selection criteria - fSelections.RemoveAll(); + fSelections.Clear(); } //_____________________________________________________________________________ @@ -173,7 +188,7 @@ void AliCDBStorage::PrintSelectionList(){ TIter iter(&fSelections); AliCDBId* aSelection; - + // loop on the list of selection criteria int index=0; while ((aSelection = (AliCDBId*) iter.Next())) { @@ -199,7 +214,7 @@ AliCDBEntry* AliCDBStorage::Get(const AliCDBId& query) { query.ToString().Data())); return NULL; } - + // This is needed otherwise TH1 objects (histos, TTree's) are lost when file is closed! Bool_t oldStatus = TH1::AddDirectoryStatus(); TH1::AddDirectory(kFALSE); @@ -210,9 +225,11 @@ AliCDBEntry* AliCDBStorage::Get(const AliCDBId& query) { TH1::AddDirectory(kTRUE); if (entry) { - AliInfo(Form("CDB object retrieved: %s", entry->GetId().ToString().Data())); + // this is to make the SHUTTLE output lighter + if(!(query.GetPath().Contains("SHUTTLE/STATUS"))) + AliInfo(Form("CDB object retrieved: %s", entry->GetId().ToString().Data())); } else { - // TODO this is to make the SHUTTLE output lighter + // this is to make the SHUTTLE output lighter if(!(query.GetPath().Contains("SHUTTLE/STATUS"))) AliInfo(Form("No valid CDB object found! request was: name = <%s>, run = %d", (query.GetPath()).Data(), query.GetFirstRun())); @@ -269,14 +286,14 @@ TList* AliCDBStorage::GetAll(const AliCDBId& query) { Int_t nEntries = result->GetEntries(); if (nEntries) { - AliInfo(Form("%d AliCDBEntry objects retrieved.",nEntries)); + AliInfo(Form("%d objects retrieved.",nEntries)); for(int i=0; iAt(i); AliInfo(Form("%s",entry->GetId().ToString().Data())); } } else { - AliInfo(Form("No valid CDB object found! request was: name = <%s>, run = %d, version = %d", + AliInfo(Form("No valid CDB object found! request was: name = <%s>, run = %d, version = %d", (query.GetPath()).Data(), query.GetFirstRun(), query.GetVersion())); } @@ -329,13 +346,13 @@ Bool_t AliCDBStorage::Put(AliCDBEntry* entry) { } if (!entry->GetId().IsValid()) { - AliError(Form("Invalid entry ID: %s", + AliError(Form("Invalid entry ID: %s", entry->GetId().ToString().Data())); return kFALSE; } if (!entry->GetId().IsSpecified()) { - AliError(Form("Unspecified entry ID: %s", + AliError(Form("Unspecified entry ID: %s", entry->GetId().ToString().Data())); return kFALSE; } @@ -346,3 +363,58 @@ Bool_t AliCDBStorage::Put(AliCDBEntry* entry) { return PutEntry(entry); } +//_____________________________________________________________________________ +void AliCDBStorage::QueryCDB(Long64_t run, const char* pathFilter, + Int_t version, AliCDBMetaData* md){ +// query CDB for files valid for given run, and fill list fValidFileIds +// Actual query is done in virtual function QueryValidFiles() + + fRun = run; + + fPathFilter = pathFilter; + if(!fPathFilter.IsValid()) { + AliError(Form("Filter not valid: %s", pathFilter)); + fPathFilter = "*"; + return; + } + + fVersion = version; + + // Clear fValidFileIds list (it cannot be filled twice! + AliDebug(2, "Clearing list of CDB Id's previously loaded"); + fValidFileIds.Clear(); + + if(fMetaDataFilter) {delete fMetaDataFilter; fMetaDataFilter=0;} + if(md) fMetaDataFilter = dynamic_cast (md->Clone()); + + QueryValidFiles(); + + AliInfo(Form("%d files valid for run %ld, path %s and version %d found in CDB storage: \n %s://%s", + fValidFileIds.GetEntries(), (long) fRun, pathFilter, version, + fType.Data(), fBaseFolder.Data())); + +} + +//_____________________________________________________________________________ +void AliCDBStorage::PrintQueryCDB(){ +// print parameters used to load list of CDB Id's (fRun, fPathFilter, fVersion) + + AliInfo(Form("QueryCDB Parameters: \n\tRun = %ld \n\tPath filter = %s \n\tVersion = %d", + (long) fRun, fPathFilter.GetPath().Data(), fVersion)); + + if(fMetaDataFilter) { + AliInfo("CDBMetaData Parameters: "); + } + fMetaDataFilter->PrintMetaData(); + + AliInfo("Id's of valid objects found:"); + TIter iter(&fValidFileIds); + AliCDBId* anId=0; + + // loop on the list of selection criteria + while ((anId = dynamic_cast(iter.Next()))) { + AliInfo(Form("%s", anId->ToString().Data())); + } + +} + diff --git a/STEER/AliCDBStorage.h b/STEER/AliCDBStorage.h index b774a2a5aa1..bf6333827de 100644 --- a/STEER/AliCDBStorage.h +++ b/STEER/AliCDBStorage.h @@ -18,6 +18,7 @@ #include class AliCDBEntry; +class AliCDBPath; class AliCDBStorage: public TObject { @@ -26,6 +27,9 @@ public: void SetURI(const TString& uri) {fURI = uri;} const TString& GetURI() const {return fURI;} + const TString& GetType() const {return fType;} + const TString& GetBaseFolder() const {return fBaseFolder;} + void ReadSelectionFromFile(const char *fileName); @@ -74,22 +78,33 @@ public: virtual Bool_t IsReadOnly() const = 0; virtual Bool_t HasSubVersion() const = 0; - virtual Bool_t Contains(const char* path) const = 0; + void QueryCDB(Long64_t run, const char* pathFilter="*", + Int_t version=-1, AliCDBMetaData *mdFilter=0); + void PrintQueryCDB(); + TList* GetQueryCDBList() {return &fValidFileIds;} + protected: - - virtual ~AliCDBStorage(); + + virtual ~AliCDBStorage(); 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; + virtual Bool_t PutEntry(AliCDBEntry* entry) = 0; virtual TList *GetIdListFromFile(const char* fileName)=0; + virtual void QueryValidFiles() = 0; -private: + TList fValidFileIds; // list of Id's of the files valid for a given run (cached as fRun) + Long64_t fRun; // run number, used to manage list of valid files + AliCDBPath fPathFilter; // path filter, used to manage list of valid files + Int_t fVersion; // version, used to manage list of valid files + AliCDBMetaData* fMetaDataFilter; // metadata, used to manage list of valid files TList fSelections; // list of selection criteria - TString fURI; //! storage URI; + TString fURI; // storage URI; + TString fType; //! Local, Grid: base folder name - Dump: file name + TString fBaseFolder; //! Local, Grid: base folder name - Dump: file name ClassDef(AliCDBStorage, 0); }; -- 2.43.0