+//_____________________________________________________________________________
+Int_t AliCDBGrid::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 = 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;
+ Int_t version = dataId->GetVersion();
+ delete dataId;
+ return version;
+
+ }
+ // 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));
+
+ TObjArray validFileIds;
+ validFileIds.SetOwner(1);
+
+ TString filter;
+ MakeQueryFilter(run, run, 0, filter);
+
+ TString pattern = Form("%s/Run*.root", path);
+ AliDebug(2,Form("pattern: %s", pattern.Data()));
+
+ TGridResult *res = gGrid->Query(fDBFolder, pattern, 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;
+
+ Int_t version = dataId->GetVersion();
+ delete dataId;
+ return version;
+
+}
+
+//_____________________________________________________________________________
+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;
+}
+
+