Implementing the possibility of loading the CDB as a snapshot in two ways:
[u/mrichter/AliRoot.git] / STEER / CDB / AliCDBManager.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 **************************************************************************/
fdf65bb5 15//-------------------------------------------------------------------------
16// Implementation of AliCDBManager and AliCDBParam classe
17// Author: Alberto Colla
18// e-mail: Alberto.Colla@cern.ch
19//-------------------------------------------------------------------------
9e1ceb13 20
21#include "AliCDBManager.h"
22#include "AliCDBStorage.h"
23#include "AliLog.h"
24#include "AliCDBDump.h"
25#include "AliCDBLocal.h"
26#include "AliCDBGrid.h"
02c4845e 27#include "AliCDBEntry.h"
7de84b33 28#include "AliCDBHandler.h"
9e1ceb13 29
02c4845e 30#include <TObjString.h>
7de84b33 31#include <TSAXParser.h>
32#include <TFile.h>
647d2bb8 33#include <TKey.h>
7de84b33 34#include <TUUID.h>
27cac7e3 35#include <TGrid.h>
9e1ceb13 36
37ClassImp(AliCDBParam)
38
39ClassImp(AliCDBManager)
40
b8ec52f6 41//TODO OCDB and Reference folder should not be fully hardcoded but built from run number (or year/LHC period)
42TString AliCDBManager::fgkCondUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/CDB?user=aliprod");
43TString AliCDBManager::fgkRefUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/Reference?user=aliprod");
7de84b33 44TString AliCDBManager::fgkMCIdealStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Ideal");
45TString AliCDBManager::fgkMCFullStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Full");
46TString AliCDBManager::fgkMCResidualStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Residual");
47TString AliCDBManager::fgkOCDBFolderXMLfile("alien:///alice/data/OCDBFoldervsRunRange.xml");
9e1ceb13 48AliCDBManager* AliCDBManager::fgInstance = 0x0;
49
50//_____________________________________________________________________________
d1982b43 51AliCDBManager* AliCDBManager::Instance(TMap *entryCache, Int_t run)
b8ec52f6 52{
9e1ceb13 53// returns AliCDBManager instance (singleton)
54
55 if (!fgInstance) {
56 fgInstance = new AliCDBManager();
d1982b43 57 if (!entryCache)
58 fgInstance->Init();
59 else
60 fgInstance->InitFromCache(entryCache,run);
9e1ceb13 61 }
62
63 return fgInstance;
64}
65
66//_____________________________________________________________________________
67void AliCDBManager::Init() {
68// factory registering
69
70 RegisterFactory(new AliCDBDumpFactory());
71 RegisterFactory(new AliCDBLocalFactory());
72 // AliCDBGridFactory is registered only if AliEn libraries are enabled in Root
73 if(!gSystem->Exec("root-config --has-alien |grep yes 2>&1 > /dev/null")){ // returns 0 if yes
74 AliInfo("AliEn classes enabled in Root. AliCDBGrid factory registered.");
75 RegisterFactory(new AliCDBGridFactory());
b8ec52f6 76 fCondParam = CreateParameter(fgkCondUri);
77 fRefParam = CreateParameter(fgkRefUri);
9e1ceb13 78 }
4667c116 79
80 InitShortLived();
9e1ceb13 81}
d1982b43 82
83//_____________________________________________________________________________
84void AliCDBManager::InitFromCache(TMap *entryCache, Int_t run) {
85// initialize manager from existing cache
86// used on the slaves in case of parallel reconstruction
87 SetRun(run);
88
89 TIter iter(entryCache->GetTable());
90 TPair* pair = 0;
91
92 while((pair = dynamic_cast<TPair*> (iter.Next()))){
93 fEntryCache.Add(pair->Key(),pair->Value());
94 }
95 // fEntry is the new owner of the cache
96 fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
77d2efce 97 entryCache->SetOwnerKeyValue(kFALSE,kFALSE);
d1982b43 98 AliInfo(Form("%d cache entries have been loaded",fEntryCache.GetEntries()));
99}
100
9e1ceb13 101//_____________________________________________________________________________
647d2bb8 102Bool_t AliCDBManager::InitFromSnapshot(const char* snapshotFileName){
103// initialize manager from a CDB snapshot, that is add the entries
104// to the entries map and the ids to the ids list taking them from
105// the map and the list found in the input file
106
107 // open the file
108 TString snapshotFile(snapshotFileName);
109 if(snapshotFile.BeginsWith("alien://")){
110 if(!gGrid) {
111 TGrid::Connect("alien://","");
112 if(!gGrid) {
113 AliError("Connection to alien failed!");
114 return kFALSE;
115 }
116 }
117 }
118
119 TFile *f = TFile::Open(snapshotFileName);
120 if (!f || f->IsZombie()){
121 AliError(Form("Cannot open file %s",snapshotFileName));
122 return kFALSE;
123 }
124
125 // retrieve entries map
126 TMap *entriesMap = 0;
127 TIter next(f->GetListOfKeys());
128 TKey *key;
129 while ((key = (TKey*)next())) {
130 if (strcmp(key->GetClassName(),"TMap") != 0) continue;
131 entriesMap = (TMap*)key->ReadObj();
132 break;
133 }
134 if (!entriesMap || entriesMap->GetEntries()==0){
135 AliError("Cannot get valid map of CDB entries from snapshot file");
136 return kFALSE;
137 }
138
139 // retrieve ids list
140 TList *idsList = 0;
141 TIter nextKey(f->GetListOfKeys());
142 TKey *keyN;
143 while ((keyN = (TKey*)nextKey())) {
144 if (strcmp(keyN->GetClassName(),"TList") != 0) continue;
145 idsList = (TList*)keyN->ReadObj();
146 break;
147 }
148 if (!idsList || idsList->GetEntries()==0){
149 AliError("Cannot get valid list of CDB entries from snapshot file");
150 return kFALSE;
151 }
152
153 TIter iterObj(entriesMap->GetTable());
154 TPair* pair = 0;
155
156 while((pair = dynamic_cast<TPair*> (iterObj.Next()))){
157 fEntryCache.Add(pair->Key(),pair->Value());
158 }
159 // fEntry is the new owner of the cache
160 fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
161 entriesMap->SetOwnerKeyValue(kFALSE,kFALSE);
162 AliInfo(Form("%d cache entries have been loaded",fEntryCache.GetEntries()));
163
164 TIter iterId(idsList);
165
166 AliCDBId* id=0;
167 while((id = dynamic_cast<AliCDBId*> (iterId.Next()))){
168 fIds->Add(id);
169 }
170 fIds->SetOwner(kTRUE);
171 idsList->SetOwner(kFALSE);
172 f->Close();
173 delete f;
174 AliInfo(Form("%d cache ids loaded. Total number of ids is %d",idsList->GetEntries(),fIds->GetEntries()));
175
176 return kTRUE;
177}
178
179//_____________________________________________________________________________
9e1ceb13 180void AliCDBManager::Destroy() {
181// delete ALCDBManager instance and active storages
182
183 if (fgInstance) {
4b5e0dce 184 //fgInstance->Delete();
9e1ceb13 185 delete fgInstance;
186 fgInstance = 0x0;
187 }
188}
189
190//_____________________________________________________________________________
191AliCDBManager::AliCDBManager():
fe12e09c 192 TObject(),
193 fFactories(),
194 fActiveStorages(),
195 fSpecificStorages(),
b21e3194 196 fEntryCache(),
197 fIds(0),
198 fStorageMap(0),
199 fShortLived(0),
fe12e09c 200 fDefaultStorage(NULL),
201 fDrainStorage(NULL),
b21e3194 202 fCondParam(0),
203 fRefParam(0),
4667c116 204 fRun(-1),
1f341624 205 fCache(kTRUE),
7de84b33 206 fLock(kFALSE),
207 fRaw(kFALSE),
208 fStartRunLHCPeriod(-1),
209 fEndRunLHCPeriod(-1),
a6f59240 210 fLHCPeriod(""),
211 fKey(0)
9e1ceb13 212{
213// default constuctor
4b5e0dce 214 fFactories.SetOwner(1);
62032124 215 fActiveStorages.SetOwner(1);
216 fSpecificStorages.SetOwner(1);
d1982b43 217 fEntryCache.SetName("CDBEntryCache");
77d2efce 218 fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
b21e3194 219
220 fStorageMap = new TMap();
221 fStorageMap->SetOwner(1);
222 fIds = new TList();
223 fIds->SetOwner(1);
9e1ceb13 224}
225
226//_____________________________________________________________________________
227AliCDBManager::~AliCDBManager() {
228// destructor
4b5e0dce 229 ClearCache();
9e1ceb13 230 DestroyActiveStorages();
62032124 231 fFactories.Delete();
b05400be 232 fDrainStorage = 0x0;
233 fDefaultStorage = 0x0;
b21e3194 234 delete fStorageMap; fStorageMap = 0;
235 delete fIds; fIds = 0;
b8ec52f6 236 delete fCondParam;
237 delete fRefParam;
4667c116 238 delete fShortLived; fShortLived = 0x0;
9e1ceb13 239}
240
241//_____________________________________________________________________________
9e1ceb13 242void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){
243// put a storage object into the list of active storages
244
245 fActiveStorages.Add(param, storage);
246 AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries()));
247}
248
249//_____________________________________________________________________________
250void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) {
251// add a storage factory to the list of registerd factories
252
253 if (!fFactories.Contains(factory)) {
254 fFactories.Add(factory);
255 }
256}
257
258//_____________________________________________________________________________
fdf65bb5 259Bool_t AliCDBManager::HasStorage(const char* dbString) const {
b21e3194 260// check if dbString is a URI valid for one of the registered factories
9e1ceb13 261
262 TIter iter(&fFactories);
263
62032124 264 AliCDBStorageFactory* factory=0;
9e1ceb13 265 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
266
267 if (factory->Validate(dbString)) {
268 return kTRUE;
4005d0b5 269 }
9e1ceb13 270 }
271
272 return kFALSE;
273}
274
275//_____________________________________________________________________________
fdf65bb5 276AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
9e1ceb13 277// create AliCDBParam object from URI string
278
279 TIter iter(&fFactories);
7de84b33 280
62032124 281 AliCDBStorageFactory* factory=0;
9e1ceb13 282 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
9e1ceb13 283 AliCDBParam* param = factory->CreateParameter(dbString);
62032124 284 if(param) return param;
9e1ceb13 285 }
286
287 return NULL;
288}
289
290//_____________________________________________________________________________
291AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) {
292// get storage object from URI string
1f341624 293
9e1ceb13 294 AliCDBParam* param = CreateParameter(dbString);
295 if (!param) {
c3a7b59a 296 AliError(Form("Failed to activate requested storage! Check URI: %s", dbString));
9e1ceb13 297 return NULL;
82096dfc 298 }
9e1ceb13 299
300 AliCDBStorage* aStorage = GetStorage(param);
301
302 delete param;
9e1ceb13 303 return aStorage;
304}
305
306//_____________________________________________________________________________
307AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) {
308// get storage object from AliCDBParam object
1f341624 309
82096dfc 310 // if the list of active storages already contains
9e1ceb13 311 // the requested storage, return it
312 AliCDBStorage* aStorage = GetActiveStorage(param);
313 if (aStorage) {
314 return aStorage;
315 }
316
1f341624 317 // if lock is ON, cannot activate more storages!
318 if(fLock) {
319 if (fDefaultStorage) {
320 AliFatal("Lock is ON, and default storage is already set: "
321 "cannot reset it or activate more storages!");
322 }
323 }
324
9e1ceb13 325 TIter iter(&fFactories);
326
62032124 327 AliCDBStorageFactory* factory=0;
917a098b 328
9e1ceb13 329 // loop on the list of registered factories
330 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
331
332 // each factory tries to create its storage from the parameter
333 aStorage = factory->Create(param);
334 if (aStorage) {
335 PutActiveStorage(param->CloneParam(), aStorage);
917a098b 336 aStorage->SetURI(param->GetURI());
6dc56e97 337 if(fRun >= 0) {
96b7636d 338 if(aStorage->GetType() == "alien"){
339 aStorage->QueryCDB(fRun);
340 } else {
341 AliDebug(2,
342 "Skipping query for valid files, it is used only in grid...");
343 }
c3a7b59a 344 }
9e1ceb13 345 return aStorage;
346 }
347 }
348
c3a7b59a 349 AliError(Form("Failed to activate requested storage! Check URI: %s", param->GetURI().Data()));
350
9e1ceb13 351 return NULL;
352}
353
354//_____________________________________________________________________________
62032124 355AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) {
356// get a storage object from the list of active storages
357
358 return dynamic_cast<AliCDBStorage*> (fActiveStorages.GetValue(param));
359}
360
361//_____________________________________________________________________________
9e1ceb13 362TList* AliCDBManager::GetActiveStorages() {
363// return list of active storages
62032124 364// user has responsibility to delete returned object
9e1ceb13 365
366 TList* result = new TList();
367
917a098b 368 TIter iter(fActiveStorages.GetTable());
62032124 369 TPair* aPair=0;
9e1ceb13 370 while ((aPair = (TPair*) iter.Next())) {
371 result->Add(aPair->Value());
372 }
373
374 return result;
375}
376
377//_____________________________________________________________________________
378void AliCDBManager::SetDrain(const char* dbString) {
379// set drain storage from URI string
380
381 fDrainStorage = GetStorage(dbString);
382}
383
384//_____________________________________________________________________________
385void AliCDBManager::SetDrain(const AliCDBParam* param) {
386// set drain storage from AliCDBParam
b8ec52f6 387
9e1ceb13 388 fDrainStorage = GetStorage(param);
389}
390
391//_____________________________________________________________________________
392void AliCDBManager::SetDrain(AliCDBStorage* storage) {
393// set drain storage from another active storage
394
395 fDrainStorage = storage;
396}
397
398//_____________________________________________________________________________
399Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
400// drain retrieved object to drain storage
401
b8ec52f6 402 AliDebug(2, "Draining into drain storage...");
9e1ceb13 403 return fDrainStorage->Put(entry);
404}
405
7de84b33 406//____________________________________________________________________________
9e1ceb13 407void AliCDBManager::SetDefaultStorage(const char* dbString) {
408// sets default storage from URI string
1f341624 409
7de84b33 410 // checking whether we are in the raw case
411 TString dbStringTemp(dbString);
27cac7e3 412 if (dbStringTemp == "raw://")
413 {
414 fRaw = kTRUE;
415 AliInfo("Setting the run-number will set the corresponding OCDB for raw data reconstruction.");
cdc36cbf 416 AliInfo("Connecting to the grid...");
417 if(!gGrid) {
418 TGrid::Connect("alien://","");
419 if(!gGrid) {
420 AliError("Connection to alien failed!");
421 return;
422 }
423 }
27cac7e3 424 return;
425 }
7de84b33 426
427 AliCDBStorage* bckStorage = fDefaultStorage;
428
82096dfc 429 fDefaultStorage = GetStorage(dbString);
95c0e132 430
431 if(!fDefaultStorage) return;
7de84b33 432
4954c5cd 433 if(bckStorage && (fDefaultStorage != bckStorage)){
434 AliWarning("Existing default storage replaced: clearing cache!");
435 ClearCache();
436 }
7de84b33 437
b21e3194 438 if (fStorageMap->Contains("default")) {
e1dd4d81 439 delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
b21e3194 440 }
441 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
9e1ceb13 442}
9e1ceb13 443//_____________________________________________________________________________
444void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
445// set default storage from AliCDBParam object
1f341624 446
4954c5cd 447 AliCDBStorage* bckStorage = fDefaultStorage;
448
b8ec52f6 449 fDefaultStorage = GetStorage(param);
4954c5cd 450
95c0e132 451 if(!fDefaultStorage) return;
452
4954c5cd 453 if(bckStorage && (fDefaultStorage != bckStorage)){
454 AliWarning("Existing default storage replaced: clearing cache!");
455 ClearCache();
456 }
b21e3194 457
458 if (fStorageMap->Contains("default")) {
e1dd4d81 459 delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
b21e3194 460 }
461 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
9e1ceb13 462}
463
464//_____________________________________________________________________________
465void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
466// set default storage from another active storage
1f341624 467
468 // if lock is ON, cannot activate more storages!
469 if(fLock) {
470 if (fDefaultStorage) {
471 AliFatal("Lock is ON, and default storage is already set: "
472 "cannot reset it or activate more storages!");
473 }
474 }
475
476 if (!storage) {
477 UnsetDefaultStorage();
478 return;
479 }
480
4954c5cd 481 AliCDBStorage* bckStorage = fDefaultStorage;
482
9e1ceb13 483 fDefaultStorage = storage;
4954c5cd 484
485 if(bckStorage && (fDefaultStorage != bckStorage)){
486 AliWarning("Existing default storage replaced: clearing cache!");
487 ClearCache();
488 }
b21e3194 489
490 if (fStorageMap->Contains("default")) {
e1dd4d81 491 delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
b21e3194 492 }
493 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
9e1ceb13 494}
4667c116 495
496//_____________________________________________________________________________
7de84b33 497void AliCDBManager::SetDefaultStorage(const char* mcString, const char* simType) {
498// sets default storage for MC data
499// mcString MUST be "MC",
500// simType can be "Ideal","Residual","Full"
501
502 TString strmcString(mcString);
503 TString strsimType(simType);
504 TString dbString;
505 if (strmcString != "MC"){
506 AliFatal("Method requires first string to be MC!");
507 }
508 else {
509 if (strsimType == "Ideal"){
510 dbString = fgkMCIdealStorage;
511 }
512 else if (strsimType == "Full"){
513 dbString = fgkMCFullStorage;
514 }
515 else if (strsimType == "Residual"){
516 dbString = fgkMCResidualStorage;
517 }
518 else {
519 AliFatal("Error in setting the storage for MC data, second argument MUST be either \"Ideal\" or \"Full\" or \"Residual\".");
520 }
521
522 SetDefaultStorage(dbString.Data());
523 if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",fLHCPeriod.Data()));
524 }
525}
526//_____________________________________________________________________________
527void AliCDBManager::SetDefaultStorageFromRun(Int_t run) {
528// set default storage from the run number - to be used only with raw data
529
530 // if lock is ON, cannot activate more storages!
531 if(fLock) {
532 if (fDefaultStorage) {
533 AliFatal("Lock is ON, and default storage is already set: "
534 "cannot activate default storage from run number");
535 }
536 }
537
538 // retrieve XML file from alien
27cac7e3 539 if(!gGrid) {
540 TGrid::Connect("alien://","");
541 if(!gGrid) {
542 AliError("Connection to alien failed!");
543 return;
544 }
545 }
7de84b33 546 TUUID uuid;
547 TString rndname = "/tmp/";
548 rndname += "OCDBFolderXML.";
549 rndname += uuid.AsString();
550 rndname += ".xml";
551 AliDebug(2, Form("file to be copied = %s", fgkOCDBFolderXMLfile.Data()));
552 if (!TFile::Cp(fgkOCDBFolderXMLfile.Data(), rndname.Data())) {
553 AliFatal(Form("Cannot make a local copy of OCDBFolder xml file in %s",rndname.Data()));
554 }
555 AliCDBHandler* saxcdb = new AliCDBHandler();
556 saxcdb->SetRun(run);
557 TSAXParser *saxParser = new TSAXParser();
558 saxParser->ConnectToHandler("AliCDBHandler", saxcdb);
559 saxParser->ParseFile(rndname.Data());
560 AliInfo(Form(" LHC folder = %s", saxcdb->GetOCDBFolder().Data()));
561 AliInfo(Form(" LHC period start run = %d", saxcdb->GetStartRunRange()));
562 AliInfo(Form(" LHC period end run = %d", saxcdb->GetEndRunRange()));
563 fLHCPeriod = saxcdb->GetOCDBFolder();
564 fStartRunLHCPeriod = saxcdb->GetStartRunRange();
565 fEndRunLHCPeriod = saxcdb->GetEndRunRange();
566
567 SetDefaultStorage(fLHCPeriod.Data());
568 if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",fLHCPeriod.Data()));
569
570}
571
572//_____________________________________________________________________________
1f341624 573void AliCDBManager::UnsetDefaultStorage() {
574// Unset default storage
575
576 // if lock is ON, action is forbidden!
577 if(fLock) {
578 if (fDefaultStorage) {
579 AliFatal("Lock is ON: cannot unset default storage!");
580 }
581 }
582
583 if (fDefaultStorage) {
584 AliWarning("Clearing cache!");
585 ClearCache();
586 }
4130f78c 587
588 fRun = fStartRunLHCPeriod = fEndRunLHCPeriod = -1;
589 fRaw = kFALSE;
1f341624 590
591 fDefaultStorage = 0x0;
4667c116 592}
9e1ceb13 593
02c4845e 594//_____________________________________________________________________________
024cf675 595void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) {
596// sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
02c4845e 597
598 AliCDBParam *aPar = CreateParameter(dbString);
599 if(!aPar) return;
024cf675 600 SetSpecificStorage(calibType, aPar);
02c4845e 601 delete aPar;
602}
603
604//_____________________________________________________________________________
647d2bb8 605void AliCDBManager::SetSpecificStorage(const char* calibType, const AliCDBParam* param) {
024cf675 606// sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
607// Default storage should be defined prior to any specific storages, e.g.:
608// AliCDBManager::instance()->SetDefaultStorage("alien://");
c3a7b59a 609// AliCDBManager::instance()->SetSpecificStorage("TPC/*","local://DB_TPC");
610// AliCDBManager::instance()->SetSpecificStorage("*/Align/*","local://DB_TPCAlign");
611// calibType must be a valid CDB path! (3 level folder structure)
02c4845e 612
7de84b33 613
b5e4b0d2 614 if(!fDefaultStorage && !fRaw) {
c3a7b59a 615 AliError("Please activate a default storage first!");
02c4845e 616 return;
617 }
4005d0b5 618
7de84b33 619
62032124 620 AliCDBPath aPath(calibType);
621 if(!aPath.IsValid()){
622 AliError(Form("Not a valid path: %s", calibType));
623 return;
624 }
625
626 TObjString *objCalibType = new TObjString(aPath.GetPath());
024cf675 627 if(fSpecificStorages.Contains(objCalibType)){
62032124 628 AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one",
024cf675 629 calibType));
4005d0b5 630 AliCDBParam *checkPar = dynamic_cast<AliCDBParam*> (fSpecificStorages.GetValue(calibType));
631 if(checkPar) delete checkPar;
8e245d15 632 delete fSpecificStorages.Remove(objCalibType);
02c4845e 633 }
95c0e132 634 AliCDBStorage *aStorage = GetStorage(param);
635 if(!aStorage) return;
96b7636d 636
637 fSpecificStorages.Add(objCalibType, param->CloneParam());
b21e3194 638
639 if(fStorageMap->Contains(objCalibType)){
640 delete fStorageMap->Remove(objCalibType);
641 }
642 fStorageMap->Add(objCalibType->Clone(), new TObjString(param->GetURI()));
643
02c4845e 644}
645
646//_____________________________________________________________________________
024cf675 647AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) {
648// get storage specific for detector or calibration type
4b5e0dce 649
9c7fb557 650 AliCDBPath calibPath(calibType);
651 if(!calibPath.IsValid()) return NULL;
96b7636d 652
9c7fb557 653 AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibPath.GetPath());
02c4845e 654 if(!checkPar){
b8ec52f6 655 AliError(Form("%s storage not found!", calibType));
02c4845e 656 return NULL;
657 } else {
658 return GetStorage(checkPar);
659 }
96b7636d 660
02c4845e 661}
662
663//_____________________________________________________________________________
024cf675 664AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) {
82096dfc 665// select storage valid for path from the list of specific storages
024cf675 666
62032124 667 AliCDBPath aPath(path);
4005d0b5 668 if(!aPath.IsValid()) return NULL;
62032124 669
024cf675 670 TIter iter(&fSpecificStorages);
62032124 671 TObjString *aCalibType=0;
96b7636d 672 AliCDBPath tmpPath("null/null/null");
024cf675 673 AliCDBParam* aPar=0;
674 while((aCalibType = (TObjString*) iter.Next())){
62032124 675 AliCDBPath calibTypePath(aCalibType->GetName());
676 if(calibTypePath.Comprises(aPath)) {
96b7636d 677 if(calibTypePath.Comprises(tmpPath)) continue;
024cf675 678 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
96b7636d 679 tmpPath.SetPath(calibTypePath.GetPath());
024cf675 680 }
681 }
682 return aPar;
683}
684
685//_____________________________________________________________________________
4667c116 686AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber,
02c4845e 687 Int_t version, Int_t subVersion) {
688// get an AliCDBEntry object from the database
689
024cf675 690 if(runNumber < 0){
691 // RunNumber is not specified. Try with fRun
692 if (fRun < 0){
693 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
694 return NULL;
695 }
696 runNumber = fRun;
697 }
698
02c4845e 699 return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
700}
701
702//_____________________________________________________________________________
4667c116 703AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path,
02c4845e 704 const AliCDBRunRange& runRange, Int_t version,
705 Int_t subVersion) {
706// get an AliCDBEntry object from the database!
707
708 return Get(AliCDBId(path, runRange, version, subVersion));
709}
710
711//_____________________________________________________________________________
4667c116 712AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) {
02c4845e 713// get an AliCDBEntry object from the database
714
02c4845e 715 // check if query's path and runRange are valid
716 // query is invalid also if version is not specified and subversion is!
717 if (!query.IsValid()) {
718 AliError(Form("Invalid query: %s", query.ToString().Data()));
719 return NULL;
720 }
024cf675 721
722 // query is not specified if path contains wildcard or run range= [-1,-1]
723 if (!query.IsSpecified()) {
4667c116 724 AliError(Form("Unspecified query: %s",
02c4845e 725 query.ToString().Data()));
726 return NULL;
727 }
728
7273fe5b 729 if(fLock && !(fRun >= query.GetFirstRun() && fRun <= query.GetLastRun()))
1f341624 730 AliFatal("Lock is ON: cannot use different run number than the internal one!");
731
7273fe5b 732 if(fCache && !(fRun >= query.GetFirstRun() && fRun <= query.GetLastRun()))
024cf675 733 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
734
024cf675 735 AliCDBEntry *entry=0;
8e245d15 736
024cf675 737 // first look into map of cached objects
62032124 738 if(fCache && query.GetFirstRun() == fRun)
024cf675 739 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
740
741 if(entry) {
b8ec52f6 742 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
024cf675 743 return entry;
744 }
96b7636d 745
d1982b43 746 if(!fDefaultStorage) {
747 AliError("No storage set!");
748 return NULL;
749 }
96b7636d 750 // Entry is not in cache -> retrieve it from CDB and cache it!!
024cf675 751 AliCDBStorage *aStorage=0;
752 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
1f341624 753// Bool_t usedDefStorage=kTRUE;
62032124 754
02c4845e 755 if(aPar) {
756 aStorage=GetStorage(aPar);
757 TString str = aPar->GetURI();
758 AliDebug(2,Form("Looking into storage: %s",str.Data()));
1f341624 759// usedDefStorage=kFALSE;
4667c116 760
02c4845e 761 } else {
762 aStorage=GetDefaultStorage();
96b7636d 763 AliDebug(2,"Looking into default storage");
02c4845e 764 }
4667c116 765
024cf675 766 entry = aStorage->Get(query);
024cf675 767
4667c116 768 if(entry && fCache && (query.GetFirstRun() == fRun)){
024cf675 769 CacheEntry(query.GetPath(), entry);
770 }
8e245d15 771
b21e3194 772 if(entry && !fIds->Contains(&entry->GetId())){
773 fIds->Add(entry->GetId().Clone());
774 }
775
776
024cf675 777 return entry;
4667c116 778
779}
780
781//_____________________________________________________________________________
0f40a831 782const char* AliCDBManager::GetURI(const char* path) {
783// return the URI of the storage where to look for path
784
785 if(!IsDefaultStorageSet()) return 0;
786
787 AliCDBParam *aPar=SelectSpecificStorage(path);
788
789 if(aPar) {
790 return aPar->GetURI().Data();
791
792 } else {
793 return GetDefaultStorage()->GetURI().Data();
794 }
795
796 return 0;
797}
798
799//_____________________________________________________________________________
4667c116 800AliCDBId* AliCDBManager::GetId(const AliCDBPath& path, Int_t runNumber,
801 Int_t version, Int_t subVersion) {
802// get the AliCDBId of the valid object from the database (does not retrieve the object)
803// User must delete returned object!
804
805 if(runNumber < 0){
806 // RunNumber is not specified. Try with fRun
807 if (fRun < 0){
808 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
809 return NULL;
810 }
811 runNumber = fRun;
812 }
813
814 return GetId(AliCDBId(path, runNumber, runNumber, version, subVersion));
815}
816
817//_____________________________________________________________________________
818AliCDBId* AliCDBManager::GetId(const AliCDBPath& path,
819 const AliCDBRunRange& runRange, Int_t version,
820 Int_t subVersion) {
821// get the AliCDBId of the valid object from the database (does not retrieve the object)
822// User must delete returned object!
823
824 return GetId(AliCDBId(path, runRange, version, subVersion));
825}
826
827//_____________________________________________________________________________
828AliCDBId* AliCDBManager::GetId(const AliCDBId& query) {
829// get the AliCDBId of the valid object from the database (does not retrieve the object)
830// User must delete returned object!
831
832 if(!fDefaultStorage) {
833 AliError("No storage set!");
834 return NULL;
835 }
836
837 // check if query's path and runRange are valid
838 // query is invalid also if version is not specified and subversion is!
839 if (!query.IsValid()) {
840 AliError(Form("Invalid query: %s", query.ToString().Data()));
841 return NULL;
842 }
843
844 // query is not specified if path contains wildcard or run range= [-1,-1]
845 if (!query.IsSpecified()) {
846 AliError(Form("Unspecified query: %s",
847 query.ToString().Data()));
848 return NULL;
849 }
850
851 if(fCache && query.GetFirstRun() != fRun)
852 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
853
854 AliCDBEntry* entry = 0;
855
856 // first look into map of cached objects
857 if(fCache && query.GetFirstRun() == fRun)
858 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
859
860 if(entry) {
861 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
862 return dynamic_cast<AliCDBId*> (entry->GetId().Clone());
863 }
864
865 // Entry is not in cache -> retrieve it from CDB and cache it!!
866 AliCDBStorage *aStorage=0;
867 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
868
869 if(aPar) {
870 aStorage=GetStorage(aPar);
871 TString str = aPar->GetURI();
872 AliDebug(2,Form("Looking into storage: %s",str.Data()));
024cf675 873
4667c116 874 } else {
875 aStorage=GetDefaultStorage();
876 AliDebug(2,"Looking into default storage");
877 }
878
879 return aStorage->GetId(query);
880
02c4845e 881}
882
883//_____________________________________________________________________________
62032124 884TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber,
02c4845e 885 Int_t version, Int_t subVersion) {
886// get multiple AliCDBEntry objects from the database
887
afd8dbf4 888 if(runNumber < 0){
889 // RunNumber is not specified. Try with fRun
890 if (fRun < 0){
891 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
892 return NULL;
893 }
894 runNumber = fRun;
895 }
896
02c4845e 897 return GetAll(AliCDBId(path, runNumber, runNumber, version,
898 subVersion));
899}
900
901//_____________________________________________________________________________
8e245d15 902TList* AliCDBManager::GetAll(const AliCDBPath& path,
02c4845e 903 const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
904// get multiple AliCDBEntry objects from the database
905
906 return GetAll(AliCDBId(path, runRange, version, subVersion));
907}
908
909//_____________________________________________________________________________
910TList* AliCDBManager::GetAll(const AliCDBId& query) {
911// get multiple AliCDBEntry objects from the database
024cf675 912// Warning: this method works correctly only for queries of the type "Detector/*"
913// and not for more specific queries e.g. "Detector/Calib/*" !
8e245d15 914// Warning #2: Entries are cached, but GetAll will keep on retrieving objects from OCDB!
915// To get an object from cache use Get() function
02c4845e 916
917 if(!fDefaultStorage) {
918 AliError("No storage set!");
919 return NULL;
920 }
921
922 if (!query.IsValid()) {
923 AliError(Form("Invalid query: %s", query.ToString().Data()));
924 return NULL;
925 }
926
afd8dbf4 927 if((fSpecificStorages.GetEntries()>0) && query.GetPath().BeginsWith('*')){
928 // if specific storages are active a query with "*" is ambiguous
929 AliError("Query too generic in this context!");
8e245d15 930 return NULL;
02c4845e 931 }
932
933 if (query.IsAnyRange()) {
934 AliError(Form("Unspecified run or runrange: %s",
8e245d15 935 query.ToString().Data()));
02c4845e 936 return NULL;
8e245d15 937 }
938
1f341624 939 if(fLock && query.GetFirstRun() != fRun)
940 AliFatal("Lock is ON: cannot use different run number than the internal one!");
941
6dc56e97 942 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
024cf675 943
8e245d15 944 AliCDBStorage *aStorage;
02c4845e 945 if(aPar) {
946 aStorage=GetStorage(aPar);
96b7636d 947 AliDebug(2,Form("Looking into storage: %s", aPar->GetURI().Data()));
8e245d15 948
02c4845e 949 } else {
950 aStorage=GetDefaultStorage();
8e245d15 951 AliDebug(2,"Looking into default storage");
02c4845e 952 }
953
96b7636d 954 TList *result = 0;
955 if(aStorage) result = aStorage->GetAll(query);
8e245d15 956 if(!result) return 0;
957
96b7636d 958 // loop on result to check whether entries should be re-queried with specific storages
959 if(fSpecificStorages.GetEntries()>0 && ! (fSpecificStorages.GetEntries() == 1 && aPar)) {
960 AliInfo("Now look into all other specific storages...");
961
962 TIter iter(result);
963 AliCDBEntry* chkEntry=0;
964
965 while((chkEntry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
966 AliCDBId& chkId = chkEntry->GetId();
967 AliDebug(2, Form("Checking id %s ", chkId.GetPath().Data()));
968 AliCDBParam *chkPar=SelectSpecificStorage(chkId.GetPath());
969 if (!chkPar || aPar == chkPar) continue;
970 AliCDBStorage *chkStorage = GetStorage(chkPar);
971 AliDebug(2, Form("Found specific storage! %s", chkPar->GetURI().Data()));
972
973 AliCDBEntry *newEntry=0;
974 chkId.SetRunRange(query.GetFirstRun(), query.GetLastRun());
975 chkId.SetVersion(query.GetVersion());
976 chkId.SetSubVersion(query.GetSubVersion());
977
978 if(chkStorage) newEntry = chkStorage->Get(chkId);
979 if(!newEntry) continue;
980
981 // object is found in specific storage: replace entry in the result list!
982 chkEntry->SetOwner(1);
983 delete result->Remove(chkEntry);
984 result->AddFirst(newEntry);
985 }
986
987 Int_t nEntries = result->GetEntries();
988 AliInfo("After look into other specific storages, result list is:");
989 for(int i=0; i<nEntries;i++){
990 AliCDBEntry *entry = (AliCDBEntry*) result->At(i);
991 AliInfo(Form("%s",entry->GetId().ToString().Data()));
992 }
993 }
994
8e245d15 995 // caching entries
b21e3194 996 TIter iter(result);
997 AliCDBEntry* entry=0;
998 while((entry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
02c4845e 999
b21e3194 1000 if(!fIds->Contains(&entry->GetId())){
1001 fIds->Add(entry->GetId().Clone());
1002 }
1003 if(fCache && (query.GetFirstRun() == fRun)){
96b7636d 1004 CacheEntry(entry->GetId().GetPath(), entry);
8e245d15 1005 }
1006 }
1007
b21e3194 1008
8e245d15 1009 return result;
02c4845e 1010}
1011
1012//_____________________________________________________________________________
647d2bb8 1013Bool_t AliCDBManager::Put(TObject* object, const AliCDBId& id, AliCDBMetaData* metaData, const DataType type){
02c4845e 1014// store an AliCDBEntry object into the database
1015
968cfa08 1016 if (object==0x0) {
1017 AliError("Null Entry! No storage will be done!");
1018 return kFALSE;
1019 }
1020
02c4845e 1021 AliCDBEntry anEntry(object, id, metaData);
b8ec52f6 1022 return Put(&anEntry, type);
02c4845e 1023
1024}
1025
1026
1027//_____________________________________________________________________________
b8ec52f6 1028Bool_t AliCDBManager::Put(AliCDBEntry* entry, DataType type){
02c4845e 1029// store an AliCDBEntry object into the database
1030
b8ec52f6 1031 if(type == kPrivate && !fDefaultStorage) {
02c4845e 1032 AliError("No storage set!");
1033 return kFALSE;
1034 }
1035
8da73612 1036 if (!entry){
1037 AliError("No entry!");
968cfa08 1038 return kFALSE;
1039 }
1040
8da73612 1041 if (entry->GetObject()==0x0){
1042 AliError("No valid object in CDB entry!");
02c4845e 1043 return kFALSE;
1044 }
1045
1046 if (!entry->GetId().IsValid()) {
1047 AliError(Form("Invalid entry ID: %s",
1048 entry->GetId().ToString().Data()));
1049 return kFALSE;
1050 }
1051
1052 if (!entry->GetId().IsSpecified()) {
1053 AliError(Form("Unspecified entry ID: %s",
1054 entry->GetId().ToString().Data()));
1055 return kFALSE;
1056 }
1057
1058 AliCDBId id = entry->GetId();
024cf675 1059 AliCDBParam *aPar = SelectSpecificStorage(id.GetPath());
1060
4005d0b5 1061 AliCDBStorage *aStorage=0;
02c4845e 1062
1063 if(aPar) {
1064 aStorage=GetStorage(aPar);
02c4845e 1065 } else {
b8ec52f6 1066 switch(type){
1067 case kCondition:
1068 aStorage = GetStorage(fCondParam);
1069 break;
1070 case kReference:
1071 aStorage = GetStorage(fRefParam);
1072 break;
1073 case kPrivate:
1074 aStorage = GetDefaultStorage();
1075 break;
1076 }
02c4845e 1077 }
1078
b8ec52f6 1079 AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data()));
1080
4005d0b5 1081 Bool_t result = aStorage->Put(entry, type);
1082
1083 if(fRun >= 0) QueryCDB();
1084
1085 return result;
02c4845e 1086
1087
1088}
9e1ceb13 1089
1090//_____________________________________________________________________________
4b5e0dce 1091void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry)
1092{
1093// cache AliCDBEntry. Cache is valid until run number is changed.
1094
96b7636d 1095 AliCDBEntry *chkEntry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(path));
1096
1097 if(chkEntry) {
1098 AliDebug(2, Form("Object %s already in cache !!", path));
1099 return;
1100 } else {
1101 AliDebug(2,Form("Caching entry %s", path));
1102 }
1103
4b5e0dce 1104 fEntryCache.Add(new TObjString(path), entry);
96b7636d 1105 AliDebug(2,Form("Cache entries: %d", fEntryCache.GetEntries()));
4b5e0dce 1106
1107}
1108
1109//_____________________________________________________________________________
917a098b 1110void AliCDBManager::Print(Option_t* /*option*/) const
1111{
1112// Print list of active storages and their URIs
917a098b 1113
b8ec52f6 1114 TString output=Form("Run number = %d; ",fRun);
1115 output += "Cache is ";
917a098b 1116 if(!fCache) output += "NOT ";
b8ec52f6 1117 output += Form("ACTIVE; Number of active storages: %d\n",fActiveStorages.GetEntries());
917a098b 1118
1119 if(fDefaultStorage) {
b8ec52f6 1120 output += Form("\t*** Default Storage URI: \"%s\"\n",fDefaultStorage->GetURI().Data());
1121// AliInfo(output.Data());
917a098b 1122 }
1123 if(fSpecificStorages.GetEntries()>0) {
917a098b 1124 TIter iter(fSpecificStorages.GetTable());
62032124 1125 TPair *aPair=0;
b8ec52f6 1126 Int_t i=1;
917a098b 1127 while((aPair = (TPair*) iter.Next())){
b8ec52f6 1128 output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n",
1129 i++, ((TObjString*) aPair->Key())->GetName(),
917a098b 1130 ((AliCDBParam*) aPair->Value())->GetURI().Data());
917a098b 1131 }
917a098b 1132 }
1133 if(fDrainStorage) {
b8ec52f6 1134 output += Form("*** Drain Storage URI: %s\n",fDrainStorage->GetURI().Data());
917a098b 1135 }
b8ec52f6 1136 AliInfo(output.Data());
917a098b 1137}
1138
1139//_____________________________________________________________________________
c3a7b59a 1140void AliCDBManager::SetRun(Int_t run)
4b5e0dce 1141{
917a098b 1142// Sets current run number.
4b5e0dce 1143// When the run number changes the caching is cleared.
1f341624 1144
27cac7e3 1145 if(fRun == run)
4b5e0dce 1146 return;
1147
1f341624 1148 if(fLock && fRun >= 0) {
1149 AliFatal("Lock is ON, cannot reset run number!");
1150 }
1151
4b5e0dce 1152 fRun = run;
27cac7e3 1153 if(fRaw){
7de84b33 1154 // here the LHCPeriod xml file is parsed; the string containing the correct period is returned; the default storage is set
1155 if (fStartRunLHCPeriod <= run && fEndRunLHCPeriod >= run){
1156 AliInfo("LHCPeriod alien folder for current run already in memory");
27cac7e3 1157 }else{
7de84b33 1158 SetDefaultStorageFromRun(run);
27cac7e3 1159 if(fEntryCache.GetEntries()!=0) ClearCache();
1160 return;
7de84b33 1161 }
1162 }
4b5e0dce 1163 ClearCache();
62032124 1164 QueryCDB();
4b5e0dce 1165}
1166
1167//_____________________________________________________________________________
1168void AliCDBManager::ClearCache(){
1169// clear AliCDBEntry cache
1170
1f341624 1171 AliDebug(2, Form("Cache entries to be deleted: %d",fEntryCache.GetEntries()));
1172
1173 /*
1174 // To clean entries one by one
1175 TIter iter(fEntryCache.GetTable());
1176 TPair* pair=0;
1177 while((pair= dynamic_cast<TPair*> (iter.Next()))){
1178
1179 TObjString* key = dynamic_cast<TObjString*> (pair->Key());
1180 AliCDBEntry* entry = dynamic_cast<AliCDBEntry*> (pair->Value());
1181 AliDebug(2, Form("Deleting entry: %s", key->GetName()));
1182 if (entry) delete entry;
1183 delete fEntryCache.Remove(key);
1184 }
1185 */
4b5e0dce 1186 fEntryCache.DeleteAll();
1f341624 1187 AliDebug(2, Form("After deleting - Cache entries: %d",fEntryCache.GetEntries()));
4b5e0dce 1188}
1189
1190//_____________________________________________________________________________
4005d0b5 1191void AliCDBManager::UnloadFromCache(const char* path){
1192// unload cached object
1193
b086955d 1194 if(!fActiveStorages.GetEntries()) {
1195 AliDebug(2, Form("No active storages. Object \"%s\" is not unloaded from cache", path));
1196 return;
1197 }
1198
4005d0b5 1199 AliCDBPath queryPath(path);
1200 if(!queryPath.IsValid()) return;
1201
1202 if(!queryPath.IsWildcard()) { // path is not wildcard, get it directly from the cache and unload it!
1203 if(fEntryCache.Contains(path)){
5379c4a3 1204 AliDebug(2, Form("Unloading object \"%s\" from cache", path));
4005d0b5 1205 TObjString pathStr(path);
4005d0b5 1206 delete fEntryCache.Remove(&pathStr);
1207 } else {
13242232 1208 AliErrorF("Cache does not contain object \"%s\"!", path);
4005d0b5 1209 }
13242232 1210 AliDebugF(2, "Cache entries: %d",fEntryCache.GetEntries());
4005d0b5 1211 return;
1212 }
1213
1214 // path is wildcard: loop on the cache and unload all comprised objects!
1215 TIter iter(fEntryCache.GetTable());
1216 TPair* pair = 0;
1217
1218 while((pair = dynamic_cast<TPair*> (iter.Next()))){
1219 AliCDBPath entryPath = pair->Key()->GetName();
1220 if(queryPath.Comprises(entryPath)) {
5379c4a3 1221 AliDebug(2, Form("Unloading object \"%s\" from cache", entryPath.GetPath().Data()));
4005d0b5 1222 TObjString pathStr(entryPath.GetPath().Data());
4005d0b5 1223 delete fEntryCache.Remove(&pathStr);
1224 }
1225 }
1226 AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries()));
1227}
1228
1229//_____________________________________________________________________________
9e1ceb13 1230void AliCDBManager::DestroyActiveStorages() {
1231// delete list of active storages
1232
1233 fActiveStorages.DeleteAll();
02c4845e 1234 fSpecificStorages.DeleteAll();
9e1ceb13 1235}
1236
1237//_____________________________________________________________________________
1238void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
b05400be 1239// destroys active storage
1240
1241/*
917a098b 1242 TIter iter(fActiveStorages.GetTable());
b05400be 1243 TPair* aPair;
1244 while ((aPair = (TPair*) iter.Next())) {
1245 if(storage == (AliCDBStorage*) aPair->Value())
1246 delete fActiveStorages.Remove(aPair->Key());
1247 storage->Delete(); storage=0x0;
1248 }
6dc56e97 1249*/
9e1ceb13 1250
1251}
1252
62032124 1253//_____________________________________________________________________________
1254void AliCDBManager::QueryCDB() {
1255// query default and specific storages for files valid for fRun. Every storage loads the Ids into its list.
1256
1257 if (fRun < 0){
1258 AliError("Run number not yet set! Use AliCDBManager::SetRun.");
1259 return;
1260 }
6dc56e97 1261 if (!fDefaultStorage){
1262 AliError("Default storage is not set! Use AliCDBManager::SetDefaultStorage");
1263 return;
1264 }
1265 if(fDefaultStorage->GetType() == "alien"){
1266 fDefaultStorage->QueryCDB(fRun);
1267 } else {
1268 AliDebug(2,"Skipping query for valid files, it used only in grid...");
1269 }
62032124 1270
1271 TIter iter(&fSpecificStorages);
1272 TObjString *aCalibType=0;
1273 AliCDBParam* aPar=0;
1274 while((aCalibType = dynamic_cast<TObjString*> (iter.Next()))){
1275 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
1276 if(aPar) {
c3a7b59a 1277 AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName()));
6dc56e97 1278 AliCDBStorage *aStorage = GetStorage(aPar);
1279 if(aStorage->GetType() == "alien"){
1280 aStorage->QueryCDB(fRun,aCalibType->GetName());
1281 } else {
1282 AliDebug(2,
1283 "Skipping query for valid files, it is used only in grid...");
1284 }
62032124 1285 }
1286 }
62032124 1287}
1288
b8ec52f6 1289//______________________________________________________________________________________________
1290const char* AliCDBManager::GetDataTypeName(DataType type)
1291{
1292 // returns the name (string) of the data type
1293
1294 switch (type){
1295 case kCondition: return "Conditions";
1296 case kReference: return "Reference";
1297 case kPrivate: return "Private";
1298 }
1299 return 0;
1300
1301}
62032124 1302
4667c116 1303//______________________________________________________________________________________________
1304void AliCDBManager::InitShortLived()
1305{
1306 // Init the list of short-lived objects
1307 // currently disabled
1308
1309 fShortLived=0x0;
1310
1311// fShortLived = new TList();
1312// fShortLived->SetOwner(1);
1313//
1314// fShortLived->Add(new TObjString("EMCAL/Calib/Data"));
1315//
1316// fShortLived->Add(new TObjString("HMPID/Calib/Nmean"));
1317// fShortLived->Add(new TObjString("HMPID/Calib/Qthre"));
1318//
1319// fShortLived->Add(new TObjString("ITS/Calib/CalibSPD"));
1320//
1321// fShortLived->Add(new TObjString("MUON/Calib/Gains"));
1322// fShortLived->Add(new TObjString("MUON/Calib/HV"));
1323// fShortLived->Add(new TObjString("MUON/Calib/Pedestals"));
1324//
1325// fShortLived->Add(new TObjString("PHOS/Calib/CpvGainPedestals"));
1326// fShortLived->Add(new TObjString("PHOS/Calib/EmcGainPedestals"));
1327//
1328// fShortLived->Add(new TObjString("PMD/Calib/Data"));
1329//
1330// fShortLived->Add(new TObjString("TRD/Calib/ChamberGainFactor"));
1331// fShortLived->Add(new TObjString("TRD/Calib/LocalGainFactor"));
1332// fShortLived->Add(new TObjString("TRD/Calib/ChamberT0"));
1333// fShortLived->Add(new TObjString("TRD/Calib/LocalT0"));
1334// fShortLived->Add(new TObjString("TRD/Calib/ChamberVdrift"));
1335// fShortLived->Add(new TObjString("TRD/Calib/LocalVdrift"));
1336//
1337// fShortLived->Add(new TObjString("ZDC/Calib/Data"));
1338
1339}
1340
1341//______________________________________________________________________________________________
1342Bool_t AliCDBManager::IsShortLived(const char* path)
1343{
1344 // returns the name (string) of the data type
1345
1346 if(!fShortLived) return kFALSE;
1347
1348 AliCDBPath aPath(path);
1349 if(!aPath.IsValid()){
1350 AliError(Form("Not a valid path: %s", path));
1351 return kFALSE;
1352 }
1353
1354 return fShortLived->Contains(path);
1355
1356}
1357
1f341624 1358//______________________________________________________________________________________________
a6f59240 1359ULong_t AliCDBManager::SetLock(Bool_t lock, ULong_t key){
1360 // To lock/unlock user must provide the key. A new key is provided after
1361 // each successful lock. User should always backup the returned key and
1362 // use it on next access.
1363 if (fLock == lock) return 0; // nothing to be done
1364 if (lock) {
1365 // User wants to lock - check his identity
1366 if (fKey) {
1367 // Lock has a user - check his key
1368 if (fKey != key) {
1369 AliFatal("Wrong key provided to lock CDB. Please remove CDB lock access from your code !");
1370 return 0;
1371 }
1372 }
1373 // Provide new key
1374 fKey = gSystem->Now();
1375 fLock = kTRUE;
1376 return fKey;
1377 }
1378 // User wants to unlock - check the provided key
1379 if (key != fKey) {
1380 AliFatal("Lock is ON: wrong key provided");
1381 return 0;
1382 }
1383 fLock = kFALSE;
1384 return key;
1f341624 1385}
1386
9e1ceb13 1387///////////////////////////////////////////////////////////
1388// AliCDBManager Parameter class //
1389// interface to specific AliCDBParameter class //
1390// (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) //
1391///////////////////////////////////////////////////////////
1392
62032124 1393AliCDBParam::AliCDBParam():
fe12e09c 1394 fType(),
1395 fURI()
62032124 1396{
9e1ceb13 1397// constructor
1398
1399}
1400
1401//_____________________________________________________________________________
1402AliCDBParam::~AliCDBParam() {
1403// destructor
1404
1405}
1406