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()
45 // returns AliCDBManager instance (singleton)
48 fgInstance = new AliCDBManager();
55 //_____________________________________________________________________________
56 void AliCDBManager::Init() {
57 // factory registering
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());
65 fCondParam = CreateParameter(fgkCondUri);
66 fRefParam = CreateParameter(fgkRefUri);
71 //_____________________________________________________________________________
72 void AliCDBManager::Destroy() {
73 // delete ALCDBManager instance and active storages
76 //fgInstance->Delete();
82 //_____________________________________________________________________________
83 AliCDBManager::AliCDBManager():
92 fDefaultStorage(NULL),
100 // default constuctor
101 fFactories.SetOwner(1);
102 fActiveStorages.SetOwner(1);
103 fSpecificStorages.SetOwner(1);
104 fEntryCache.SetOwner(1);
106 fStorageMap = new TMap();
107 fStorageMap->SetOwner(1);
112 //_____________________________________________________________________________
113 AliCDBManager::~AliCDBManager() {
116 DestroyActiveStorages();
119 fDefaultStorage = 0x0;
120 delete fStorageMap; fStorageMap = 0;
121 delete fIds; fIds = 0;
124 delete fShortLived; fShortLived = 0x0;
127 //_____________________________________________________________________________
128 void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){
129 // put a storage object into the list of active storages
131 fActiveStorages.Add(param, storage);
132 AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries()));
135 //_____________________________________________________________________________
136 void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) {
137 // add a storage factory to the list of registerd factories
139 if (!fFactories.Contains(factory)) {
140 fFactories.Add(factory);
144 //_____________________________________________________________________________
145 Bool_t AliCDBManager::HasStorage(const char* dbString) const {
146 // check if dbString is a URI valid for one of the registered factories
148 TIter iter(&fFactories);
150 AliCDBStorageFactory* factory=0;
151 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
153 if (factory->Validate(dbString)) {
161 //_____________________________________________________________________________
162 AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
163 // create AliCDBParam object from URI string
165 TIter iter(&fFactories);
167 AliCDBStorageFactory* factory=0;
168 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
169 AliCDBParam* param = factory->CreateParameter(dbString);
170 if(param) return param;
176 //_____________________________________________________________________________
177 AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) {
178 // get storage object from URI string
180 AliCDBParam* param = CreateParameter(dbString);
182 AliError(Form("Failed to activate requested storage! Check URI: %s", dbString));
186 AliCDBStorage* aStorage = GetStorage(param);
192 //_____________________________________________________________________________
193 AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) {
194 // get storage object from AliCDBParam object
196 // if the list of active storages already contains
197 // the requested storage, return it
198 AliCDBStorage* aStorage = GetActiveStorage(param);
203 // if lock is ON, cannot activate more storages!
205 if (fDefaultStorage) {
206 AliFatal("Lock is ON, and default storage is already set: "
207 "cannot reset it or activate more storages!");
211 TIter iter(&fFactories);
213 AliCDBStorageFactory* factory=0;
215 // loop on the list of registered factories
216 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
218 // each factory tries to create its storage from the parameter
219 aStorage = factory->Create(param);
221 PutActiveStorage(param->CloneParam(), aStorage);
222 aStorage->SetURI(param->GetURI());
224 if(aStorage->GetType() == "alien"){
225 aStorage->QueryCDB(fRun);
228 "Skipping query for valid files, it is used only in grid...");
235 AliError(Form("Failed to activate requested storage! Check URI: %s", param->GetURI().Data()));
240 //_____________________________________________________________________________
241 AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) {
242 // get a storage object from the list of active storages
244 return dynamic_cast<AliCDBStorage*> (fActiveStorages.GetValue(param));
247 //_____________________________________________________________________________
248 TList* AliCDBManager::GetActiveStorages() {
249 // return list of active storages
250 // user has responsibility to delete returned object
252 TList* result = new TList();
254 TIter iter(fActiveStorages.GetTable());
256 while ((aPair = (TPair*) iter.Next())) {
257 result->Add(aPair->Value());
263 //_____________________________________________________________________________
264 void AliCDBManager::SetDrain(const char* dbString) {
265 // set drain storage from URI string
267 fDrainStorage = GetStorage(dbString);
270 //_____________________________________________________________________________
271 void AliCDBManager::SetDrain(const AliCDBParam* param) {
272 // set drain storage from AliCDBParam
274 fDrainStorage = GetStorage(param);
277 //_____________________________________________________________________________
278 void AliCDBManager::SetDrain(AliCDBStorage* storage) {
279 // set drain storage from another active storage
281 fDrainStorage = storage;
284 //_____________________________________________________________________________
285 Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
286 // drain retrieved object to drain storage
288 AliDebug(2, "Draining into drain storage...");
289 return fDrainStorage->Put(entry);
292 //_____________________________________________________________________________
293 void AliCDBManager::SetDefaultStorage(const char* dbString) {
294 // sets default storage from URI string
296 AliInfo(Form("Setting Default storage to: %s",dbString));
297 AliCDBStorage* bckStorage = fDefaultStorage;
299 fDefaultStorage = GetStorage(dbString);
301 if(bckStorage && (fDefaultStorage != bckStorage)){
302 AliWarning("Existing default storage replaced: clearing cache!");
306 if (fStorageMap->Contains("default")) {
307 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
309 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
312 //_____________________________________________________________________________
313 void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
314 // set default storage from AliCDBParam object
316 AliCDBStorage* bckStorage = fDefaultStorage;
318 fDefaultStorage = GetStorage(param);
320 if(bckStorage && (fDefaultStorage != bckStorage)){
321 AliWarning("Existing default storage replaced: clearing cache!");
325 if (fStorageMap->Contains("default")) {
326 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
328 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
331 //_____________________________________________________________________________
332 void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
333 // set default storage from another active storage
335 // if lock is ON, cannot activate more storages!
337 if (fDefaultStorage) {
338 AliFatal("Lock is ON, and default storage is already set: "
339 "cannot reset it or activate more storages!");
344 UnsetDefaultStorage();
348 AliCDBStorage* bckStorage = fDefaultStorage;
350 fDefaultStorage = storage;
352 if(bckStorage && (fDefaultStorage != bckStorage)){
353 AliWarning("Existing default storage replaced: clearing cache!");
357 if (fStorageMap->Contains("default")) {
358 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
360 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
363 //_____________________________________________________________________________
364 void AliCDBManager::UnsetDefaultStorage() {
365 // Unset default storage
367 // if lock is ON, action is forbidden!
369 if (fDefaultStorage) {
370 AliFatal("Lock is ON: cannot unset default storage!");
374 if (fDefaultStorage) {
375 AliWarning("Clearing cache!");
379 fDefaultStorage = 0x0;
382 //_____________________________________________________________________________
383 void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) {
384 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
386 AliCDBParam *aPar = CreateParameter(dbString);
388 SetSpecificStorage(calibType, aPar);
392 //_____________________________________________________________________________
393 void AliCDBManager::SetSpecificStorage(const char* calibType, AliCDBParam* param) {
394 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
395 // Default storage should be defined prior to any specific storages, e.g.:
396 // AliCDBManager::instance()->SetDefaultStorage("alien://");
397 // AliCDBManager::instance()->SetSpecificStorage("TPC/*","local://DB_TPC");
398 // AliCDBManager::instance()->SetSpecificStorage("*/Align/*","local://DB_TPCAlign");
399 // calibType must be a valid CDB path! (3 level folder structure)
401 if(!fDefaultStorage) {
402 AliError("Please activate a default storage first!");
406 AliCDBPath aPath(calibType);
407 if(!aPath.IsValid()){
408 AliError(Form("Not a valid path: %s", calibType));
412 TObjString *objCalibType = new TObjString(aPath.GetPath());
413 if(fSpecificStorages.Contains(objCalibType)){
414 AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one",
416 AliCDBParam *checkPar = dynamic_cast<AliCDBParam*> (fSpecificStorages.GetValue(calibType));
417 if(checkPar) delete checkPar;
418 delete fSpecificStorages.Remove(objCalibType);
422 fSpecificStorages.Add(objCalibType, param->CloneParam());
424 if(fStorageMap->Contains(objCalibType)){
425 delete fStorageMap->Remove(objCalibType);
427 fStorageMap->Add(objCalibType->Clone(), new TObjString(param->GetURI()));
431 //_____________________________________________________________________________
432 AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) {
433 // get storage specific for detector or calibration type
435 AliCDBPath calibPath(calibType);
436 if(!calibPath.IsValid()) return NULL;
438 AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibPath.GetPath());
440 AliError(Form("%s storage not found!", calibType));
443 return GetStorage(checkPar);
448 //_____________________________________________________________________________
449 AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) {
450 // select storage valid for path from the list of specific storages
452 AliCDBPath aPath(path);
453 if(!aPath.IsValid()) return NULL;
455 TIter iter(&fSpecificStorages);
456 TObjString *aCalibType=0;
457 AliCDBPath tmpPath("null/null/null");
459 while((aCalibType = (TObjString*) iter.Next())){
460 AliCDBPath calibTypePath(aCalibType->GetName());
461 if(calibTypePath.Comprises(aPath)) {
462 if(calibTypePath.Comprises(tmpPath)) continue;
463 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
464 tmpPath.SetPath(calibTypePath.GetPath());
470 //_____________________________________________________________________________
471 AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber,
472 Int_t version, Int_t subVersion) {
473 // get an AliCDBEntry object from the database
476 // RunNumber is not specified. Try with fRun
478 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
484 return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
487 //_____________________________________________________________________________
488 AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path,
489 const AliCDBRunRange& runRange, Int_t version,
491 // get an AliCDBEntry object from the database!
493 return Get(AliCDBId(path, runRange, version, subVersion));
496 //_____________________________________________________________________________
497 AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) {
498 // get an AliCDBEntry object from the database
500 if(!fDefaultStorage) {
501 AliError("No storage set!");
505 // check if query's path and runRange are valid
506 // query is invalid also if version is not specified and subversion is!
507 if (!query.IsValid()) {
508 AliError(Form("Invalid query: %s", query.ToString().Data()));
512 // query is not specified if path contains wildcard or run range= [-1,-1]
513 if (!query.IsSpecified()) {
514 AliError(Form("Unspecified query: %s",
515 query.ToString().Data()));
519 if(fLock && query.GetFirstRun() != fRun)
520 AliFatal("Lock is ON: cannot use different run number than the internal one!");
522 if(fCache && query.GetFirstRun() != fRun)
523 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
525 AliCDBEntry *entry=0;
527 // first look into map of cached objects
528 if(fCache && query.GetFirstRun() == fRun)
529 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
532 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
536 // Entry is not in cache -> retrieve it from CDB and cache it!!
537 AliCDBStorage *aStorage=0;
538 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
539 // Bool_t usedDefStorage=kTRUE;
542 aStorage=GetStorage(aPar);
543 TString str = aPar->GetURI();
544 AliDebug(2,Form("Looking into storage: %s",str.Data()));
545 // usedDefStorage=kFALSE;
548 aStorage=GetDefaultStorage();
549 AliDebug(2,"Looking into default storage");
552 entry = aStorage->Get(query);
554 if(entry && fCache && (query.GetFirstRun() == fRun)){
555 CacheEntry(query.GetPath(), entry);
558 if(entry && !fIds->Contains(&entry->GetId())){
559 fIds->Add(entry->GetId().Clone());
567 //_____________________________________________________________________________
568 const char* AliCDBManager::GetURI(const char* path) {
569 // return the URI of the storage where to look for path
571 if(!IsDefaultStorageSet()) return 0;
573 AliCDBParam *aPar=SelectSpecificStorage(path);
576 return aPar->GetURI().Data();
579 return GetDefaultStorage()->GetURI().Data();
585 //_____________________________________________________________________________
586 AliCDBId* AliCDBManager::GetId(const AliCDBPath& path, Int_t runNumber,
587 Int_t version, Int_t subVersion) {
588 // get the AliCDBId of the valid object from the database (does not retrieve the object)
589 // User must delete returned object!
592 // RunNumber is not specified. Try with fRun
594 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
600 return GetId(AliCDBId(path, runNumber, runNumber, version, subVersion));
603 //_____________________________________________________________________________
604 AliCDBId* AliCDBManager::GetId(const AliCDBPath& path,
605 const AliCDBRunRange& runRange, Int_t version,
607 // get the AliCDBId of the valid object from the database (does not retrieve the object)
608 // User must delete returned object!
610 return GetId(AliCDBId(path, runRange, version, subVersion));
613 //_____________________________________________________________________________
614 AliCDBId* AliCDBManager::GetId(const AliCDBId& query) {
615 // get the AliCDBId of the valid object from the database (does not retrieve the object)
616 // User must delete returned object!
618 if(!fDefaultStorage) {
619 AliError("No storage set!");
623 // check if query's path and runRange are valid
624 // query is invalid also if version is not specified and subversion is!
625 if (!query.IsValid()) {
626 AliError(Form("Invalid query: %s", query.ToString().Data()));
630 // query is not specified if path contains wildcard or run range= [-1,-1]
631 if (!query.IsSpecified()) {
632 AliError(Form("Unspecified query: %s",
633 query.ToString().Data()));
637 if(fCache && query.GetFirstRun() != fRun)
638 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
640 AliCDBEntry* entry = 0;
642 // first look into map of cached objects
643 if(fCache && query.GetFirstRun() == fRun)
644 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
647 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
648 return dynamic_cast<AliCDBId*> (entry->GetId().Clone());
651 // Entry is not in cache -> retrieve it from CDB and cache it!!
652 AliCDBStorage *aStorage=0;
653 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
656 aStorage=GetStorage(aPar);
657 TString str = aPar->GetURI();
658 AliDebug(2,Form("Looking into storage: %s",str.Data()));
661 aStorage=GetDefaultStorage();
662 AliDebug(2,"Looking into default storage");
665 return aStorage->GetId(query);
669 //_____________________________________________________________________________
670 TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber,
671 Int_t version, Int_t subVersion) {
672 // get multiple AliCDBEntry objects from the database
675 // RunNumber is not specified. Try with fRun
677 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
683 return GetAll(AliCDBId(path, runNumber, runNumber, version,
687 //_____________________________________________________________________________
688 TList* AliCDBManager::GetAll(const AliCDBPath& path,
689 const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
690 // get multiple AliCDBEntry objects from the database
692 return GetAll(AliCDBId(path, runRange, version, subVersion));
695 //_____________________________________________________________________________
696 TList* AliCDBManager::GetAll(const AliCDBId& query) {
697 // get multiple AliCDBEntry objects from the database
698 // Warning: this method works correctly only for queries of the type "Detector/*"
699 // and not for more specific queries e.g. "Detector/Calib/*" !
700 // Warning #2: Entries are cached, but GetAll will keep on retrieving objects from OCDB!
701 // To get an object from cache use Get() function
703 if(!fDefaultStorage) {
704 AliError("No storage set!");
708 if (!query.IsValid()) {
709 AliError(Form("Invalid query: %s", query.ToString().Data()));
713 if((fSpecificStorages.GetEntries()>0) && query.GetPath().BeginsWith('*')){
714 // if specific storages are active a query with "*" is ambiguous
715 AliError("Query too generic in this context!");
719 if (query.IsAnyRange()) {
720 AliError(Form("Unspecified run or runrange: %s",
721 query.ToString().Data()));
725 if(fLock && query.GetFirstRun() != fRun)
726 AliFatal("Lock is ON: cannot use different run number than the internal one!");
728 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
730 AliCDBStorage *aStorage;
732 aStorage=GetStorage(aPar);
733 AliDebug(2,Form("Looking into storage: %s", aPar->GetURI().Data()));
736 aStorage=GetDefaultStorage();
737 AliDebug(2,"Looking into default storage");
741 if(aStorage) result = aStorage->GetAll(query);
742 if(!result) return 0;
744 // loop on result to check whether entries should be re-queried with specific storages
745 if(fSpecificStorages.GetEntries()>0 && ! (fSpecificStorages.GetEntries() == 1 && aPar)) {
746 AliInfo("Now look into all other specific storages...");
749 AliCDBEntry* chkEntry=0;
751 while((chkEntry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
752 AliCDBId& chkId = chkEntry->GetId();
753 AliDebug(2, Form("Checking id %s ", chkId.GetPath().Data()));
754 AliCDBParam *chkPar=SelectSpecificStorage(chkId.GetPath());
755 if (!chkPar || aPar == chkPar) continue;
756 AliCDBStorage *chkStorage = GetStorage(chkPar);
757 AliDebug(2, Form("Found specific storage! %s", chkPar->GetURI().Data()));
759 AliCDBEntry *newEntry=0;
760 chkId.SetRunRange(query.GetFirstRun(), query.GetLastRun());
761 chkId.SetVersion(query.GetVersion());
762 chkId.SetSubVersion(query.GetSubVersion());
764 if(chkStorage) newEntry = chkStorage->Get(chkId);
765 if(!newEntry) continue;
767 // object is found in specific storage: replace entry in the result list!
768 chkEntry->SetOwner(1);
769 delete result->Remove(chkEntry);
770 result->AddFirst(newEntry);
773 Int_t nEntries = result->GetEntries();
774 AliInfo("After look into other specific storages, result list is:");
775 for(int i=0; i<nEntries;i++){
776 AliCDBEntry *entry = (AliCDBEntry*) result->At(i);
777 AliInfo(Form("%s",entry->GetId().ToString().Data()));
783 AliCDBEntry* entry=0;
784 while((entry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
786 if(!fIds->Contains(&entry->GetId())){
787 fIds->Add(entry->GetId().Clone());
789 if(fCache && (query.GetFirstRun() == fRun)){
790 CacheEntry(entry->GetId().GetPath(), entry);
798 //_____________________________________________________________________________
799 Bool_t AliCDBManager::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData, DataType type){
800 // store an AliCDBEntry object into the database
802 AliCDBEntry anEntry(object, id, metaData);
803 return Put(&anEntry, type);
808 //_____________________________________________________________________________
809 Bool_t AliCDBManager::Put(AliCDBEntry* entry, DataType type){
810 // store an AliCDBEntry object into the database
812 if(type == kPrivate && !fDefaultStorage) {
813 AliError("No storage set!");
818 AliError("No entry!");
822 if (!entry->GetId().IsValid()) {
823 AliError(Form("Invalid entry ID: %s",
824 entry->GetId().ToString().Data()));
828 if (!entry->GetId().IsSpecified()) {
829 AliError(Form("Unspecified entry ID: %s",
830 entry->GetId().ToString().Data()));
834 AliCDBId id = entry->GetId();
835 AliCDBParam *aPar = SelectSpecificStorage(id.GetPath());
837 AliCDBStorage *aStorage=0;
840 aStorage=GetStorage(aPar);
844 aStorage = GetStorage(fCondParam);
847 aStorage = GetStorage(fRefParam);
850 aStorage = GetDefaultStorage();
855 AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data()));
857 Bool_t result = aStorage->Put(entry, type);
859 if(fRun >= 0) QueryCDB();
866 //_____________________________________________________________________________
867 void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry)
869 // cache AliCDBEntry. Cache is valid until run number is changed.
871 AliCDBEntry *chkEntry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(path));
874 AliDebug(2, Form("Object %s already in cache !!", path));
877 AliDebug(2,Form("Caching entry %s", path));
880 fEntryCache.Add(new TObjString(path), entry);
881 AliDebug(2,Form("Cache entries: %d", fEntryCache.GetEntries()));
885 //_____________________________________________________________________________
886 void AliCDBManager::Print(Option_t* /*option*/) const
888 // Print list of active storages and their URIs
890 TString output=Form("Run number = %d; ",fRun);
891 output += "Cache is ";
892 if(!fCache) output += "NOT ";
893 output += Form("ACTIVE; Number of active storages: %d\n",fActiveStorages.GetEntries());
895 if(fDefaultStorage) {
896 output += Form("\t*** Default Storage URI: \"%s\"\n",fDefaultStorage->GetURI().Data());
897 // AliInfo(output.Data());
899 if(fSpecificStorages.GetEntries()>0) {
900 TIter iter(fSpecificStorages.GetTable());
903 while((aPair = (TPair*) iter.Next())){
904 output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n",
905 i++, ((TObjString*) aPair->Key())->GetName(),
906 ((AliCDBParam*) aPair->Value())->GetURI().Data());
910 output += Form("*** Drain Storage URI: %s\n",fDrainStorage->GetURI().Data());
912 AliInfo(output.Data());
915 //_____________________________________________________________________________
916 void AliCDBManager::SetRun(Int_t run)
918 // Sets current run number.
919 // When the run number changes the caching is cleared.
924 if(fLock && fRun >= 0) {
925 AliFatal("Lock is ON, cannot reset run number!");
933 //_____________________________________________________________________________
934 void AliCDBManager::ClearCache(){
935 // clear AliCDBEntry cache
937 AliDebug(2, Form("Cache entries to be deleted: %d",fEntryCache.GetEntries()));
940 // To clean entries one by one
941 TIter iter(fEntryCache.GetTable());
943 while((pair= dynamic_cast<TPair*> (iter.Next()))){
945 TObjString* key = dynamic_cast<TObjString*> (pair->Key());
946 AliCDBEntry* entry = dynamic_cast<AliCDBEntry*> (pair->Value());
947 AliDebug(2, Form("Deleting entry: %s", key->GetName()));
948 if (entry) delete entry;
949 delete fEntryCache.Remove(key);
952 fEntryCache.DeleteAll();
953 AliDebug(2, Form("After deleting - Cache entries: %d",fEntryCache.GetEntries()));
956 //_____________________________________________________________________________
957 void AliCDBManager::UnloadFromCache(const char* path){
958 // unload cached object
960 AliCDBPath queryPath(path);
961 if(!queryPath.IsValid()) return;
963 if(!queryPath.IsWildcard()) { // path is not wildcard, get it directly from the cache and unload it!
964 if(fEntryCache.Contains(path)){
965 AliInfo(Form("Unloading object \"%s\" from cache", path));
966 TObjString pathStr(path);
967 AliCDBEntry *entry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(&pathStr));
968 if(entry) delete entry;
969 delete fEntryCache.Remove(&pathStr);
971 AliError(Form("Cache does not contain object \"%s\"!", path))
973 AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries()));
977 // path is wildcard: loop on the cache and unload all comprised objects!
978 TIter iter(fEntryCache.GetTable());
981 while((pair = dynamic_cast<TPair*> (iter.Next()))){
982 AliCDBPath entryPath = pair->Key()->GetName();
983 if(queryPath.Comprises(entryPath)) {
984 AliInfo(Form("Unloading object \"%s\" from cache", entryPath.GetPath().Data()));
985 TObjString pathStr(entryPath.GetPath().Data());
986 AliCDBEntry *entry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(&pathStr));
987 if(entry) delete entry;
988 delete fEntryCache.Remove(&pathStr);
991 AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries()));
994 //_____________________________________________________________________________
995 void AliCDBManager::DestroyActiveStorages() {
996 // delete list of active storages
998 fActiveStorages.DeleteAll();
999 fSpecificStorages.DeleteAll();
1002 //_____________________________________________________________________________
1003 void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
1004 // destroys active storage
1007 TIter iter(fActiveStorages.GetTable());
1009 while ((aPair = (TPair*) iter.Next())) {
1010 if(storage == (AliCDBStorage*) aPair->Value())
1011 delete fActiveStorages.Remove(aPair->Key());
1012 storage->Delete(); storage=0x0;
1018 //_____________________________________________________________________________
1019 void AliCDBManager::QueryCDB() {
1020 // query default and specific storages for files valid for fRun. Every storage loads the Ids into its list.
1023 AliError("Run number not yet set! Use AliCDBManager::SetRun.");
1026 if (!fDefaultStorage){
1027 AliError("Default storage is not set! Use AliCDBManager::SetDefaultStorage");
1030 if(fDefaultStorage->GetType() == "alien"){
1031 fDefaultStorage->QueryCDB(fRun);
1033 AliDebug(2,"Skipping query for valid files, it used only in grid...");
1036 TIter iter(&fSpecificStorages);
1037 TObjString *aCalibType=0;
1038 AliCDBParam* aPar=0;
1039 while((aCalibType = dynamic_cast<TObjString*> (iter.Next()))){
1040 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
1042 AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName()));
1043 AliCDBStorage *aStorage = GetStorage(aPar);
1044 if(aStorage->GetType() == "alien"){
1045 aStorage->QueryCDB(fRun,aCalibType->GetName());
1048 "Skipping query for valid files, it is used only in grid...");
1054 //______________________________________________________________________________________________
1055 const char* AliCDBManager::GetDataTypeName(DataType type)
1057 // returns the name (string) of the data type
1060 case kCondition: return "Conditions";
1061 case kReference: return "Reference";
1062 case kPrivate: return "Private";
1068 //______________________________________________________________________________________________
1069 void AliCDBManager::InitShortLived()
1071 // Init the list of short-lived objects
1072 // currently disabled
1076 // fShortLived = new TList();
1077 // fShortLived->SetOwner(1);
1079 // fShortLived->Add(new TObjString("EMCAL/Calib/Data"));
1081 // fShortLived->Add(new TObjString("HMPID/Calib/Nmean"));
1082 // fShortLived->Add(new TObjString("HMPID/Calib/Qthre"));
1084 // fShortLived->Add(new TObjString("ITS/Calib/CalibSPD"));
1086 // fShortLived->Add(new TObjString("MUON/Calib/Gains"));
1087 // fShortLived->Add(new TObjString("MUON/Calib/HV"));
1088 // fShortLived->Add(new TObjString("MUON/Calib/Pedestals"));
1090 // fShortLived->Add(new TObjString("PHOS/Calib/CpvGainPedestals"));
1091 // fShortLived->Add(new TObjString("PHOS/Calib/EmcGainPedestals"));
1093 // fShortLived->Add(new TObjString("PMD/Calib/Data"));
1095 // fShortLived->Add(new TObjString("TRD/Calib/ChamberGainFactor"));
1096 // fShortLived->Add(new TObjString("TRD/Calib/LocalGainFactor"));
1097 // fShortLived->Add(new TObjString("TRD/Calib/ChamberT0"));
1098 // fShortLived->Add(new TObjString("TRD/Calib/LocalT0"));
1099 // fShortLived->Add(new TObjString("TRD/Calib/ChamberVdrift"));
1100 // fShortLived->Add(new TObjString("TRD/Calib/LocalVdrift"));
1102 // fShortLived->Add(new TObjString("ZDC/Calib/Data"));
1106 //______________________________________________________________________________________________
1107 Bool_t AliCDBManager::IsShortLived(const char* path)
1109 // returns the name (string) of the data type
1111 if(!fShortLived) return kFALSE;
1113 AliCDBPath aPath(path);
1114 if(!aPath.IsValid()){
1115 AliError(Form("Not a valid path: %s", path));
1119 return fShortLived->Contains(path);
1123 //______________________________________________________________________________________________
1124 void AliCDBManager::SetLock(Bool_t lock){
1126 if(fLock == kTRUE && lock == kFALSE) {
1127 AliFatal("Lock is ON: cannot reset it!");
1133 ///////////////////////////////////////////////////////////
1134 // AliCDBManager Parameter class //
1135 // interface to specific AliCDBParameter class //
1136 // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) //
1137 ///////////////////////////////////////////////////////////
1139 AliCDBParam::AliCDBParam():
1147 //_____________________________________________________________________________
1148 AliCDBParam::~AliCDBParam() {