]>
Commit | Line | Data |
---|---|---|
9e1ceb13 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
15 | ||
16 | ///////////////////////////////////////////////////////////////////////////////////////////////// | |
17 | // // | |
18 | // AliCDBGrid // | |
19 | // access class to a DataBase in an AliEn storage // | |
20 | // // | |
21 | ///////////////////////////////////////////////////////////////////////////////////////////////// | |
22 | ||
23 | ||
24 | #include <TGrid.h> | |
25 | #include <TGridResult.h> | |
26 | #include <TFile.h> | |
6dc56e97 | 27 | #include <TKey.h> |
9e1ceb13 | 28 | #include <TROOT.h> |
4667c116 | 29 | #include <TList.h> |
9e1ceb13 | 30 | #include <TObjArray.h> |
31 | #include <TObjString.h> | |
32 | #include <TRegexp.h> | |
33 | ||
34 | #include "AliLog.h" | |
fdf65bb5 | 35 | #include "AliCDBEntry.h" |
9e1ceb13 | 36 | #include "AliCDBGrid.h" |
4667c116 | 37 | #include "AliCDBManager.h" |
9e1ceb13 | 38 | |
39 | ||
40 | ClassImp(AliCDBGrid) | |
41 | ||
42 | //_____________________________________________________________________________ | |
c75fabed | 43 | AliCDBGrid::AliCDBGrid(const char *gridUrl, const char *user, const char *dbFolder, |
44 | const char *se, const char* cacheFolder, Bool_t operateDisconnected, | |
45 | Long64_t cacheSize, Long_t cleanupInterval) : | |
9e1ceb13 | 46 | AliCDBStorage(), |
b05400be | 47 | fGridUrl(gridUrl), |
9e1ceb13 | 48 | fUser(user), |
b05400be | 49 | fDBFolder(dbFolder), |
c75fabed | 50 | fSE(se), |
51 | fCacheFolder(cacheFolder), | |
52 | fOperateDisconnected(operateDisconnected), | |
53 | fCacheSize(cacheSize), | |
54 | fCleanupInterval(cleanupInterval) | |
9e1ceb13 | 55 | { |
56 | // constructor // | |
57 | ||
9e1ceb13 | 58 | // if the same Grid is alreay active, skip connection |
4667c116 | 59 | if (!gGrid || fGridUrl != gGrid->GridUrl() |
024cf675 | 60 | || (( fUser != "" ) && ( fUser != gGrid->GetUser() )) ) { |
9e1ceb13 | 61 | // connection to the Grid |
62032124 | 62 | AliInfo("Connection to the Grid..."); |
024cf675 | 63 | if(gGrid){ |
64 | AliInfo(Form("gGrid = %x; fGridUrl = %s; gGrid->GridUrl() = %s",gGrid,fGridUrl.Data(), gGrid->GridUrl())); | |
65 | AliInfo(Form("fUser = %s; gGrid->GetUser() = %s",fUser.Data(), gGrid->GetUser())); | |
66 | } | |
b05400be | 67 | TGrid::Connect(fGridUrl.Data(),fUser.Data()); |
9e1ceb13 | 68 | } |
69 | ||
70 | if(!gGrid) { | |
71 | AliError("Connection failed!"); | |
72 | return; | |
73 | } | |
74 | ||
75 | TString initDir(gGrid->Pwd(0)); | |
b05400be | 76 | if (fDBFolder[0] != '/') { |
77 | fDBFolder.Prepend(initDir); | |
9e1ceb13 | 78 | } |
79 | ||
80 | // check DBFolder: trying to cd to DBFolder; if it does not exist, create it | |
b05400be | 81 | if(!gGrid->Cd(fDBFolder.Data(),0)){ |
82 | AliDebug(2,Form("Creating new folder <%s> ...",fDBFolder.Data())); | |
83 | if(!gGrid->Mkdir(fDBFolder.Data(),"",0)){ | |
4667c116 | 84 | AliError(Form("Cannot create folder <%s> !",fDBFolder.Data())); |
9e1ceb13 | 85 | } |
86 | } else { | |
b05400be | 87 | AliDebug(2,Form("Folder <%s> found",fDBFolder.Data())); |
9e1ceb13 | 88 | } |
89 | ||
90 | // removes any '/' at the end of path, then append one '/' | |
b05400be | 91 | while(fDBFolder.EndsWith("/")) fDBFolder.Remove(fDBFolder.Last('/')); |
92 | fDBFolder+="/"; | |
9e1ceb13 | 93 | |
62032124 | 94 | fType="alien"; |
95 | fBaseFolder = fDBFolder; | |
96 | ||
c75fabed | 97 | // Setting the cache |
98 | ||
99 | // Check if local cache folder is already defined | |
100 | TString origCache(TFile::GetCacheFileDir()); | |
101 | if(fCacheFolder.Length() > 0) { | |
102 | if(origCache.Length() == 0) { | |
103 | AliInfo(Form("Setting local cache to: %s", fCacheFolder.Data())); | |
104 | } else if(fCacheFolder != origCache) { | |
105 | AliWarning(Form("Local cache folder was already defined, changing it to: %s", | |
106 | fCacheFolder.Data())); | |
107 | } | |
108 | ||
109 | // default settings are: operateDisconnected=kTRUE, forceCacheread = kFALSE | |
110 | if(!TFile::SetCacheFileDir(fCacheFolder.Data(), fOperateDisconnected)) { | |
111 | AliError(Form("Could not set cache folder %s !", fCacheFolder.Data())); | |
112 | fCacheFolder = ""; | |
113 | } else { | |
114 | // reset fCacheFolder because the function may have | |
115 | // slightly changed the folder name (e.g. '/' added) | |
116 | fCacheFolder = TFile::GetCacheFileDir(); | |
117 | } | |
118 | ||
119 | // default settings are: cacheSize=1GB, cleanupInterval = 0 | |
120 | if(!TFile::ShrinkCacheFileDir(fCacheSize, fCleanupInterval)) { | |
121 | AliError(Form("Could not set following values " | |
122 | "to ShrinkCacheFileDir: cacheSize = %d, cleanupInterval = %d !", | |
123 | fCacheSize, fCleanupInterval)); | |
124 | } | |
125 | } | |
126 | ||
9e1ceb13 | 127 | // return to the initial directory |
128 | gGrid->Cd(initDir.Data(),0); | |
129 | } | |
130 | ||
131 | //_____________________________________________________________________________ | |
132 | AliCDBGrid::~AliCDBGrid() | |
133 | { | |
134 | // destructor | |
62032124 | 135 | delete gGrid; gGrid=0; |
9e1ceb13 | 136 | |
137 | } | |
138 | ||
139 | //_____________________________________________________________________________ | |
62032124 | 140 | Bool_t AliCDBGrid::FilenameToId(TString& filename, AliCDBId& id) { |
4005d0b5 | 141 | // build AliCDBId from full path filename (fDBFolder/path/Run#x_#y_v#z_s0.root) |
62032124 | 142 | |
143 | if(filename.Contains(fDBFolder)){ | |
144 | filename = filename(fDBFolder.Length(),filename.Length()-fDBFolder.Length()); | |
145 | } | |
146 | ||
147 | TString idPath = filename(0,filename.Last('/')); | |
148 | id.SetPath(idPath); | |
149 | if(!id.IsValid()) return kFALSE; | |
150 | ||
151 | filename=filename(idPath.Length()+1,filename.Length()-idPath.Length()); | |
9e1ceb13 | 152 | |
153 | Ssiz_t mSize; | |
4005d0b5 | 154 | // valid filename: Run#firstRun_#lastRun_v#version_s0.root |
155 | TRegexp keyPattern("^Run[0-9]+_[0-9]+_v[0-9]+_s0.root$"); | |
9e1ceb13 | 156 | keyPattern.Index(filename, &mSize); |
157 | if (!mSize) { | |
4005d0b5 | 158 | |
159 | // TODO backward compatibility ... maybe remove later! | |
160 | Ssiz_t oldmSize; | |
161 | TRegexp oldKeyPattern("^Run[0-9]+_[0-9]+_v[0-9]+.root$"); | |
162 | oldKeyPattern.Index(filename, &oldmSize); | |
163 | if(!oldmSize) { | |
164 | AliDebug(2,Form("Bad filename <%s>.", filename.Data())); | |
165 | return kFALSE; | |
166 | } else { | |
167 | AliDebug(2,Form("Old filename format <%s>.", filename.Data())); | |
168 | id.SetSubVersion(-11); // TODO trick to ensure backward compatibility | |
169 | } | |
170 | ||
171 | } else { | |
172 | id.SetSubVersion(-1); // TODO trick to ensure backward compatibility | |
173 | } | |
9e1ceb13 | 174 | |
62032124 | 175 | filename.Resize(filename.Length() - sizeof(".root") + 1); |
9e1ceb13 | 176 | |
62032124 | 177 | TObjArray* strArray = (TObjArray*) filename.Tokenize("_"); |
9e1ceb13 | 178 | |
179 | TString firstRunString(((TObjString*) strArray->At(0))->GetString()); | |
62032124 | 180 | id.SetFirstRun(atoi(firstRunString.Data() + 3)); |
181 | id.SetLastRun(atoi(((TObjString*) strArray->At(1))->GetString())); | |
182 | ||
9e1ceb13 | 183 | TString verString(((TObjString*) strArray->At(2))->GetString()); |
62032124 | 184 | id.SetVersion(atoi(verString.Data() + 1)); |
9e1ceb13 | 185 | |
186 | delete strArray; | |
187 | ||
188 | return kTRUE; | |
189 | } | |
190 | ||
191 | //_____________________________________________________________________________ | |
c3a7b59a | 192 | Bool_t AliCDBGrid::IdToFilename(const AliCDBId& id, TString& filename) const { |
62032124 | 193 | // build file name from AliCDBId (path, run range, version) and fDBFolder |
9e1ceb13 | 194 | |
62032124 | 195 | if (!id.GetAliCDBRunRange().IsValid()) { |
196 | AliDebug(2,Form("Invalid run range <%d, %d>.", | |
197 | id.GetFirstRun(), id.GetLastRun())); | |
9e1ceb13 | 198 | return kFALSE; |
199 | } | |
200 | ||
62032124 | 201 | if (id.GetVersion() < 0) { |
202 | AliDebug(2,Form("Invalid version <%d>.", id.GetVersion())); | |
9e1ceb13 | 203 | return kFALSE; |
204 | } | |
62032124 | 205 | |
4005d0b5 | 206 | filename = Form("Run%d_%d_v%d", |
62032124 | 207 | id.GetFirstRun(), |
208 | id.GetLastRun(), | |
209 | id.GetVersion()); | |
210 | ||
4005d0b5 | 211 | if (id.GetSubVersion() != -11) filename += "_s0"; // TODO to ensure backward compatibility |
212 | filename += ".root"; | |
213 | ||
62032124 | 214 | filename.Prepend(fDBFolder + id.GetPath() + '/'); |
9e1ceb13 | 215 | |
216 | return kTRUE; | |
217 | } | |
218 | ||
219 | //_____________________________________________________________________________ | |
220 | Bool_t AliCDBGrid::PrepareId(AliCDBId& id) { | |
221 | // prepare id (version) of the object that will be stored (called by PutEntry) | |
222 | ||
223 | TString initDir(gGrid->Pwd(0)); | |
9e1ceb13 | 224 | |
b05400be | 225 | TString dirName(fDBFolder); |
9e1ceb13 | 226 | |
227 | Bool_t dirExist=kFALSE; | |
4005d0b5 | 228 | |
4667c116 | 229 | |
230 | ||
9e1ceb13 | 231 | // go to the path; if directory does not exist, create it |
4667c116 | 232 | for(int i=0;i<3;i++){ |
233 | dirName+=Form("%s/",id.GetPathLevel(i).Data()); | |
9e1ceb13 | 234 | dirExist=gGrid->Cd(dirName,0); |
235 | if (!dirExist) { | |
b05400be | 236 | AliDebug(2,Form("Creating new folder <%s> ...",dirName.Data())); |
9e1ceb13 | 237 | if(!gGrid->Mkdir(dirName,"",0)){ |
238 | AliError(Form("Cannot create directory <%s> !",dirName.Data())); | |
239 | gGrid->Cd(initDir.Data()); | |
240 | return kFALSE; | |
241 | } | |
4667c116 | 242 | |
243 | // if folders are new add tags to them | |
244 | if(i == 1) { | |
245 | // TODO Currently disabled | |
c75fabed | 246 | // add short lived tag! |
4667c116 | 247 | // AliInfo("Tagging level 1 folder with \"ShortLived\" tag"); |
248 | // if(!AddTag(dirName,"ShortLived_try")){ | |
249 | // AliError(Form("Could not tag folder %s !", dirName.Data())); | |
250 | // if(!gGrid->Rmdir(dirName.Data())){ | |
251 | // AliError(Form("Unexpected: could not remove %s directory!", dirName.Data())); | |
252 | // } | |
253 | // return 0; | |
254 | //} | |
255 | ||
256 | } else if(i == 2) { | |
c75fabed | 257 | AliDebug(2,"Tagging level 2 folder with \"CDB\" and \"CDB_MD\" tag"); |
4667c116 | 258 | if(!AddTag(dirName,"CDB")){ |
259 | AliError(Form("Could not tag folder %s !", dirName.Data())); | |
260 | if(!gGrid->Rmdir(dirName.Data())){ | |
261 | AliError(Form("Unexpected: could not remove %s directory!", dirName.Data())); | |
262 | } | |
263 | return 0; | |
264 | } | |
265 | if(!AddTag(dirName,"CDB_MD")){ | |
266 | AliError(Form("Could not tag folder %s !", dirName.Data())); | |
267 | if(!gGrid->Rmdir(dirName.Data())){ | |
268 | AliError(Form("Unexpected: could not remove %s directory!", dirName.Data())); | |
269 | } | |
270 | return 0; | |
271 | } | |
272 | ||
4667c116 | 273 | // TODO Currently disabled |
c75fabed | 274 | // add short lived tag! |
4667c116 | 275 | // TString path=id.GetPath(); |
276 | // if(AliCDBManager::Instance()->IsShortLived(path.Data())) { | |
277 | // AliInfo(Form("Tagging %s as short lived", dirName.Data())); | |
278 | // if(!TagShortLived(dirName, kTRUE)){ | |
279 | // AliError(Form("Could not tag folder %s !", dirName.Data())); | |
280 | // if(!gGrid->Rmdir(dirName.Data())){ | |
281 | // AliError(Form("Unexpected: could not remove %s directory!", dirName.Data())); | |
282 | // } | |
283 | // return 0; | |
284 | // } | |
285 | // } else { | |
286 | // AliInfo(Form("Tagging %s as long lived", dirName.Data())); | |
287 | // if(!TagShortLived(dirName, kFALSE)){ | |
288 | // AliError(Form("Could not tag folder %s !", dirName.Data())); | |
289 | // if(!gGrid->Rmdir(dirName.Data())){ | |
290 | // AliError(Form("Unexpected: could not remove %s directory!", dirName.Data())); | |
291 | // } | |
292 | // return 0; | |
293 | // } | |
294 | // } | |
295 | } | |
9e1ceb13 | 296 | } |
297 | } | |
9e1ceb13 | 298 | gGrid->Cd(initDir,0); |
299 | ||
62032124 | 300 | TString filename; |
301 | AliCDBId anId; // the id got from filename | |
9e1ceb13 | 302 | AliCDBRunRange lastRunRange(-1,-1); // highest runRange found |
9e1ceb13 | 303 | Int_t lastVersion=0; // highest version found |
304 | ||
305 | TGridResult *res = gGrid->Ls(dirName); | |
306 | ||
307 | //loop on the files in the directory, look for highest version | |
308 | for(int i=0; i < res->GetEntries(); i++){ | |
62032124 | 309 | filename=res->GetFileNamePath(i); |
310 | if (!FilenameToId(filename, anId)) continue; | |
311 | if (anId.GetAliCDBRunRange().Overlaps(id.GetAliCDBRunRange()) && anId.GetVersion() > lastVersion) { | |
312 | lastVersion = anId.GetVersion(); | |
313 | lastRunRange = anId.GetAliCDBRunRange(); | |
9e1ceb13 | 314 | } |
315 | ||
316 | } | |
4005d0b5 | 317 | delete res; |
318 | ||
9e1ceb13 | 319 | id.SetVersion(lastVersion + 1); |
4005d0b5 | 320 | id.SetSubVersion(0); |
9e1ceb13 | 321 | |
322 | TString lastStorage = id.GetLastStorage(); | |
323 | if(lastStorage.Contains(TString("new"), TString::kIgnoreCase) && id.GetVersion() > 1 ){ | |
84090f85 | 324 | AliDebug(2, Form("A NEW object is being stored with version %d", |
9e1ceb13 | 325 | id.GetVersion())); |
84090f85 | 326 | AliDebug(2, Form("and it will hide previously stored object with version %d!", |
9e1ceb13 | 327 | id.GetVersion()-1)); |
328 | } | |
329 | ||
4005d0b5 | 330 | if(!lastRunRange.IsAnyRange() && !(lastRunRange.IsEqual(&id.GetAliCDBRunRange()))) |
9e1ceb13 | 331 | AliWarning(Form("Run range modified w.r.t. previous version (Run%d_%d_v%d)", |
332 | lastRunRange.GetFirstRun(), lastRunRange.GetLastRun(), id.GetVersion())); | |
4005d0b5 | 333 | |
9e1ceb13 | 334 | return kTRUE; |
335 | } | |
336 | ||
337 | //_____________________________________________________________________________ | |
6dc56e97 | 338 | AliCDBId* AliCDBGrid::GetId(const TObjArray& validFileIds, const AliCDBId& query) { |
62032124 | 339 | // look for the Id that matches query's requests (highest or exact version) |
9e1ceb13 | 340 | |
6dc56e97 | 341 | if(validFileIds.GetEntriesFast() < 1) { |
62032124 | 342 | return NULL; |
6dc56e97 | 343 | } else if (validFileIds.GetEntriesFast() == 1) { |
4667c116 | 344 | return dynamic_cast<AliCDBId*> (validFileIds.At(0)->Clone()); |
62032124 | 345 | } |
9e1ceb13 | 346 | |
62032124 | 347 | TIter iter(&validFileIds); |
9e1ceb13 | 348 | |
62032124 | 349 | AliCDBId *anIdPtr=0; |
350 | AliCDBId* result=0; | |
9e1ceb13 | 351 | |
62032124 | 352 | while((anIdPtr = dynamic_cast<AliCDBId*> (iter.Next()))){ |
62032124 | 353 | if(anIdPtr->GetPath() != query.GetPath()) continue; |
354 | ||
355 | //if(!CheckVersion(query, anIdPtr, result)) return NULL; | |
9e1ceb13 | 356 | |
357 | if (!query.HasVersion()){ // look for highest version | |
62032124 | 358 | if(result && result->GetVersion() > anIdPtr->GetVersion()) continue; |
359 | if(result && result->GetVersion() == anIdPtr->GetVersion()) { | |
4667c116 | 360 | AliError(Form("More than one object valid for run %d, version %d!", |
62032124 | 361 | query.GetFirstRun(), anIdPtr->GetVersion())); |
362 | return NULL; | |
9e1ceb13 | 363 | } |
62032124 | 364 | result = anIdPtr; |
9e1ceb13 | 365 | } else { // look for specified version |
62032124 | 366 | if(query.GetVersion() != anIdPtr->GetVersion()) continue; |
367 | if(result && result->GetVersion() == anIdPtr->GetVersion()){ | |
4667c116 | 368 | AliError(Form("More than one object valid for run %d, version %d!", |
62032124 | 369 | query.GetFirstRun(), anIdPtr->GetVersion())); |
370 | return NULL; | |
9e1ceb13 | 371 | } |
62032124 | 372 | result = anIdPtr; |
9e1ceb13 | 373 | } |
62032124 | 374 | |
375 | } | |
c75fabed | 376 | |
377 | if (!result) return NULL; | |
62032124 | 378 | |
4667c116 | 379 | return dynamic_cast<AliCDBId*> (result->Clone()); |
62032124 | 380 | } |
381 | ||
9e1ceb13 | 382 | //_____________________________________________________________________________ |
4667c116 | 383 | AliCDBId* AliCDBGrid::GetEntryId(const AliCDBId& queryId) { |
384 | // get AliCDBId from the database | |
385 | // User must delete returned object | |
9e1ceb13 | 386 | |
62032124 | 387 | AliCDBId* dataId=0; |
388 | ||
389 | AliCDBId selectedId(queryId); | |
390 | if (!selectedId.HasVersion()) { | |
9e1ceb13 | 391 | // if version is not specified, first check the selection criteria list |
4b5e0dce | 392 | GetSelection(&selectedId); |
62032124 | 393 | } |
394 | ||
6dc56e97 | 395 | TObjArray validFileIds; |
62032124 | 396 | validFileIds.SetOwner(1); |
397 | ||
398 | // look for file matching query requests (path, runRange, version) | |
399 | if(selectedId.GetFirstRun() == fRun && | |
c3a7b59a | 400 | fPathFilter.Comprises(selectedId.GetAliCDBPath()) && fVersion < 0 && !fMetaDataFilter){ |
62032124 | 401 | // look into list of valid files previously loaded with AliCDBStorage::FillValidFileIds() |
402 | AliDebug(2, Form("List of files valid for run %d and for path %s was loaded. Looking there!", | |
403 | selectedId.GetFirstRun(), selectedId.GetPath().Data())); | |
404 | dataId = GetId(fValidFileIds, selectedId); | |
405 | ||
9e1ceb13 | 406 | } else { |
62032124 | 407 | // List of files valid for reqested run was not loaded. Looking directly into CDB |
408 | AliDebug(2, Form("List of files valid for run %d and for path %s was not loaded. Looking directly into CDB!", | |
409 | selectedId.GetFirstRun(), selectedId.GetPath().Data())); | |
410 | ||
411 | TString filter; | |
6dc56e97 | 412 | MakeQueryFilter(selectedId.GetFirstRun(), selectedId.GetLastRun(), 0, filter); |
62032124 | 413 | |
6dc56e97 | 414 | TString pattern = Form("%s/Run*", selectedId.GetPath().Data()); |
4005d0b5 | 415 | if(selectedId.GetVersion() >= 0) pattern += Form("_v%d*",selectedId.GetVersion()); |
6dc56e97 | 416 | pattern += ".root"; |
417 | AliDebug(2,Form("pattern: %s", pattern.Data())); | |
418 | ||
419 | TGridResult *res = gGrid->Query(fDBFolder, pattern, filter, ""); | |
62032124 | 420 | AliCDBId validFileId; |
421 | for(int i=0; i<res->GetEntries(); i++){ | |
422 | TString filename = res->GetKey(i, "lfn"); | |
c3a7b59a | 423 | if(filename == "") continue; |
62032124 | 424 | if(FilenameToId(filename, validFileId)) |
425 | validFileIds.AddLast(validFileId.Clone()); | |
426 | } | |
427 | delete res; | |
428 | dataId = GetId(validFileIds, selectedId); | |
9e1ceb13 | 429 | } |
430 | ||
4667c116 | 431 | return dataId; |
432 | } | |
433 | ||
434 | //_____________________________________________________________________________ | |
435 | AliCDBEntry* AliCDBGrid::GetEntry(const AliCDBId& queryId) { | |
436 | // get AliCDBEntry from the database | |
437 | ||
438 | AliCDBId* dataId = GetEntryId(queryId); | |
439 | ||
62032124 | 440 | if (!dataId) return NULL; |
9e1ceb13 | 441 | |
442 | TString filename; | |
62032124 | 443 | if (!IdToFilename(*dataId, filename)) { |
024cf675 | 444 | AliDebug(2,Form("Bad data ID encountered! Subnormal error!")); |
4667c116 | 445 | delete dataId; |
9e1ceb13 | 446 | return NULL; |
447 | } | |
448 | ||
62032124 | 449 | AliCDBEntry* anEntry = GetEntryFromFile(filename, dataId); |
450 | ||
4667c116 | 451 | delete dataId; |
62032124 | 452 | return anEntry; |
453 | } | |
454 | ||
455 | //_____________________________________________________________________________ | |
8e245d15 | 456 | AliCDBEntry* AliCDBGrid::GetEntryFromFile(TString& filename, AliCDBId* dataId){ |
62032124 | 457 | // Get AliCBEntry object from file "filename" |
9e1ceb13 | 458 | |
024cf675 | 459 | AliDebug(2,Form("Opening file: %s",filename.Data())); |
62032124 | 460 | |
461 | filename.Prepend("/alien"); | |
c75fabed | 462 | |
463 | // if option="CACHEREAD" TFile will use the local caching facility! | |
464 | TString option="READ"; | |
465 | if(fCacheFolder != ""){ | |
466 | ||
467 | // Check if local cache folder was changed in the meanwhile | |
468 | TString origCache(TFile::GetCacheFileDir()); | |
469 | if(fCacheFolder != origCache) { | |
470 | AliWarning(Form("Local cache folder has been overwritten!! fCacheFolder = %s origCache = %s", | |
471 | fCacheFolder.Data(), origCache.Data())); | |
472 | TFile::SetCacheFileDir(fCacheFolder.Data(), fOperateDisconnected); | |
473 | TFile::ShrinkCacheFileDir(fCacheSize, fCleanupInterval); | |
474 | } | |
475 | ||
476 | option.Prepend("CACHE"); | |
477 | } | |
478 | ||
479 | AliDebug(2, Form("Option: %s", option.Data())); | |
480 | ||
481 | TFile *file = TFile::Open(filename, option); | |
9e1ceb13 | 482 | if (!file) { |
024cf675 | 483 | AliDebug(2,Form("Can't open file <%s>!", filename.Data())); |
9e1ceb13 | 484 | return NULL; |
485 | } | |
486 | ||
487 | // get the only AliCDBEntry object from the file | |
488 | // the object in the file is an AliCDBEntry entry named "AliCDBEntry" | |
489 | ||
62032124 | 490 | AliCDBEntry* anEntry = dynamic_cast<AliCDBEntry*> (file->Get("AliCDBEntry")); |
9e1ceb13 | 491 | |
62032124 | 492 | if (!anEntry) { |
493 | AliDebug(2,Form("Bad storage data: file does not contain an AliCDBEntry object!")); | |
494 | file->Close(); | |
9e1ceb13 | 495 | return NULL; |
496 | } | |
497 | ||
9e1ceb13 | 498 | // The object's Id is not reset during storage |
499 | // If object's Id runRange or version do not match with filename, | |
500 | // it means that someone renamed file by hand. In this case a warning msg is issued. | |
62032124 | 501 | |
502 | if(anEntry){ | |
503 | AliCDBId entryId = anEntry->GetId(); | |
4005d0b5 | 504 | Int_t tmpSubVersion = dataId->GetSubVersion(); |
505 | dataId->SetSubVersion(entryId.GetSubVersion()); // otherwise filename and id may mismatch | |
8e245d15 | 506 | if(!entryId.IsEqual(dataId)){ |
b8ec52f6 | 507 | AliWarning(Form("Mismatch between file name and object's Id!")); |
508 | AliWarning(Form("File name: %s", dataId->ToString().Data())); | |
509 | AliWarning(Form("Object's Id: %s", entryId.ToString().Data())); | |
62032124 | 510 | } |
4005d0b5 | 511 | dataId->SetSubVersion(tmpSubVersion); |
9e1ceb13 | 512 | } |
513 | ||
62032124 | 514 | anEntry->SetLastStorage("grid"); |
515 | ||
145f45a2 | 516 | // Check whether entry contains a TTree. In case load the tree in memory! |
517 | LoadTreeFromFile(anEntry); | |
518 | ||
9e1ceb13 | 519 | // close file, return retieved entry |
520 | file->Close(); delete file; file=0; | |
62032124 | 521 | |
522 | return anEntry; | |
9e1ceb13 | 523 | } |
524 | ||
525 | //_____________________________________________________________________________ | |
62032124 | 526 | TList* AliCDBGrid::GetEntries(const AliCDBId& queryId) { |
9e1ceb13 | 527 | // multiple request (AliCDBStorage::GetAll) |
528 | ||
62032124 | 529 | TList* result = new TList(); |
530 | result->SetOwner(); | |
9e1ceb13 | 531 | |
6dc56e97 | 532 | TObjArray validFileIds; |
62032124 | 533 | validFileIds.SetOwner(1); |
9e1ceb13 | 534 | |
62032124 | 535 | Bool_t alreadyLoaded = kFALSE; |
9e1ceb13 | 536 | |
62032124 | 537 | // look for file matching query requests (path, runRange) |
538 | if(queryId.GetFirstRun() == fRun && | |
c3a7b59a | 539 | fPathFilter.Comprises(queryId.GetAliCDBPath()) && fVersion < 0 && !fMetaDataFilter){ |
62032124 | 540 | // look into list of valid files previously loaded with AliCDBStorage::FillValidFileIds() |
541 | AliDebug(2,Form("List of files valid for run %d and for path %s was loaded. Looking there!", | |
542 | queryId.GetFirstRun(), queryId.GetPath().Data())); | |
9e1ceb13 | 543 | |
62032124 | 544 | alreadyLoaded = kTRUE; |
9e1ceb13 | 545 | |
62032124 | 546 | } else { |
547 | // List of files valid for reqested run was not loaded. Looking directly into CDB | |
548 | AliDebug(2,Form("List of files valid for run %d and for path %s was not loaded. Looking directly into CDB!", | |
549 | queryId.GetFirstRun(), queryId.GetPath().Data())); | |
550 | ||
551 | TString filter; | |
6dc56e97 | 552 | MakeQueryFilter(queryId.GetFirstRun(), queryId.GetLastRun(), 0, filter); |
553 | ||
554 | TString pattern = Form("%s/Run*.root", queryId.GetPath().Data()); | |
555 | AliDebug(2,Form("pattern: %s", pattern.Data())); | |
556 | ||
557 | TGridResult *res = gGrid->Query(fDBFolder, pattern, filter, ""); | |
62032124 | 558 | |
62032124 | 559 | AliCDBId validFileId; |
560 | for(int i=0; i<res->GetEntries(); i++){ | |
561 | TString filename = res->GetKey(i, "lfn"); | |
c3a7b59a | 562 | if(filename == "") continue; |
62032124 | 563 | if(FilenameToId(filename, validFileId)) |
564 | validFileIds.AddLast(validFileId.Clone()); | |
565 | } | |
566 | delete res; | |
9e1ceb13 | 567 | } |
568 | ||
62032124 | 569 | TIter *iter=0; |
570 | if(alreadyLoaded){ | |
571 | iter = new TIter(&fValidFileIds); | |
572 | } else { | |
573 | iter = new TIter(&validFileIds); | |
574 | } | |
9e1ceb13 | 575 | |
6dc56e97 | 576 | TObjArray selectedIds; |
62032124 | 577 | selectedIds.SetOwner(1); |
578 | ||
579 | // loop on list of valid Ids to select the right version to get. | |
580 | // According to query and to the selection criteria list, version can be the highest or exact | |
581 | AliCDBPath pathCopy; | |
582 | AliCDBId* anIdPtr=0; | |
583 | AliCDBId* dataId=0; | |
584 | AliCDBPath queryPath = queryId.GetAliCDBPath(); | |
585 | while((anIdPtr = dynamic_cast<AliCDBId*> (iter->Next()))){ | |
586 | AliCDBPath thisCDBPath = anIdPtr->GetAliCDBPath(); | |
587 | if(!(queryPath.Comprises(thisCDBPath)) || pathCopy.GetPath() == thisCDBPath.GetPath()) continue; | |
588 | pathCopy = thisCDBPath; | |
589 | ||
590 | // check the selection criteria list for this query | |
591 | AliCDBId thisId(*anIdPtr); | |
592 | thisId.SetVersion(queryId.GetVersion()); | |
593 | if(!thisId.HasVersion()) GetSelection(&thisId); | |
594 | ||
595 | if(alreadyLoaded){ | |
596 | dataId = GetId(fValidFileIds, thisId); | |
597 | } else { | |
598 | dataId = GetId(validFileIds, thisId); | |
9e1ceb13 | 599 | } |
4667c116 | 600 | if(dataId) selectedIds.Add(dataId); |
9e1ceb13 | 601 | } |
9e1ceb13 | 602 | |
62032124 | 603 | delete iter; iter=0; |
9e1ceb13 | 604 | |
62032124 | 605 | // selectedIds contains the Ids of the files matching all requests of query! |
606 | // All the objects are now ready to be retrieved | |
607 | iter = new TIter(&selectedIds); | |
608 | while((anIdPtr = dynamic_cast<AliCDBId*> (iter->Next()))){ | |
609 | TString filename; | |
610 | if (!IdToFilename(*anIdPtr, filename)) { | |
611 | AliDebug(2,Form("Bad data ID encountered! Subnormal error!")); | |
612 | continue; | |
613 | } | |
9e1ceb13 | 614 | |
62032124 | 615 | AliCDBEntry* anEntry = GetEntryFromFile(filename, anIdPtr); |
9e1ceb13 | 616 | |
62032124 | 617 | if(anEntry) result->Add(anEntry); |
9e1ceb13 | 618 | |
62032124 | 619 | } |
620 | delete iter; iter=0; | |
621 | ||
622 | return result; | |
9e1ceb13 | 623 | } |
624 | ||
625 | //_____________________________________________________________________________ | |
626 | Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry) { | |
627 | // put an AliCDBEntry object into the database | |
62032124 | 628 | |
9e1ceb13 | 629 | AliCDBId& id = entry->GetId(); |
630 | ||
631 | // set version for the entry to be stored | |
62032124 | 632 | if (!PrepareId(id)) return kFALSE; |
9e1ceb13 | 633 | |
634 | // build filename from entry's id | |
635 | TString filename; | |
62032124 | 636 | if (!IdToFilename(id, filename)) { |
9e1ceb13 | 637 | AliError("Bad ID encountered! Subnormal error!"); |
638 | return kFALSE; | |
62032124 | 639 | } |
640 | ||
641 | TString folderToTag = Form("%s%s", | |
642 | fDBFolder.Data(), | |
643 | id.GetPath().Data()); | |
644 | ||
9e1ceb13 | 645 | TDirectory* saveDir = gDirectory; |
646 | ||
fb33abde | 647 | TString fullFilename = Form("/alien%s", filename.Data()); |
62032124 | 648 | // specify SE to filename |
fb33abde | 649 | if (fSE != "default") fullFilename += Form("?se=%s",fSE.Data()); |
62032124 | 650 | |
9e1ceb13 | 651 | // open file |
145f45a2 | 652 | TFile *file = TFile::Open(fullFilename,"CREATE"); |
653 | if(!file || !file->IsWritable()){ | |
654 | AliError(Form("Can't open file <%s>!", filename.Data())); | |
655 | if(file && !file->IsWritable()) file->Close(); delete file; file=0; | |
656 | return kFALSE; | |
657 | } | |
62032124 | 658 | |
659 | file->cd(); | |
9e1ceb13 | 660 | |
ed343d5e | 661 | //SetTreeToFile(entry, file); |
145f45a2 | 662 | |
9e1ceb13 | 663 | entry->SetVersion(id.GetVersion()); |
664 | ||
665 | // write object (key name: "AliCDBEntry") | |
145f45a2 | 666 | Bool_t result = (file->WriteTObject(entry, "AliCDBEntry") != 0); |
62032124 | 667 | if (!result) AliError(Form("Can't write entry to file <%s>!", filename.Data())); |
9e1ceb13 | 668 | |
669 | ||
670 | if (saveDir) saveDir->cd(); else gROOT->cd(); | |
671 | file->Close(); delete file; file=0; | |
c3a7b59a | 672 | |
9e1ceb13 | 673 | if(result) { |
c75fabed | 674 | |
c3a7b59a | 675 | if(!TagFileId(filename, &id)){ |
676 | AliInfo(Form("CDB tagging failed. Deleting file %s!",filename.Data())); | |
677 | if(!gGrid->Rm(filename.Data())) | |
678 | AliError("Can't delete file!"); | |
679 | return kFALSE; | |
680 | } | |
681 | ||
682 | TagFileMetaData(filename, entry->GetMetaData()); | |
9e1ceb13 | 683 | } |
62032124 | 684 | |
c75fabed | 685 | AliInfo(Form("CDB object stored into file %s", filename.Data())); |
686 | AliInfo(Form("Storage Element: %s", fSE.Data())); | |
62032124 | 687 | return result; |
688 | } | |
689 | //_____________________________________________________________________________ | |
690 | Bool_t AliCDBGrid::AddTag(TString& folderToTag, const char* tagname){ | |
691 | // add "tagname" tag (CDB or CDB_MD) to folder where object will be stored | |
692 | ||
693 | Bool_t result = kTRUE; | |
694 | AliDebug(2, Form("adding %s tag to folder %s", tagname, folderToTag.Data())); | |
695 | TString addTag = Form("addTag %s %s", folderToTag.Data(), tagname); | |
696 | TGridResult *gridres = gGrid->Command(addTag.Data()); | |
697 | const char* resCode = gridres->GetKey(0,"__result__"); // '1' if success | |
698 | if(resCode[0] != '1') { | |
699 | AliError(Form("Couldn't add %s tags to folder %s !", | |
700 | tagname, folderToTag.Data())); | |
701 | result = kFALSE; | |
702 | } | |
703 | delete gridres; | |
9e1ceb13 | 704 | return result; |
705 | } | |
706 | ||
62032124 | 707 | //_____________________________________________________________________________ |
c3a7b59a | 708 | Bool_t AliCDBGrid::TagFileId(TString& filename, const AliCDBId* id){ |
62032124 | 709 | // tag stored object in CDB table using object Id's parameters |
710 | ||
f430a9ce | 711 | TString addTagValue1 = Form("addTagValue %s CDB ", filename.Data()); |
712 | TString addTagValue2 = Form("first_run=%d last_run=%d version=%d ", | |
62032124 | 713 | id->GetFirstRun(), |
714 | id->GetLastRun(), | |
715 | id->GetVersion()); | |
f430a9ce | 716 | TString addTagValue3 = Form("path_level_0=\"%s\" path_level_1=\"%s\" path_level_2=\"%s\"", |
4667c116 | 717 | id->GetPathLevel(0).Data(), |
718 | id->GetPathLevel(1).Data(), | |
719 | id->GetPathLevel(2).Data()); | |
62032124 | 720 | TString addTagValue = Form("%s%s%s", |
f430a9ce | 721 | addTagValue1.Data(), |
722 | addTagValue2.Data(), | |
723 | addTagValue3.Data()); | |
62032124 | 724 | |
c3a7b59a | 725 | Bool_t result = kFALSE; |
62032124 | 726 | AliDebug(2, Form("Tagging file. Tag command: %s", addTagValue.Data())); |
727 | TGridResult* res = gGrid->Command(addTagValue.Data()); | |
728 | const char* resCode = res->GetKey(0,"__result__"); // '1' if success | |
729 | if(resCode[0] != '1') { | |
c3a7b59a | 730 | AliError(Form("Couldn't add CDB tag value to file %s !", |
62032124 | 731 | filename.Data())); |
c3a7b59a | 732 | result = kFALSE; |
62032124 | 733 | } else { |
c75fabed | 734 | AliDebug(2, "Object successfully tagged."); |
c3a7b59a | 735 | result = kTRUE; |
62032124 | 736 | } |
737 | delete res; | |
c3a7b59a | 738 | return result; |
62032124 | 739 | |
740 | } | |
741 | ||
4667c116 | 742 | //_____________________________________________________________________________ |
743 | Bool_t AliCDBGrid::TagShortLived(TString& filename, Bool_t value){ | |
744 | // tag folder with ShortLived tag | |
745 | ||
746 | TString addTagValue = Form("addTagValue %s ShortLived_try value=%d", filename.Data(), value); | |
747 | ||
748 | Bool_t result = kFALSE; | |
749 | AliDebug(2, Form("Tagging file. Tag command: %s", addTagValue.Data())); | |
750 | TGridResult* res = gGrid->Command(addTagValue.Data()); | |
751 | const char* resCode = res->GetKey(0,"__result__"); // '1' if success | |
752 | if(resCode[0] != '1') { | |
753 | AliError(Form("Couldn't add ShortLived tag value to file %s !", filename.Data())); | |
754 | result = kFALSE; | |
755 | } else { | |
c75fabed | 756 | AliDebug(2,"Object successfully tagged."); |
4667c116 | 757 | result = kTRUE; |
758 | } | |
759 | delete res; | |
760 | return result; | |
761 | ||
762 | } | |
763 | ||
62032124 | 764 | //_____________________________________________________________________________ |
c3a7b59a | 765 | Bool_t AliCDBGrid::TagFileMetaData(TString& filename, const AliCDBMetaData* md){ |
62032124 | 766 | // tag stored object in CDB table using object Id's parameters |
767 | ||
f430a9ce | 768 | TString addTagValue1 = Form("addTagValue %s CDB_MD ", filename.Data()); |
769 | TString addTagValue2 = Form("object_classname=\"%s\" responsible=\"%s\" beam_period=%d ", | |
62032124 | 770 | md->GetObjectClassName(), |
771 | md->GetResponsible(), | |
772 | md->GetBeamPeriod()); | |
f430a9ce | 773 | TString addTagValue3 = Form("aliroot_version=\"%s\" comment=\"%s\"", |
62032124 | 774 | md->GetAliRootVersion(), |
775 | md->GetComment()); | |
776 | TString addTagValue = Form("%s%s%s", | |
f430a9ce | 777 | addTagValue1.Data(), |
778 | addTagValue2.Data(), | |
779 | addTagValue3.Data()); | |
62032124 | 780 | |
c3a7b59a | 781 | Bool_t result = kFALSE; |
62032124 | 782 | AliDebug(2, Form("Tagging file. Tag command: %s", addTagValue.Data())); |
783 | TGridResult* res = gGrid->Command(addTagValue.Data()); | |
784 | const char* resCode = res->GetKey(0,"__result__"); // '1' if success | |
785 | if(resCode[0] != '1') { | |
786 | AliWarning(Form("Couldn't add CDB_MD tag value to file %s !", | |
787 | filename.Data())); | |
c3a7b59a | 788 | result = kFALSE; |
62032124 | 789 | } else { |
c75fabed | 790 | AliDebug(2,"Object successfully tagged."); |
c3a7b59a | 791 | result = kTRUE; |
62032124 | 792 | } |
c3a7b59a | 793 | return result; |
62032124 | 794 | } |
795 | ||
b05400be | 796 | //_____________________________________________________________________________ |
797 | TList* AliCDBGrid::GetIdListFromFile(const char* fileName){ | |
6dc56e97 | 798 | |
b05400be | 799 | TString turl(fileName); |
800 | turl.Prepend("/alien" + fDBFolder); | |
62032124 | 801 | turl += "?se="; turl += fSE.Data(); |
b05400be | 802 | TFile *file = TFile::Open(turl); |
803 | if (!file) { | |
804 | AliError(Form("Can't open selection file <%s>!", turl.Data())); | |
805 | return NULL; | |
806 | } | |
807 | ||
808 | TList *list = new TList(); | |
809 | list->SetOwner(); | |
810 | int i=0; | |
811 | TString keycycle; | |
62032124 | 812 | |
b05400be | 813 | AliCDBId *id; |
814 | while(1){ | |
815 | i++; | |
816 | keycycle = "AliCDBId;"; | |
817 | keycycle+=i; | |
818 | ||
819 | id = (AliCDBId*) file->Get(keycycle); | |
820 | if(!id) break; | |
821 | list->AddFirst(id); | |
822 | } | |
823 | file->Close(); delete file; file=0; | |
824 | ||
825 | return list; | |
826 | ||
827 | ||
828 | } | |
829 | ||
830 | //_____________________________________________________________________________ | |
831 | Bool_t AliCDBGrid::Contains(const char* path) const{ | |
832 | // check for path in storage's DBFolder | |
833 | ||
834 | TString initDir(gGrid->Pwd(0)); | |
835 | TString dirName(fDBFolder); | |
836 | dirName += path; // dirName = fDBFolder/path | |
837 | Bool_t result=kFALSE; | |
838 | if (gGrid->Cd(dirName,0)) result=kTRUE; | |
839 | gGrid->Cd(initDir.Data(),0); | |
840 | return result; | |
841 | } | |
842 | ||
62032124 | 843 | //_____________________________________________________________________________ |
844 | void AliCDBGrid::QueryValidFiles() | |
845 | { | |
846 | // Query the CDB for files valid for AliCDBStorage::fRun | |
847 | // fills list fValidFileIds with AliCDBId objects created from file name | |
848 | ||
849 | TString filter; | |
6dc56e97 | 850 | MakeQueryFilter(fRun, fRun, fMetaDataFilter, filter); |
851 | ||
852 | TString pattern = Form("%s/Run*", fPathFilter.GetPath().Data()); | |
4005d0b5 | 853 | if(fVersion >= 0) pattern += Form("_v%d*", fVersion); |
6dc56e97 | 854 | pattern += ".root"; |
855 | AliDebug(2,Form("pattern: %s", pattern.Data())); | |
856 | ||
857 | TGridResult *res = gGrid->Query(fDBFolder, pattern, filter, ""); | |
62032124 | 858 | |
62032124 | 859 | AliCDBId validFileId; |
860 | for(int i=0; i<res->GetEntries(); i++){ | |
861 | TString filename = res->GetKey(i, "lfn"); | |
c3a7b59a | 862 | if(filename == "") continue; |
62032124 | 863 | AliDebug(2,Form("Found valid file: %s", filename.Data())); |
864 | Bool_t result = FilenameToId(filename, validFileId); | |
865 | if(result) { | |
866 | fValidFileIds.AddLast(validFileId.Clone()); | |
867 | } | |
868 | } | |
869 | delete res; | |
870 | ||
871 | } | |
872 | ||
873 | //_____________________________________________________________________________ | |
c3a7b59a | 874 | void AliCDBGrid::MakeQueryFilter(Int_t firstRun, Int_t lastRun, |
62032124 | 875 | const AliCDBMetaData* md, TString& result) const |
876 | { | |
877 | // create filter for file query | |
878 | ||
c3a7b59a | 879 | result = Form("CDB:first_run<=%d and CDB:last_run>=%d", firstRun, lastRun); |
62032124 | 880 | |
6dc56e97 | 881 | // if(version >= 0) { |
882 | // result += Form(" and CDB:version=%d", version); | |
883 | // } | |
884 | // if(pathFilter.GetLevel0() != "*") { | |
885 | // result += Form(" and CDB:path_level_0=\"%s\"", pathFilter.GetLevel0().Data()); | |
886 | // } | |
887 | // if(pathFilter.GetLevel1() != "*") { | |
888 | // result += Form(" and CDB:path_level_1=\"%s\"", pathFilter.GetLevel1().Data()); | |
889 | // } | |
890 | // if(pathFilter.GetLevel2() != "*") { | |
891 | // result += Form(" and CDB:path_level_2=\"%s\"", pathFilter.GetLevel2().Data()); | |
892 | // } | |
62032124 | 893 | |
894 | if(md){ | |
895 | if(md->GetObjectClassName()[0] != '\0') { | |
896 | result += Form(" and CDB_MD:object_classname=\"%s\"", md->GetObjectClassName()); | |
897 | } | |
898 | if(md->GetResponsible()[0] != '\0') { | |
899 | result += Form(" and CDB_MD:responsible=\"%s\"", md->GetResponsible()); | |
900 | } | |
901 | if(md->GetBeamPeriod() != 0) { | |
902 | result += Form(" and CDB_MD:beam_period=%d", md->GetBeamPeriod()); | |
903 | } | |
904 | if(md->GetAliRootVersion()[0] != '\0') { | |
905 | result += Form(" and CDB_MD:aliroot_version=\"%s\"", md->GetAliRootVersion()); | |
906 | } | |
907 | if(md->GetComment()[0] != '\0') { | |
908 | result += Form(" and CDB_MD:comment=\"%s\"", md->GetComment()); | |
909 | } | |
910 | } | |
911 | AliDebug(2, Form("filter: %s",result.Data())); | |
912 | ||
913 | } | |
914 | ||
c3a7b59a | 915 | //_____________________________________________________________________________ |
916 | Int_t AliCDBGrid::GetLatestVersion(const char* path, Int_t run){ | |
917 | // get last version found in the database valid for run and path | |
918 | ||
c3a7b59a | 919 | AliCDBPath aCDBPath(path); |
920 | if(!aCDBPath.IsValid() || aCDBPath.IsWildcard()) { | |
921 | AliError(Form("Invalid path in request: %s", path)); | |
922 | return -1; | |
923 | } | |
924 | AliCDBId query(path, run, run, -1, -1); | |
925 | AliCDBId* dataId = 0; | |
926 | ||
927 | // look for file matching query requests (path, runRange, version) | |
6dc56e97 | 928 | if(run == fRun && fPathFilter.Comprises(aCDBPath) && fVersion < 0){ |
c3a7b59a | 929 | // look into list of valid files previously loaded with AliCDBStorage::FillValidFileIds() |
930 | AliDebug(2, Form("List of files valid for run %d and for path %s was loaded. Looking there!", | |
931 | run, path)); | |
932 | dataId = GetId(fValidFileIds, query); | |
933 | if (!dataId) return -1; | |
4667c116 | 934 | Int_t version = dataId->GetVersion(); |
935 | delete dataId; | |
936 | return version; | |
c3a7b59a | 937 | |
938 | } | |
939 | // List of files valid for reqested run was not loaded. Looking directly into CDB | |
940 | AliDebug(2, Form("List of files valid for run %d and for path %s was not loaded. Looking directly into CDB!", | |
941 | run, path)); | |
942 | ||
4667c116 | 943 | TObjArray validFileIds; |
944 | validFileIds.SetOwner(1); | |
945 | ||
c3a7b59a | 946 | TString filter; |
6dc56e97 | 947 | MakeQueryFilter(run, run, 0, filter); |
948 | ||
949 | TString pattern = Form("%s/Run*.root", path); | |
950 | AliDebug(2,Form("pattern: %s", pattern.Data())); | |
c3a7b59a | 951 | |
6dc56e97 | 952 | TGridResult *res = gGrid->Query(fDBFolder, pattern, filter, ""); |
c3a7b59a | 953 | AliCDBId validFileId; |
954 | for(int i=0; i<res->GetEntries(); i++){ | |
955 | TString filename = res->GetKey(i, "lfn"); | |
956 | if(filename == "") continue; | |
957 | if(FilenameToId(filename, validFileId)) | |
958 | validFileIds.AddLast(validFileId.Clone()); | |
959 | } | |
960 | delete res; | |
961 | ||
962 | dataId = GetId(validFileIds, query); | |
963 | if (!dataId) return -1; | |
964 | ||
4667c116 | 965 | Int_t version = dataId->GetVersion(); |
966 | delete dataId; | |
967 | return version; | |
c3a7b59a | 968 | |
969 | } | |
970 | ||
971 | //_____________________________________________________________________________ | |
972 | Int_t AliCDBGrid::GetLatestSubVersion(const char* /*path*/, Int_t /*run*/, Int_t /*version*/){ | |
973 | // get last subversion found in the database valid for run and path | |
974 | AliError("Objects in GRID storage have no sub version!"); | |
975 | return -1; | |
976 | } | |
977 | ||
978 | ||
9e1ceb13 | 979 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
980 | // // | |
981 | // AliCDBGrid factory // | |
982 | // // | |
983 | ///////////////////////////////////////////////////////////////////////////////////////////////// | |
984 | ||
985 | ClassImp(AliCDBGridFactory) | |
986 | ||
987 | //_____________________________________________________________________________ | |
988 | Bool_t AliCDBGridFactory::Validate(const char* gridString) { | |
989 | // check if the string is valid Grid URI | |
990 | ||
b05400be | 991 | TRegexp gridPattern("^alien://.+$"); |
9e1ceb13 | 992 | |
993 | return TString(gridString).Contains(gridPattern); | |
994 | } | |
995 | ||
996 | //_____________________________________________________________________________ | |
997 | AliCDBParam* AliCDBGridFactory::CreateParameter(const char* gridString) { | |
998 | // create AliCDBGridParam class from the URI string | |
999 | ||
1000 | if (!Validate(gridString)) { | |
1001 | return NULL; | |
1002 | } | |
c75fabed | 1003 | |
b05400be | 1004 | TString buffer(gridString); |
c3a7b59a | 1005 | |
1006 | TString gridUrl = "alien://"; | |
b05400be | 1007 | TString user = ""; |
4667c116 | 1008 | TString dbFolder = ""; |
fb33abde | 1009 | TString se = "default"; |
c75fabed | 1010 | TString cacheFolder = ""; |
1011 | Bool_t operateDisconnected = kTRUE; | |
1012 | Long64_t cacheSize = (UInt_t) 1024*1024*1024; // 1GB | |
1013 | Long_t cleanupInterval = 0; | |
b05400be | 1014 | |
1015 | TObjArray *arr = buffer.Tokenize('?'); | |
1016 | TIter iter(arr); | |
62032124 | 1017 | TObjString *str = 0; |
4667c116 | 1018 | |
b05400be | 1019 | while((str = (TObjString*) iter.Next())){ |
1020 | TString entry(str->String()); | |
1021 | Int_t indeq = entry.Index('='); | |
1022 | if(indeq == -1) { | |
1023 | if(entry.BeginsWith("alien://")) { // maybe it's a gridUrl! | |
1024 | gridUrl = entry; | |
1025 | continue; | |
1026 | } else { | |
1027 | AliError(Form("Invalid entry! %s",entry.Data())); | |
1028 | continue; | |
1029 | } | |
1030 | } | |
1031 | ||
1032 | TString key = entry(0,indeq); | |
1033 | TString value = entry(indeq+1,entry.Length()-indeq); | |
1034 | ||
1035 | if(key.Contains("grid",TString::kIgnoreCase)) { | |
1036 | gridUrl += value; | |
c75fabed | 1037 | } |
b05400be | 1038 | else if (key.Contains("user",TString::kIgnoreCase)){ |
1039 | user = value; | |
1040 | } | |
1041 | else if (key.Contains("folder",TString::kIgnoreCase)){ | |
1042 | dbFolder = value; | |
1043 | } | |
1044 | else if (key.Contains("se",TString::kIgnoreCase)){ | |
1045 | se = value; | |
1046 | } | |
c75fabed | 1047 | else if (key.Contains("cacheFold",TString::kIgnoreCase)){ |
1048 | cacheFolder = value; | |
1049 | if (!cacheFolder.EndsWith("/")) | |
1050 | cacheFolder += "/"; | |
1051 | } | |
1052 | else if (key.Contains("operateDisc",TString::kIgnoreCase)){ | |
1053 | if(value == "kTRUE") { | |
1054 | operateDisconnected = kTRUE; | |
1055 | } else if (value == "kFALSE") { | |
1056 | operateDisconnected = kFALSE; | |
1057 | } else if (value == "0" || value == "1") { | |
1058 | operateDisconnected = (Bool_t) value.Atoi(); | |
1059 | } else { | |
1060 | AliError(Form("Invalid entry! %s",entry.Data())); | |
1061 | return NULL; | |
1062 | } | |
1063 | } | |
1064 | else if (key.Contains("cacheSiz",TString::kIgnoreCase)){ | |
1065 | if(value.IsDigit()) { | |
1066 | cacheSize = value.Atoi(); | |
1067 | } else { | |
1068 | AliError(Form("Invalid entry! %s",entry.Data())); | |
1069 | return NULL; | |
1070 | } | |
1071 | } | |
1072 | else if (key.Contains("cleanupInt",TString::kIgnoreCase)){ | |
1073 | if(value.IsDigit()) { | |
1074 | cleanupInterval = value.Atoi(); | |
1075 | } else { | |
1076 | AliError(Form("Invalid entry! %s",entry.Data())); | |
1077 | return NULL; | |
1078 | } | |
1079 | } | |
b05400be | 1080 | else{ |
1081 | AliError(Form("Invalid entry! %s",entry.Data())); | |
c75fabed | 1082 | return NULL; |
b05400be | 1083 | } |
1084 | } | |
1085 | delete arr; arr=0; | |
c75fabed | 1086 | |
1087 | AliDebug(2, Form("gridUrl: %s", gridUrl.Data())); | |
1088 | AliDebug(2, Form("user: %s", user.Data())); | |
1089 | AliDebug(2, Form("dbFolder: %s", dbFolder.Data())); | |
1090 | AliDebug(2, Form("s.e.: %s", se.Data())); | |
1091 | AliDebug(2, Form("local cache folder: %s", cacheFolder.Data())); | |
1092 | AliDebug(2, Form("local cache operate disconnected: %d", operateDisconnected)); | |
1093 | AliDebug(2, Form("local cache size: %d", cacheSize)); | |
1094 | AliDebug(2, Form("local cache cleanup interval: %d", cleanupInterval)); | |
9e1ceb13 | 1095 | |
4667c116 | 1096 | if(dbFolder == ""){ |
c75fabed | 1097 | AliError("Base folder must be specified!"); |
4667c116 | 1098 | return NULL; |
1099 | } | |
1100 | ||
c75fabed | 1101 | return new AliCDBGridParam(gridUrl.Data(), user.Data(), |
1102 | dbFolder.Data(), se.Data(), cacheFolder.Data(), | |
1103 | operateDisconnected, cacheSize, cleanupInterval); | |
9e1ceb13 | 1104 | } |
1105 | ||
1106 | //_____________________________________________________________________________ | |
1107 | AliCDBStorage* AliCDBGridFactory::Create(const AliCDBParam* param) { | |
1108 | // create AliCDBGrid storage instance from parameters | |
1109 | ||
62032124 | 1110 | AliCDBGrid *grid = 0; |
9e1ceb13 | 1111 | if (AliCDBGridParam::Class() == param->IsA()) { |
62032124 | 1112 | |
9e1ceb13 | 1113 | const AliCDBGridParam* gridParam = (const AliCDBGridParam*) param; |
62032124 | 1114 | grid = new AliCDBGrid(gridParam->GridUrl().Data(), |
1115 | gridParam->GetUser().Data(), | |
1116 | gridParam->GetDBFolder().Data(), | |
c75fabed | 1117 | gridParam->GetSE().Data(), |
1118 | gridParam->GetCacheFolder().Data(), | |
1119 | gridParam->GetOperateDisconnected(), | |
1120 | gridParam->GetCacheSize(), | |
1121 | gridParam->GetCleanupInterval()); | |
9e1ceb13 | 1122 | |
9e1ceb13 | 1123 | } |
1124 | ||
c3a7b59a | 1125 | if(!gGrid && grid) { |
1126 | delete grid; grid=0; | |
1127 | } | |
1128 | ||
62032124 | 1129 | return grid; |
9e1ceb13 | 1130 | } |
1131 | ||
1132 | ///////////////////////////////////////////////////////////////////////////////////////////////// | |
1133 | // // | |
c75fabed | 1134 | // AliCDBGrid Parameter class // // |
9e1ceb13 | 1135 | // // |
1136 | ///////////////////////////////////////////////////////////////////////////////////////////////// | |
1137 | ||
1138 | ClassImp(AliCDBGridParam) | |
1139 | ||
1140 | //_____________________________________________________________________________ | |
62032124 | 1141 | AliCDBGridParam::AliCDBGridParam(): |
1142 | AliCDBParam(), | |
1143 | fGridUrl(), | |
1144 | fUser(), | |
1145 | fDBFolder(), | |
c75fabed | 1146 | fSE(), |
1147 | fCacheFolder(), | |
1148 | fOperateDisconnected(), | |
1149 | fCacheSize(), | |
1150 | fCleanupInterval() | |
1151 | ||
62032124 | 1152 | { |
9e1ceb13 | 1153 | // default constructor |
1154 | ||
1155 | } | |
1156 | ||
1157 | //_____________________________________________________________________________ | |
c75fabed | 1158 | AliCDBGridParam::AliCDBGridParam(const char* gridUrl, const char* user, const char* dbFolder, |
1159 | const char* se, const char* cacheFolder, Bool_t operateDisconnected, | |
1160 | Long64_t cacheSize, Long_t cleanupInterval): | |
62032124 | 1161 | AliCDBParam(), |
b05400be | 1162 | fGridUrl(gridUrl), |
9e1ceb13 | 1163 | fUser(user), |
b05400be | 1164 | fDBFolder(dbFolder), |
c75fabed | 1165 | fSE(se), |
1166 | fCacheFolder(cacheFolder), | |
1167 | fOperateDisconnected(operateDisconnected), | |
1168 | fCacheSize(cacheSize), | |
1169 | fCleanupInterval(cleanupInterval) | |
9e1ceb13 | 1170 | { |
1171 | // constructor | |
c75fabed | 1172 | |
9e1ceb13 | 1173 | SetType("alien"); |
1174 | ||
c75fabed | 1175 | TString uri = Form("%s?User=%s?DBFolder=%s?SE=%s?CacheFolder=%s" |
1176 | "?OperateDisconnected=%d?CacheSize=%d?CleanupInterval=%d", | |
62032124 | 1177 | fGridUrl.Data(), fUser.Data(), |
c75fabed | 1178 | fDBFolder.Data(), fSE.Data(), fCacheFolder.Data(), |
1179 | fOperateDisconnected, fCacheSize, fCleanupInterval); | |
62032124 | 1180 | |
1181 | SetURI(uri.Data()); | |
9e1ceb13 | 1182 | } |
1183 | ||
1184 | //_____________________________________________________________________________ | |
1185 | AliCDBGridParam::~AliCDBGridParam() { | |
1186 | // destructor | |
1187 | ||
1188 | } | |
1189 | ||
1190 | //_____________________________________________________________________________ | |
1191 | AliCDBParam* AliCDBGridParam::CloneParam() const { | |
1192 | // clone parameter | |
1193 | ||
62032124 | 1194 | return new AliCDBGridParam(fGridUrl.Data(), fUser.Data(), |
c75fabed | 1195 | fDBFolder.Data(), fSE.Data(), fCacheFolder.Data(), |
1196 | fOperateDisconnected, fCacheSize, fCleanupInterval); | |
9e1ceb13 | 1197 | } |
1198 | ||
1199 | //_____________________________________________________________________________ | |
1200 | ULong_t AliCDBGridParam::Hash() const { | |
1201 | // return Hash function | |
1202 | ||
c75fabed | 1203 | return fGridUrl.Hash()+fUser.Hash()+fDBFolder.Hash()+fSE.Hash()+fCacheFolder.Hash(); |
9e1ceb13 | 1204 | } |
1205 | ||
1206 | //_____________________________________________________________________________ | |
1207 | Bool_t AliCDBGridParam::IsEqual(const TObject* obj) const { | |
1208 | // check if this object is equal to AliCDBParam obj | |
1209 | ||
1210 | if (this == obj) { | |
1211 | return kTRUE; | |
1212 | } | |
1213 | ||
1214 | if (AliCDBGridParam::Class() != obj->IsA()) { | |
1215 | return kFALSE; | |
1216 | } | |
1217 | ||
1218 | AliCDBGridParam* other = (AliCDBGridParam*) obj; | |
1219 | ||
b05400be | 1220 | if(fGridUrl != other->fGridUrl) return kFALSE; |
9e1ceb13 | 1221 | if(fUser != other->fUser) return kFALSE; |
b05400be | 1222 | if(fDBFolder != other->fDBFolder) return kFALSE; |
9e1ceb13 | 1223 | if(fSE != other->fSE) return kFALSE; |
c75fabed | 1224 | if(fCacheFolder != other->fCacheFolder) return kFALSE; |
1225 | if(fOperateDisconnected != other->fOperateDisconnected) return kFALSE; | |
1226 | if(fCacheSize != other->fCacheSize) return kFALSE; | |
1227 | if(fCleanupInterval != other->fCleanupInterval) return kFALSE; | |
9e1ceb13 | 1228 | return kTRUE; |
1229 | } | |
1230 |