]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliCDBManager.cxx
No HLT specific for HMPID (not needed)
[u/mrichter/AliRoot.git] / STEER / 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"
28#include "AliCDBMetaData.h"
9e1ceb13 29
02c4845e 30#include <TObjString.h>
9e1ceb13 31#include <TSystem.h>
32
33ClassImp(AliCDBParam)
34
35ClassImp(AliCDBManager)
36
b8ec52f6 37//TODO OCDB and Reference folder should not be fully hardcoded but built from run number (or year/LHC period)
38TString AliCDBManager::fgkCondUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/CDB?user=aliprod");
39TString AliCDBManager::fgkRefUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/Reference?user=aliprod");
9e1ceb13 40AliCDBManager* AliCDBManager::fgInstance = 0x0;
41
42//_____________________________________________________________________________
b8ec52f6 43AliCDBManager* AliCDBManager::Instance()
44{
9e1ceb13 45// returns AliCDBManager instance (singleton)
46
47 if (!fgInstance) {
48 fgInstance = new AliCDBManager();
49 fgInstance->Init();
50 }
51
52 return fgInstance;
53}
54
55//_____________________________________________________________________________
56void AliCDBManager::Init() {
57// factory registering
58
59 RegisterFactory(new AliCDBDumpFactory());
60 RegisterFactory(new AliCDBLocalFactory());
61 // AliCDBGridFactory is registered only if AliEn libraries are enabled in Root
62 if(!gSystem->Exec("root-config --has-alien |grep yes 2>&1 > /dev/null")){ // returns 0 if yes
63 AliInfo("AliEn classes enabled in Root. AliCDBGrid factory registered.");
64 RegisterFactory(new AliCDBGridFactory());
b8ec52f6 65 fCondParam = CreateParameter(fgkCondUri);
66 fRefParam = CreateParameter(fgkRefUri);
9e1ceb13 67 }
4667c116 68
69 InitShortLived();
9e1ceb13 70}
71//_____________________________________________________________________________
72void AliCDBManager::Destroy() {
73// delete ALCDBManager instance and active storages
74
75 if (fgInstance) {
4b5e0dce 76 //fgInstance->Delete();
9e1ceb13 77 delete fgInstance;
78 fgInstance = 0x0;
79 }
80}
81
82//_____________________________________________________________________________
83AliCDBManager::AliCDBManager():
fe12e09c 84 TObject(),
85 fFactories(),
86 fActiveStorages(),
87 fSpecificStorages(),
b21e3194 88 fEntryCache(),
89 fIds(0),
90 fStorageMap(0),
91 fShortLived(0),
fe12e09c 92 fDefaultStorage(NULL),
4667c116 93 fRemoteStorage(NULL),
fe12e09c 94 fDrainStorage(NULL),
b21e3194 95 fCondParam(0),
96 fRefParam(0),
4667c116 97 fRun(-1),
b21e3194 98 fCache(kTRUE)
9e1ceb13 99{
100// default constuctor
4b5e0dce 101 fFactories.SetOwner(1);
62032124 102 fActiveStorages.SetOwner(1);
103 fSpecificStorages.SetOwner(1);
104 fEntryCache.SetOwner(1);
b21e3194 105
106 fStorageMap = new TMap();
107 fStorageMap->SetOwner(1);
108 fIds = new TList();
109 fIds->SetOwner(1);
9e1ceb13 110}
111
112//_____________________________________________________________________________
113AliCDBManager::~AliCDBManager() {
114// destructor
4b5e0dce 115 ClearCache();
9e1ceb13 116 DestroyActiveStorages();
62032124 117 fFactories.Delete();
b05400be 118 fDrainStorage = 0x0;
119 fDefaultStorage = 0x0;
4667c116 120 fRemoteStorage = 0x0;
b21e3194 121 delete fStorageMap; fStorageMap = 0;
122 delete fIds; fIds = 0;
b8ec52f6 123 delete fCondParam;
124 delete fRefParam;
4667c116 125 delete fShortLived; fShortLived = 0x0;
9e1ceb13 126}
127
9e1ceb13 128//_____________________________________________________________________________
129void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){
130// put a storage object into the list of active storages
131
132 fActiveStorages.Add(param, storage);
133 AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries()));
134}
135
136//_____________________________________________________________________________
137void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) {
138// add a storage factory to the list of registerd factories
139
140 if (!fFactories.Contains(factory)) {
141 fFactories.Add(factory);
142 }
143}
144
145//_____________________________________________________________________________
fdf65bb5 146Bool_t AliCDBManager::HasStorage(const char* dbString) const {
b21e3194 147// check if dbString is a URI valid for one of the registered factories
9e1ceb13 148
149 TIter iter(&fFactories);
150
62032124 151 AliCDBStorageFactory* factory=0;
9e1ceb13 152 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
153
154 if (factory->Validate(dbString)) {
155 return kTRUE;
4005d0b5 156 }
9e1ceb13 157 }
158
159 return kFALSE;
160}
161
162//_____________________________________________________________________________
fdf65bb5 163AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
9e1ceb13 164// create AliCDBParam object from URI string
165
166 TIter iter(&fFactories);
167
62032124 168 AliCDBStorageFactory* factory=0;
9e1ceb13 169 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
9e1ceb13 170 AliCDBParam* param = factory->CreateParameter(dbString);
62032124 171 if(param) return param;
9e1ceb13 172 }
173
174 return NULL;
175}
176
177//_____________________________________________________________________________
178AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) {
179// get storage object from URI string
180
181 AliCDBParam* param = CreateParameter(dbString);
182 if (!param) {
c3a7b59a 183 AliError(Form("Failed to activate requested storage! Check URI: %s", dbString));
9e1ceb13 184 return NULL;
82096dfc 185 }
9e1ceb13 186
187 AliCDBStorage* aStorage = GetStorage(param);
188
189 delete param;
9e1ceb13 190 return aStorage;
191}
192
193//_____________________________________________________________________________
194AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) {
195// get storage object from AliCDBParam object
196
82096dfc 197 // if the list of active storages already contains
9e1ceb13 198 // the requested storage, return it
199 AliCDBStorage* aStorage = GetActiveStorage(param);
200 if (aStorage) {
201 return aStorage;
202 }
203
204 TIter iter(&fFactories);
205
62032124 206 AliCDBStorageFactory* factory=0;
917a098b 207
9e1ceb13 208 // loop on the list of registered factories
209 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
210
211 // each factory tries to create its storage from the parameter
212 aStorage = factory->Create(param);
213 if (aStorage) {
214 PutActiveStorage(param->CloneParam(), aStorage);
917a098b 215 aStorage->SetURI(param->GetURI());
6dc56e97 216 if(fRun >= 0) {
96b7636d 217 if(aStorage->GetType() == "alien"){
218 aStorage->QueryCDB(fRun);
219 } else {
220 AliDebug(2,
221 "Skipping query for valid files, it is used only in grid...");
222 }
c3a7b59a 223 }
9e1ceb13 224 return aStorage;
225 }
226 }
227
c3a7b59a 228 AliError(Form("Failed to activate requested storage! Check URI: %s", param->GetURI().Data()));
229
9e1ceb13 230 return NULL;
231}
232
62032124 233//_____________________________________________________________________________
234AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) {
235// get a storage object from the list of active storages
236
237 return dynamic_cast<AliCDBStorage*> (fActiveStorages.GetValue(param));
238}
239
9e1ceb13 240//_____________________________________________________________________________
241TList* AliCDBManager::GetActiveStorages() {
242// return list of active storages
62032124 243// user has responsibility to delete returned object
9e1ceb13 244
245 TList* result = new TList();
246
917a098b 247 TIter iter(fActiveStorages.GetTable());
62032124 248 TPair* aPair=0;
9e1ceb13 249 while ((aPair = (TPair*) iter.Next())) {
250 result->Add(aPair->Value());
251 }
252
253 return result;
254}
255
256//_____________________________________________________________________________
257void AliCDBManager::SetDrain(const char* dbString) {
258// set drain storage from URI string
259
260 fDrainStorage = GetStorage(dbString);
261}
262
263//_____________________________________________________________________________
264void AliCDBManager::SetDrain(const AliCDBParam* param) {
265// set drain storage from AliCDBParam
b8ec52f6 266
9e1ceb13 267 fDrainStorage = GetStorage(param);
268}
269
270//_____________________________________________________________________________
271void AliCDBManager::SetDrain(AliCDBStorage* storage) {
272// set drain storage from another active storage
273
274 fDrainStorage = storage;
275}
276
277//_____________________________________________________________________________
278Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
279// drain retrieved object to drain storage
280
b8ec52f6 281 AliDebug(2, "Draining into drain storage...");
9e1ceb13 282 return fDrainStorage->Put(entry);
283}
284
9e1ceb13 285//_____________________________________________________________________________
286void AliCDBManager::SetDefaultStorage(const char* dbString) {
287// sets default storage from URI string
288
82096dfc 289 AliInfo(Form("Setting Default storage to: %s",dbString));
4954c5cd 290 AliCDBStorage* bckStorage = fDefaultStorage;
291
82096dfc 292 fDefaultStorage = GetStorage(dbString);
4954c5cd 293
294 if(bckStorage && (fDefaultStorage != bckStorage)){
295 AliWarning("Existing default storage replaced: clearing cache!");
296 ClearCache();
297 }
b21e3194 298
299 if (fStorageMap->Contains("default")) {
300 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
301 }
302 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
9e1ceb13 303}
304
305//_____________________________________________________________________________
306void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
307// set default storage from AliCDBParam object
4667c116 308
4954c5cd 309 AliCDBStorage* bckStorage = fDefaultStorage;
310
b8ec52f6 311 fDefaultStorage = GetStorage(param);
4954c5cd 312
313 if(bckStorage && (fDefaultStorage != bckStorage)){
314 AliWarning("Existing default storage replaced: clearing cache!");
315 ClearCache();
316 }
b21e3194 317
318 if (fStorageMap->Contains("default")) {
319 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
320 }
321 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
9e1ceb13 322}
323
324//_____________________________________________________________________________
325void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
326// set default storage from another active storage
4667c116 327
4954c5cd 328 AliCDBStorage* bckStorage = fDefaultStorage;
329
9e1ceb13 330 fDefaultStorage = storage;
4954c5cd 331
332 if(bckStorage && (fDefaultStorage != bckStorage)){
333 AliWarning("Existing default storage replaced: clearing cache!");
334 ClearCache();
335 }
b21e3194 336
337 if (fStorageMap->Contains("default")) {
338 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
339 }
340 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
9e1ceb13 341}
4667c116 342//_____________________________________________________________________________
343void AliCDBManager::SetRemoteStorage(const char* dbString) {
344// sets remote storage from URI string
345// Remote storage is queried if it is activated and if object was not found in default storage
346
4954c5cd 347 AliInfo(Form("Setting remote storage to: %s",dbString));
4667c116 348 fRemoteStorage = GetStorage(dbString);
349}
350
351//_____________________________________________________________________________
352void AliCDBManager::SetRemoteStorage(const AliCDBParam* param) {
353// set remote storage from AliCDBParam object
354// Remote storage is queried if it is activated and if object was not found in default storage
355
356 fRemoteStorage = GetStorage(param);
357}
358
359//_____________________________________________________________________________
360void AliCDBManager::SetRemoteStorage(AliCDBStorage* storage) {
361// set remote storage from another active storage
362// Remote storage is queried if it is activated and if object was not found in default storage
363
364 fRemoteStorage = storage;
365}
9e1ceb13 366
02c4845e 367//_____________________________________________________________________________
024cf675 368void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) {
369// sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
02c4845e 370
371 AliCDBParam *aPar = CreateParameter(dbString);
372 if(!aPar) return;
024cf675 373 SetSpecificStorage(calibType, aPar);
02c4845e 374 delete aPar;
375}
376
377//_____________________________________________________________________________
024cf675 378void AliCDBManager::SetSpecificStorage(const char* calibType, AliCDBParam* param) {
379// sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
380// Default storage should be defined prior to any specific storages, e.g.:
381// AliCDBManager::instance()->SetDefaultStorage("alien://");
c3a7b59a 382// AliCDBManager::instance()->SetSpecificStorage("TPC/*","local://DB_TPC");
383// AliCDBManager::instance()->SetSpecificStorage("*/Align/*","local://DB_TPCAlign");
384// calibType must be a valid CDB path! (3 level folder structure)
02c4845e 385
386 if(!fDefaultStorage) {
c3a7b59a 387 AliError("Please activate a default storage first!");
02c4845e 388 return;
389 }
4005d0b5 390
62032124 391 AliCDBPath aPath(calibType);
392 if(!aPath.IsValid()){
393 AliError(Form("Not a valid path: %s", calibType));
394 return;
395 }
396
397 TObjString *objCalibType = new TObjString(aPath.GetPath());
024cf675 398 if(fSpecificStorages.Contains(objCalibType)){
62032124 399 AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one",
024cf675 400 calibType));
4005d0b5 401 AliCDBParam *checkPar = dynamic_cast<AliCDBParam*> (fSpecificStorages.GetValue(calibType));
402 if(checkPar) delete checkPar;
8e245d15 403 delete fSpecificStorages.Remove(objCalibType);
02c4845e 404 }
405 GetStorage(param);
96b7636d 406
407 fSpecificStorages.Add(objCalibType, param->CloneParam());
b21e3194 408
409 if(fStorageMap->Contains(objCalibType)){
410 delete fStorageMap->Remove(objCalibType);
411 }
412 fStorageMap->Add(objCalibType->Clone(), new TObjString(param->GetURI()));
413
02c4845e 414}
415
416//_____________________________________________________________________________
024cf675 417AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) {
418// get storage specific for detector or calibration type
4b5e0dce 419
9c7fb557 420 AliCDBPath calibPath(calibType);
421 if(!calibPath.IsValid()) return NULL;
96b7636d 422
9c7fb557 423 AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibPath.GetPath());
02c4845e 424 if(!checkPar){
b8ec52f6 425 AliError(Form("%s storage not found!", calibType));
02c4845e 426 return NULL;
427 } else {
428 return GetStorage(checkPar);
429 }
96b7636d 430
02c4845e 431}
432
024cf675 433//_____________________________________________________________________________
434AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) {
82096dfc 435// select storage valid for path from the list of specific storages
024cf675 436
62032124 437 AliCDBPath aPath(path);
4005d0b5 438 if(!aPath.IsValid()) return NULL;
62032124 439
024cf675 440 TIter iter(&fSpecificStorages);
62032124 441 TObjString *aCalibType=0;
96b7636d 442 AliCDBPath tmpPath("null/null/null");
024cf675 443 AliCDBParam* aPar=0;
444 while((aCalibType = (TObjString*) iter.Next())){
62032124 445 AliCDBPath calibTypePath(aCalibType->GetName());
446 if(calibTypePath.Comprises(aPath)) {
96b7636d 447 if(calibTypePath.Comprises(tmpPath)) continue;
024cf675 448 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
96b7636d 449 tmpPath.SetPath(calibTypePath.GetPath());
024cf675 450 }
451 }
452 return aPar;
453}
454
02c4845e 455//_____________________________________________________________________________
4667c116 456AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber,
02c4845e 457 Int_t version, Int_t subVersion) {
458// get an AliCDBEntry object from the database
459
024cf675 460 if(runNumber < 0){
461 // RunNumber is not specified. Try with fRun
462 if (fRun < 0){
463 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
464 return NULL;
465 }
466 runNumber = fRun;
467 }
468
02c4845e 469 return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
470}
471
472//_____________________________________________________________________________
4667c116 473AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path,
02c4845e 474 const AliCDBRunRange& runRange, Int_t version,
475 Int_t subVersion) {
476// get an AliCDBEntry object from the database!
477
478 return Get(AliCDBId(path, runRange, version, subVersion));
479}
480
481//_____________________________________________________________________________
4667c116 482AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) {
02c4845e 483// get an AliCDBEntry object from the database
484
485 if(!fDefaultStorage) {
486 AliError("No storage set!");
487 return NULL;
488 }
489
490 // check if query's path and runRange are valid
491 // query is invalid also if version is not specified and subversion is!
492 if (!query.IsValid()) {
493 AliError(Form("Invalid query: %s", query.ToString().Data()));
494 return NULL;
495 }
024cf675 496
497 // query is not specified if path contains wildcard or run range= [-1,-1]
498 if (!query.IsSpecified()) {
4667c116 499 AliError(Form("Unspecified query: %s",
02c4845e 500 query.ToString().Data()));
501 return NULL;
502 }
503
4667c116 504 if(fCache && query.GetFirstRun() != fRun)
024cf675 505 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
506
8e245d15 507
024cf675 508 AliCDBEntry *entry=0;
8e245d15 509
024cf675 510 // first look into map of cached objects
62032124 511 if(fCache && query.GetFirstRun() == fRun)
024cf675 512 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
513
514 if(entry) {
b8ec52f6 515 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
024cf675 516 return entry;
517 }
96b7636d 518
519 // Entry is not in cache -> retrieve it from CDB and cache it!!
024cf675 520 AliCDBStorage *aStorage=0;
521 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
4667c116 522 Bool_t usedDefStorage=kTRUE;
62032124 523
02c4845e 524 if(aPar) {
525 aStorage=GetStorage(aPar);
526 TString str = aPar->GetURI();
527 AliDebug(2,Form("Looking into storage: %s",str.Data()));
4667c116 528 usedDefStorage=kFALSE;
529
02c4845e 530 } else {
531 aStorage=GetDefaultStorage();
96b7636d 532 AliDebug(2,"Looking into default storage");
02c4845e 533 }
4667c116 534
024cf675 535 entry = aStorage->Get(query);
024cf675 536
4667c116 537 if (!entry && usedDefStorage && IsRemoteStorageSet()) {
538 AliWarning(Form("Object not found in default storage: Looking into remote storage!"));
539 entry = fRemoteStorage->Get(query);
540 }
541
542 if(entry && fCache && (query.GetFirstRun() == fRun)){
024cf675 543 CacheEntry(query.GetPath(), entry);
544 }
8e245d15 545
b21e3194 546 if(entry && !fIds->Contains(&entry->GetId())){
547 fIds->Add(entry->GetId().Clone());
548 }
549
550
024cf675 551 return entry;
4667c116 552
553}
554
555//_____________________________________________________________________________
556AliCDBId* AliCDBManager::GetId(const AliCDBPath& path, Int_t runNumber,
557 Int_t version, Int_t subVersion) {
558// get the AliCDBId of the valid object from the database (does not retrieve the object)
559// User must delete returned object!
560
561 if(runNumber < 0){
562 // RunNumber is not specified. Try with fRun
563 if (fRun < 0){
564 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
565 return NULL;
566 }
567 runNumber = fRun;
568 }
569
570 return GetId(AliCDBId(path, runNumber, runNumber, version, subVersion));
571}
572
573//_____________________________________________________________________________
574AliCDBId* AliCDBManager::GetId(const AliCDBPath& path,
575 const AliCDBRunRange& runRange, Int_t version,
576 Int_t subVersion) {
577// get the AliCDBId of the valid object from the database (does not retrieve the object)
578// User must delete returned object!
579
580 return GetId(AliCDBId(path, runRange, version, subVersion));
581}
582
583//_____________________________________________________________________________
584AliCDBId* AliCDBManager::GetId(const AliCDBId& query) {
585// get the AliCDBId of the valid object from the database (does not retrieve the object)
586// User must delete returned object!
587
588 if(!fDefaultStorage) {
589 AliError("No storage set!");
590 return NULL;
591 }
592
593 // check if query's path and runRange are valid
594 // query is invalid also if version is not specified and subversion is!
595 if (!query.IsValid()) {
596 AliError(Form("Invalid query: %s", query.ToString().Data()));
597 return NULL;
598 }
599
600 // query is not specified if path contains wildcard or run range= [-1,-1]
601 if (!query.IsSpecified()) {
602 AliError(Form("Unspecified query: %s",
603 query.ToString().Data()));
604 return NULL;
605 }
606
607 if(fCache && query.GetFirstRun() != fRun)
608 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
609
610 AliCDBEntry* entry = 0;
611
612 // first look into map of cached objects
613 if(fCache && query.GetFirstRun() == fRun)
614 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
615
616 if(entry) {
617 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
618 return dynamic_cast<AliCDBId*> (entry->GetId().Clone());
619 }
620
621 // Entry is not in cache -> retrieve it from CDB and cache it!!
622 AliCDBStorage *aStorage=0;
623 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
624
625 if(aPar) {
626 aStorage=GetStorage(aPar);
627 TString str = aPar->GetURI();
628 AliDebug(2,Form("Looking into storage: %s",str.Data()));
024cf675 629
4667c116 630 } else {
631 aStorage=GetDefaultStorage();
632 AliDebug(2,"Looking into default storage");
633 }
634
635 return aStorage->GetId(query);
636
02c4845e 637}
638
639//_____________________________________________________________________________
62032124 640TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber,
02c4845e 641 Int_t version, Int_t subVersion) {
642// get multiple AliCDBEntry objects from the database
643
afd8dbf4 644 if(runNumber < 0){
645 // RunNumber is not specified. Try with fRun
646 if (fRun < 0){
647 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
648 return NULL;
649 }
650 runNumber = fRun;
651 }
652
02c4845e 653 return GetAll(AliCDBId(path, runNumber, runNumber, version,
654 subVersion));
655}
656
657//_____________________________________________________________________________
8e245d15 658TList* AliCDBManager::GetAll(const AliCDBPath& path,
02c4845e 659 const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
660// get multiple AliCDBEntry objects from the database
661
662 return GetAll(AliCDBId(path, runRange, version, subVersion));
663}
664
665//_____________________________________________________________________________
666TList* AliCDBManager::GetAll(const AliCDBId& query) {
667// get multiple AliCDBEntry objects from the database
024cf675 668// Warning: this method works correctly only for queries of the type "Detector/*"
669// and not for more specific queries e.g. "Detector/Calib/*" !
8e245d15 670// Warning #2: Entries are cached, but GetAll will keep on retrieving objects from OCDB!
671// To get an object from cache use Get() function
02c4845e 672
673 if(!fDefaultStorage) {
674 AliError("No storage set!");
675 return NULL;
676 }
677
678 if (!query.IsValid()) {
679 AliError(Form("Invalid query: %s", query.ToString().Data()));
680 return NULL;
681 }
682
afd8dbf4 683 if((fSpecificStorages.GetEntries()>0) && query.GetPath().BeginsWith('*')){
684 // if specific storages are active a query with "*" is ambiguous
685 AliError("Query too generic in this context!");
8e245d15 686 return NULL;
02c4845e 687 }
688
689 if (query.IsAnyRange()) {
690 AliError(Form("Unspecified run or runrange: %s",
8e245d15 691 query.ToString().Data()));
02c4845e 692 return NULL;
8e245d15 693 }
694
6dc56e97 695 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
024cf675 696
8e245d15 697 AliCDBStorage *aStorage;
02c4845e 698 if(aPar) {
699 aStorage=GetStorage(aPar);
96b7636d 700 AliDebug(2,Form("Looking into storage: %s", aPar->GetURI().Data()));
8e245d15 701
02c4845e 702 } else {
703 aStorage=GetDefaultStorage();
8e245d15 704 AliDebug(2,"Looking into default storage");
02c4845e 705 }
706
96b7636d 707 TList *result = 0;
708 if(aStorage) result = aStorage->GetAll(query);
8e245d15 709 if(!result) return 0;
710
96b7636d 711 // loop on result to check whether entries should be re-queried with specific storages
712 if(fSpecificStorages.GetEntries()>0 && ! (fSpecificStorages.GetEntries() == 1 && aPar)) {
713 AliInfo("Now look into all other specific storages...");
714
715 TIter iter(result);
716 AliCDBEntry* chkEntry=0;
717
718 while((chkEntry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
719 AliCDBId& chkId = chkEntry->GetId();
720 AliDebug(2, Form("Checking id %s ", chkId.GetPath().Data()));
721 AliCDBParam *chkPar=SelectSpecificStorage(chkId.GetPath());
722 if (!chkPar || aPar == chkPar) continue;
723 AliCDBStorage *chkStorage = GetStorage(chkPar);
724 AliDebug(2, Form("Found specific storage! %s", chkPar->GetURI().Data()));
725
726 AliCDBEntry *newEntry=0;
727 chkId.SetRunRange(query.GetFirstRun(), query.GetLastRun());
728 chkId.SetVersion(query.GetVersion());
729 chkId.SetSubVersion(query.GetSubVersion());
730
731 if(chkStorage) newEntry = chkStorage->Get(chkId);
732 if(!newEntry) continue;
733
734 // object is found in specific storage: replace entry in the result list!
735 chkEntry->SetOwner(1);
736 delete result->Remove(chkEntry);
737 result->AddFirst(newEntry);
738 }
739
740 Int_t nEntries = result->GetEntries();
741 AliInfo("After look into other specific storages, result list is:");
742 for(int i=0; i<nEntries;i++){
743 AliCDBEntry *entry = (AliCDBEntry*) result->At(i);
744 AliInfo(Form("%s",entry->GetId().ToString().Data()));
745 }
746 }
747
8e245d15 748 // caching entries
b21e3194 749 TIter iter(result);
750 AliCDBEntry* entry=0;
751 while((entry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
02c4845e 752
b21e3194 753 if(!fIds->Contains(&entry->GetId())){
754 fIds->Add(entry->GetId().Clone());
755 }
756 if(fCache && (query.GetFirstRun() == fRun)){
96b7636d 757 CacheEntry(entry->GetId().GetPath(), entry);
8e245d15 758 }
759 }
760
b21e3194 761
8e245d15 762 return result;
02c4845e 763}
764
765//_____________________________________________________________________________
b8ec52f6 766Bool_t AliCDBManager::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData, DataType type){
02c4845e 767// store an AliCDBEntry object into the database
768
769 AliCDBEntry anEntry(object, id, metaData);
b8ec52f6 770 return Put(&anEntry, type);
02c4845e 771
772}
773
774
775//_____________________________________________________________________________
b8ec52f6 776Bool_t AliCDBManager::Put(AliCDBEntry* entry, DataType type){
02c4845e 777// store an AliCDBEntry object into the database
778
b8ec52f6 779 if(type == kPrivate && !fDefaultStorage) {
02c4845e 780 AliError("No storage set!");
781 return kFALSE;
782 }
783
784 if (!entry){
785 AliError("No entry!");
786 return kFALSE;
787 }
788
789 if (!entry->GetId().IsValid()) {
790 AliError(Form("Invalid entry ID: %s",
791 entry->GetId().ToString().Data()));
792 return kFALSE;
793 }
794
795 if (!entry->GetId().IsSpecified()) {
796 AliError(Form("Unspecified entry ID: %s",
797 entry->GetId().ToString().Data()));
798 return kFALSE;
799 }
800
801 AliCDBId id = entry->GetId();
024cf675 802 AliCDBParam *aPar = SelectSpecificStorage(id.GetPath());
803
4005d0b5 804 AliCDBStorage *aStorage=0;
02c4845e 805
806 if(aPar) {
807 aStorage=GetStorage(aPar);
02c4845e 808 } else {
b8ec52f6 809 switch(type){
810 case kCondition:
811 aStorage = GetStorage(fCondParam);
812 break;
813 case kReference:
814 aStorage = GetStorage(fRefParam);
815 break;
816 case kPrivate:
817 aStorage = GetDefaultStorage();
818 break;
819 }
02c4845e 820 }
821
b8ec52f6 822 AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data()));
823
4005d0b5 824 Bool_t result = aStorage->Put(entry, type);
825
826 if(fRun >= 0) QueryCDB();
827
828 return result;
02c4845e 829
830
831}
9e1ceb13 832
4b5e0dce 833//_____________________________________________________________________________
834void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry)
835{
836// cache AliCDBEntry. Cache is valid until run number is changed.
837
96b7636d 838 AliCDBEntry *chkEntry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(path));
839
840 if(chkEntry) {
841 AliDebug(2, Form("Object %s already in cache !!", path));
842 return;
843 } else {
844 AliDebug(2,Form("Caching entry %s", path));
845 }
846
4b5e0dce 847 fEntryCache.Add(new TObjString(path), entry);
96b7636d 848 AliDebug(2,Form("Cache entries: %d", fEntryCache.GetEntries()));
4b5e0dce 849
850}
851
917a098b 852//_____________________________________________________________________________
853void AliCDBManager::Print(Option_t* /*option*/) const
854{
855// Print list of active storages and their URIs
917a098b 856
b8ec52f6 857 TString output=Form("Run number = %d; ",fRun);
858 output += "Cache is ";
917a098b 859 if(!fCache) output += "NOT ";
b8ec52f6 860 output += Form("ACTIVE; Number of active storages: %d\n",fActiveStorages.GetEntries());
917a098b 861
862 if(fDefaultStorage) {
b8ec52f6 863 output += Form("\t*** Default Storage URI: \"%s\"\n",fDefaultStorage->GetURI().Data());
864// AliInfo(output.Data());
917a098b 865 }
866 if(fSpecificStorages.GetEntries()>0) {
917a098b 867 TIter iter(fSpecificStorages.GetTable());
62032124 868 TPair *aPair=0;
b8ec52f6 869 Int_t i=1;
917a098b 870 while((aPair = (TPair*) iter.Next())){
b8ec52f6 871 output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n",
872 i++, ((TObjString*) aPair->Key())->GetName(),
917a098b 873 ((AliCDBParam*) aPair->Value())->GetURI().Data());
917a098b 874 }
917a098b 875 }
876 if(fDrainStorage) {
b8ec52f6 877 output += Form("*** Drain Storage URI: %s\n",fDrainStorage->GetURI().Data());
917a098b 878 }
b8ec52f6 879 AliInfo(output.Data());
917a098b 880}
881
4b5e0dce 882//_____________________________________________________________________________
c3a7b59a 883void AliCDBManager::SetRun(Int_t run)
4b5e0dce 884{
917a098b 885// Sets current run number.
4b5e0dce 886// When the run number changes the caching is cleared.
4b5e0dce 887
888 if (fRun == run)
889 return;
890
891 fRun = run;
892 ClearCache();
62032124 893 QueryCDB();
4b5e0dce 894}
895
896//_____________________________________________________________________________
897void AliCDBManager::ClearCache(){
898// clear AliCDBEntry cache
899
900 AliDebug(2,Form("Clearing cache!"));
901 fEntryCache.DeleteAll();
902 AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries()));
903
904}
905
4005d0b5 906//_____________________________________________________________________________
907void AliCDBManager::UnloadFromCache(const char* path){
908// unload cached object
909
910 AliCDBPath queryPath(path);
911 if(!queryPath.IsValid()) return;
912
913 if(!queryPath.IsWildcard()) { // path is not wildcard, get it directly from the cache and unload it!
914 if(fEntryCache.Contains(path)){
915 AliInfo(Form("Unloading object \"%s\" from cache", path));
916 TObjString pathStr(path);
917 AliCDBEntry *entry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(&pathStr));
918 if(entry) delete entry;
919 delete fEntryCache.Remove(&pathStr);
920 } else {
921 AliError(Form("Cache does not contain object \"%s\"!", path))
922 }
923 AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries()));
924 return;
925 }
926
927 // path is wildcard: loop on the cache and unload all comprised objects!
928 TIter iter(fEntryCache.GetTable());
929 TPair* pair = 0;
930
931 while((pair = dynamic_cast<TPair*> (iter.Next()))){
932 AliCDBPath entryPath = pair->Key()->GetName();
933 if(queryPath.Comprises(entryPath)) {
934 AliInfo(Form("Unloading object \"%s\" from cache", entryPath.GetPath().Data()));
935 TObjString pathStr(entryPath.GetPath().Data());
936 AliCDBEntry *entry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(&pathStr));
937 if(entry) delete entry;
938 delete fEntryCache.Remove(&pathStr);
939 }
940 }
941 AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries()));
942}
943
9e1ceb13 944//_____________________________________________________________________________
945void AliCDBManager::DestroyActiveStorages() {
946// delete list of active storages
947
948 fActiveStorages.DeleteAll();
02c4845e 949 fSpecificStorages.DeleteAll();
9e1ceb13 950}
951
952//_____________________________________________________________________________
953void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
b05400be 954// destroys active storage
955
956/*
917a098b 957 TIter iter(fActiveStorages.GetTable());
b05400be 958 TPair* aPair;
959 while ((aPair = (TPair*) iter.Next())) {
960 if(storage == (AliCDBStorage*) aPair->Value())
961 delete fActiveStorages.Remove(aPair->Key());
962 storage->Delete(); storage=0x0;
963 }
6dc56e97 964*/
9e1ceb13 965
966}
967
62032124 968//_____________________________________________________________________________
969void AliCDBManager::QueryCDB() {
970// query default and specific storages for files valid for fRun. Every storage loads the Ids into its list.
971
972 if (fRun < 0){
973 AliError("Run number not yet set! Use AliCDBManager::SetRun.");
974 return;
975 }
6dc56e97 976 if (!fDefaultStorage){
977 AliError("Default storage is not set! Use AliCDBManager::SetDefaultStorage");
978 return;
979 }
980 if(fDefaultStorage->GetType() == "alien"){
981 fDefaultStorage->QueryCDB(fRun);
982 } else {
983 AliDebug(2,"Skipping query for valid files, it used only in grid...");
984 }
62032124 985
986 TIter iter(&fSpecificStorages);
987 TObjString *aCalibType=0;
988 AliCDBParam* aPar=0;
989 while((aCalibType = dynamic_cast<TObjString*> (iter.Next()))){
990 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
991 if(aPar) {
c3a7b59a 992 AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName()));
6dc56e97 993 AliCDBStorage *aStorage = GetStorage(aPar);
994 if(aStorage->GetType() == "alien"){
995 aStorage->QueryCDB(fRun,aCalibType->GetName());
996 } else {
997 AliDebug(2,
998 "Skipping query for valid files, it is used only in grid...");
999 }
62032124 1000 }
1001 }
62032124 1002}
1003
b8ec52f6 1004//______________________________________________________________________________________________
1005const char* AliCDBManager::GetDataTypeName(DataType type)
1006{
1007 // returns the name (string) of the data type
1008
1009 switch (type){
1010 case kCondition: return "Conditions";
1011 case kReference: return "Reference";
1012 case kPrivate: return "Private";
1013 }
1014 return 0;
1015
1016}
62032124 1017
4667c116 1018//______________________________________________________________________________________________
1019void AliCDBManager::InitShortLived()
1020{
1021 // Init the list of short-lived objects
1022 // currently disabled
1023
1024 fShortLived=0x0;
1025
1026// fShortLived = new TList();
1027// fShortLived->SetOwner(1);
1028//
1029// fShortLived->Add(new TObjString("EMCAL/Calib/Data"));
1030//
1031// fShortLived->Add(new TObjString("HMPID/Calib/Nmean"));
1032// fShortLived->Add(new TObjString("HMPID/Calib/Qthre"));
1033//
1034// fShortLived->Add(new TObjString("ITS/Calib/CalibSPD"));
1035//
1036// fShortLived->Add(new TObjString("MUON/Calib/Gains"));
1037// fShortLived->Add(new TObjString("MUON/Calib/HV"));
1038// fShortLived->Add(new TObjString("MUON/Calib/Pedestals"));
1039//
1040// fShortLived->Add(new TObjString("PHOS/Calib/CpvGainPedestals"));
1041// fShortLived->Add(new TObjString("PHOS/Calib/EmcGainPedestals"));
1042//
1043// fShortLived->Add(new TObjString("PMD/Calib/Data"));
1044//
1045// fShortLived->Add(new TObjString("TRD/Calib/ChamberGainFactor"));
1046// fShortLived->Add(new TObjString("TRD/Calib/LocalGainFactor"));
1047// fShortLived->Add(new TObjString("TRD/Calib/ChamberT0"));
1048// fShortLived->Add(new TObjString("TRD/Calib/LocalT0"));
1049// fShortLived->Add(new TObjString("TRD/Calib/ChamberVdrift"));
1050// fShortLived->Add(new TObjString("TRD/Calib/LocalVdrift"));
1051//
1052// fShortLived->Add(new TObjString("ZDC/Calib/Data"));
1053
1054}
1055
1056//______________________________________________________________________________________________
1057Bool_t AliCDBManager::IsShortLived(const char* path)
1058{
1059 // returns the name (string) of the data type
1060
1061 if(!fShortLived) return kFALSE;
1062
1063 AliCDBPath aPath(path);
1064 if(!aPath.IsValid()){
1065 AliError(Form("Not a valid path: %s", path));
1066 return kFALSE;
1067 }
1068
1069 return fShortLived->Contains(path);
1070
1071}
1072
9e1ceb13 1073///////////////////////////////////////////////////////////
1074// AliCDBManager Parameter class //
1075// interface to specific AliCDBParameter class //
1076// (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) //
1077///////////////////////////////////////////////////////////
1078
62032124 1079AliCDBParam::AliCDBParam():
fe12e09c 1080 fType(),
1081 fURI()
62032124 1082{
9e1ceb13 1083// constructor
1084
1085}
1086
1087//_____________________________________________________________________________
1088AliCDBParam::~AliCDBParam() {
1089// destructor
1090
1091}
1092