1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15 //-------------------------------------------------------------------------
16 // Implementation of AliCDBManager and AliCDBParam classe
17 // Author: Alberto Colla
18 // e-mail: Alberto.Colla@cern.ch
19 //-------------------------------------------------------------------------
21 #include "AliCDBManager.h"
22 #include "AliCDBStorage.h"
24 #include "AliCDBDump.h"
25 #include "AliCDBLocal.h"
26 #include "AliCDBGrid.h"
27 #include "AliCDBEntry.h"
28 #include "AliCDBMetaData.h"
30 #include <TObjString.h>
35 ClassImp(AliCDBManager)
37 //TODO OCDB and Reference folder should not be fully hardcoded but built from run number (or year/LHC period)
38 TString AliCDBManager::fgkCondUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/CDB?user=aliprod");
39 TString AliCDBManager::fgkRefUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/Reference?user=aliprod");
40 AliCDBManager* AliCDBManager::fgInstance = 0x0;
42 //_____________________________________________________________________________
43 AliCDBManager* AliCDBManager::Instance(TMap *entryCache, Int_t run)
45 // returns AliCDBManager instance (singleton)
48 fgInstance = new AliCDBManager();
52 fgInstance->InitFromCache(entryCache,run);
58 //_____________________________________________________________________________
59 void AliCDBManager::Init() {
60 // factory registering
62 RegisterFactory(new AliCDBDumpFactory());
63 RegisterFactory(new AliCDBLocalFactory());
64 // AliCDBGridFactory is registered only if AliEn libraries are enabled in Root
65 if(!gSystem->Exec("root-config --has-alien |grep yes 2>&1 > /dev/null")){ // returns 0 if yes
66 AliInfo("AliEn classes enabled in Root. AliCDBGrid factory registered.");
67 RegisterFactory(new AliCDBGridFactory());
68 fCondParam = CreateParameter(fgkCondUri);
69 fRefParam = CreateParameter(fgkRefUri);
75 //_____________________________________________________________________________
76 void AliCDBManager::InitFromCache(TMap *entryCache, Int_t run) {
77 // initialize manager from existing cache
78 // used on the slaves in case of parallel reconstruction
81 TIter iter(entryCache->GetTable());
84 while((pair = dynamic_cast<TPair*> (iter.Next()))){
85 fEntryCache.Add(pair->Key(),pair->Value());
87 // fEntry is the new owner of the cache
88 fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
89 AliInfo(Form("%d cache entries have been loaded",fEntryCache.GetEntries()));
92 //_____________________________________________________________________________
93 void AliCDBManager::Destroy() {
94 // delete ALCDBManager instance and active storages
97 //fgInstance->Delete();
103 //_____________________________________________________________________________
104 AliCDBManager::AliCDBManager():
113 fDefaultStorage(NULL),
121 // default constuctor
122 fFactories.SetOwner(1);
123 fActiveStorages.SetOwner(1);
124 fSpecificStorages.SetOwner(1);
125 fEntryCache.SetName("CDBEntryCache");
126 fEntryCache.SetOwner(1);
128 fStorageMap = new TMap();
129 fStorageMap->SetOwner(1);
134 //_____________________________________________________________________________
135 AliCDBManager::~AliCDBManager() {
138 DestroyActiveStorages();
141 fDefaultStorage = 0x0;
142 delete fStorageMap; fStorageMap = 0;
143 delete fIds; fIds = 0;
146 delete fShortLived; fShortLived = 0x0;
149 //_____________________________________________________________________________
150 void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){
151 // put a storage object into the list of active storages
153 fActiveStorages.Add(param, storage);
154 AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries()));
157 //_____________________________________________________________________________
158 void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) {
159 // add a storage factory to the list of registerd factories
161 if (!fFactories.Contains(factory)) {
162 fFactories.Add(factory);
166 //_____________________________________________________________________________
167 Bool_t AliCDBManager::HasStorage(const char* dbString) const {
168 // check if dbString is a URI valid for one of the registered factories
170 TIter iter(&fFactories);
172 AliCDBStorageFactory* factory=0;
173 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
175 if (factory->Validate(dbString)) {
183 //_____________________________________________________________________________
184 AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
185 // create AliCDBParam object from URI string
187 TIter iter(&fFactories);
189 AliCDBStorageFactory* factory=0;
190 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
191 AliCDBParam* param = factory->CreateParameter(dbString);
192 if(param) return param;
198 //_____________________________________________________________________________
199 AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) {
200 // get storage object from URI string
202 AliCDBParam* param = CreateParameter(dbString);
204 AliError(Form("Failed to activate requested storage! Check URI: %s", dbString));
208 AliCDBStorage* aStorage = GetStorage(param);
214 //_____________________________________________________________________________
215 AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) {
216 // get storage object from AliCDBParam object
218 // if the list of active storages already contains
219 // the requested storage, return it
220 AliCDBStorage* aStorage = GetActiveStorage(param);
225 // if lock is ON, cannot activate more storages!
227 if (fDefaultStorage) {
228 AliFatal("Lock is ON, and default storage is already set: "
229 "cannot reset it or activate more storages!");
233 TIter iter(&fFactories);
235 AliCDBStorageFactory* factory=0;
237 // loop on the list of registered factories
238 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
240 // each factory tries to create its storage from the parameter
241 aStorage = factory->Create(param);
243 PutActiveStorage(param->CloneParam(), aStorage);
244 aStorage->SetURI(param->GetURI());
246 if(aStorage->GetType() == "alien"){
247 aStorage->QueryCDB(fRun);
250 "Skipping query for valid files, it is used only in grid...");
257 AliError(Form("Failed to activate requested storage! Check URI: %s", param->GetURI().Data()));
262 //_____________________________________________________________________________
263 AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) {
264 // get a storage object from the list of active storages
266 return dynamic_cast<AliCDBStorage*> (fActiveStorages.GetValue(param));
269 //_____________________________________________________________________________
270 TList* AliCDBManager::GetActiveStorages() {
271 // return list of active storages
272 // user has responsibility to delete returned object
274 TList* result = new TList();
276 TIter iter(fActiveStorages.GetTable());
278 while ((aPair = (TPair*) iter.Next())) {
279 result->Add(aPair->Value());
285 //_____________________________________________________________________________
286 void AliCDBManager::SetDrain(const char* dbString) {
287 // set drain storage from URI string
289 fDrainStorage = GetStorage(dbString);
292 //_____________________________________________________________________________
293 void AliCDBManager::SetDrain(const AliCDBParam* param) {
294 // set drain storage from AliCDBParam
296 fDrainStorage = GetStorage(param);
299 //_____________________________________________________________________________
300 void AliCDBManager::SetDrain(AliCDBStorage* storage) {
301 // set drain storage from another active storage
303 fDrainStorage = storage;
306 //_____________________________________________________________________________
307 Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
308 // drain retrieved object to drain storage
310 AliDebug(2, "Draining into drain storage...");
311 return fDrainStorage->Put(entry);
314 //_____________________________________________________________________________
315 void AliCDBManager::SetDefaultStorage(const char* dbString) {
316 // sets default storage from URI string
318 AliInfo(Form("Setting Default storage to: %s",dbString));
319 AliCDBStorage* bckStorage = fDefaultStorage;
321 fDefaultStorage = GetStorage(dbString);
323 if(!fDefaultStorage) return;
325 if(bckStorage && (fDefaultStorage != bckStorage)){
326 AliWarning("Existing default storage replaced: clearing cache!");
330 if (fStorageMap->Contains("default")) {
331 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
333 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
336 //_____________________________________________________________________________
337 void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
338 // set default storage from AliCDBParam object
340 AliCDBStorage* bckStorage = fDefaultStorage;
342 fDefaultStorage = GetStorage(param);
344 if(!fDefaultStorage) return;
346 if(bckStorage && (fDefaultStorage != bckStorage)){
347 AliWarning("Existing default storage replaced: clearing cache!");
351 if (fStorageMap->Contains("default")) {
352 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
354 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
357 //_____________________________________________________________________________
358 void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
359 // set default storage from another active storage
361 // if lock is ON, cannot activate more storages!
363 if (fDefaultStorage) {
364 AliFatal("Lock is ON, and default storage is already set: "
365 "cannot reset it or activate more storages!");
370 UnsetDefaultStorage();
374 AliCDBStorage* bckStorage = fDefaultStorage;
376 fDefaultStorage = storage;
378 if(bckStorage && (fDefaultStorage != bckStorage)){
379 AliWarning("Existing default storage replaced: clearing cache!");
383 if (fStorageMap->Contains("default")) {
384 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
386 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
389 //_____________________________________________________________________________
390 void AliCDBManager::UnsetDefaultStorage() {
391 // Unset default storage
393 // if lock is ON, action is forbidden!
395 if (fDefaultStorage) {
396 AliFatal("Lock is ON: cannot unset default storage!");
400 if (fDefaultStorage) {
401 AliWarning("Clearing cache!");
405 fDefaultStorage = 0x0;
408 //_____________________________________________________________________________
409 void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) {
410 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
412 AliCDBParam *aPar = CreateParameter(dbString);
414 SetSpecificStorage(calibType, aPar);
418 //_____________________________________________________________________________
419 void AliCDBManager::SetSpecificStorage(const char* calibType, AliCDBParam* param) {
420 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
421 // Default storage should be defined prior to any specific storages, e.g.:
422 // AliCDBManager::instance()->SetDefaultStorage("alien://");
423 // AliCDBManager::instance()->SetSpecificStorage("TPC/*","local://DB_TPC");
424 // AliCDBManager::instance()->SetSpecificStorage("*/Align/*","local://DB_TPCAlign");
425 // calibType must be a valid CDB path! (3 level folder structure)
427 if(!fDefaultStorage) {
428 AliError("Please activate a default storage first!");
432 AliCDBPath aPath(calibType);
433 if(!aPath.IsValid()){
434 AliError(Form("Not a valid path: %s", calibType));
438 TObjString *objCalibType = new TObjString(aPath.GetPath());
439 if(fSpecificStorages.Contains(objCalibType)){
440 AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one",
442 AliCDBParam *checkPar = dynamic_cast<AliCDBParam*> (fSpecificStorages.GetValue(calibType));
443 if(checkPar) delete checkPar;
444 delete fSpecificStorages.Remove(objCalibType);
446 AliCDBStorage *aStorage = GetStorage(param);
447 if(!aStorage) return;
449 fSpecificStorages.Add(objCalibType, param->CloneParam());
451 if(fStorageMap->Contains(objCalibType)){
452 delete fStorageMap->Remove(objCalibType);
454 fStorageMap->Add(objCalibType->Clone(), new TObjString(param->GetURI()));
458 //_____________________________________________________________________________
459 AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) {
460 // get storage specific for detector or calibration type
462 AliCDBPath calibPath(calibType);
463 if(!calibPath.IsValid()) return NULL;
465 AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibPath.GetPath());
467 AliError(Form("%s storage not found!", calibType));
470 return GetStorage(checkPar);
475 //_____________________________________________________________________________
476 AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) {
477 // select storage valid for path from the list of specific storages
479 AliCDBPath aPath(path);
480 if(!aPath.IsValid()) return NULL;
482 TIter iter(&fSpecificStorages);
483 TObjString *aCalibType=0;
484 AliCDBPath tmpPath("null/null/null");
486 while((aCalibType = (TObjString*) iter.Next())){
487 AliCDBPath calibTypePath(aCalibType->GetName());
488 if(calibTypePath.Comprises(aPath)) {
489 if(calibTypePath.Comprises(tmpPath)) continue;
490 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
491 tmpPath.SetPath(calibTypePath.GetPath());
497 //_____________________________________________________________________________
498 AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber,
499 Int_t version, Int_t subVersion) {
500 // get an AliCDBEntry object from the database
503 // RunNumber is not specified. Try with fRun
505 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
511 return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
514 //_____________________________________________________________________________
515 AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path,
516 const AliCDBRunRange& runRange, Int_t version,
518 // get an AliCDBEntry object from the database!
520 return Get(AliCDBId(path, runRange, version, subVersion));
523 //_____________________________________________________________________________
524 AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) {
525 // get an AliCDBEntry object from the database
527 // check if query's path and runRange are valid
528 // query is invalid also if version is not specified and subversion is!
529 if (!query.IsValid()) {
530 AliError(Form("Invalid query: %s", query.ToString().Data()));
534 // query is not specified if path contains wildcard or run range= [-1,-1]
535 if (!query.IsSpecified()) {
536 AliError(Form("Unspecified query: %s",
537 query.ToString().Data()));
541 if(fLock && query.GetFirstRun() != fRun)
542 AliFatal("Lock is ON: cannot use different run number than the internal one!");
544 if(fCache && query.GetFirstRun() != fRun)
545 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
547 AliCDBEntry *entry=0;
549 // first look into map of cached objects
550 if(fCache && query.GetFirstRun() == fRun)
551 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
554 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
558 if(!fDefaultStorage) {
559 AliError("No storage set!");
562 // Entry is not in cache -> retrieve it from CDB and cache it!!
563 AliCDBStorage *aStorage=0;
564 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
565 // Bool_t usedDefStorage=kTRUE;
568 aStorage=GetStorage(aPar);
569 TString str = aPar->GetURI();
570 AliDebug(2,Form("Looking into storage: %s",str.Data()));
571 // usedDefStorage=kFALSE;
574 aStorage=GetDefaultStorage();
575 AliDebug(2,"Looking into default storage");
578 entry = aStorage->Get(query);
580 if(entry && fCache && (query.GetFirstRun() == fRun)){
581 CacheEntry(query.GetPath(), entry);
584 if(entry && !fIds->Contains(&entry->GetId())){
585 fIds->Add(entry->GetId().Clone());
593 //_____________________________________________________________________________
594 const char* AliCDBManager::GetURI(const char* path) {
595 // return the URI of the storage where to look for path
597 if(!IsDefaultStorageSet()) return 0;
599 AliCDBParam *aPar=SelectSpecificStorage(path);
602 return aPar->GetURI().Data();
605 return GetDefaultStorage()->GetURI().Data();
611 //_____________________________________________________________________________
612 AliCDBId* AliCDBManager::GetId(const AliCDBPath& path, Int_t runNumber,
613 Int_t version, Int_t subVersion) {
614 // get the AliCDBId of the valid object from the database (does not retrieve the object)
615 // User must delete returned object!
618 // RunNumber is not specified. Try with fRun
620 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
626 return GetId(AliCDBId(path, runNumber, runNumber, version, subVersion));
629 //_____________________________________________________________________________
630 AliCDBId* AliCDBManager::GetId(const AliCDBPath& path,
631 const AliCDBRunRange& runRange, Int_t version,
633 // get the AliCDBId of the valid object from the database (does not retrieve the object)
634 // User must delete returned object!
636 return GetId(AliCDBId(path, runRange, version, subVersion));
639 //_____________________________________________________________________________
640 AliCDBId* AliCDBManager::GetId(const AliCDBId& query) {
641 // get the AliCDBId of the valid object from the database (does not retrieve the object)
642 // User must delete returned object!
644 if(!fDefaultStorage) {
645 AliError("No storage set!");
649 // check if query's path and runRange are valid
650 // query is invalid also if version is not specified and subversion is!
651 if (!query.IsValid()) {
652 AliError(Form("Invalid query: %s", query.ToString().Data()));
656 // query is not specified if path contains wildcard or run range= [-1,-1]
657 if (!query.IsSpecified()) {
658 AliError(Form("Unspecified query: %s",
659 query.ToString().Data()));
663 if(fCache && query.GetFirstRun() != fRun)
664 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
666 AliCDBEntry* entry = 0;
668 // first look into map of cached objects
669 if(fCache && query.GetFirstRun() == fRun)
670 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
673 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
674 return dynamic_cast<AliCDBId*> (entry->GetId().Clone());
677 // Entry is not in cache -> retrieve it from CDB and cache it!!
678 AliCDBStorage *aStorage=0;
679 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
682 aStorage=GetStorage(aPar);
683 TString str = aPar->GetURI();
684 AliDebug(2,Form("Looking into storage: %s",str.Data()));
687 aStorage=GetDefaultStorage();
688 AliDebug(2,"Looking into default storage");
691 return aStorage->GetId(query);
695 //_____________________________________________________________________________
696 TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber,
697 Int_t version, Int_t subVersion) {
698 // get multiple AliCDBEntry objects from the database
701 // RunNumber is not specified. Try with fRun
703 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
709 return GetAll(AliCDBId(path, runNumber, runNumber, version,
713 //_____________________________________________________________________________
714 TList* AliCDBManager::GetAll(const AliCDBPath& path,
715 const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
716 // get multiple AliCDBEntry objects from the database
718 return GetAll(AliCDBId(path, runRange, version, subVersion));
721 //_____________________________________________________________________________
722 TList* AliCDBManager::GetAll(const AliCDBId& query) {
723 // get multiple AliCDBEntry objects from the database
724 // Warning: this method works correctly only for queries of the type "Detector/*"
725 // and not for more specific queries e.g. "Detector/Calib/*" !
726 // Warning #2: Entries are cached, but GetAll will keep on retrieving objects from OCDB!
727 // To get an object from cache use Get() function
729 if(!fDefaultStorage) {
730 AliError("No storage set!");
734 if (!query.IsValid()) {
735 AliError(Form("Invalid query: %s", query.ToString().Data()));
739 if((fSpecificStorages.GetEntries()>0) && query.GetPath().BeginsWith('*')){
740 // if specific storages are active a query with "*" is ambiguous
741 AliError("Query too generic in this context!");
745 if (query.IsAnyRange()) {
746 AliError(Form("Unspecified run or runrange: %s",
747 query.ToString().Data()));
751 if(fLock && query.GetFirstRun() != fRun)
752 AliFatal("Lock is ON: cannot use different run number than the internal one!");
754 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
756 AliCDBStorage *aStorage;
758 aStorage=GetStorage(aPar);
759 AliDebug(2,Form("Looking into storage: %s", aPar->GetURI().Data()));
762 aStorage=GetDefaultStorage();
763 AliDebug(2,"Looking into default storage");
767 if(aStorage) result = aStorage->GetAll(query);
768 if(!result) return 0;
770 // loop on result to check whether entries should be re-queried with specific storages
771 if(fSpecificStorages.GetEntries()>0 && ! (fSpecificStorages.GetEntries() == 1 && aPar)) {
772 AliInfo("Now look into all other specific storages...");
775 AliCDBEntry* chkEntry=0;
777 while((chkEntry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
778 AliCDBId& chkId = chkEntry->GetId();
779 AliDebug(2, Form("Checking id %s ", chkId.GetPath().Data()));
780 AliCDBParam *chkPar=SelectSpecificStorage(chkId.GetPath());
781 if (!chkPar || aPar == chkPar) continue;
782 AliCDBStorage *chkStorage = GetStorage(chkPar);
783 AliDebug(2, Form("Found specific storage! %s", chkPar->GetURI().Data()));
785 AliCDBEntry *newEntry=0;
786 chkId.SetRunRange(query.GetFirstRun(), query.GetLastRun());
787 chkId.SetVersion(query.GetVersion());
788 chkId.SetSubVersion(query.GetSubVersion());
790 if(chkStorage) newEntry = chkStorage->Get(chkId);
791 if(!newEntry) continue;
793 // object is found in specific storage: replace entry in the result list!
794 chkEntry->SetOwner(1);
795 delete result->Remove(chkEntry);
796 result->AddFirst(newEntry);
799 Int_t nEntries = result->GetEntries();
800 AliInfo("After look into other specific storages, result list is:");
801 for(int i=0; i<nEntries;i++){
802 AliCDBEntry *entry = (AliCDBEntry*) result->At(i);
803 AliInfo(Form("%s",entry->GetId().ToString().Data()));
809 AliCDBEntry* entry=0;
810 while((entry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
812 if(!fIds->Contains(&entry->GetId())){
813 fIds->Add(entry->GetId().Clone());
815 if(fCache && (query.GetFirstRun() == fRun)){
816 CacheEntry(entry->GetId().GetPath(), entry);
824 //_____________________________________________________________________________
825 Bool_t AliCDBManager::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData, DataType type){
826 // store an AliCDBEntry object into the database
829 AliError("Null Entry! No storage will be done!");
833 AliCDBEntry anEntry(object, id, metaData);
834 return Put(&anEntry, type);
839 //_____________________________________________________________________________
840 Bool_t AliCDBManager::Put(AliCDBEntry* entry, DataType type){
841 // store an AliCDBEntry object into the database
843 if(type == kPrivate && !fDefaultStorage) {
844 AliError("No storage set!");
848 if (entry->GetObject()==0x0){
849 AliError("No valid object in CDB entry!");
854 AliError("No entry!");
858 if (!entry->GetId().IsValid()) {
859 AliError(Form("Invalid entry ID: %s",
860 entry->GetId().ToString().Data()));
864 if (!entry->GetId().IsSpecified()) {
865 AliError(Form("Unspecified entry ID: %s",
866 entry->GetId().ToString().Data()));
870 AliCDBId id = entry->GetId();
871 AliCDBParam *aPar = SelectSpecificStorage(id.GetPath());
873 AliCDBStorage *aStorage=0;
876 aStorage=GetStorage(aPar);
880 aStorage = GetStorage(fCondParam);
883 aStorage = GetStorage(fRefParam);
886 aStorage = GetDefaultStorage();
891 AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data()));
893 Bool_t result = aStorage->Put(entry, type);
895 if(fRun >= 0) QueryCDB();
902 //_____________________________________________________________________________
903 void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry)
905 // cache AliCDBEntry. Cache is valid until run number is changed.
907 AliCDBEntry *chkEntry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(path));
910 AliDebug(2, Form("Object %s already in cache !!", path));
913 AliDebug(2,Form("Caching entry %s", path));
916 fEntryCache.Add(new TObjString(path), entry);
917 AliDebug(2,Form("Cache entries: %d", fEntryCache.GetEntries()));
921 //_____________________________________________________________________________
922 void AliCDBManager::Print(Option_t* /*option*/) const
924 // Print list of active storages and their URIs
926 TString output=Form("Run number = %d; ",fRun);
927 output += "Cache is ";
928 if(!fCache) output += "NOT ";
929 output += Form("ACTIVE; Number of active storages: %d\n",fActiveStorages.GetEntries());
931 if(fDefaultStorage) {
932 output += Form("\t*** Default Storage URI: \"%s\"\n",fDefaultStorage->GetURI().Data());
933 // AliInfo(output.Data());
935 if(fSpecificStorages.GetEntries()>0) {
936 TIter iter(fSpecificStorages.GetTable());
939 while((aPair = (TPair*) iter.Next())){
940 output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n",
941 i++, ((TObjString*) aPair->Key())->GetName(),
942 ((AliCDBParam*) aPair->Value())->GetURI().Data());
946 output += Form("*** Drain Storage URI: %s\n",fDrainStorage->GetURI().Data());
948 AliInfo(output.Data());
951 //_____________________________________________________________________________
952 void AliCDBManager::SetRun(Int_t run)
954 // Sets current run number.
955 // When the run number changes the caching is cleared.
960 if(fLock && fRun >= 0) {
961 AliFatal("Lock is ON, cannot reset run number!");
969 //_____________________________________________________________________________
970 void AliCDBManager::ClearCache(){
971 // clear AliCDBEntry cache
973 AliDebug(2, Form("Cache entries to be deleted: %d",fEntryCache.GetEntries()));
976 // To clean entries one by one
977 TIter iter(fEntryCache.GetTable());
979 while((pair= dynamic_cast<TPair*> (iter.Next()))){
981 TObjString* key = dynamic_cast<TObjString*> (pair->Key());
982 AliCDBEntry* entry = dynamic_cast<AliCDBEntry*> (pair->Value());
983 AliDebug(2, Form("Deleting entry: %s", key->GetName()));
984 if (entry) delete entry;
985 delete fEntryCache.Remove(key);
988 fEntryCache.DeleteAll();
989 AliDebug(2, Form("After deleting - Cache entries: %d",fEntryCache.GetEntries()));
992 //_____________________________________________________________________________
993 void AliCDBManager::UnloadFromCache(const char* path){
994 // unload cached object
996 AliCDBPath queryPath(path);
997 if(!queryPath.IsValid()) return;
999 if(!queryPath.IsWildcard()) { // path is not wildcard, get it directly from the cache and unload it!
1000 if(fEntryCache.Contains(path)){
1001 AliInfo(Form("Unloading object \"%s\" from cache", path));
1002 TObjString pathStr(path);
1003 AliCDBEntry *entry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(&pathStr));
1004 if(entry) delete entry;
1005 delete fEntryCache.Remove(&pathStr);
1007 AliError(Form("Cache does not contain object \"%s\"!", path))
1009 AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries()));
1013 // path is wildcard: loop on the cache and unload all comprised objects!
1014 TIter iter(fEntryCache.GetTable());
1017 while((pair = dynamic_cast<TPair*> (iter.Next()))){
1018 AliCDBPath entryPath = pair->Key()->GetName();
1019 if(queryPath.Comprises(entryPath)) {
1020 AliInfo(Form("Unloading object \"%s\" from cache", entryPath.GetPath().Data()));
1021 TObjString pathStr(entryPath.GetPath().Data());
1022 AliCDBEntry *entry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(&pathStr));
1023 if(entry) delete entry;
1024 delete fEntryCache.Remove(&pathStr);
1027 AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries()));
1030 //_____________________________________________________________________________
1031 void AliCDBManager::DestroyActiveStorages() {
1032 // delete list of active storages
1034 fActiveStorages.DeleteAll();
1035 fSpecificStorages.DeleteAll();
1038 //_____________________________________________________________________________
1039 void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
1040 // destroys active storage
1043 TIter iter(fActiveStorages.GetTable());
1045 while ((aPair = (TPair*) iter.Next())) {
1046 if(storage == (AliCDBStorage*) aPair->Value())
1047 delete fActiveStorages.Remove(aPair->Key());
1048 storage->Delete(); storage=0x0;
1054 //_____________________________________________________________________________
1055 void AliCDBManager::QueryCDB() {
1056 // query default and specific storages for files valid for fRun. Every storage loads the Ids into its list.
1059 AliError("Run number not yet set! Use AliCDBManager::SetRun.");
1062 if (!fDefaultStorage){
1063 AliError("Default storage is not set! Use AliCDBManager::SetDefaultStorage");
1066 if(fDefaultStorage->GetType() == "alien"){
1067 fDefaultStorage->QueryCDB(fRun);
1069 AliDebug(2,"Skipping query for valid files, it used only in grid...");
1072 TIter iter(&fSpecificStorages);
1073 TObjString *aCalibType=0;
1074 AliCDBParam* aPar=0;
1075 while((aCalibType = dynamic_cast<TObjString*> (iter.Next()))){
1076 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
1078 AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName()));
1079 AliCDBStorage *aStorage = GetStorage(aPar);
1080 if(aStorage->GetType() == "alien"){
1081 aStorage->QueryCDB(fRun,aCalibType->GetName());
1084 "Skipping query for valid files, it is used only in grid...");
1090 //______________________________________________________________________________________________
1091 const char* AliCDBManager::GetDataTypeName(DataType type)
1093 // returns the name (string) of the data type
1096 case kCondition: return "Conditions";
1097 case kReference: return "Reference";
1098 case kPrivate: return "Private";
1104 //______________________________________________________________________________________________
1105 void AliCDBManager::InitShortLived()
1107 // Init the list of short-lived objects
1108 // currently disabled
1112 // fShortLived = new TList();
1113 // fShortLived->SetOwner(1);
1115 // fShortLived->Add(new TObjString("EMCAL/Calib/Data"));
1117 // fShortLived->Add(new TObjString("HMPID/Calib/Nmean"));
1118 // fShortLived->Add(new TObjString("HMPID/Calib/Qthre"));
1120 // fShortLived->Add(new TObjString("ITS/Calib/CalibSPD"));
1122 // fShortLived->Add(new TObjString("MUON/Calib/Gains"));
1123 // fShortLived->Add(new TObjString("MUON/Calib/HV"));
1124 // fShortLived->Add(new TObjString("MUON/Calib/Pedestals"));
1126 // fShortLived->Add(new TObjString("PHOS/Calib/CpvGainPedestals"));
1127 // fShortLived->Add(new TObjString("PHOS/Calib/EmcGainPedestals"));
1129 // fShortLived->Add(new TObjString("PMD/Calib/Data"));
1131 // fShortLived->Add(new TObjString("TRD/Calib/ChamberGainFactor"));
1132 // fShortLived->Add(new TObjString("TRD/Calib/LocalGainFactor"));
1133 // fShortLived->Add(new TObjString("TRD/Calib/ChamberT0"));
1134 // fShortLived->Add(new TObjString("TRD/Calib/LocalT0"));
1135 // fShortLived->Add(new TObjString("TRD/Calib/ChamberVdrift"));
1136 // fShortLived->Add(new TObjString("TRD/Calib/LocalVdrift"));
1138 // fShortLived->Add(new TObjString("ZDC/Calib/Data"));
1142 //______________________________________________________________________________________________
1143 Bool_t AliCDBManager::IsShortLived(const char* path)
1145 // returns the name (string) of the data type
1147 if(!fShortLived) return kFALSE;
1149 AliCDBPath aPath(path);
1150 if(!aPath.IsValid()){
1151 AliError(Form("Not a valid path: %s", path));
1155 return fShortLived->Contains(path);
1159 //______________________________________________________________________________________________
1160 void AliCDBManager::SetLock(Bool_t lock){
1162 if(fLock == kTRUE && lock == kFALSE) {
1163 AliFatal("Lock is ON: cannot reset it!");
1169 ///////////////////////////////////////////////////////////
1170 // AliCDBManager Parameter class //
1171 // interface to specific AliCDBParameter class //
1172 // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) //
1173 ///////////////////////////////////////////////////////////
1175 AliCDBParam::AliCDBParam():
1183 //_____________________________________________________________________________
1184 AliCDBParam::~AliCDBParam() {