// write object (key name: Run#firstRun_#lastRun_v#version_s#subVersion)
Bool_t result = gDirectory->WriteTObject(entry, keyname);
if (!result) {
- AliError(Form("Can't write entry to file: %s",
+ AliError(Form("Can't write entry to file: %s",
fFile->GetName()));
}
//_____________________________________________________________________________
void AliCDBDump::QueryValidFiles()
{
-// blabla
+// Query the CDB for files valid for AliCDBStorage::fRun
+// fills list fValidFileIds with AliCDBId objects created from file name
+
+ AliError("Not yet (and maybe never) implemented");
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBDump::IdToFilename(const AliCDBId& /*id*/, TString& /*filename*/) const {
+// build file name from AliCDBId (path, run range, version) and fDBFolder
+
+ AliError("Not implemented");
+ return kFALSE;
+}
+
+//_____________________________________________________________________________
+Int_t AliCDBDump::GetLatestVersion(const char* path, Int_t run){
+// get last version found in the database valid for run and path
+
+ AliCDBPath aCDBPath(path);
+ if(!aCDBPath.IsValid() || aCDBPath.IsWildcard()) {
+ AliError(Form("Invalid path in request: %s", path));
+ return -1;
+ }
+
+ AliCDBId query(path, run, run, -1, -1);
+ AliCDBId dataId;
+
+ GetId(query,dataId);
+
+ return dataId.GetVersion();
+}
+
+//_____________________________________________________________________________
+Int_t AliCDBDump::GetLatestSubVersion(const char* path, Int_t run, Int_t version){
+// get last version found in the database valid for run and path
+
+ AliCDBPath aCDBPath(path);
+ if(!aCDBPath.IsValid() || aCDBPath.IsWildcard()) {
+ AliError(Form("Invalid path in request: %s", path));
+ return -1;
+ }
+
+ AliCDBId query(path, run, run, version, -1);
+ AliCDBId dataId;
+
+ GetId(query,dataId);
+
+ return dataId.GetSubVersion();
}
virtual Bool_t IsReadOnly() const {return fReadOnly;};
virtual Bool_t HasSubVersion() const {return kFALSE;};
virtual Bool_t Contains(const char* path) const;
+ virtual Int_t GetLatestVersion(const char* path, Int_t run);
+ virtual Int_t GetLatestSubVersion(const char* path, Int_t run, Int_t version=-1);
+ virtual Bool_t IdToFilename(const AliCDBId& id, TString& filename) const;
protected:
}
//_____________________________________________________________________________
-Bool_t AliCDBGrid::IdToFilename(const AliCDBId& id, TString& filename) {
+Bool_t AliCDBGrid::IdToFilename(const AliCDBId& id, TString& filename) const {
// build file name from AliCDBId (path, run range, version) and fDBFolder
if (!id.GetAliCDBRunRange().IsValid()) {
AliCDBId* result=0;
while((anIdPtr = dynamic_cast<AliCDBId*> (iter.Next()))){
-
if(anIdPtr->GetPath() != query.GetPath()) continue;
//if(!CheckVersion(query, anIdPtr, result)) return NULL;
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
// look for file matching query requests (path, runRange, version)
if(selectedId.GetFirstRun() == fRun &&
- fPathFilter.Comprises(selectedId.GetAliCDBPath()) && fVersion < 0){
+ fPathFilter.Comprises(selectedId.GetAliCDBPath()) && fVersion < 0 && !fMetaDataFilter){
// 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()));
AliCDBId validFileId;
for(int i=0; i<res->GetEntries(); i++){
TString filename = res->GetKey(i, "lfn");
+ if(filename == "") continue;
if(FilenameToId(filename, validFileId))
validFileIds.AddLast(validFileId.Clone());
}
// look for file matching query requests (path, runRange)
if(queryId.GetFirstRun() == fRun &&
- fPathFilter.Comprises(queryId.GetAliCDBPath()) && fVersion < 0){
+ fPathFilter.Comprises(queryId.GetAliCDBPath()) && fVersion < 0 && !fMetaDataFilter){
// 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()));
AliCDBId validFileId;
for(int i=0; i<res->GetEntries(); i++){
TString filename = res->GetKey(i, "lfn");
+ if(filename == "") continue;
if(FilenameToId(filename, validFileId))
validFileIds.AddLast(validFileId.Clone());
}
// 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");
+ AddTag(folderToTag,"CDB");
+ AddTag(folderToTag,"CDB_MD");
TDirectory* saveDir = gDirectory;
if (saveDir) saveDir->cd(); else gROOT->cd();
file->Close(); delete file; file=0;
+
if(result) {
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());
+ if(!TagFileId(filename, &id)){
+ AliInfo(Form("CDB tagging failed. Deleting file %s!",filename.Data()));
+ if(!gGrid->Rm(filename.Data()))
+ AliError("Can't delete file!");
+ return kFALSE;
+ }
+
+ TagFileMetaData(filename, entry->GetMetaData());
}
return result;
}
//_____________________________________________________________________________
-void AliCDBGrid::TagFileId(TString& filename, const AliCDBId* id){
+Bool_t 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());
addTagValue_2.Data(),
addTagValue_3.Data());
+ Bool_t result = kFALSE;
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 !",
+ AliError(Form("Couldn't add CDB tag value to file %s !",
filename.Data()));
+ result = kFALSE;
} else {
AliInfo("Object successfully tagged.");
+ result = kTRUE;
}
delete res;
-
+ return result;
}
//_____________________________________________________________________________
-void AliCDBGrid::TagFileMetaData(TString& filename, const AliCDBMetaData* md){
+Bool_t 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());
addTagValue_2.Data(),
addTagValue_3.Data());
+ Bool_t result = kFALSE;
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()));
+ result = kFALSE;
} else {
AliInfo("Object successfully tagged.");
+ result = kTRUE;
}
-
+ return result;
}
//_____________________________________________________________________________
AliCDBId validFileId;
for(int i=0; i<res->GetEntries(); i++){
TString filename = res->GetKey(i, "lfn");
+ if(filename == "") continue;
AliDebug(2,Form("Found valid file: %s", filename.Data()));
Bool_t result = FilenameToId(filename, validFileId);
if(result) {
}
//_____________________________________________________________________________
-void AliCDBGrid::MakeQueryFilter(Long64_t firstRun, Long64_t lastRun,
+void AliCDBGrid::MakeQueryFilter(Int_t firstRun, Int_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);
+ result = Form("CDB:first_run<=%d and CDB:last_run>=%d", firstRun, lastRun);
if(version >= 0) {
result += Form(" and CDB:version=%d", version);
}
+//_____________________________________________________________________________
+Int_t AliCDBGrid::GetLatestVersion(const char* path, Int_t run){
+// get last version found in the database valid for run and path
+
+ TList validFileIds;
+ validFileIds.SetOwner(1);
+
+ AliCDBPath aCDBPath(path);
+ if(!aCDBPath.IsValid() || aCDBPath.IsWildcard()) {
+ AliError(Form("Invalid path in request: %s", path));
+ return -1;
+ }
+ AliCDBId query(path, run, run, -1, -1);
+ AliCDBId* dataId = 0;
+
+ // look for file matching query requests (path, runRange, version)
+ if(run == fRun &&
+ fPathFilter.Comprises(aCDBPath) && 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!",
+ run, path));
+ dataId = GetId(fValidFileIds, query);
+ if (!dataId) return -1;
+ return dataId->GetVersion();
+
+ }
+ // 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!",
+ run, path));
+
+ TString filter;
+ MakeQueryFilter(run, run, aCDBPath, -1, 0, filter);
+
+ TGridResult *res = gGrid->Query(fDBFolder, "Run*.root", filter, "");
+ AliCDBId validFileId;
+ for(int i=0; i<res->GetEntries(); i++){
+ TString filename = res->GetKey(i, "lfn");
+ if(filename == "") continue;
+ if(FilenameToId(filename, validFileId))
+ validFileIds.AddLast(validFileId.Clone());
+ }
+ delete res;
+
+ dataId = GetId(validFileIds, query);
+ if (!dataId) return -1;
+
+ return dataId->GetVersion();
+
+}
+
+//_____________________________________________________________________________
+Int_t AliCDBGrid::GetLatestSubVersion(const char* /*path*/, Int_t /*run*/, Int_t /*version*/){
+// get last subversion found in the database valid for run and path
+ AliError("Objects in GRID storage have no sub version!");
+ return -1;
+}
+
+
/////////////////////////////////////////////////////////////////////////////////////////////////
// //
// AliCDBGrid factory //
}
//TString buffer(gridString + sizeof("alien://") - 1);
TString buffer(gridString);
-
- TString gridUrl = "alien://";
+
+ TString gridUrl = "alien://";
TString user = "";
TString dbFolder = "DBGrid";
TString se = "ALICE::CERN::se01";
}
+ if(!gGrid && grid) {
+ delete grid; grid=0;
+ }
+
return grid;
}
public:
- virtual Bool_t IsReadOnly() const {return kFALSE;};
- virtual Bool_t HasSubVersion() const {return kFALSE;};
+ virtual Bool_t IsReadOnly() const {return kFALSE;}
+ virtual Bool_t HasSubVersion() const {return kFALSE;}
virtual Bool_t Contains(const char* path) const;
-
+ virtual Int_t GetLatestVersion(const char* path, Int_t run);
+ virtual Int_t GetLatestSubVersion(const char* path, Int_t run, Int_t version);
+ virtual Bool_t IdToFilename(const AliCDBId& id, TString& filename) const;
+
protected:
virtual AliCDBEntry* GetEntry(const AliCDBId& queryId);
AliCDBGrid& operator = (const AliCDBGrid& db);
Bool_t FilenameToId(TString& filename, AliCDBId& id);
- Bool_t IdToFilename(const AliCDBId& id, TString& filename);
Bool_t PrepareId(AliCDBId& id);
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);
+ Bool_t TagFileId(TString& filename, const AliCDBId* id);
+ Bool_t TagFileMetaData(TString& filename, const AliCDBMetaData* md);
// Bool_t CheckVersion(const AliCDBId& query, AliCDBId* idToCheck, AliCDBId* result);
- void MakeQueryFilter(Long64_t firstRun, Long64_t lastRun, const AliCDBPath& pathFilter, Int_t version,
+ void MakeQueryFilter(Int_t firstRun, Int_t lastRun, const AliCDBPath& pathFilter, Int_t version,
const AliCDBMetaData* md, TString& result) const;
virtual void QueryValidFiles();
TString AliCDBId::ToString() const {
// returns a string of Id data
- TString result;
- result += "path \"";
- result += GetPath();
- result += "\"; run range [";
- result += GetFirstRun();
- result += ",";
- result += GetLastRun();
- result += "]; version v";
- result += GetVersion();
- if(GetSubVersion()>0){
- result += "_s";
- result += GetSubVersion();
- }
- return result;
+ TString result = Form("path: \"%s\"; run range: [%d,%d]",
+ GetPath().Data(), GetFirstRun(), GetLastRun());
+
+ if(GetVersion() >= 0) result += Form("; version: v%d", GetVersion());
+ if(GetSubVersion() >= 0) result += Form("_s%d", GetSubVersion());
+ return result;
}
//_____________________________________________________________________________
-Bool_t AliCDBLocal::IdToFilename(const AliCDBRunRange& runRange, Int_t version,
- Int_t subVersion, TString& filename) {
+Bool_t AliCDBLocal::IdToFilename(const AliCDBId& id, TString& filename) const {
// build file name from AliCDBId data (run range, version, subVersion)
- if (!runRange.IsValid()) {
+ if (!id.GetAliCDBRunRange().IsValid()) {
AliDebug(2,Form("Invalid run range <%d, %d>.",
- runRange.GetFirstRun(), runRange.GetLastRun()));
+ id.GetFirstRun(), id.GetLastRun()));
return kFALSE;
}
- if (version < 0) {
- AliDebug(2,Form("Invalid version <%d>.", version));
+ if (id.GetVersion() < 0) {
+ AliDebug(2,Form("Invalid version <%d>.", id.GetVersion()));
return kFALSE;
}
- if (subVersion < 0) {
- AliDebug(2,Form("Invalid subversion <%s>.", subVersion));
+ if (id.GetSubVersion() < 0) {
+ AliDebug(2,Form("Invalid subversion <%s>.", id.GetSubVersion()));
return kFALSE;
}
- filename += "Run";
- filename += runRange.GetFirstRun();
- filename += "_";
- filename += runRange.GetLastRun();
- filename += "_v";
- filename += version;
- filename += "_s";
- filename += subVersion;
- filename += ".root";
+ filename = Form("Run%d_%d_v%d_s%d.root", id.GetFirstRun(), id.GetLastRun(),
+ id.GetVersion(), id.GetSubVersion());
+
+ filename.Prepend(fBaseDirectory +'/' + id.GetPath() + '/');
return kTRUE;
}
Bool_t AliCDBLocal::PrepareId(AliCDBId& id) {
// prepare id (version, subVersion) of the object that will be stored (called by PutEntry)
- TString dirName;
- dirName += fBaseDirectory;
- dirName += '/';
- dirName += id.GetPath();
+ TString dirName = Form("%s/%s", fBaseDirectory.Data(), id.GetPath().Data());
// go to the path; if directory does not exist, create it
void* dirPtr = gSystem->OpenDirectory(dirName);
Bool_t AliCDBLocal::GetId(const AliCDBId& query, AliCDBId& result) {
// look for filename matching query (called by GetEntry)
- TString dirName;
- dirName += fBaseDirectory;
- dirName += '/';
- dirName += query.GetPath(); // dirName = fDBPath/idPath
+ TString dirName = Form("%s/%s", fBaseDirectory.Data(), query.GetPath().Data());
- void* dirPtr = gSystem->OpenDirectory(dirName);
+ void* dirPtr = gSystem->OpenDirectory(dirName);
if (!dirPtr) {
AliDebug(2,Form("Directory <%s> not found", (query.GetPath()).Data()));
AliDebug(2,Form("in DB folder %s", fBaseDirectory.Data()));
return kFALSE;
}
- const char* filename;
-
+ const char* filename;
+
AliCDBRunRange aRunRange; // the runRange got from filename
Int_t aVersion, aSubVersion; // the version and subVersion got from filename
if (!query.HasVersion()) { // neither version and subversion specified -> look for highest version and subVersion
-
+
while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
-
+
TString aString(filename);
if (aString == "." || aString == "..") continue;
if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
// aRunRange contains requested run!
-
+
if (result.GetVersion() < aVersion) {
result.SetVersion(aVersion);
result.SetSubVersion(aSubVersion);
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
if (!result || !dataId.IsSpecified()) return NULL;
TString filename;
- if (!IdToFilename(dataId.GetAliCDBRunRange(), dataId.GetVersion(),
- dataId.GetSubVersion(), filename)) {
+ if (!IdToFilename(dataId, filename)) {
AliDebug(2,Form("Bad data ID encountered! Subnormal error!"));
return NULL;
}
-
- filename.Prepend((fBaseDirectory +'/' + queryId.GetPath() + '/'));
TFile file(filename, "READ"); // open file
if (!file.IsOpen()) {
const AliCDBId& queryId, TList* result) {
// multiple request (AliCDBStorage::GetAll)
- TString level0Dir;
- level0Dir += fBaseDirectory;
- level0Dir += '/';
- level0Dir += level0;
-
+ TString level0Dir = Form("%s/%s", fBaseDirectory.Data(), level0);
+
void* level0DirPtr = gSystem->OpenDirectory(level0Dir);
if (!level0DirPtr) {
- AliDebug(2,Form("Can't open level0 directory <%s>!",
+ AliDebug(2,Form("Can't open level0 directory <%s>!",
level0Dir.Data()));
return;
- }
+ }
const char* level1;
while ((level1 = gSystem->GetDirEntry(level0DirPtr))) {
const AliCDBId& queryId, TList* result) {
// multiple request (AliCDBStorage::GetAll)
- TString level1Dir;
- level1Dir += fBaseDirectory;
- level1Dir += '/';
- level1Dir += level0;
- level1Dir += '/';
- level1Dir += level1;
+ TString level1Dir = Form("%s/%s/%s", fBaseDirectory.Data(), level0,level1);
void* level1DirPtr = gSystem->OpenDirectory(level1Dir);
if (!level1DirPtr) {
- AliDebug(2,Form("Can't open level1 directory <%s>!",
+ AliDebug(2,Form("Can't open level1 directory <%s>!",
level1Dir.Data()));
return;
}
AliDebug(2,Form("Can't open storage directory <%s>",
fBaseDirectory.Data()));
return NULL;
- }
+ }
TList* result = new TList();
result->SetOwner();
const char* level0;
while ((level0 = gSystem->GetDirEntry(storageDirPtr))) {
-
+
TString level0Str(level0);
if (level0Str == "." || level0Str == "..") {
continue;
}
if (queryId.GetAliCDBPath().Level0Comprises(level0)) {
- GetEntriesForLevel0(level0, queryId, result);
+ GetEntriesForLevel0(level0, queryId, result);
}
- }
-
+ }
+
gSystem->FreeDirectory(storageDirPtr);
return result;
AliCDBId& id = entry->GetId();
// set version and subVersion 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(),
- id.GetSubVersion(), filename)) {
+ if (!IdToFilename(id, filename)) {
AliDebug(2,Form("Bad ID encountered! Subnormal error!"));
return kFALSE;
}
-
- filename.Prepend(fBaseDirectory +'/' + id.GetPath() + '/');
-
+
// open file
TFile file(filename, "CREATE");
if (!file.IsOpen()) {
file.Close();
if(result) {
- // TODO this is to make the SHUTTLE output lighter
if(!(id.GetPath().Contains("SHUTTLE/STATUS")))
AliInfo(Form("CDB object stored into file %s",filename.Data()));
}
Bool_t AliCDBLocal::Contains(const char* path) const{
// check for path in storage's fBaseDirectory
- TString dirName;
- dirName += fBaseDirectory;
- dirName += '/';
- dirName += path; // dirName = fDBPath/path
+ TString dirName = Form("%s/%s", fBaseDirectory.Data(), path);
Bool_t result=kFALSE;
void* dirPtr = gSystem->OpenDirectory(dirName);
//_____________________________________________________________________________
void AliCDBLocal::QueryValidFiles()
{
-// blabla
+// Query the CDB for files valid for AliCDBStorage::fRun
+// fills list fValidFileIds with AliCDBId objects created from file name
+
+ if(fVersion != -1) AliWarning ("Version parameter is not used by local storage query!");
+ if(fMetaDataFilter) {
+ AliWarning ("CDB meta data parameters are not used by local storage query!");
+ delete fMetaDataFilter; fMetaDataFilter=0;
+ }
+
+ void* storageDirPtr = gSystem->OpenDirectory(fBaseDirectory);
+
+ const char* level0;
+ while ((level0 = gSystem->GetDirEntry(storageDirPtr))) {
+
+ TString level0Str(level0);
+ if (level0Str == "." || level0Str == "..") {
+ continue;
+ }
+
+ if (fPathFilter.Level0Comprises(level0)) {
+ TString level0Dir = Form("%s/%s",fBaseDirectory.Data(),level0);
+ void* level0DirPtr = gSystem->OpenDirectory(level0Dir);
+ const char* level1;
+ while ((level1 = gSystem->GetDirEntry(level0DirPtr))) {
+
+ TString level1Str(level1);
+ if (level1Str == "." || level1Str == "..") {
+ continue;
+ }
+
+ if (fPathFilter.Level1Comprises(level1)) {
+ TString level1Dir = Form("%s/%s/%s",
+ fBaseDirectory.Data(),level0,level1);
+
+ void* level1DirPtr = gSystem->OpenDirectory(level1Dir);
+ const char* level2;
+ while ((level2 = gSystem->GetDirEntry(level1DirPtr))) {
+
+ TString level2Str(level2);
+ if (level2Str == "." || level2Str == "..") {
+ continue;
+ }
+
+ if (fPathFilter.Level2Comprises(level2)) {
+ TString dirName = Form("%s/%s/%s/%s",
+ fBaseDirectory.Data(),level0,level1,level2);
+
+ void* dirPtr = gSystem->OpenDirectory(dirName);
+
+ const char* filename;
+
+ AliCDBRunRange aRunRange; // the runRange got from filename
+ Int_t aVersion, aSubVersion; // the version and subVersion got from filename
+
+ while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
+
+ TString aString(filename);
+ if (aString == "." || aString == "..") continue;
+
+ if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
+ AliCDBRunRange runrg(fRun,fRun);
+ if (!aRunRange.Comprises(runrg)) continue;
+ // aRunRange contains requested run!
+ AliCDBPath validPath(level0,level1,level2);
+ AliCDBId validId(validPath,aRunRange,aVersion,aSubVersion);
+ fValidFileIds.AddLast(validId.Clone());
+ }
+ gSystem->FreeDirectory(dirPtr);
+ }
+ }
+ gSystem->FreeDirectory(level1DirPtr);
+ }
+ }
+ gSystem->FreeDirectory(level0DirPtr);
+ }
+ }
+ gSystem->FreeDirectory(storageDirPtr);
+
+}
+
+//_____________________________________________________________________________
+Int_t AliCDBLocal::GetLatestVersion(const char* path, Int_t run){
+// get last version found in the database valid for run and path
+
+ AliCDBPath aCDBPath(path);
+ if(!aCDBPath.IsValid() || aCDBPath.IsWildcard()) {
+ AliError(Form("Invalid path in request: %s", path));
+ return -1;
+ }
+
+ AliCDBId query(path, run, run, -1, -1);
+ AliCDBId dataId;
+
+ GetId(query,dataId);
+
+ return dataId.GetVersion();
+
+}
+
+//_____________________________________________________________________________
+Int_t AliCDBLocal::GetLatestSubVersion(const char* path, Int_t run, Int_t version){
+// get last version found in the database valid for run and path
+
+ AliCDBPath aCDBPath(path);
+ if(!aCDBPath.IsValid() || aCDBPath.IsWildcard()) {
+ AliError(Form("Invalid path in request: %s", path));
+ return -1;
+ }
+
+ AliCDBId query(path, run, run, version, -1);
+ AliCDBId dataId;
+
+ GetId(query,dataId);
+
+ return dataId.GetSubVersion();
}
virtual Bool_t IsReadOnly() const {return kFALSE;};
virtual Bool_t HasSubVersion() const {return kTRUE;};
virtual Bool_t Contains(const char* path) const;
+ virtual Int_t GetLatestVersion(const char* path, Int_t run);
+ virtual Int_t GetLatestSubVersion(const char* path, Int_t run, Int_t version=-1);
+ virtual Bool_t IdToFilename(const AliCDBId& id, TString& filename) const;
protected:
- virtual AliCDBEntry* GetEntry(const AliCDBId& queryId);
- virtual TList* GetEntries(const AliCDBId& queryId);
- virtual Bool_t PutEntry(AliCDBEntry* entry);
+ virtual AliCDBEntry* GetEntry(const AliCDBId& queryId);
+ virtual TList* GetEntries(const AliCDBId& queryId);
+ virtual Bool_t PutEntry(AliCDBEntry* entry);
virtual TList* GetIdListFromFile(const char* fileName);
private:
Bool_t FilenameToId(const char* filename, AliCDBRunRange& runRange,
Int_t& version, Int_t& subVersion);
- Bool_t IdToFilename(const AliCDBRunRange& runRange, Int_t version,
- Int_t subVersion, TString& filename);
Bool_t PrepareId(AliCDBId& id);
Bool_t GetId(const AliCDBId& query, AliCDBId& result);
AliCDBParam* param = CreateParameter(dbString);
if (!param) {
+ AliError(Form("Failed to activate requested storage! Check URI: %s", dbString));
return NULL;
}
if (aStorage) {
PutActiveStorage(param->CloneParam(), aStorage);
aStorage->SetURI(param->GetURI());
+ if(fRun > 0) {
+ aStorage->QueryCDB(fRun);
+ }
return aStorage;
}
}
+ AliError(Form("Failed to activate requested storage! Check URI: %s", param->GetURI().Data()));
+
return NULL;
}
// sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
// Default storage should be defined prior to any specific storages, e.g.:
// AliCDBManager::instance()->SetDefaultStorage("alien://");
-// AliCDBManager::instance()->SetSpecificStorage("TPC","local://DB_TPC");
-// AliCDBManager::instance()->SetSpecificStorage("RICH/Align","local://DB_TPCAlign");
+// AliCDBManager::instance()->SetSpecificStorage("TPC/*","local://DB_TPC");
+// AliCDBManager::instance()->SetSpecificStorage("*/Align/*","local://DB_TPCAlign");
+// calibType must be a valid CDB path! (3 level folder structure)
if(!fDefaultStorage) {
- AliError("Please activate a default storage first!");
+ AliError("Please activate a default storage first!");
return;
}
}
//_____________________________________________________________________________
-void AliCDBManager::SetRun(Long64_t run)
+void AliCDBManager::SetRun(Int_t run)
{
// Sets current run number.
// When the run number changes the caching is cleared.
return;
}
- AliInfo(Form("Querying default and specific storages for files valid for run %ld", (long) fRun));
+ AliInfo(Form("Querying default and specific storages for files valid for run %d", fRun));
fDefaultStorage->QueryCDB(fRun);
TIter iter(&fSpecificStorages);
while((aCalibType = dynamic_cast<TObjString*> (iter.Next()))){
aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
if(aPar) {
- AliDebug(2,Form("Qerying specific storage %s",aCalibType->GetName()));
+ AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName()));
GetStorage(aPar)->QueryCDB(fRun,aCalibType->GetName());
}
void SetCacheFlag(Bool_t cacheFlag) {fCache=cacheFlag;}
Bool_t GetCacheFlag() const {return fCache;}
- void SetRun(Long64_t run);
- Long64_t GetRun() const {return fRun;}
+ void SetRun(Int_t run);
+ Int_t GetRun() const {return fRun;}
// AliCDBEntry* Get(const char* path);
TMap fEntryCache; //! cache of the retrieved objects
Bool_t fCache; //! The cache flag
- Long64_t fRun; //! The run number
+ Int_t fRun; //! The run number
ClassDef(AliCDBManager, 0);
};
AliCDBMetaData::AliCDBMetaData() :
TObject(),
fObjectClassName(""),
-fResponsible(""),
-fBeamPeriod(0),
+fResponsible(""),
+fBeamPeriod(0),
fAliRootVersion(""),
fComment(""),
fProperties()
fProperties.SetOwner(1);
}
+//_____________________________________________________________________________
+AliCDBMetaData::AliCDBMetaData(const char *responsible, UInt_t beamPeriod,
+ const char* alirootVersion, const char* comment) :
+TObject(),
+fObjectClassName(""),
+fResponsible(responsible),
+fBeamPeriod(beamPeriod),
+fAliRootVersion(alirootVersion),
+fComment(comment),
+fProperties()
+{
+// constructor
+
+ fProperties.SetOwner(1);
+}
+
//_____________________________________________________________________________
AliCDBMetaData::~AliCDBMetaData() {
// destructor
message += Form("\t\t%s\n", ((TObjString* ) aPair->Key())->String().Data());
}
}
- AliInfo(Form("**** Object's MetaData set **** \n%s", message.Data()));
+ message += '\n';
+ AliInfo(Form("**** Object's MetaData parameters **** \n%s", message.Data()));
}
public:
AliCDBMetaData();
+ AliCDBMetaData(const char *responsible, UInt_t beamPeriod=0, const char* alirootVersion="", const char* comment="");
virtual ~AliCDBMetaData();
void SetObjectClassName(const char* name)
virtual Bool_t IsEqual(const TObject *obj) const;
- static UInt_t Infinity() {return fgkInfinity;}
+ static Int_t Infinity() {return fgkInfinity;}
private:
Int_t fFirstRun; // first valid run
Int_t fLastRun; // last valid run
- static const UInt_t fgkInfinity = 999999999; //! Flag for "infinity"
+ static const Int_t fgkInfinity = 999999999; //! Flag for "infinity"
ClassDef(AliCDBRunRange, 1);
};
} else {
// 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()));
+ AliInfo(Form("No valid CDB object found! request was: %s", query.ToString().Data()));
}
// if drain storage is set, drain entry into drain storage
}
} else {
- AliInfo(Form("No valid CDB object found! request was: name = <%s>, run = %d, version = %d",
- (query.GetPath()).Data(), query.GetFirstRun(), query.GetVersion()));
+ AliInfo(Form("No valid CDB object found! request was: %s", query.ToString().Data()));
}
// if drain storage is set, drain entries into drain storage
}
//_____________________________________________________________________________
-void AliCDBStorage::QueryCDB(Long64_t run, const char* pathFilter,
+void AliCDBStorage::QueryCDB(Int_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()
if(md) fMetaDataFilter = dynamic_cast<AliCDBMetaData*> (md->Clone());
QueryValidFiles();
+ AliCDBId queryId(pathFilter,run,run,version);
- 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,
+ AliInfo(Form("%d files valid for request <%s> found in CDB storage \"%s://%s\"",
+ fValidFileIds.GetEntries(), queryId.ToString().Data(),
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));
+ AliCDBId paramId(fPathFilter, fRun, fRun, fVersion);
+ AliInfo(Form("**** QueryCDB Parameters **** \n\t<%s>\n",
+ paramId.ToString().Data()));
+
+ if(fMetaDataFilter) fMetaDataFilter->PrintMetaData();
- if(fMetaDataFilter) {
- AliInfo("CDBMetaData Parameters: ");
- }
- fMetaDataFilter->PrintMetaData();
- AliInfo("Id's of valid objects found:");
+ TString message = "**** Id's of valid objects found *****\n";
TIter iter(&fValidFileIds);
AliCDBId* anId=0;
// loop on the list of selection criteria
while ((anId = dynamic_cast<AliCDBId*>(iter.Next()))) {
- AliInfo(Form("%s", anId->ToString().Data()));
+ message += Form("\t%s\n", anId->ToString().Data());
}
-
+ message += Form("\n\tTotal: %d objects found\n", fValidFileIds.GetEntries());
+ AliInfo(Form("%s", message.Data()));
}
virtual Bool_t IsReadOnly() const = 0;
virtual Bool_t HasSubVersion() const = 0;
virtual Bool_t Contains(const char* path) const = 0;
+ virtual Bool_t IdToFilename(const AliCDBId& id, TString& filename) const = 0;
- void QueryCDB(Long64_t run, const char* pathFilter="*",
+ void QueryCDB(Int_t run, const char* pathFilter="*",
Int_t version=-1, AliCDBMetaData *mdFilter=0);
void PrintQueryCDB();
TList* GetQueryCDBList() {return &fValidFileIds;}
+ virtual Int_t GetLatestVersion(const char* path, Int_t run)=0;
+ virtual Int_t GetLatestSubVersion(const char* path, Int_t run, Int_t version=-1)=0;
+
protected:
virtual ~AliCDBStorage();
virtual void QueryValidFiles() = 0;
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
+ Int_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
TString fType; //! Local, Grid: base folder name - Dump: file name
TString fBaseFolder; //! Local, Grid: base folder name - Dump: file name
- private:
+private:
AliCDBStorage(const AliCDBStorage & source);
AliCDBStorage & operator=(const AliCDBStorage & source);
}
// Now activate the detector specific CDB storage locations
- for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
- TString detName = fgkDetectorName[iDet];
- TObject* obj = fSpecCDBUri.FindObject(detName.Data());
- if (obj) {
- AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- AliWarning(Form("Specific CDB storage for %s is set to: %s",detName.Data(),obj->GetTitle()));
- AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- man->SetSpecificStorage(detName.Data(),obj->GetTitle());
- }
+ for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
+ TObject* obj = fSpecCDBUri[i];
+ if (!obj) continue;
+ AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+ AliWarning(Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
+ AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+ man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
}
man->Print();
}
}
//_____________________________________________________________________________
-void AliReconstruction::SetSpecificStorage(const char* detName, const char* uri) {
+void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
// Store a detector-specific CDB storage location
// Activate it later within the Run() method
- TObject* obj = fSpecCDBUri.FindObject(detName);
+ AliCDBPath aPath(calibType);
+ if(!aPath.IsValid()){
+ // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
+ for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
+ if(!strcmp(calibType, fgkDetectorName[iDet])) {
+ aPath.SetPath(Form("%s/*", calibType));
+ AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
+ break;
+ }
+ }
+ if(!aPath.IsValid()){
+ AliError(Form("Not a valid path or detector: %s", calibType));
+ return;
+ }
+ }
+
+ // check that calibType refers to a "valid" detector name
+ Bool_t isDetector = kFALSE;
+ for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
+ TString detName = fgkDetectorName[iDet];
+ if(aPath.GetLevel0() == detName) {
+ isDetector = kTRUE;
+ break;
+ }
+ }
+
+ if(!isDetector) {
+ AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
+ return;
+ }
+
+ TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
if (obj) fSpecCDBUri.Remove(obj);
- fSpecCDBUri.Add(new TNamed(detName, uri));
+ fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
}
// CDB storage activation
void InitCDBStorage();
void SetDefaultStorage(const char* uri);
- void SetSpecificStorage(const char* detName, const char* uri);
+ void SetSpecificStorage(const char* calibType, const char* uri);
Bool_t SetRunNumber();
AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
AliWarning(Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- man->SetSpecificStorage(obj->GetName(),obj->GetTitle());
+ man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
}
man->Print();
}
}
//_____________________________________________________________________________
-void AliSimulation::SetSpecificStorage(const char* detName, const char* uri) {
+void AliSimulation::SetSpecificStorage(const char* calibType, const char* uri) {
// Store a detector-specific CDB storage location
// Activate it later within the Run() method
- TObject* obj = fSpecCDBUri.FindObject(detName);
+ AliCDBPath aPath(calibType);
+ if(!aPath.IsValid()){
+ AliError(Form("Not a valid path: %s", calibType));
+ return;
+ }
+
+ TObject* obj = fSpecCDBUri.FindObject(calibType);
if (obj) fSpecCDBUri.Remove(obj);
- fSpecCDBUri.Add(new TNamed(detName, uri));
+ fSpecCDBUri.Add(new TNamed(calibType, uri));
}
// CDB storage activation
void InitCDBStorage();
void SetDefaultStorage(const char* uri);
- void SetSpecificStorage(const char* detName, const char* uri);
+ void SetSpecificStorage(const char* calibType, const char* uri);
virtual Bool_t Run(Int_t nEvents = 0);