25 #include <TGridResult.h> 30 #include <TObjArray.h> 31 #include <TObjString.h> 44 Bool_t
AliCDBGrid::fgForbidGRPOverride = kTRUE;
48 const
char *se, const
char* cacheFolder, Bool_t operateDisconnected,
49 Long64_t cacheSize, Long_t cleanupInterval) :
56 fCacheFolder(cacheFolder),
57 fOperateDisconnected(operateDisconnected),
58 fCacheSize(cacheSize),
59 fCleanupInterval(cleanupInterval)
64 if (!gGrid || fGridUrl != gGrid->GridUrl()
65 || (( fUser !=
"" ) && ( fUser != gGrid->GetUser() )) ) {
67 AliInfo(
"Connection to the Grid...");
69 AliInfo(Form(
"gGrid = %p; fGridUrl = %s; gGrid->GridUrl() = %s",gGrid,fGridUrl.Data(), gGrid->GridUrl()));
70 AliInfo(Form(
"fUser = %s; gGrid->GetUser() = %s",fUser.Data(), gGrid->GetUser()));
72 TGrid::Connect(fGridUrl.Data(),fUser.Data());
80 TString initDir(gGrid->Pwd(0));
81 if (fDBFolder[0] !=
'/') {
82 fDBFolder.Prepend(initDir);
86 if(!gGrid->Cd(fDBFolder.Data(),0)){
87 AliDebug(2,Form(
"Creating new folder <%s> ...",fDBFolder.Data()));
88 TGridResult*
res = gGrid->Command(Form(
"mkdir -p %s",fDBFolder.Data()));
89 TString result = res->GetKey(0,
"__result__");
91 AliFatal(Form(
"Cannot create folder <%s> !",fDBFolder.Data()));
95 AliDebug(2,Form(
"Folder <%s> found",fDBFolder.Data()));
99 while(fDBFolder.EndsWith(
"/")) fDBFolder.Remove(fDBFolder.Last(
'/'));
103 fBaseFolder = fDBFolder;
108 TString origCache(TFile::GetCacheFileDir());
109 if(fCacheFolder.Length() > 0) {
110 if(origCache.Length() == 0) {
111 AliInfo(Form(
"Setting local cache to: %s", fCacheFolder.Data()));
112 }
else if(fCacheFolder != origCache) {
113 AliWarning(Form(
"Local cache folder was already defined, changing it to: %s",
114 fCacheFolder.Data()));
118 if(!TFile::SetCacheFileDir(fCacheFolder.Data(), fOperateDisconnected)) {
119 AliError(Form(
"Could not set cache folder %s !", fCacheFolder.Data()));
124 fCacheFolder = TFile::GetCacheFileDir();
128 if(!TFile::ShrinkCacheFileDir(fCacheSize, fCleanupInterval)) {
129 AliError(Form(
"Could not set following values " 130 "to ShrinkCacheFileDir: cacheSize = %lld, cleanupInterval = %ld !",
131 fCacheSize, fCleanupInterval));
136 gGrid->Cd(initDir.Data(),0);
139 fInitRetrySeconds = 5;
145 delete gGrid; gGrid=0;
157 TString idPath = filename(0,filename.Last(
'/'));
159 if(!
id.IsValid())
return kFALSE;
161 filename=filename(idPath.Length()+1,filename.Length()-idPath.Length());
165 TRegexp keyPattern(
"^Run[0-9]+_[0-9]+_v[0-9]+_s0.root$");
166 keyPattern.Index(filename, &mSize);
171 TRegexp oldKeyPattern(
"^Run[0-9]+_[0-9]+_v[0-9]+.root$");
172 oldKeyPattern.Index(filename, &oldmSize);
174 AliDebug(2,Form(
"Bad filename <%s>.", filename.Data()));
177 AliDebug(2,Form(
"Old filename format <%s>.", filename.Data()));
178 id.SetSubVersion(-11);
182 id.SetSubVersion(-1);
185 filename.Resize(filename.Length() -
sizeof(
".root") + 1);
189 TString firstRunString(((TObjString*) strArray->At(0))->GetString());
190 id.SetFirstRun(atoi(firstRunString.Data() + 3));
191 id.SetLastRun(atoi(((TObjString*) strArray->At(1))->GetString()));
193 TString verString(((TObjString*) strArray->At(2))->GetString());
194 id.SetVersion(atoi(verString.Data() + 1));
205 if (!
id.GetAliCDBRunRange().IsValid()) {
206 AliDebug(2,Form(
"Invalid run range <%d, %d>.",
207 id.GetFirstRun(),
id.GetLastRun()));
211 if (
id.GetVersion() < 0) {
212 AliDebug(2,Form(
"Invalid version <%d>.",
id.GetVersion()));
216 filename = Form(
"Run%d_%d_v%d",
221 if (
id.GetSubVersion() != -11) filename +=
"_s0";
224 filename.Prepend(
fDBFolder +
id.GetPath() +
'/');
234 AliWarning(
"WARNING!!! You are changing the exponential retry times and delay: this function should be used by experts!");
245 TString initDir(gGrid->Pwd(0));
249 Bool_t dirExist=kFALSE;
254 for(
int i=0;i<3;i++){
259 dirName+=Form(
"%s/",
id.GetPathLevel(i).Data());
260 dirExist=gGrid->Cd(dirName,0);
262 AliDebug(2,Form(
"Creating new folder <%s> ...",dirName.Data()));
263 if(!gGrid->Mkdir(dirName,
"",0)){
264 AliError(Form(
"Cannot create directory <%s> !",dirName.Data()));
265 gGrid->Cd(initDir.Data());
283 AliDebug(2,
"Tagging level 2 folder with \"CDB\" and \"CDB_MD\" tag");
284 if(!
AddTag(dirName,
"CDB")){
285 AliError(Form(
"Could not tag folder %s !", dirName.Data()));
286 if(!gGrid->Rmdir(dirName.Data())){
287 AliError(Form(
"Unexpected: could not remove %s directory!", dirName.Data()));
291 if(!
AddTag(dirName,
"CDB_MD")){
292 AliError(Form(
"Could not tag folder %s !", dirName.Data()));
293 if(!gGrid->Rmdir(dirName.Data())){
294 AliError(Form(
"Unexpected: could not remove %s directory!", dirName.Data()));
324 gGrid->Cd(initDir,0);
331 TGridResult *
res = gGrid->Ls(dirName);
334 for(
int i=0; i < res->GetEntries(); i++){
335 filename=res->GetFileNamePath(i);
346 if(
id.GetPath().
Contains(
"GRP") &&
id.HasVersion() && lastVersion!=0)
349 AliDebug(5,Form(
"Entry %s won't be put in the destination OCDB",
id.ToString().Data()));
353 AliInfo(
"ATTENTION: Interdiction to override GRP* objects was explicitly disabled");
357 id.SetVersion(lastVersion + 1);
360 TString lastStorage =
id.GetLastStorage();
361 if(lastStorage.Contains(TString(
"new"), TString::kIgnoreCase) &&
id.GetVersion() > 1 ){
362 AliDebug(2, Form(
"A NEW object is being stored with version %d",
364 AliDebug(2, Form(
"and it will hide previously stored object with version %d!",
368 if(!lastRunRange.
IsAnyRange() && !(lastRunRange.
IsEqual(&
id.GetAliCDBRunRange())))
369 AliWarning(Form(
"Run range modified w.r.t. previous version (Run%d_%d_v%d)",
379 if(validFileIds.GetEntriesFast() < 1)
382 TIter iter(&validFileIds);
387 while((anIdPtr = dynamic_cast<AliCDBId*> (iter.Next()))){
395 AliError(Form(
"More than one object valid for run %d, version %d!",
403 AliError(Form(
"More than one object valid for run %d, version %d!",
429 validFileIds.SetOwner(1);
435 AliDebug(2, Form(
"List of files valid for run %d was loaded. Looking there for fileids valid for path %s!",
441 AliDebug(2, Form(
"List of files valid for run %d and version %d was not loaded. Looking directly into CDB for fileids valid for path %s!",
447 TString pattern =
".root";
448 TString optionQuery =
"-y -m";
450 pattern.Prepend(Form(
"_v%d_s0",selectedId.
GetVersion()));
454 TString folderCopy(Form(
"%s%s/Run",
fDBFolder.Data(),selectedId.
GetPath().Data()));
456 if (optionQuery.Contains(
"-y")){
457 AliInfo(
"Only latest version will be returned");
460 AliDebug(2,Form(
"** fDBFolder = %s, pattern = %s, filter = %s",folderCopy.Data(), pattern.Data(), filter.Data()));
461 TGridResult *
res = gGrid->Query(folderCopy, pattern, filter, optionQuery.Data());
463 for(
int i=0; i<res->GetEntries(); i++){
465 TString filename = res->GetKey(i,
"lfn");
466 if(filename ==
"")
continue;
468 validFileIds.AddLast(validFileId);
475 dataId =
GetId(validFileIds, selectedId);
487 TString errMessage(TString::Format(
"No valid CDB object found! request was: %s", queryId.
ToString().Data()));
490 AliError(Form(
"No file found matching this id!"));
491 throw std::runtime_error(errMessage.Data());
497 AliDebug(2,Form(
"Bad data ID encountered! Subnormal error!"));
499 throw std::runtime_error(errMessage.Data());
507 AliError(Form(
"Error getting CDB Entry from file"));
508 throw std::runtime_error(errMessage.Data());
519 AliDebug(2,Form(
"Opening file: %s",filename.Data()));
521 filename.Prepend(
"/alien");
524 TString option=
"READ";
528 TString origCache(TFile::GetCacheFileDir());
530 AliWarning(Form(
"Local cache folder has been overwritten!! fCacheFolder = %s origCache = %s",
536 option.Prepend(
"CACHE");
539 AliDebug(2, Form(
"Option: %s", option.Data()));
543 AliDebug(2,Form(
"Can't open file <%s>!", filename.Data()));
553 AliDebug(2,Form(
"Bad storage data: file does not contain an AliCDBEntry object!"));
567 AliWarning(Form(
"Mismatch between file name and object's Id!"));
580 file->Close();
delete file; file=0;
589 TList* result =
new TList();
593 validFileIds.SetOwner(1);
595 Bool_t alreadyLoaded = kFALSE;
601 AliDebug(2,Form(
"List of files valid for run %d and for path %s was loaded. Looking there!",
604 alreadyLoaded = kTRUE;
608 AliDebug(2,Form(
"List of files valid for run %d and for path %s was not loaded. Looking directly into CDB!",
616 TString pattern =
"Run*.root";
617 TString optionQuery =
"-y";
619 TString addFolder =
"";
620 if (!path.Contains(
"*")){
621 if (!path.BeginsWith(
"/")) addFolder +=
"/";
625 if (path.BeginsWith(
"/")) path.Remove(0,1);
626 if (path.EndsWith(
"/")) path.Remove(path.Length()-1,1);
627 TObjArray* tokenArr = path.Tokenize(
"/");
628 if (tokenArr->GetEntries() != 3) {
629 AliError(
"Not a 3 level path! Keeping old query...");
630 pattern.Prepend(path+
"/");
633 TString str0 = ((TObjString*)tokenArr->At(0))->String();
634 TString str1 = ((TObjString*)tokenArr->At(1))->String();
635 TString str2 = ((TObjString*)tokenArr->At(2))->String();
636 if (str0 !=
"*" && str1 !=
"*" && str2 ==
"*"){
638 addFolder =
"/"+str0+
"/"+str1;
640 else if (str0 !=
"*" && str1 ==
"*" && str2 ==
"*"){
642 addFolder =
"/"+str0;
644 else if (str0 ==
"*" && str1 ==
"*" && str2 ==
"*"){
650 pattern.Prepend(path+
"/");
653 delete tokenArr; tokenArr=0;
656 TString folderCopy(Form(
"%s%s",
fDBFolder.Data(),addFolder.Data()));
658 AliDebug(2,Form(
"fDBFolder = %s, pattern = %s, filter = %s",folderCopy.Data(), pattern.Data(), filter.Data()));
660 TGridResult *
res = gGrid->Query(folderCopy, pattern, filter, optionQuery.Data());
667 for(
int i=0; i<res->GetEntries(); i++){
669 TString filename = res->GetKey(i,
"lfn");
670 if(filename ==
"")
continue;
672 validFileIds.AddLast(validFileId);
681 iter =
new TIter(&validFileIds);
685 selectedIds.SetOwner(1);
693 while((anIdPtr = dynamic_cast<AliCDBId*> (iter->Next()))){
696 pathCopy = thisCDBPath;
706 dataId =
GetId(validFileIds, thisId);
708 if(dataId) selectedIds.Add(dataId);
715 iter =
new TIter(&selectedIds);
716 while((anIdPtr = dynamic_cast<AliCDBId*> (iter->Next()))){
719 AliDebug(2,Form(
"Bad data ID encountered! Subnormal error!"));
725 if(anEntry) result->Add(anEntry);
745 AliError(
"Bad ID encountered, cannot make a file name out of it!");
749 TString folderToTag = Form(
"%s%s",
751 id.GetPath().Data());
753 TDirectory* saveDir = gDirectory;
755 TString fullFilename = Form(
"/alien%s", filename.Data());
756 TString seMirrors(mirrors);
757 if(seMirrors.IsNull() || seMirrors.IsWhitespace()) seMirrors=
GetMirrorSEs();
762 TObjArray *arraySEs = seMirrors.Tokenize(
',');
763 Int_t nSEs = arraySEs->GetEntries();
764 Int_t remainingSEs = 1;
766 if (
fSE !=
"default") fullFilename += Form(
"?se=%s",
fSE.Data());
773 TFile *reopenedFile = 0;
775 TString targetSE(
"");
777 Bool_t result = kFALSE;
778 Bool_t reOpenResult = kFALSE;
779 Int_t reOpenAttempts=0;
780 while( !reOpenResult && reOpenAttempts<2 ) {
783 while( !file && remainingSEs>0 ) {
785 TObjString *target = (TObjString*) arraySEs->At(nSEs-remainingSEs);
786 targetSE=target->String();
787 if ( !(targetSE.BeginsWith(
"ALICE::") && targetSE.CountChar(
':')==4) ) {
788 AliError( Form(
"\"%s\" is an invalid storage element identifier.",targetSE.Data()) );
791 if ( fullFilename.Contains(
'?')) fullFilename.Remove(fullFilename.Last(
'?') );
792 fullFilename += Form(
"?se=%s",targetSE.Data());
794 Int_t remainingAttempts=
fNretry;
796 AliDebug(2, Form(
"Uploading file into SE #%d: %s",nSEs-remainingSEs+1,targetSE.Data()));
797 while(remainingAttempts > 0) {
798 AliDebug(2, Form(
"Uploading file into OCDB at %s - Attempt #%d",targetSE.Data(),
fNretry-remainingAttempts+1));
801 if(!file || !file->IsWritable()){
803 file->Close();
delete file; file=0;
805 TString message(TString::Format(
"Attempt %d failed.",
fNretry-remainingAttempts));
806 if(remainingAttempts>0) {
807 message +=
" Sleeping for "; message += nsleep; message +=
" seconds";
809 if(remainingSEs>0) message +=
" Trying to upload at next SE";
812 if(remainingAttempts>0) sleep(nsleep);
821 AliError(Form(
"All %d attempts have failed on all %d SEs. Returning...",
fNretry,nSEs));
831 result = (file->WriteTObject(entry,
"AliCDBEntry") != 0);
834 AliError(Form(
"Can't write entry to file <%s>!", filename.Data()));
836 AliDebug(2, Form(
"Reopening file %s for checking its correctness",fullFilename.Data()));
837 reopenedFile =
TFile::Open(fullFilename.Data(),
"READ");
839 reOpenResult = kFALSE;
840 AliInfo(Form(
"The file %s was closed successfully but cannot be reopened. Trying now to regenerate it (regeneration attempt number %d)",
841 fullFilename.Data(),++reOpenAttempts));
843 AliDebug(2, Form(
"Removing file %s", filename.Data()));
844 if(!gGrid->Rm(filename.Data()))
848 reOpenResult = kTRUE;
850 reopenedFile->Close();
851 delete reopenedFile; reopenedFile=0;
857 if (saveDir) saveDir->cd();
else gROOT->cd();
860 if(result && reOpenResult) {
863 AliInfo(Form(
"CDB tagging failed. Deleting file %s!",filename.Data()));
864 if(!gGrid->Rm(filename.Data()))
871 AliError(
"The file could not be opened or the object could not be written.");
872 if(!gGrid->Rm(filename.Data()))
877 AliInfo(Form(
"CDB object stored into file %s", filename.Data()));
879 AliInfo(Form(
"Storage Element: %s",
fSE.Data()));
881 AliInfo(Form(
"Storage Element: %s", targetSE.Data()));
884 for(Int_t i=0; i<nSEs; i++){
885 if(i==nSEs-remainingSEs-1)
continue;
886 TString mirrorCmd(
"mirror ");
887 mirrorCmd += filename;
889 TObjString *target = (TObjString*) arraySEs->At(i);
890 TString mirrorSE(target->String());
891 mirrorCmd += mirrorSE;
892 AliDebug(5,Form(
"mirror command: \"%s\"",mirrorCmd.Data()));
893 AliInfo(Form(
"Mirroring to storage element: %s", mirrorSE.Data()));
894 gGrid->Command(mirrorCmd.Data());
896 arraySEs->Delete(); arraySEs=0;
899 if ( !filename.BeginsWith(
"/alice/data") && !filename.BeginsWith(
"/alice/simulation/2008/v4-15-Release") ) {
900 AliError ( Form (
"Cannot upload to CVMFS OCDBs a non official CDB object: \"%s\"!", filename.Data() ) );
903 AliError( Form(
"Could not upload AliEn file \"%s\" to CVMFS OCDB!", filename.Data() ) );
905 reopenedFile->Close();
906 delete reopenedFile; reopenedFile=0;
917 TString cvmfsFilename( filename );
919 TString basename = ( cvmfsFilename( cvmfsFilename.Last(
'/' ) + 1, cvmfsFilename.Length() ) );
920 TString cvmfsDirname = cvmfsFilename.Remove( cvmfsFilename.Last(
'/' ), cvmfsFilename.Length() );
921 TRegexp threeLevelsRE(
"[^/]+/[^/]+/[^/]+$" );
922 TString threeLevels = cvmfsDirname( threeLevelsRE );
924 TRegexp re_RawFolder(
"^/alice/data/20[0-9]+/OCDB");
925 TRegexp re_MCFolder(
"^/alice/simulation/2008/v4-15-Release");
926 TString rawFolder = cvmfsDirname(re_RawFolder);
927 TString mcFolder = cvmfsDirname(re_MCFolder);
928 if ( !rawFolder.IsNull() ) {
929 cvmfsDirname.Replace(0, 6,
"/cvmfs/alice-ocdb.cern.ch/calibration");
930 }
else if ( !mcFolder.IsNull() ){
931 cvmfsDirname.Replace(0,36,
"/cvmfs/alice-ocdb.cern.ch/calibration/MC");
933 AliError(Form(
"OCDB folder set for an invalid OCDB storage:\n %s", cvmfsDirname.Data()));
937 AliDebug(3, Form(
"Publishing \"%s\" in \"%s\"", basename.Data(), cvmfsDirname.Data()));
942 TString firstLevel(threeLevels(0, threeLevels.First(
'/')));
943 TString tempDir(
"tmpToCvmfsOcdbs");
944 gSystem->Exec( Form(
"rm -r %s > /dev/null 2>&1", tempDir.Data()) );
945 Int_t result = gSystem->Exec( Form(
"mkdir -p %s/%s", tempDir.Data(), threeLevels.Data()) );
947 AliError ( Form (
"Could not create the directory \"%s/%s\"", tempDir.Data(), threeLevels.Data() ) );
950 cdbFile->Cp(Form(
"%s/%s/%s", tempDir.Data(), threeLevels.Data(), basename.Data() ));
951 TString tarFileName(
"cdbObjectToAdd.tar.gz");
952 TString cvmfsBaseFolder(cvmfsDirname(0, cvmfsDirname.Last(
'/')));
953 cvmfsBaseFolder = cvmfsBaseFolder(0, cvmfsBaseFolder.Last(
'/'));
954 cvmfsBaseFolder = cvmfsBaseFolder(0, cvmfsBaseFolder.Last(
'/'));
956 result = gSystem->Exec ( Form(
"tar --transform 's,^%s,%s,S' -cvzf %s %s", tempDir.Data(), cvmfsBaseFolder.Data(), tarFileName.Data(), tempDir.Data() ) );
958 AliError ( Form (
"Could not create the tarball for the object \"%s\"", filename.Data() ) );
963 result = gSystem->Exec( Form(
"ocdb-cvmfs %s", tarFileName.Data() ) );
965 AliError ( Form (
"Could not execute \"ocdb-cvmfs %s\"", filename.Data() ) );
970 gSystem->Exec( Form(
"rm -r %s", tempDir.Data() ) );
971 gSystem->Exec( Form(
"rm %s", tarFileName.Data() ) );
980 Bool_t result = kTRUE;
981 AliDebug(2, Form(
"adding %s tag to folder %s", tagname, folderToTag.Data()));
982 TString addTag = Form(
"addTag %s %s", folderToTag.Data(), tagname);
983 TGridResult *gridres = gGrid->Command(addTag.Data());
984 const char* resCode = gridres->GetKey(0,
"__result__");
985 if(resCode[0] !=
'1') {
986 AliError(Form(
"Couldn't add %s tags to folder %s !",
987 tagname, folderToTag.Data()));
999 TString dirname(filename);
1000 Int_t dirNumber = gGrid->Mkdir(dirname.Remove(dirname.Last(
'/')),
"-d");
1002 TString addTagValue1 = Form(
"addTagValue %s CDB ", filename.Data());
1003 TString addTagValue2 = Form(
"first_run=%d last_run=%d version=%d ",
1007 TString addTagValue3 = Form(
"path_level_0=\"%s\" path_level_1=\"%s\" path_level_2=\"%s\" ",
1009 id->GetPathLevel(1).Data(),
1010 id->GetPathLevel(2).Data());
1012 TString addTagValue4 = Form(
"version_path=\"%09d%s\" dir_number=%d",id->
GetVersion(),filename.Data(),dirNumber);
1013 TString addTagValue = Form(
"%s%s%s%s",
1014 addTagValue1.Data(),
1015 addTagValue2.Data(),
1016 addTagValue3.Data(),
1017 addTagValue4.Data());
1019 Bool_t result = kFALSE;
1020 AliDebug(2, Form(
"Tagging file. Tag command: %s", addTagValue.Data()));
1021 TGridResult*
res = gGrid->Command(addTagValue.Data());
1022 const char* resCode = res->GetKey(0,
"__result__");
1023 if(resCode[0] !=
'1') {
1024 AliError(Form(
"Couldn't add CDB tag value to file %s !",
1028 AliDebug(2,
"Object successfully tagged.");
1040 TString addTagValue = Form(
"addTagValue %s ShortLived_try value=%d", filename.Data(), value);
1042 Bool_t result = kFALSE;
1043 AliDebug(2, Form(
"Tagging file. Tag command: %s", addTagValue.Data()));
1044 TGridResult*
res = gGrid->Command(addTagValue.Data());
1045 const char* resCode = res->GetKey(0,
"__result__");
1046 if(resCode[0] !=
'1') {
1047 AliError(Form(
"Couldn't add ShortLived tag value to file %s !", filename.Data()));
1050 AliDebug(2,
"Object successfully tagged.");
1062 TString addTagValue1 = Form(
"addTagValue %s CDB_MD ", filename.Data());
1063 TString addTagValue2 = Form(
"object_classname=\"%s\" responsible=\"%s\" beam_period=%d ",
1067 TString addTagValue3 = Form(
"aliroot_version=\"%s\" comment=\"%s\"",
1070 TString addTagValue = Form(
"%s%s%s",
1071 addTagValue1.Data(),
1072 addTagValue2.Data(),
1073 addTagValue3.Data());
1075 Bool_t result = kFALSE;
1076 AliDebug(2, Form(
"Tagging file. Tag command: %s", addTagValue.Data()));
1077 TGridResult*
res = gGrid->Command(addTagValue.Data());
1078 const char* resCode = res->GetKey(0,
"__result__");
1079 if(resCode[0] !=
'1') {
1080 AliWarning(Form(
"Couldn't add CDB_MD tag value to file %s !",
1084 AliDebug(2,
"Object successfully tagged.");
1093 TString turl(fileName);
1095 turl +=
"?se="; turl +=
fSE.Data();
1098 AliError(Form(
"Can't open selection file <%s>!", turl.Data()));
1102 TList *list =
new TList();
1110 keycycle =
"AliCDBId;";
1113 id = (
AliCDBId*) file->Get(keycycle);
1117 file->Close();
delete file; file=0;
1128 TString initDir(gGrid->Pwd(0));
1131 Bool_t result=kFALSE;
1132 if (gGrid->Cd(dirName,0)) result=kTRUE;
1133 gGrid->Cd(initDir.Data(),0);
1150 TString pattern =
"Run*";
1151 TString optionQuery =
"-y";
1154 AliInfoF(
"Returning only latest versions as they were at %s UTC", TTimeStamp(
fMaxDate).AsString(
"s"));
1157 pattern += Form(
"_v%d_s0",
fVersion);
1161 AliDebug(2,Form(
"pattern: %s", pattern.Data()));
1163 TString addFolder =
"";
1164 if (!path.Contains(
"*")){
1165 if (!path.BeginsWith(
"/")) addFolder +=
"/";
1169 if (path.BeginsWith(
"/")) path.Remove(0,1);
1170 if (path.EndsWith(
"/")) path.Remove(path.Length()-1,1);
1171 TObjArray* tokenArr = path.Tokenize(
"/");
1172 if (tokenArr->GetEntries() != 3) {
1173 AliError(
"Not a 3 level path! Keeping old query...");
1174 pattern.Prepend(path+
"/");
1177 TString str0 = ((TObjString*)tokenArr->At(0))->String();
1178 TString str1 = ((TObjString*)tokenArr->At(1))->String();
1179 TString str2 = ((TObjString*)tokenArr->At(2))->String();
1180 if (str0 !=
"*" && str1 !=
"*" && str2 ==
"*"){
1182 addFolder =
"/"+str0+
"/"+str1;
1184 else if (str0 !=
"*" && str1 ==
"*" && str2 ==
"*"){
1186 addFolder =
"/"+str0;
1188 else if (str0 ==
"*" && str1 ==
"*" && str2 ==
"*"){
1194 pattern.Prepend(path+
"/");
1197 delete tokenArr; tokenArr=0;
1200 TString folderCopy(Form(
"%s%s",
fDBFolder.Data(),addFolder.Data()));
1202 AliDebug(2,Form(
"fDBFolder = %s, pattern = %s, filter = %s",folderCopy.Data(), pattern.Data(), filter.Data()));
1204 if (optionQuery ==
"-y"){
1205 AliInfo(
"Only latest version will be returned");
1208 TGridResult *
res = gGrid->Query(folderCopy, pattern, filter, optionQuery.Data());
1217 while ((map = (TMap*)next())) {
1219 if ((entry = (TObjString *)(map->GetValue(
"lfn")))) {
1220 TString& filename = entry->String();
1221 if(filename.IsNull())
continue;
1222 AliDebug(2,Form(
"Found valid file: %s", filename.Data()));
1230 TObjString *o_guid = (TObjString *)map->GetValue(
"guid");
1231 if (!o_guid)
AliFatal(
"guid not found in AliEn find query result!");
1233 AliDebugF(3,
"Apply time filter: skip file %s", filename.Data());
1240 while (( curId = (
AliCDBId *)iterIds() )) {
1272 result = Form(
"CDB:first_run<=%d and CDB:last_run>=%d", firstRun, lastRun);
1292 result += Form(
" and CDB_MD:responsible=\"%s\"", md->
GetResponsible());
1295 result += Form(
" and CDB_MD:beam_period=%d", md->
GetBeamPeriod());
1301 result += Form(
" and CDB_MD:comment=\"%s\"", md->
GetComment());
1304 AliDebug(2, Form(
"filter: %s",result.Data()));
1321 TRegexp gridPattern(
"^alien://.+$");
1323 return TString(gridString).Contains(gridPattern);
1330 if (!Validate(gridString)) {
1334 TString buffer(gridString);
1336 TString gridUrl =
"alien://";
1338 TString dbFolder =
"";
1339 TString se =
"default";
1340 TString cacheFolder =
"";
1341 Bool_t operateDisconnected = kTRUE;
1342 Long64_t cacheSize = (UInt_t) 1024*1024*1024;
1343 Long_t cleanupInterval = 0;
1347 TObjString *str = 0;
1349 while((str = (TObjString*) iter.Next())){
1350 TString entry(str->String());
1351 Int_t indeq = entry.Index(
'=');
1353 if(entry.BeginsWith(
"alien://")) {
1357 AliError(Form(
"Invalid entry! %s",entry.Data()));
1362 TString key = entry(0,indeq);
1363 TString value = entry(indeq+1,entry.Length()-indeq);
1365 if(key.Contains(
"grid",TString::kIgnoreCase)) {
1368 else if (key.Contains(
"user",TString::kIgnoreCase)){
1371 else if (key.Contains(
"se",TString::kIgnoreCase)){
1374 else if (key.Contains(
"cacheF",TString::kIgnoreCase)){
1375 cacheFolder = value;
1376 if (!cacheFolder.IsNull() && !cacheFolder.EndsWith(
"/"))
1379 else if (key.Contains(
"folder",TString::kIgnoreCase)){
1382 else if (key.Contains(
"operateDisc",TString::kIgnoreCase)){
1383 if(value ==
"kTRUE") {
1384 operateDisconnected = kTRUE;
1385 }
else if (value ==
"kFALSE") {
1386 operateDisconnected = kFALSE;
1387 }
else if (value ==
"0" || value ==
"1") {
1388 operateDisconnected = (Bool_t) value.Atoi();
1390 AliError(Form(
"Invalid entry! %s",entry.Data()));
1394 else if (key.Contains(
"cacheS",TString::kIgnoreCase)){
1395 if(value.IsDigit()) {
1396 cacheSize = value.Atoi();
1398 AliError(Form(
"Invalid entry! %s",entry.Data()));
1402 else if (key.Contains(
"cleanupInt",TString::kIgnoreCase)){
1403 if(value.IsDigit()) {
1404 cleanupInterval = value.Atoi();
1406 AliError(Form(
"Invalid entry! %s",entry.Data()));
1411 AliError(Form(
"Invalid entry! %s",entry.Data()));
1417 AliDebug(2, Form(
"gridUrl: %s", gridUrl.Data()));
1418 AliDebug(2, Form(
"user: %s", user.Data()));
1419 AliDebug(2, Form(
"dbFolder: %s", dbFolder.Data()));
1420 AliDebug(2, Form(
"s.e.: %s", se.Data()));
1421 AliDebug(2, Form(
"local cache folder: %s", cacheFolder.Data()));
1422 AliDebug(2, Form(
"local cache operate disconnected: %d", operateDisconnected));
1423 AliDebug(2, Form(
"local cache size: %lld", cacheSize));
1424 AliDebug(2, Form(
"local cache cleanup interval: %ld", cleanupInterval));
1427 AliError(
"The CDB base folder must be specified by preceding it with the \"folder=\" key!");
1428 AliError(
"Example: \"alien://folder=/alice/data/2015/OCDB\"");
1433 dbFolder.Data(), se.Data(), cacheFolder.Data(),
1434 operateDisconnected, cacheSize, cleanupInterval);
1442 if (AliCDBGridParam::Class() == param->IsA()) {
1448 gridParam->
GetSE().Data(),
1456 if(!gGrid && grid) {
1457 delete grid; grid=0;
1490 const char* se,
const char* cacheFolder, Bool_t operateDisconnected,
1491 Long64_t cacheSize, Long_t cleanupInterval):
1506 TString uri = Form(
"%s?User=%s?DBFolder=%s?SE=%s?CacheFolder=%s" 1507 "?OperateDisconnected=%d?CacheSize=%lld?CleanupInterval=%ld",
1545 if (AliCDBGridParam::Class() != obj->IsA()) {
1554 if(
fSE != other->
fSE)
return kFALSE;
void SetURI(const char *uri)
virtual TList * GetEntries(const AliCDBId &queryId)
TFile * Open(const char *filename, Long64_t &nevents)
const TString & GetPath() const
void SetVersion(Int_t version)
Bool_t Comprises(const AliCDBPath &other) const
const TString & GetSE() const
time_t GuidToCreationTimestamp(const TString &guid) const
static Bool_t GetForbidGRPOverride()
Bool_t Overlaps(const AliCDBRunRange &other) const
void SetSubVersion(Int_t subVersion)
AliCDBEntry * GetEntryFromFile(TString &filename, AliCDBId *dataId)
virtual AliCDBParam * CloneParam() const
const AliCDBPath & GetAliCDBPath() const
Short_t fInitRetrySeconds
virtual Bool_t IsEqual(const TObject *obj) const
Bool_t FilenameToId(TString &filename, AliCDBId &id)
#define AliInfoF(message,...)
const AliCDBRunRange & GetAliCDBRunRange() const
TString fileName(const char *dir, int runNumber, const char *da, int i, const char *type)
#define AliWarning(message)
virtual Bool_t Contains(const char *path) const
Long64_t GetCacheSize() const
Bool_t fOperateDisconnected
virtual ~AliCDBGridParam()
virtual TList * GetIdListFromFile(const char *fileName)
virtual void QueryValidFiles()
Bool_t TagFileId(TString &filename, const AliCDBId *id)
void SetVersion(Int_t version)
virtual Bool_t IsEqual(const TObject *obj) const
const TString & GridUrl() const
const TString & GetUser() const
void GetSelection(AliCDBId *id)
virtual AliCDBEntry * GetEntry(const AliCDBId &queryId)
Int_t GetFirstRun() const
const TString GetPathLevel(Int_t i) const
#define AliFatal(message)
Bool_t IsAnyRange() const
Long_t GetCleanupInterval() const
void MakeQueryFilter(Int_t firstRun, Int_t lastRun, const AliCDBMetaData *md, TString &result) const
const TString & GetCacheFolder() const
Bool_t PutInCvmfs(TString &fullFilename, TFile *cdbFile) const
void LoadTreeFromFile(AliCDBEntry *entry) const
#define AliDebug(logLevel, message)
AliCDBMetaData * GetMetaData()
void SetType(const char *type)
Bool_t HasVersion() const
Bool_t TagFileMetaData(TString &filename, const AliCDBMetaData *md)
virtual Bool_t IsEqual(const TObject *obj) const
virtual Bool_t IdToFilename(const AliCDBId &id, TString &filename) const
Bool_t TagShortLived(TString &filename, Bool_t value)
virtual const char * GetMirrorSEs() const
void SetLastStorage(TString lastStorage)
AliCDBId * GetId(const TObjArray &validFileIds, const AliCDBId &query)
const TString & GetPath() const
virtual AliCDBParam * CreateParameter(const char *gridString)
Bool_t PrepareId(AliCDBId &id)
virtual Bool_t PutEntry(AliCDBEntry *entry, const char *mirrors="")
virtual void SetRetry(Int_t nretry, Int_t initsec)
#define AliError(message)
virtual AliCDBId * GetEntryId(const AliCDBId &queryId)
static AliCDBManager * Instance(TMap *entryCache=NULL, Int_t run=-1)
Bool_t AddTag(TString &foldername, const char *tagname)
#define AliDebugF(logLevel, format,...)
AliCDBMetaData * fMetaDataFilter
Bool_t fOperateDisconnected
Short_t fNretry
Local, Grid: base folder name - Dump: file name.
Int_t GetFirstRun() const
AliCDBGrid(const char *gridUrl, const char *user, const char *dbFolder, const char *se, const char *cacheFolder, Bool_t operateDisconnected, Long64_t cacheSize, Long_t cleanupInterval)
virtual AliCDBStorage * Create(const AliCDBParam *param)
virtual ULong_t Hash() const
Bool_t GetOperateDisconnected() const
const TString & GetDBFolder() const
Int_t GetSubVersion() const