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