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 fRemoteStorage = 0x0;
121 delete fStorageMap; fStorageMap = 0;
122 delete fIds; fIds = 0;
125 delete fShortLived; fShortLived = 0x0;
128 //_____________________________________________________________________________
129 void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){
130 // put a storage object into the list of active storages
132 fActiveStorages.Add(param, storage);
133 AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries()));
136 //_____________________________________________________________________________
137 void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) {
138 // add a storage factory to the list of registerd factories
140 if (!fFactories.Contains(factory)) {
141 fFactories.Add(factory);
145 //_____________________________________________________________________________
146 Bool_t AliCDBManager::HasStorage(const char* dbString) const {
147 // check if dbString is a URI valid for one of the registered factories
149 TIter iter(&fFactories);
151 AliCDBStorageFactory* factory=0;
152 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
154 if (factory->Validate(dbString)) {
162 //_____________________________________________________________________________
163 AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
164 // create AliCDBParam object from URI string
166 TIter iter(&fFactories);
168 AliCDBStorageFactory* factory=0;
169 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
170 AliCDBParam* param = factory->CreateParameter(dbString);
171 if(param) return param;
177 //_____________________________________________________________________________
178 AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) {
179 // get storage object from URI string
181 AliCDBParam* param = CreateParameter(dbString);
183 AliError(Form("Failed to activate requested storage! Check URI: %s", dbString));
187 AliCDBStorage* aStorage = GetStorage(param);
193 //_____________________________________________________________________________
194 AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) {
195 // get storage object from AliCDBParam object
197 // if the list of active storages already contains
198 // the requested storage, return it
199 AliCDBStorage* aStorage = GetActiveStorage(param);
204 TIter iter(&fFactories);
206 AliCDBStorageFactory* factory=0;
208 // loop on the list of registered factories
209 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
211 // each factory tries to create its storage from the parameter
212 aStorage = factory->Create(param);
214 PutActiveStorage(param->CloneParam(), aStorage);
215 aStorage->SetURI(param->GetURI());
217 if(aStorage->GetType() == "alien"){
218 aStorage->QueryCDB(fRun);
221 "Skipping query for valid files, it is used only in grid...");
228 AliError(Form("Failed to activate requested storage! Check URI: %s", param->GetURI().Data()));
233 //_____________________________________________________________________________
234 AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) {
235 // get a storage object from the list of active storages
237 return dynamic_cast<AliCDBStorage*> (fActiveStorages.GetValue(param));
240 //_____________________________________________________________________________
241 TList* AliCDBManager::GetActiveStorages() {
242 // return list of active storages
243 // user has responsibility to delete returned object
245 TList* result = new TList();
247 TIter iter(fActiveStorages.GetTable());
249 while ((aPair = (TPair*) iter.Next())) {
250 result->Add(aPair->Value());
256 //_____________________________________________________________________________
257 void AliCDBManager::SetDrain(const char* dbString) {
258 // set drain storage from URI string
260 fDrainStorage = GetStorage(dbString);
263 //_____________________________________________________________________________
264 void AliCDBManager::SetDrain(const AliCDBParam* param) {
265 // set drain storage from AliCDBParam
267 fDrainStorage = GetStorage(param);
270 //_____________________________________________________________________________
271 void AliCDBManager::SetDrain(AliCDBStorage* storage) {
272 // set drain storage from another active storage
274 fDrainStorage = storage;
277 //_____________________________________________________________________________
278 Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
279 // drain retrieved object to drain storage
281 AliDebug(2, "Draining into drain storage...");
282 return fDrainStorage->Put(entry);
285 //_____________________________________________________________________________
286 void AliCDBManager::SetDefaultStorage(const char* dbString) {
287 // sets default storage from URI string
289 AliInfo(Form("Setting Default storage to: %s",dbString));
290 AliCDBStorage* bckStorage = fDefaultStorage;
292 fDefaultStorage = GetStorage(dbString);
294 if(bckStorage && (fDefaultStorage != bckStorage)){
295 AliWarning("Existing default storage replaced: clearing cache!");
299 if (fStorageMap->Contains("default")) {
300 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
302 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
305 //_____________________________________________________________________________
306 void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
307 // set default storage from AliCDBParam object
309 AliCDBStorage* bckStorage = fDefaultStorage;
311 fDefaultStorage = GetStorage(param);
313 if(bckStorage && (fDefaultStorage != bckStorage)){
314 AliWarning("Existing default storage replaced: clearing cache!");
318 if (fStorageMap->Contains("default")) {
319 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
321 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
324 //_____________________________________________________________________________
325 void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
326 // set default storage from another active storage
328 AliCDBStorage* bckStorage = fDefaultStorage;
330 fDefaultStorage = storage;
332 if(bckStorage && (fDefaultStorage != bckStorage)){
333 AliWarning("Existing default storage replaced: clearing cache!");
337 if (fStorageMap->Contains("default")) {
338 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
340 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
342 //_____________________________________________________________________________
343 void AliCDBManager::SetRemoteStorage(const char* dbString) {
344 // sets remote storage from URI string
345 // Remote storage is queried if it is activated and if object was not found in default storage
347 AliInfo(Form("Setting remote storage to: %s",dbString));
348 fRemoteStorage = GetStorage(dbString);
351 //_____________________________________________________________________________
352 void AliCDBManager::SetRemoteStorage(const AliCDBParam* param) {
353 // set remote storage from AliCDBParam object
354 // Remote storage is queried if it is activated and if object was not found in default storage
356 fRemoteStorage = GetStorage(param);
359 //_____________________________________________________________________________
360 void AliCDBManager::SetRemoteStorage(AliCDBStorage* storage) {
361 // set remote storage from another active storage
362 // Remote storage is queried if it is activated and if object was not found in default storage
364 fRemoteStorage = storage;
367 //_____________________________________________________________________________
368 void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) {
369 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
371 AliCDBParam *aPar = CreateParameter(dbString);
373 SetSpecificStorage(calibType, aPar);
377 //_____________________________________________________________________________
378 void AliCDBManager::SetSpecificStorage(const char* calibType, AliCDBParam* param) {
379 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
380 // Default storage should be defined prior to any specific storages, e.g.:
381 // AliCDBManager::instance()->SetDefaultStorage("alien://");
382 // AliCDBManager::instance()->SetSpecificStorage("TPC/*","local://DB_TPC");
383 // AliCDBManager::instance()->SetSpecificStorage("*/Align/*","local://DB_TPCAlign");
384 // calibType must be a valid CDB path! (3 level folder structure)
386 if(!fDefaultStorage) {
387 AliError("Please activate a default storage first!");
391 AliCDBPath aPath(calibType);
392 if(!aPath.IsValid()){
393 AliError(Form("Not a valid path: %s", calibType));
397 TObjString *objCalibType = new TObjString(aPath.GetPath());
398 if(fSpecificStorages.Contains(objCalibType)){
399 AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one",
401 AliCDBParam *checkPar = dynamic_cast<AliCDBParam*> (fSpecificStorages.GetValue(calibType));
402 if(checkPar) delete checkPar;
403 delete fSpecificStorages.Remove(objCalibType);
407 fSpecificStorages.Add(objCalibType, param->CloneParam());
409 if(fStorageMap->Contains(objCalibType)){
410 delete fStorageMap->Remove(objCalibType);
412 fStorageMap->Add(objCalibType->Clone(), new TObjString(param->GetURI()));
416 //_____________________________________________________________________________
417 AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) {
418 // get storage specific for detector or calibration type
420 AliCDBPath calibPath(calibType);
421 if(!calibPath.IsValid()) return NULL;
423 AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibPath.GetPath());
425 AliError(Form("%s storage not found!", calibType));
428 return GetStorage(checkPar);
433 //_____________________________________________________________________________
434 AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) {
435 // select storage valid for path from the list of specific storages
437 AliCDBPath aPath(path);
438 if(!aPath.IsValid()) return NULL;
440 TIter iter(&fSpecificStorages);
441 TObjString *aCalibType=0;
442 AliCDBPath tmpPath("null/null/null");
444 while((aCalibType = (TObjString*) iter.Next())){
445 AliCDBPath calibTypePath(aCalibType->GetName());
446 if(calibTypePath.Comprises(aPath)) {
447 if(calibTypePath.Comprises(tmpPath)) continue;
448 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
449 tmpPath.SetPath(calibTypePath.GetPath());
455 //_____________________________________________________________________________
456 AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber,
457 Int_t version, Int_t subVersion) {
458 // get an AliCDBEntry object from the database
461 // RunNumber is not specified. Try with fRun
463 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
469 return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
472 //_____________________________________________________________________________
473 AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path,
474 const AliCDBRunRange& runRange, Int_t version,
476 // get an AliCDBEntry object from the database!
478 return Get(AliCDBId(path, runRange, version, subVersion));
481 //_____________________________________________________________________________
482 AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) {
483 // get an AliCDBEntry object from the database
485 if(!fDefaultStorage) {
486 AliError("No storage set!");
490 // check if query's path and runRange are valid
491 // query is invalid also if version is not specified and subversion is!
492 if (!query.IsValid()) {
493 AliError(Form("Invalid query: %s", query.ToString().Data()));
497 // query is not specified if path contains wildcard or run range= [-1,-1]
498 if (!query.IsSpecified()) {
499 AliError(Form("Unspecified query: %s",
500 query.ToString().Data()));
504 if(fCache && query.GetFirstRun() != fRun)
505 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
508 AliCDBEntry *entry=0;
510 // first look into map of cached objects
511 if(fCache && query.GetFirstRun() == fRun)
512 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
515 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
519 // Entry is not in cache -> retrieve it from CDB and cache it!!
520 AliCDBStorage *aStorage=0;
521 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
522 Bool_t usedDefStorage=kTRUE;
525 aStorage=GetStorage(aPar);
526 TString str = aPar->GetURI();
527 AliDebug(2,Form("Looking into storage: %s",str.Data()));
528 usedDefStorage=kFALSE;
531 aStorage=GetDefaultStorage();
532 AliDebug(2,"Looking into default storage");
535 entry = aStorage->Get(query);
537 if (!entry && usedDefStorage && IsRemoteStorageSet()) {
538 AliWarning(Form("Object not found in default storage: Looking into remote storage!"));
539 entry = fRemoteStorage->Get(query);
542 if(entry && fCache && (query.GetFirstRun() == fRun)){
543 CacheEntry(query.GetPath(), entry);
546 if(entry && !fIds->Contains(&entry->GetId())){
547 fIds->Add(entry->GetId().Clone());
555 //_____________________________________________________________________________
556 AliCDBId* AliCDBManager::GetId(const AliCDBPath& path, Int_t runNumber,
557 Int_t version, Int_t subVersion) {
558 // get the AliCDBId of the valid object from the database (does not retrieve the object)
559 // User must delete returned object!
562 // RunNumber is not specified. Try with fRun
564 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
570 return GetId(AliCDBId(path, runNumber, runNumber, version, subVersion));
573 //_____________________________________________________________________________
574 AliCDBId* AliCDBManager::GetId(const AliCDBPath& path,
575 const AliCDBRunRange& runRange, Int_t version,
577 // get the AliCDBId of the valid object from the database (does not retrieve the object)
578 // User must delete returned object!
580 return GetId(AliCDBId(path, runRange, version, subVersion));
583 //_____________________________________________________________________________
584 AliCDBId* AliCDBManager::GetId(const AliCDBId& query) {
585 // get the AliCDBId of the valid object from the database (does not retrieve the object)
586 // User must delete returned object!
588 if(!fDefaultStorage) {
589 AliError("No storage set!");
593 // check if query's path and runRange are valid
594 // query is invalid also if version is not specified and subversion is!
595 if (!query.IsValid()) {
596 AliError(Form("Invalid query: %s", query.ToString().Data()));
600 // query is not specified if path contains wildcard or run range= [-1,-1]
601 if (!query.IsSpecified()) {
602 AliError(Form("Unspecified query: %s",
603 query.ToString().Data()));
607 if(fCache && query.GetFirstRun() != fRun)
608 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
610 AliCDBEntry* entry = 0;
612 // first look into map of cached objects
613 if(fCache && query.GetFirstRun() == fRun)
614 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
617 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
618 return dynamic_cast<AliCDBId*> (entry->GetId().Clone());
621 // Entry is not in cache -> retrieve it from CDB and cache it!!
622 AliCDBStorage *aStorage=0;
623 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
626 aStorage=GetStorage(aPar);
627 TString str = aPar->GetURI();
628 AliDebug(2,Form("Looking into storage: %s",str.Data()));
631 aStorage=GetDefaultStorage();
632 AliDebug(2,"Looking into default storage");
635 return aStorage->GetId(query);
639 //_____________________________________________________________________________
640 TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber,
641 Int_t version, Int_t subVersion) {
642 // get multiple AliCDBEntry objects from the database
645 // RunNumber is not specified. Try with fRun
647 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
653 return GetAll(AliCDBId(path, runNumber, runNumber, version,
657 //_____________________________________________________________________________
658 TList* AliCDBManager::GetAll(const AliCDBPath& path,
659 const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
660 // get multiple AliCDBEntry objects from the database
662 return GetAll(AliCDBId(path, runRange, version, subVersion));
665 //_____________________________________________________________________________
666 TList* AliCDBManager::GetAll(const AliCDBId& query) {
667 // get multiple AliCDBEntry objects from the database
668 // Warning: this method works correctly only for queries of the type "Detector/*"
669 // and not for more specific queries e.g. "Detector/Calib/*" !
670 // Warning #2: Entries are cached, but GetAll will keep on retrieving objects from OCDB!
671 // To get an object from cache use Get() function
673 if(!fDefaultStorage) {
674 AliError("No storage set!");
678 if (!query.IsValid()) {
679 AliError(Form("Invalid query: %s", query.ToString().Data()));
683 if((fSpecificStorages.GetEntries()>0) && query.GetPath().BeginsWith('*')){
684 // if specific storages are active a query with "*" is ambiguous
685 AliError("Query too generic in this context!");
689 if (query.IsAnyRange()) {
690 AliError(Form("Unspecified run or runrange: %s",
691 query.ToString().Data()));
695 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
697 AliCDBStorage *aStorage;
699 aStorage=GetStorage(aPar);
700 AliDebug(2,Form("Looking into storage: %s", aPar->GetURI().Data()));
703 aStorage=GetDefaultStorage();
704 AliDebug(2,"Looking into default storage");
708 if(aStorage) result = aStorage->GetAll(query);
709 if(!result) return 0;
711 // loop on result to check whether entries should be re-queried with specific storages
712 if(fSpecificStorages.GetEntries()>0 && ! (fSpecificStorages.GetEntries() == 1 && aPar)) {
713 AliInfo("Now look into all other specific storages...");
716 AliCDBEntry* chkEntry=0;
718 while((chkEntry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
719 AliCDBId& chkId = chkEntry->GetId();
720 AliDebug(2, Form("Checking id %s ", chkId.GetPath().Data()));
721 AliCDBParam *chkPar=SelectSpecificStorage(chkId.GetPath());
722 if (!chkPar || aPar == chkPar) continue;
723 AliCDBStorage *chkStorage = GetStorage(chkPar);
724 AliDebug(2, Form("Found specific storage! %s", chkPar->GetURI().Data()));
726 AliCDBEntry *newEntry=0;
727 chkId.SetRunRange(query.GetFirstRun(), query.GetLastRun());
728 chkId.SetVersion(query.GetVersion());
729 chkId.SetSubVersion(query.GetSubVersion());
731 if(chkStorage) newEntry = chkStorage->Get(chkId);
732 if(!newEntry) continue;
734 // object is found in specific storage: replace entry in the result list!
735 chkEntry->SetOwner(1);
736 delete result->Remove(chkEntry);
737 result->AddFirst(newEntry);
740 Int_t nEntries = result->GetEntries();
741 AliInfo("After look into other specific storages, result list is:");
742 for(int i=0; i<nEntries;i++){
743 AliCDBEntry *entry = (AliCDBEntry*) result->At(i);
744 AliInfo(Form("%s",entry->GetId().ToString().Data()));
750 AliCDBEntry* entry=0;
751 while((entry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
753 if(!fIds->Contains(&entry->GetId())){
754 fIds->Add(entry->GetId().Clone());
756 if(fCache && (query.GetFirstRun() == fRun)){
757 CacheEntry(entry->GetId().GetPath(), entry);
765 //_____________________________________________________________________________
766 Bool_t AliCDBManager::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData, DataType type){
767 // store an AliCDBEntry object into the database
769 AliCDBEntry anEntry(object, id, metaData);
770 return Put(&anEntry, type);
775 //_____________________________________________________________________________
776 Bool_t AliCDBManager::Put(AliCDBEntry* entry, DataType type){
777 // store an AliCDBEntry object into the database
779 if(type == kPrivate && !fDefaultStorage) {
780 AliError("No storage set!");
785 AliError("No entry!");
789 if (!entry->GetId().IsValid()) {
790 AliError(Form("Invalid entry ID: %s",
791 entry->GetId().ToString().Data()));
795 if (!entry->GetId().IsSpecified()) {
796 AliError(Form("Unspecified entry ID: %s",
797 entry->GetId().ToString().Data()));
801 AliCDBId id = entry->GetId();
802 AliCDBParam *aPar = SelectSpecificStorage(id.GetPath());
804 AliCDBStorage *aStorage=0;
807 aStorage=GetStorage(aPar);
811 aStorage = GetStorage(fCondParam);
814 aStorage = GetStorage(fRefParam);
817 aStorage = GetDefaultStorage();
822 AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data()));
824 Bool_t result = aStorage->Put(entry, type);
826 if(fRun >= 0) QueryCDB();
833 //_____________________________________________________________________________
834 void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry)
836 // cache AliCDBEntry. Cache is valid until run number is changed.
838 AliCDBEntry *chkEntry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(path));
841 AliDebug(2, Form("Object %s already in cache !!", path));
844 AliDebug(2,Form("Caching entry %s", path));
847 fEntryCache.Add(new TObjString(path), entry);
848 AliDebug(2,Form("Cache entries: %d", fEntryCache.GetEntries()));
852 //_____________________________________________________________________________
853 void AliCDBManager::Print(Option_t* /*option*/) const
855 // Print list of active storages and their URIs
857 TString output=Form("Run number = %d; ",fRun);
858 output += "Cache is ";
859 if(!fCache) output += "NOT ";
860 output += Form("ACTIVE; Number of active storages: %d\n",fActiveStorages.GetEntries());
862 if(fDefaultStorage) {
863 output += Form("\t*** Default Storage URI: \"%s\"\n",fDefaultStorage->GetURI().Data());
864 // AliInfo(output.Data());
866 if(fSpecificStorages.GetEntries()>0) {
867 TIter iter(fSpecificStorages.GetTable());
870 while((aPair = (TPair*) iter.Next())){
871 output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n",
872 i++, ((TObjString*) aPair->Key())->GetName(),
873 ((AliCDBParam*) aPair->Value())->GetURI().Data());
877 output += Form("*** Drain Storage URI: %s\n",fDrainStorage->GetURI().Data());
879 AliInfo(output.Data());
882 //_____________________________________________________________________________
883 void AliCDBManager::SetRun(Int_t run)
885 // Sets current run number.
886 // When the run number changes the caching is cleared.
896 //_____________________________________________________________________________
897 void AliCDBManager::ClearCache(){
898 // clear AliCDBEntry cache
900 AliDebug(2,Form("Clearing cache!"));
901 fEntryCache.DeleteAll();
902 AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries()));
906 //_____________________________________________________________________________
907 void AliCDBManager::UnloadFromCache(const char* path){
908 // unload cached object
910 AliCDBPath queryPath(path);
911 if(!queryPath.IsValid()) return;
913 if(!queryPath.IsWildcard()) { // path is not wildcard, get it directly from the cache and unload it!
914 if(fEntryCache.Contains(path)){
915 AliInfo(Form("Unloading object \"%s\" from cache", path));
916 TObjString pathStr(path);
917 AliCDBEntry *entry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(&pathStr));
918 if(entry) delete entry;
919 delete fEntryCache.Remove(&pathStr);
921 AliError(Form("Cache does not contain object \"%s\"!", path))
923 AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries()));
927 // path is wildcard: loop on the cache and unload all comprised objects!
928 TIter iter(fEntryCache.GetTable());
931 while((pair = dynamic_cast<TPair*> (iter.Next()))){
932 AliCDBPath entryPath = pair->Key()->GetName();
933 if(queryPath.Comprises(entryPath)) {
934 AliInfo(Form("Unloading object \"%s\" from cache", entryPath.GetPath().Data()));
935 TObjString pathStr(entryPath.GetPath().Data());
936 AliCDBEntry *entry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(&pathStr));
937 if(entry) delete entry;
938 delete fEntryCache.Remove(&pathStr);
941 AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries()));
944 //_____________________________________________________________________________
945 void AliCDBManager::DestroyActiveStorages() {
946 // delete list of active storages
948 fActiveStorages.DeleteAll();
949 fSpecificStorages.DeleteAll();
952 //_____________________________________________________________________________
953 void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
954 // destroys active storage
957 TIter iter(fActiveStorages.GetTable());
959 while ((aPair = (TPair*) iter.Next())) {
960 if(storage == (AliCDBStorage*) aPair->Value())
961 delete fActiveStorages.Remove(aPair->Key());
962 storage->Delete(); storage=0x0;
968 //_____________________________________________________________________________
969 void AliCDBManager::QueryCDB() {
970 // query default and specific storages for files valid for fRun. Every storage loads the Ids into its list.
973 AliError("Run number not yet set! Use AliCDBManager::SetRun.");
976 if (!fDefaultStorage){
977 AliError("Default storage is not set! Use AliCDBManager::SetDefaultStorage");
980 if(fDefaultStorage->GetType() == "alien"){
981 fDefaultStorage->QueryCDB(fRun);
983 AliDebug(2,"Skipping query for valid files, it used only in grid...");
986 TIter iter(&fSpecificStorages);
987 TObjString *aCalibType=0;
989 while((aCalibType = dynamic_cast<TObjString*> (iter.Next()))){
990 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
992 AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName()));
993 AliCDBStorage *aStorage = GetStorage(aPar);
994 if(aStorage->GetType() == "alien"){
995 aStorage->QueryCDB(fRun,aCalibType->GetName());
998 "Skipping query for valid files, it is used only in grid...");
1004 //______________________________________________________________________________________________
1005 const char* AliCDBManager::GetDataTypeName(DataType type)
1007 // returns the name (string) of the data type
1010 case kCondition: return "Conditions";
1011 case kReference: return "Reference";
1012 case kPrivate: return "Private";
1018 //______________________________________________________________________________________________
1019 void AliCDBManager::InitShortLived()
1021 // Init the list of short-lived objects
1022 // currently disabled
1026 // fShortLived = new TList();
1027 // fShortLived->SetOwner(1);
1029 // fShortLived->Add(new TObjString("EMCAL/Calib/Data"));
1031 // fShortLived->Add(new TObjString("HMPID/Calib/Nmean"));
1032 // fShortLived->Add(new TObjString("HMPID/Calib/Qthre"));
1034 // fShortLived->Add(new TObjString("ITS/Calib/CalibSPD"));
1036 // fShortLived->Add(new TObjString("MUON/Calib/Gains"));
1037 // fShortLived->Add(new TObjString("MUON/Calib/HV"));
1038 // fShortLived->Add(new TObjString("MUON/Calib/Pedestals"));
1040 // fShortLived->Add(new TObjString("PHOS/Calib/CpvGainPedestals"));
1041 // fShortLived->Add(new TObjString("PHOS/Calib/EmcGainPedestals"));
1043 // fShortLived->Add(new TObjString("PMD/Calib/Data"));
1045 // fShortLived->Add(new TObjString("TRD/Calib/ChamberGainFactor"));
1046 // fShortLived->Add(new TObjString("TRD/Calib/LocalGainFactor"));
1047 // fShortLived->Add(new TObjString("TRD/Calib/ChamberT0"));
1048 // fShortLived->Add(new TObjString("TRD/Calib/LocalT0"));
1049 // fShortLived->Add(new TObjString("TRD/Calib/ChamberVdrift"));
1050 // fShortLived->Add(new TObjString("TRD/Calib/LocalVdrift"));
1052 // fShortLived->Add(new TObjString("ZDC/Calib/Data"));
1056 //______________________________________________________________________________________________
1057 Bool_t AliCDBManager::IsShortLived(const char* path)
1059 // returns the name (string) of the data type
1061 if(!fShortLived) return kFALSE;
1063 AliCDBPath aPath(path);
1064 if(!aPath.IsValid()){
1065 AliError(Form("Not a valid path: %s", path));
1069 return fShortLived->Contains(path);
1073 ///////////////////////////////////////////////////////////
1074 // AliCDBManager Parameter class //
1075 // interface to specific AliCDBParameter class //
1076 // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) //
1077 ///////////////////////////////////////////////////////////
1079 AliCDBParam::AliCDBParam():
1087 //_____________________________________________________________________________
1088 AliCDBParam::~AliCDBParam() {