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