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