X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=STEER%2FAliCDBGrid.cxx;h=640a558c88c39fcb8584f28d269335a6f241b68a;hb=330bfc2fa932f6ca620bb2ad88508865209f5bfb;hp=6a695d2846d5dbdb3c0795b6cc6898a93967d5a2;hpb=fdf65bb545d3ae693c2713661993bc6bf1f3bfa0;p=u%2Fmrichter%2FAliRoot.git diff --git a/STEER/AliCDBGrid.cxx b/STEER/AliCDBGrid.cxx index 6a695d2846d..640a558c88c 100644 --- a/STEER/AliCDBGrid.cxx +++ b/STEER/AliCDBGrid.cxx @@ -39,25 +39,25 @@ ClassImp(AliCDBGrid) //_____________________________________________________________________________ -AliCDBGrid::AliCDBGrid(const char *host, const Int_t port, - const char *user, const char *dbPath, const char *se) : +AliCDBGrid::AliCDBGrid(const char *gridUrl, const char *user, const char *dbFolder, const char *se) : AliCDBStorage(), -fHost(host), -fPort(port), +fGridUrl(gridUrl), fUser(user), -fDBPath(dbPath), +fDBFolder(dbFolder), fSE(se) { // constructor // - TString grid="alien://"; - grid+=host; grid+=":"; grid+=port; - // if the same Grid is alreay active, skip connection - if (!gGrid || TString(host) != gGrid->GetHost() || - port != gGrid->GetPort() || TString(user) != gGrid->GetUser()) { + if (!gGrid || fGridUrl != gGrid->GridUrl() + || (( fUser != "" ) && ( fUser != gGrid->GetUser() )) ) { // connection to the Grid - TGrid::Connect(grid.Data(),fUser.Data()); + 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())); + } + TGrid::Connect(fGridUrl.Data(),fUser.Data()); } if(!gGrid) { @@ -66,23 +66,23 @@ fSE(se) } TString initDir(gGrid->Pwd(0)); - if (fDBPath[0] != '/') { - fDBPath.Prepend(initDir); + if (fDBFolder[0] != '/') { + fDBFolder.Prepend(initDir); } // check DBFolder: trying to cd to DBFolder; if it does not exist, create it - if(!gGrid->Cd(fDBPath.Data(),0)){ - AliDebug(2,Form("Creating new folder <%s> ...",fDBPath.Data())); - if(!gGrid->Mkdir(fDBPath.Data(),"",0)){ - AliError(Form("Cannot create folder <%s> !",fDBPath.Data())); + if(!gGrid->Cd(fDBFolder.Data(),0)){ + AliDebug(2,Form("Creating new folder <%s> ...",fDBFolder.Data())); + if(!gGrid->Mkdir(fDBFolder.Data(),"",0)){ + AliError(Form("Cannot create folder <%s> !",fDBFolder.Data())); } } else { - AliDebug(2,Form("Folder <%s> found",fDBPath.Data())); + AliDebug(2,Form("Folder <%s> found",fDBFolder.Data())); } // removes any '/' at the end of path, then append one '/' - while(fDBPath.EndsWith("/")) fDBPath.Remove(fDBPath.Last('/')); - fDBPath+="/"; + while(fDBFolder.EndsWith("/")) fDBFolder.Remove(fDBFolder.Last('/')); + fDBFolder+="/"; // return to the initial directory gGrid->Cd(initDir.Data(),0); @@ -133,13 +133,13 @@ Bool_t AliCDBGrid::IdToFilename(const AliCDBRunRange& runRange, Int_t gridVersio // build file name from AliCDBId data (run range, version) if (!runRange.IsValid()) { - AliWarning(Form("Invalid run range <%d, %d>.", + AliDebug(2,Form("Invalid run range <%d, %d>.", runRange.GetFirstRun(), runRange.GetLastRun())); return kFALSE; } if (gridVersion < 0) { - AliWarning(Form("Invalid version <%d>.", gridVersion)); + AliDebug(2,Form("Invalid version <%d>.", gridVersion)); return kFALSE; } @@ -161,7 +161,7 @@ Bool_t AliCDBGrid::PrepareId(AliCDBId& id) { TString initDir(gGrid->Pwd(0)); TString pathName= id.GetPath(); - TString dirName(fDBPath); + TString dirName(fDBFolder); Bool_t dirExist=kFALSE; @@ -172,7 +172,7 @@ Bool_t AliCDBGrid::PrepareId(AliCDBId& id) { dirName+=buffer; dirName+="/"; dirExist=gGrid->Cd(dirName,0); if (!dirExist) { - AliInfo(Form("Creating new folder <%s> ...",dirName.Data())); + AliDebug(2,Form("Creating new folder <%s> ...",dirName.Data())); if(!gGrid->Mkdir(dirName,"",0)){ AliError(Form("Cannot create directory <%s> !",dirName.Data())); gGrid->Cd(initDir.Data()); @@ -207,7 +207,7 @@ Bool_t AliCDBGrid::PrepareId(AliCDBId& id) { TString lastStorage = id.GetLastStorage(); if(lastStorage.Contains(TString("new"), TString::kIgnoreCase) && id.GetVersion() > 1 ){ - AliWarning(Form("*** WARNING! a NEW object is being stored with version %d", + AliWarning(Form("A NEW object is being stored with version %d", id.GetVersion())); AliWarning(Form("and it will hide previously stored object with version %d!", id.GetVersion()-1)); @@ -221,20 +221,18 @@ Bool_t AliCDBGrid::PrepareId(AliCDBId& id) { } //_____________________________________________________________________________ -AliCDBId AliCDBGrid::GetId(const AliCDBId& query) { +Bool_t AliCDBGrid::GetId(const AliCDBId& query, AliCDBId& result) { // look for filename matching query (called by GetEntry) TString initDir(gGrid->Pwd(0)); - AliCDBId result(query.GetAliCDBPath(), -1, -1, -1, -1); - - TString dirName(fDBPath); - dirName += query.GetPath(); // dirName = fDBPath/idPath + TString dirName(fDBFolder); + dirName += query.GetPath(); // dirName = fDBFolder/idPath if (!gGrid->Cd(dirName,0)) { - AliError(Form("Directory <%s> not found", (query.GetPath()).Data())); - AliError(Form("in DB folder %s", fDBPath.Data())); - return result; + 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); @@ -254,10 +252,9 @@ AliCDBId AliCDBGrid::GetId(const AliCDBId& query) { if (!query.HasVersion()){ // look for highest version if(result.GetVersion() > aVersion) continue; if(result.GetVersion() == aVersion) { - AliError(Form("More than one object valid for run %d, version %d!", + AliDebug(2,Form("More than one object valid for run %d, version %d!", query.GetFirstRun(), aVersion)); - result.SetRunRange(-1,-1); result.SetVersion(-1); - return result; + return kFALSE; } result.SetVersion(aVersion); result.SetFirstRun(aRunRange.GetFirstRun()); @@ -266,10 +263,9 @@ AliCDBId AliCDBGrid::GetId(const AliCDBId& query) { } else { // look for specified version if(query.GetVersion() != aVersion) continue; if(result.GetVersion() == aVersion){ - AliError(Form("More than one object valid for run %d, version %d!", + AliDebug(2,Form("More than one object valid for run %d, version %d!", query.GetFirstRun(), aVersion)); - result.SetRunRange(-1,-1); result.SetVersion(-1); - return result; + return kFALSE; } result.SetVersion(aVersion); result.SetFirstRun(aRunRange.GetFirstRun()); @@ -280,38 +276,41 @@ AliCDBId AliCDBGrid::GetId(const AliCDBId& query) { gGrid->Cd(initDir.Data(),0); - return result; + return kTRUE; } //_____________________________________________________________________________ AliCDBEntry* AliCDBGrid::GetEntry(const AliCDBId& queryId) { // get AliCDBEntry from the database - AliCDBId dataId; + AliCDBId dataId(queryId.GetAliCDBPath(), -1, -1, -1, -1); + Bool_t result; // look for a filename matching query requests (path, runRange, version, subVersion) if (!queryId.HasVersion()) { // if version is not specified, first check the selection criteria list - dataId = GetId(GetSelection(queryId)); + AliCDBId selectedId(queryId); + GetSelection(&selectedId); + result = GetId(selectedId,dataId); } else { - dataId = GetId(queryId); + result = GetId(queryId,dataId); } - if (!dataId.IsSpecified()) return NULL; + if (!result || !dataId.IsSpecified()) return NULL; TString filename; if (!IdToFilename(dataId.GetAliCDBRunRange(), dataId.GetVersion(),filename)) { - AliError("Bad data ID encountered! Subnormal error!"); + AliDebug(2,Form("Bad data ID encountered! Subnormal error!")); return NULL; } - filename.Prepend("/alien" + fDBPath + queryId.GetPath() + '/'); + filename.Prepend("/alien" + fDBFolder + queryId.GetPath() + '/'); filename += "?se="; filename += fSE.Data(); - AliInfo(Form("Opening file: %s",filename.Data())); + AliDebug(2,Form("Opening file: %s",filename.Data())); TFile *file = TFile::Open(filename); if (!file) { - AliError(Form("Can't open file <%s>!", filename.Data())); + AliDebug(2,Form("Can't open file <%s>!", filename.Data())); return NULL; } @@ -321,12 +320,12 @@ AliCDBEntry* AliCDBGrid::GetEntry(const AliCDBId& queryId) { TObject* anObject = file->Get("AliCDBEntry"); if (!anObject) { - AliError("Bad storage data: NULL entry object!"); + AliDebug(2,Form("Bad storage data: NULL entry object!")); return NULL; } if (AliCDBEntry::Class() != anObject->IsA()) { - AliError("Bad storage data: Invalid entry object!"); + AliDebug(2,Form("Bad storage data: Invalid entry object!")); return NULL; } @@ -354,11 +353,11 @@ void AliCDBGrid::GetEntriesForLevel0(const char* level0, const AliCDBId& queryId, TList* result) { // multiple request (AliCDBStorage::GetAll) - TString level0Dir=fDBPath; + TString level0Dir=fDBFolder; level0Dir += level0; if (!gGrid->Cd(level0Dir,0)) { - AliError(Form("Level0 directory <%s> not found", level0Dir.Data())); + AliDebug(2,Form("Level0 directory <%s> not found", level0Dir.Data())); return; } @@ -377,13 +376,13 @@ void AliCDBGrid::GetEntriesForLevel1(const char* level0, const char* level1, const AliCDBId& queryId, TList* result) { // multiple request (AliCDBStorage::GetAll) - TString level1Dir=fDBPath; + TString level1Dir=fDBFolder; level1Dir += level0; level1Dir += '/'; level1Dir += level1; if (!gGrid->Cd(level1Dir,0)) { - AliError(Form("Level1 directory <%s> not found", level1Dir.Data())); + AliDebug(2,Form("Level1 directory <%s> not found", level1Dir.Data())); return; } @@ -415,7 +414,7 @@ TList* AliCDBGrid::GetEntries(const AliCDBId& queryId) { TString initDir(gGrid->Pwd(0)); - TGridResult *res = gGrid->Ls(fDBPath); + TGridResult *res = gGrid->Ls(fDBFolder); TString level0; for(int i=0; i < res->GetEntries(); i++){ @@ -445,7 +444,7 @@ Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry) { return kFALSE; } - filename.Prepend("/alien" + fDBPath + id.GetPath() + '/'); + filename.Prepend("/alien" + fDBFolder + id.GetPath() + '/'); TString filenameCopy(filename); filename += "?se="; filename += fSE.Data(); @@ -471,13 +470,60 @@ Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry) { if (saveDir) saveDir->cd(); else gROOT->cd(); file->Close(); delete file; file=0; if(result) { - AliInfo(Form("AliCDBEntry stored into file %s",filenameCopy.Data())); + AliInfo(Form("CDB object stored into file %s",filenameCopy.Data())); AliInfo(Form("using S.E. %s", fSE.Data())); } return result; } +//_____________________________________________________________________________ +TList* AliCDBGrid::GetIdListFromFile(const char* fileName){ + + TString turl(fileName); + turl.Prepend("/alien" + fDBFolder); + turl += "?se="; turl += fSE.Data(); + TFile *file = TFile::Open(turl); + if (!file) { + AliError(Form("Can't open selection file <%s>!", turl.Data())); + return NULL; + } + + TList *list = new TList(); + list->SetOwner(); + int i=0; + TString keycycle; + + AliCDBId *id; + while(1){ + i++; + keycycle = "AliCDBId;"; + keycycle+=i; + + id = (AliCDBId*) file->Get(keycycle); + if(!id) break; + list->AddFirst(id); + } + file->Close(); delete file; file=0; + + return list; + + +} + +//_____________________________________________________________________________ +Bool_t AliCDBGrid::Contains(const char* path) const{ +// check for path in storage's DBFolder + + TString initDir(gGrid->Pwd(0)); + TString dirName(fDBFolder); + dirName += path; // dirName = fDBFolder/path + Bool_t result=kFALSE; + if (gGrid->Cd(dirName,0)) result=kTRUE; + gGrid->Cd(initDir.Data(),0); + return result; +} + ///////////////////////////////////////////////////////////////////////////////////////////////// // // // AliCDBGrid factory // @@ -493,7 +539,8 @@ Bool_t AliCDBGridFactory::Validate(const char* gridString) { // pattern: alien://hostName:Port;user;dbPath;SE // example of a valid pattern: // "alien://aliendb4.cern.ch:9000;colla;DBTest;ALICE::CERN::Server" - TRegexp gridPattern("^alien://.+:[0-9]+;[a-zA-Z0-9_-.]+;.+;.+$"); +// TRegexp gridPattern("^alien://.+:[0-9]+;[a-zA-Z0-9_-.]+;.+;.+$"); + TRegexp gridPattern("^alien://.+$"); return TString(gridString).Contains(gridPattern); } @@ -505,24 +552,58 @@ AliCDBParam* AliCDBGridFactory::CreateParameter(const char* gridString) { if (!Validate(gridString)) { return NULL; } - TString buffer(gridString + sizeof("alien://") - 1); - TString host = buffer(0,buffer.First(':')); // host (ex. aliendb4.cern.ch) - buffer = buffer(host.Sizeof(),buffer.Sizeof()); - TString strPort = buffer(0, buffer.First(';')); - Int_t port = atoi(strPort.Data()); // port number (ex. 9000) - buffer = buffer(strPort.Sizeof(),buffer.Sizeof()); - TString user = buffer(0,buffer.First(';')); // user (ex. colla) - buffer = buffer(user.Sizeof(),buffer.Sizeof()); - TString dbPath = buffer(0,buffer.First(';')); // DB path (ex. /alice/cern.ch/user/c/colla/DB) - TString se = buffer(dbPath.Sizeof(),buffer.Sizeof()); // storage element (ex. ALICE::CERN::Server) + //TString buffer(gridString + sizeof("alien://") - 1); + TString buffer(gridString); + + TString gridUrl = "alien://"; + TString user = ""; + TString dbFolder = "DBGrid"; + TString se = "ALICE::CERN::se01"; + + TObjArray *arr = buffer.Tokenize('?'); + TIter iter(arr); + TObjString *str; - AliInfo(Form("host: %s",host.Data())); - AliInfo(Form("port: %d",port)); - AliInfo(Form("user: %s",user.Data())); - AliInfo(Form("dbPath: %s",dbPath.Data())); - AliInfo(Form("s.e.: %s",se.Data())); + while((str = (TObjString*) iter.Next())){ + TString entry(str->String()); + Int_t indeq = entry.Index('='); + if(indeq == -1) { + if(entry.BeginsWith("alien://")) { // maybe it's a gridUrl! + gridUrl = entry; + continue; + } else { + AliError(Form("Invalid entry! %s",entry.Data())); + continue; + } + } + + TString key = entry(0,indeq); + TString value = entry(indeq+1,entry.Length()-indeq); + + if(key.Contains("grid",TString::kIgnoreCase)) { + gridUrl += value; + } + else if (key.Contains("user",TString::kIgnoreCase)){ + user = value; + } + else if (key.Contains("folder",TString::kIgnoreCase)){ + dbFolder = value; + } + else if (key.Contains("se",TString::kIgnoreCase)){ + se = value; + } + else{ + AliError(Form("Invalid entry! %s",entry.Data())); + } + } + delete arr; arr=0; + + AliInfo(Form("gridUrl: %s",gridUrl.Data())); + AliInfo(Form("user: %s",user.Data())); + AliInfo(Form("dbFolder: %s",dbFolder.Data())); + AliInfo(Form("s.e.: %s",se.Data())); - return new AliCDBGridParam(host, port, user, dbPath, se); + return new AliCDBGridParam(gridUrl, user, dbFolder, se); } //_____________________________________________________________________________ @@ -532,8 +613,8 @@ AliCDBStorage* AliCDBGridFactory::Create(const AliCDBParam* param) { if (AliCDBGridParam::Class() == param->IsA()) { const AliCDBGridParam* gridParam = (const AliCDBGridParam*) param; - AliCDBGrid *grid = new AliCDBGrid(gridParam->GetHost(), gridParam->GetPort(), - gridParam->GetUser(), gridParam->GetPath(), + AliCDBGrid *grid = new AliCDBGrid(gridParam->GridUrl(), + gridParam->GetUser(), gridParam->GetDBFolder(), gridParam->GetSE()); if(gGrid) return grid; @@ -557,25 +638,24 @@ AliCDBGridParam::AliCDBGridParam() { } //_____________________________________________________________________________ -AliCDBGridParam::AliCDBGridParam(const char* host, - const Int_t port, +AliCDBGridParam::AliCDBGridParam(const char* gridUrl, const char* user, - const char* dbPath, + const char* dbFolder, const char* se): - fHost(host), - fPort(port), + fGridUrl(gridUrl), fUser(user), - fDBPath(dbPath), + fDBFolder(dbFolder), fSE(se) { // constructor SetType("alien"); - TString uri=("alien://"); - uri+=host; uri+=":"; uri+=port; uri+=";"; - uri+=user; uri+=";"; uri+=dbPath; uri+=";"; - uri+=se; + TString uri; + uri+=fGridUrl; uri+="?"; + uri+="User="; uri+=fUser; uri+="?"; + uri+="DBFolder="; uri+=fDBFolder; uri+="?"; + uri+="SE="; uri+=fSE; SetURI(uri); } @@ -590,14 +670,14 @@ AliCDBGridParam::~AliCDBGridParam() { AliCDBParam* AliCDBGridParam::CloneParam() const { // clone parameter - return new AliCDBGridParam(fHost, fPort, fUser, fDBPath, fSE); + return new AliCDBGridParam(fGridUrl, fUser, fDBFolder, fSE); } //_____________________________________________________________________________ ULong_t AliCDBGridParam::Hash() const { // return Hash function - return fHost.Hash()+fPort+fUser.Hash()+fDBPath.Hash()+fSE.Hash(); + return fGridUrl.Hash()+fUser.Hash()+fDBFolder.Hash()+fSE.Hash(); } //_____________________________________________________________________________ @@ -614,10 +694,9 @@ Bool_t AliCDBGridParam::IsEqual(const TObject* obj) const { AliCDBGridParam* other = (AliCDBGridParam*) obj; - if(fHost != other->fHost) return kFALSE; - if(fPort != other->fPort) return kFALSE; + if(fGridUrl != other->fGridUrl) return kFALSE; if(fUser != other->fUser) return kFALSE; - if(fDBPath != other->fDBPath) return kFALSE; + if(fDBFolder != other->fDBFolder) return kFALSE; if(fSE != other->fSE) return kFALSE; return kTRUE; }