1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 /////////////////////////////////////////////////////////////////////////////////////////////////
19 // access class to a DataBase in an AliEn storage //
21 /////////////////////////////////////////////////////////////////////////////////////////////////
25 #include <TGridResult.h>
30 #include <TObjArray.h>
31 #include <TObjString.h>
35 #include "AliCDBEntry.h"
36 #include "AliCDBGrid.h"
41 //_____________________________________________________________________________
42 AliCDBGrid::AliCDBGrid(const char *gridUrl, const char *user, const char *dbFolder, const char *se) :
51 // if the same Grid is alreay active, skip connection
52 if (!gGrid || fGridUrl != gGrid->GridUrl()
53 || (( fUser != "" ) && ( fUser != gGrid->GetUser() )) ) {
54 // connection to the Grid
55 AliInfo("Connection to the Grid...");
57 AliInfo(Form("gGrid = %x; fGridUrl = %s; gGrid->GridUrl() = %s",gGrid,fGridUrl.Data(), gGrid->GridUrl()));
58 AliInfo(Form("fUser = %s; gGrid->GetUser() = %s",fUser.Data(), gGrid->GetUser()));
60 TGrid::Connect(fGridUrl.Data(),fUser.Data());
64 AliError("Connection failed!");
68 TString initDir(gGrid->Pwd(0));
69 if (fDBFolder[0] != '/') {
70 fDBFolder.Prepend(initDir);
73 // check DBFolder: trying to cd to DBFolder; if it does not exist, create it
74 if(!gGrid->Cd(fDBFolder.Data(),0)){
75 AliDebug(2,Form("Creating new folder <%s> ...",fDBFolder.Data()));
76 if(!gGrid->Mkdir(fDBFolder.Data(),"",0)){
77 AliError(Form("Cannot create folder <%s> !",fDBFolder.Data()));
80 AliDebug(2,Form("Folder <%s> found",fDBFolder.Data()));
83 // removes any '/' at the end of path, then append one '/'
84 while(fDBFolder.EndsWith("/")) fDBFolder.Remove(fDBFolder.Last('/'));
88 fBaseFolder = fDBFolder;
90 // return to the initial directory
91 gGrid->Cd(initDir.Data(),0);
94 //_____________________________________________________________________________
95 AliCDBGrid::~AliCDBGrid()
98 delete gGrid; gGrid=0;
102 //_____________________________________________________________________________
103 Bool_t AliCDBGrid::FilenameToId(TString& filename, AliCDBId& id) {
104 // build AliCDBId from full path filename (fDBFolder/path/Run#x_#y_v#z.root)
106 if(filename.Contains(fDBFolder)){
107 filename = filename(fDBFolder.Length(),filename.Length()-fDBFolder.Length());
110 TString idPath = filename(0,filename.Last('/'));
112 if(!id.IsValid()) return kFALSE;
114 filename=filename(idPath.Length()+1,filename.Length()-idPath.Length());
117 // valid filename: Run#firstRun_#lastRun_v#version.root
118 TRegexp keyPattern("^Run[0-9]+_[0-9]+_v[0-9]+.root$");
119 keyPattern.Index(filename, &mSize);
121 AliDebug(2,Form("Bad filename <%s>.", filename.Data()));
125 filename.Resize(filename.Length() - sizeof(".root") + 1);
127 TObjArray* strArray = (TObjArray*) filename.Tokenize("_");
129 TString firstRunString(((TObjString*) strArray->At(0))->GetString());
130 id.SetFirstRun(atoi(firstRunString.Data() + 3));
131 id.SetLastRun(atoi(((TObjString*) strArray->At(1))->GetString()));
133 TString verString(((TObjString*) strArray->At(2))->GetString());
134 id.SetVersion(atoi(verString.Data() + 1));
141 //_____________________________________________________________________________
142 Bool_t AliCDBGrid::IdToFilename(const AliCDBId& id, TString& filename) {
143 // build file name from AliCDBId (path, run range, version) and fDBFolder
145 if (!id.GetAliCDBRunRange().IsValid()) {
146 AliDebug(2,Form("Invalid run range <%d, %d>.",
147 id.GetFirstRun(), id.GetLastRun()));
151 if (id.GetVersion() < 0) {
152 AliDebug(2,Form("Invalid version <%d>.", id.GetVersion()));
156 filename = Form("Run%d_%d_v%d.root",
161 filename.Prepend(fDBFolder + id.GetPath() + '/');
166 //_____________________________________________________________________________
167 Bool_t AliCDBGrid::PrepareId(AliCDBId& id) {
168 // prepare id (version) of the object that will be stored (called by PutEntry)
170 TString initDir(gGrid->Pwd(0));
171 TString pathName= id.GetPath();
173 TString dirName(fDBFolder);
175 Bool_t dirExist=kFALSE;
177 // go to the path; if directory does not exist, create it
178 TObjArray *arrName=pathName.Tokenize("/");
179 for(int i=0;i<arrName->GetEntries();i++){
180 TString buffer((arrName->At(i))->GetName());
181 dirName+=buffer; dirName+="/";
182 dirExist=gGrid->Cd(dirName,0);
184 AliDebug(2,Form("Creating new folder <%s> ...",dirName.Data()));
185 if(!gGrid->Mkdir(dirName,"",0)){
186 AliError(Form("Cannot create directory <%s> !",dirName.Data()));
187 gGrid->Cd(initDir.Data());
193 gGrid->Cd(initDir,0);
196 AliCDBId anId; // the id got from filename
197 AliCDBRunRange lastRunRange(-1,-1); // highest runRange found
198 Int_t lastVersion=0; // highest version found
200 TGridResult *res = gGrid->Ls(dirName);
202 //loop on the files in the directory, look for highest version
203 for(int i=0; i < res->GetEntries(); i++){
204 filename=res->GetFileNamePath(i);
205 if (!FilenameToId(filename, anId)) continue;
206 if (anId.GetAliCDBRunRange().Overlaps(id.GetAliCDBRunRange()) && anId.GetVersion() > lastVersion) {
207 lastVersion = anId.GetVersion();
208 lastRunRange = anId.GetAliCDBRunRange();
214 id.SetVersion(lastVersion + 1);
216 TString lastStorage = id.GetLastStorage();
217 if(lastStorage.Contains(TString("new"), TString::kIgnoreCase) && id.GetVersion() > 1 ){
218 AliDebug(2, Form("A NEW object is being stored with version %d",
220 AliDebug(2, Form("and it will hide previously stored object with version %d!",
224 if(!lastRunRange.IsAnyRange() && !(lastRunRange.IsEqual(&id.GetAliCDBRunRange())))
225 AliWarning(Form("Run range modified w.r.t. previous version (Run%d_%d_v%d)",
226 lastRunRange.GetFirstRun(), lastRunRange.GetLastRun(), id.GetVersion()));
231 //_____________________________________________________________________________
232 AliCDBId* AliCDBGrid::GetId(const TList& validFileIds, const AliCDBId& query) {
233 // look for the Id that matches query's requests (highest or exact version)
235 if(validFileIds.GetEntries() < 1) {
237 } else if (validFileIds.GetEntries() == 1) {
238 return dynamic_cast<AliCDBId*> (validFileIds.At(0));
241 TIter iter(&validFileIds);
246 while((anIdPtr = dynamic_cast<AliCDBId*> (iter.Next()))){
248 if(anIdPtr->GetPath() != query.GetPath()) continue;
250 //if(!CheckVersion(query, anIdPtr, result)) return NULL;
252 if (!query.HasVersion()){ // look for highest version
253 if(result && result->GetVersion() > anIdPtr->GetVersion()) continue;
254 if(result && result->GetVersion() == anIdPtr->GetVersion()) {
255 AliDebug(2,Form("More than one object valid for run %d, version %d!",
256 query.GetFirstRun(), anIdPtr->GetVersion()));
260 } else { // look for specified version
261 if(query.GetVersion() != anIdPtr->GetVersion()) continue;
262 if(result && result->GetVersion() == anIdPtr->GetVersion()){
263 AliDebug(2,Form("More than one object valid for run %d, version %d!",
264 query.GetFirstRun(), anIdPtr->GetVersion()));
277 //_____________________________________________________________________________
278 Bool_t AliCDBGrid::CheckVersion(const AliCDBId& query, AliCDBId* idToCheck, AliCDBId* result){
279 // Check if idToCheck has the "right" requested version and return it in result
283 AliInfo(Form("all'inizio: result = %s", result->ToString().Data()));
287 AliInfo(Form("result = %s", result->ToString().Data()));
289 if (!query.HasVersion()){ // look for highest version
290 if(result->GetVersion() > idToCheck->GetVersion()) return kTRUE;
291 if(result->GetVersion() == idToCheck->GetVersion()) {
292 AliDebug(2,Form("More than one object valid for run %d, version %d!",
293 query.GetFirstRun(), idToCheck->GetVersion()));
297 } else { // look for specified version
298 if(query.GetVersion() != idToCheck->GetVersion()) return kTRUE;
299 if(result->GetVersion() == idToCheck->GetVersion()){
300 AliDebug(2,Form("More than one object valid for run %d, version %d!",
301 query.GetFirstRun(), idToCheck->GetVersion()));
306 AliInfo(Form("alla fine: result = %s", result->ToString().Data()));
311 //_____________________________________________________________________________
312 AliCDBEntry* AliCDBGrid::GetEntry(const AliCDBId& queryId) {
313 // get AliCDBEntry from the database
317 AliCDBId selectedId(queryId);
318 if (!selectedId.HasVersion()) {
319 // if version is not specified, first check the selection criteria list
320 GetSelection(&selectedId);
324 validFileIds.SetOwner(1);
326 // look for file matching query requests (path, runRange, version)
327 if(selectedId.GetFirstRun() == fRun &&
328 fPathFilter.Comprises(selectedId.GetAliCDBPath()) && fVersion < 0){
329 // look into list of valid files previously loaded with AliCDBStorage::FillValidFileIds()
330 AliDebug(2, Form("List of files valid for run %d and for path %s was loaded. Looking there!",
331 selectedId.GetFirstRun(), selectedId.GetPath().Data()));
332 dataId = GetId(fValidFileIds, selectedId);
335 // List of files valid for reqested run was not loaded. Looking directly into CDB
336 AliDebug(2, Form("List of files valid for run %d and for path %s was not loaded. Looking directly into CDB!",
337 selectedId.GetFirstRun(), selectedId.GetPath().Data()));
340 MakeQueryFilter(selectedId.GetFirstRun(), selectedId.GetLastRun(),
341 selectedId.GetAliCDBPath(), selectedId.GetVersion(), 0, filter);
343 TGridResult *res = gGrid->Query(fDBFolder, "Run*.root", filter, "");
344 AliCDBId validFileId;
345 for(int i=0; i<res->GetEntries(); i++){
346 TString filename = res->GetKey(i, "lfn");
347 if(FilenameToId(filename, validFileId))
348 validFileIds.AddLast(validFileId.Clone());
351 dataId = GetId(validFileIds, selectedId);
354 if (!dataId) return NULL;
357 if (!IdToFilename(*dataId, filename)) {
358 AliDebug(2,Form("Bad data ID encountered! Subnormal error!"));
362 AliCDBEntry* anEntry = GetEntryFromFile(filename, dataId);
367 //_____________________________________________________________________________
368 AliCDBEntry* AliCDBGrid::GetEntryFromFile(TString& filename, const AliCDBId* dataId){
369 // Get AliCBEntry object from file "filename"
371 AliDebug(2,Form("Opening file: %s",filename.Data()));
373 filename.Prepend("/alien");
374 TFile *file = TFile::Open(filename);
376 AliDebug(2,Form("Can't open file <%s>!", filename.Data()));
380 // get the only AliCDBEntry object from the file
381 // the object in the file is an AliCDBEntry entry named "AliCDBEntry"
383 AliCDBEntry* anEntry = dynamic_cast<AliCDBEntry*> (file->Get("AliCDBEntry"));
386 AliDebug(2,Form("Bad storage data: file does not contain an AliCDBEntry object!"));
391 // The object's Id is not reset during storage
392 // If object's Id runRange or version do not match with filename,
393 // it means that someone renamed file by hand. In this case a warning msg is issued.
396 AliCDBId entryId = anEntry->GetId();
397 if(!((entryId.GetAliCDBRunRange()).IsEqual(&(dataId->GetAliCDBRunRange()))) ||
398 entryId.GetVersion() != dataId->GetVersion()){
399 AliWarning(Form("Either RunRange or gridVersion in the object's metadata"));
400 AliWarning(Form("do noth match with fileName numbers:"));
401 AliWarning(Form("someone renamed file by hand!"));
405 anEntry->SetLastStorage("grid");
407 // close file, return retieved entry
408 file->Close(); delete file; file=0;
413 //_____________________________________________________________________________
414 TList* AliCDBGrid::GetEntries(const AliCDBId& queryId) {
415 // multiple request (AliCDBStorage::GetAll)
417 TList* result = new TList();
421 validFileIds.SetOwner(1);
423 Bool_t alreadyLoaded = kFALSE;
425 // look for file matching query requests (path, runRange)
426 if(queryId.GetFirstRun() == fRun &&
427 fPathFilter.Comprises(queryId.GetAliCDBPath()) && fVersion < 0){
428 // look into list of valid files previously loaded with AliCDBStorage::FillValidFileIds()
429 AliDebug(2,Form("List of files valid for run %d and for path %s was loaded. Looking there!",
430 queryId.GetFirstRun(), queryId.GetPath().Data()));
432 alreadyLoaded = kTRUE;
435 // List of files valid for reqested run was not loaded. Looking directly into CDB
436 AliDebug(2,Form("List of files valid for run %d and for path %s was not loaded. Looking directly into CDB!",
437 queryId.GetFirstRun(), queryId.GetPath().Data()));
440 MakeQueryFilter(queryId.GetFirstRun(), queryId.GetLastRun(),
441 queryId.GetAliCDBPath(), queryId.GetVersion(), 0, filter);
443 TGridResult *res = gGrid->Query(fDBFolder, "Run*.root", filter, "");
444 AliCDBId validFileId;
445 for(int i=0; i<res->GetEntries(); i++){
446 TString filename = res->GetKey(i, "lfn");
447 if(FilenameToId(filename, validFileId))
448 validFileIds.AddLast(validFileId.Clone());
455 iter = new TIter(&fValidFileIds);
457 iter = new TIter(&validFileIds);
461 selectedIds.SetOwner(1);
463 // loop on list of valid Ids to select the right version to get.
464 // According to query and to the selection criteria list, version can be the highest or exact
468 AliCDBPath queryPath = queryId.GetAliCDBPath();
469 while((anIdPtr = dynamic_cast<AliCDBId*> (iter->Next()))){
470 AliCDBPath thisCDBPath = anIdPtr->GetAliCDBPath();
471 if(!(queryPath.Comprises(thisCDBPath)) || pathCopy.GetPath() == thisCDBPath.GetPath()) continue;
472 pathCopy = thisCDBPath;
474 // check the selection criteria list for this query
475 AliCDBId thisId(*anIdPtr);
476 thisId.SetVersion(queryId.GetVersion());
477 if(!thisId.HasVersion()) GetSelection(&thisId);
480 dataId = GetId(fValidFileIds, thisId);
482 dataId = GetId(validFileIds, thisId);
484 if(dataId) selectedIds.Add(dataId->Clone());
489 // selectedIds contains the Ids of the files matching all requests of query!
490 // All the objects are now ready to be retrieved
491 iter = new TIter(&selectedIds);
492 while((anIdPtr = dynamic_cast<AliCDBId*> (iter->Next()))){
494 if (!IdToFilename(*anIdPtr, filename)) {
495 AliDebug(2,Form("Bad data ID encountered! Subnormal error!"));
499 AliCDBEntry* anEntry = GetEntryFromFile(filename, anIdPtr);
501 if(anEntry) result->Add(anEntry);
509 //_____________________________________________________________________________
510 Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry) {
511 // put an AliCDBEntry object into the database
513 AliCDBId& id = entry->GetId();
515 // set version for the entry to be stored
516 if (!PrepareId(id)) return kFALSE;
518 // build filename from entry's id
520 if (!IdToFilename(id, filename)) {
521 AliError("Bad ID encountered! Subnormal error!");
525 TString folderToTag = Form("%s%s",
527 id.GetPath().Data());
529 // add CDB and CDB_MD tag to folder
530 // TODO how to check that folder has already tags?
531 Bool_t tagCDB = AddTag(folderToTag,"CDB");
532 Bool_t tagCDBmd = AddTag(folderToTag,"CDB_MD");
534 TDirectory* saveDir = gDirectory;
536 // specify SE to filename
537 TString fullFilename = Form("/alien%s?se=%s", filename.Data(), fSE.Data());
540 TFile *file = TFile::Open(fullFilename,"CREATE");
541 if(!file || !file->IsWritable()){
542 AliError(Form("Can't open file <%s>!", filename.Data()));
543 if(file && !file->IsWritable()) file->Close(); delete file; file=0;
549 entry->SetVersion(id.GetVersion());
551 // write object (key name: "AliCDBEntry")
552 Bool_t result = (entry->Write("AliCDBEntry") != 0);
553 if (!result) AliError(Form("Can't write entry to file <%s>!", filename.Data()));
556 if (saveDir) saveDir->cd(); else gROOT->cd();
557 file->Close(); delete file; file=0;
559 AliInfo(Form("CDB object stored into file %s", filename.Data()));
560 AliInfo(Form("using S.E. %s", fSE.Data()));
562 if(tagCDB) TagFileId(filename, &id);
563 if(tagCDBmd) TagFileMetaData(filename, entry->GetMetaData());
568 //_____________________________________________________________________________
569 Bool_t AliCDBGrid::AddTag(TString& folderToTag, const char* tagname){
570 // add "tagname" tag (CDB or CDB_MD) to folder where object will be stored
572 Bool_t result = kTRUE;
573 AliDebug(2, Form("adding %s tag to folder %s", tagname, folderToTag.Data()));
574 TString addTag = Form("addTag %s %s", folderToTag.Data(), tagname);
575 TGridResult *gridres = gGrid->Command(addTag.Data());
576 const char* resCode = gridres->GetKey(0,"__result__"); // '1' if success
577 if(resCode[0] != '1') {
578 AliError(Form("Couldn't add %s tags to folder %s !",
579 tagname, folderToTag.Data()));
586 //_____________________________________________________________________________
587 void AliCDBGrid::TagFileId(TString& filename, const AliCDBId* id){
588 // tag stored object in CDB table using object Id's parameters
590 TString addTagValue_1 = Form("addTagValue %s CDB ", filename.Data());
591 TString addTagValue_2 = Form("first_run=%d last_run=%d version=%d ",
595 TString addTagValue_3 = Form("path_level_0=\"%s\" path_level_1=\"%s\" path_level_2=\"%s\"",
596 id->GetLevel0().Data(),
597 id->GetLevel1().Data(),
598 id->GetLevel2().Data());
599 TString addTagValue = Form("%s%s%s",
600 addTagValue_1.Data(),
601 addTagValue_2.Data(),
602 addTagValue_3.Data());
604 AliDebug(2, Form("Tagging file. Tag command: %s", addTagValue.Data()));
605 TGridResult* res = gGrid->Command(addTagValue.Data());
606 const char* resCode = res->GetKey(0,"__result__"); // '1' if success
607 if(resCode[0] != '1') {
608 AliWarning(Form("Couldn't add CDB tag value to file %s !",
611 AliInfo("Object successfully tagged.");
618 //_____________________________________________________________________________
619 void AliCDBGrid::TagFileMetaData(TString& filename, const AliCDBMetaData* md){
620 // tag stored object in CDB table using object Id's parameters
622 TString addTagValue_1 = Form("addTagValue %s CDB_MD ", filename.Data());
623 TString addTagValue_2 = Form("object_classname=\"%s\" responsible=\"%s\" beam_period=%d ",
624 md->GetObjectClassName(),
625 md->GetResponsible(),
626 md->GetBeamPeriod());
627 TString addTagValue_3 = Form("aliroot_version=\"%s\" comment=\"%s\"",
628 md->GetAliRootVersion(),
630 TString addTagValue = Form("%s%s%s",
631 addTagValue_1.Data(),
632 addTagValue_2.Data(),
633 addTagValue_3.Data());
635 AliDebug(2, Form("Tagging file. Tag command: %s", addTagValue.Data()));
636 TGridResult* res = gGrid->Command(addTagValue.Data());
637 const char* resCode = res->GetKey(0,"__result__"); // '1' if success
638 if(resCode[0] != '1') {
639 AliWarning(Form("Couldn't add CDB_MD tag value to file %s !",
642 AliInfo("Object successfully tagged.");
647 //_____________________________________________________________________________
648 TList* AliCDBGrid::GetIdListFromFile(const char* fileName){
650 TString turl(fileName);
651 turl.Prepend("/alien" + fDBFolder);
652 turl += "?se="; turl += fSE.Data();
653 TFile *file = TFile::Open(turl);
655 AliError(Form("Can't open selection file <%s>!", turl.Data()));
659 TList *list = new TList();
667 keycycle = "AliCDBId;";
670 id = (AliCDBId*) file->Get(keycycle);
674 file->Close(); delete file; file=0;
681 //_____________________________________________________________________________
682 Bool_t AliCDBGrid::Contains(const char* path) const{
683 // check for path in storage's DBFolder
685 TString initDir(gGrid->Pwd(0));
686 TString dirName(fDBFolder);
687 dirName += path; // dirName = fDBFolder/path
688 Bool_t result=kFALSE;
689 if (gGrid->Cd(dirName,0)) result=kTRUE;
690 gGrid->Cd(initDir.Data(),0);
694 //_____________________________________________________________________________
695 void AliCDBGrid::QueryValidFiles()
697 // Query the CDB for files valid for AliCDBStorage::fRun
698 // fills list fValidFileIds with AliCDBId objects created from file name
701 MakeQueryFilter(fRun, fRun, fPathFilter, fVersion, fMetaDataFilter, filter);
703 TGridResult *res = gGrid->Query(fDBFolder, "Run*.root", filter, "");
704 AliCDBId validFileId;
705 for(int i=0; i<res->GetEntries(); i++){
706 TString filename = res->GetKey(i, "lfn");
707 AliDebug(2,Form("Found valid file: %s", filename.Data()));
708 Bool_t result = FilenameToId(filename, validFileId);
710 fValidFileIds.AddLast(validFileId.Clone());
717 //_____________________________________________________________________________
718 void AliCDBGrid::MakeQueryFilter(Long64_t firstRun, Long64_t lastRun,
719 const AliCDBPath& pathFilter, Int_t version,
720 const AliCDBMetaData* md, TString& result) const
722 // create filter for file query
724 result = Form("CDB:first_run<=%ld and CDB:last_run>=%ld", (long) firstRun, (long) lastRun);
727 result += Form(" and CDB:version=%d", version);
729 if(pathFilter.GetLevel0() != "*") {
730 result += Form(" and CDB:path_level_0=\"%s\"", pathFilter.GetLevel0().Data());
732 if(pathFilter.GetLevel1() != "*") {
733 result += Form(" and CDB:path_level_1=\"%s\"", pathFilter.GetLevel1().Data());
735 if(pathFilter.GetLevel2() != "*") {
736 result += Form(" and CDB:path_level_2=\"%s\"", pathFilter.GetLevel2().Data());
740 if(md->GetObjectClassName()[0] != '\0') {
741 result += Form(" and CDB_MD:object_classname=\"%s\"", md->GetObjectClassName());
743 if(md->GetResponsible()[0] != '\0') {
744 result += Form(" and CDB_MD:responsible=\"%s\"", md->GetResponsible());
746 if(md->GetBeamPeriod() != 0) {
747 result += Form(" and CDB_MD:beam_period=%d", md->GetBeamPeriod());
749 if(md->GetAliRootVersion()[0] != '\0') {
750 result += Form(" and CDB_MD:aliroot_version=\"%s\"", md->GetAliRootVersion());
752 if(md->GetComment()[0] != '\0') {
753 result += Form(" and CDB_MD:comment=\"%s\"", md->GetComment());
756 AliDebug(2, Form("filter: %s",result.Data()));
760 /////////////////////////////////////////////////////////////////////////////////////////////////
762 // AliCDBGrid factory //
764 /////////////////////////////////////////////////////////////////////////////////////////////////
766 ClassImp(AliCDBGridFactory)
768 //_____________________________________________________________________________
769 Bool_t AliCDBGridFactory::Validate(const char* gridString) {
770 // check if the string is valid Grid URI
772 // pattern: alien://hostName:Port;user;dbPath;SE
773 // example of a valid pattern:
774 // "alien://aliendb4.cern.ch:9000;colla;DBTest;ALICE::CERN::Server"
775 // TRegexp gridPattern("^alien://.+:[0-9]+;[a-zA-Z0-9_-.]+;.+;.+$");
776 TRegexp gridPattern("^alien://.+$");
778 return TString(gridString).Contains(gridPattern);
781 //_____________________________________________________________________________
782 AliCDBParam* AliCDBGridFactory::CreateParameter(const char* gridString) {
783 // create AliCDBGridParam class from the URI string
785 if (!Validate(gridString)) {
788 //TString buffer(gridString + sizeof("alien://") - 1);
789 TString buffer(gridString);
791 TString gridUrl = "alien://";
793 TString dbFolder = "DBGrid";
794 TString se = "ALICE::CERN::se01";
796 TObjArray *arr = buffer.Tokenize('?');
800 while((str = (TObjString*) iter.Next())){
801 TString entry(str->String());
802 Int_t indeq = entry.Index('=');
804 if(entry.BeginsWith("alien://")) { // maybe it's a gridUrl!
808 AliError(Form("Invalid entry! %s",entry.Data()));
813 TString key = entry(0,indeq);
814 TString value = entry(indeq+1,entry.Length()-indeq);
816 if(key.Contains("grid",TString::kIgnoreCase)) {
819 else if (key.Contains("user",TString::kIgnoreCase)){
822 else if (key.Contains("folder",TString::kIgnoreCase)){
825 else if (key.Contains("se",TString::kIgnoreCase)){
829 AliError(Form("Invalid entry! %s",entry.Data()));
834 AliDebug(2, Form("gridUrl: %s",gridUrl.Data()));
835 AliDebug(2, Form("user: %s",user.Data()));
836 AliDebug(2, Form("dbFolder: %s",dbFolder.Data()));
837 AliDebug(2, Form("s.e.: %s",se.Data()));
839 return new AliCDBGridParam(gridUrl.Data(), user.Data(), dbFolder.Data(), se.Data());
842 //_____________________________________________________________________________
843 AliCDBStorage* AliCDBGridFactory::Create(const AliCDBParam* param) {
844 // create AliCDBGrid storage instance from parameters
846 AliCDBGrid *grid = 0;
847 if (AliCDBGridParam::Class() == param->IsA()) {
849 const AliCDBGridParam* gridParam = (const AliCDBGridParam*) param;
850 grid = new AliCDBGrid(gridParam->GridUrl().Data(),
851 gridParam->GetUser().Data(),
852 gridParam->GetDBFolder().Data(),
853 gridParam->GetSE().Data());
860 /////////////////////////////////////////////////////////////////////////////////////////////////
862 // AliCDBGrid Parameter class // //
864 /////////////////////////////////////////////////////////////////////////////////////////////////
866 ClassImp(AliCDBGridParam)
868 //_____________________________________________________________________________
869 AliCDBGridParam::AliCDBGridParam():
876 // default constructor
880 //_____________________________________________________________________________
881 AliCDBGridParam::AliCDBGridParam(const char* gridUrl,
883 const char* dbFolder,
895 TString uri = Form("%s?User=%s?DBFolder=%s?SE=%s",
896 fGridUrl.Data(), fUser.Data(),
897 fDBFolder.Data(), fSE.Data());
902 //_____________________________________________________________________________
903 AliCDBGridParam::~AliCDBGridParam() {
908 //_____________________________________________________________________________
909 AliCDBParam* AliCDBGridParam::CloneParam() const {
912 return new AliCDBGridParam(fGridUrl.Data(), fUser.Data(),
913 fDBFolder.Data(), fSE.Data());
916 //_____________________________________________________________________________
917 ULong_t AliCDBGridParam::Hash() const {
918 // return Hash function
920 return fGridUrl.Hash()+fUser.Hash()+fDBFolder.Hash()+fSE.Hash();
923 //_____________________________________________________________________________
924 Bool_t AliCDBGridParam::IsEqual(const TObject* obj) const {
925 // check if this object is equal to AliCDBParam obj
931 if (AliCDBGridParam::Class() != obj->IsA()) {
935 AliCDBGridParam* other = (AliCDBGridParam*) obj;
937 if(fGridUrl != other->fGridUrl) return kFALSE;
938 if(fUser != other->fUser) return kFALSE;
939 if(fDBFolder != other->fDBFolder) return kFALSE;
940 if(fSE != other->fSE) return kFALSE;