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"
29 #include "AliCDBHandler.h"
31 #include <TObjString.h>
33 #include <TSAXParser.h>
39 ClassImp(AliCDBManager)
41 //TODO OCDB and Reference folder should not be fully hardcoded but built from run number (or year/LHC period)
42 TString AliCDBManager::fgkCondUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/CDB?user=aliprod");
43 TString AliCDBManager::fgkRefUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/Reference?user=aliprod");
44 TString AliCDBManager::fgkMCIdealStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Ideal");
45 TString AliCDBManager::fgkMCFullStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Full");
46 TString AliCDBManager::fgkMCResidualStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Residual");
47 TString AliCDBManager::fgkOCDBFolderXMLfile("alien:///alice/data/OCDBFoldervsRunRange.xml");
48 AliCDBManager* AliCDBManager::fgInstance = 0x0;
50 //_____________________________________________________________________________
51 AliCDBManager* AliCDBManager::Instance(TMap *entryCache, Int_t run)
53 // returns AliCDBManager instance (singleton)
56 fgInstance = new AliCDBManager();
60 fgInstance->InitFromCache(entryCache,run);
66 //_____________________________________________________________________________
67 void AliCDBManager::Init() {
68 // factory registering
70 RegisterFactory(new AliCDBDumpFactory());
71 RegisterFactory(new AliCDBLocalFactory());
72 // AliCDBGridFactory is registered only if AliEn libraries are enabled in Root
73 if(!gSystem->Exec("root-config --has-alien |grep yes 2>&1 > /dev/null")){ // returns 0 if yes
74 AliInfo("AliEn classes enabled in Root. AliCDBGrid factory registered.");
75 RegisterFactory(new AliCDBGridFactory());
76 fCondParam = CreateParameter(fgkCondUri);
77 fRefParam = CreateParameter(fgkRefUri);
83 //_____________________________________________________________________________
84 void AliCDBManager::InitFromCache(TMap *entryCache, Int_t run) {
85 // initialize manager from existing cache
86 // used on the slaves in case of parallel reconstruction
89 TIter iter(entryCache->GetTable());
92 while((pair = dynamic_cast<TPair*> (iter.Next()))){
93 fEntryCache.Add(pair->Key(),pair->Value());
95 // fEntry is the new owner of the cache
96 fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
97 entryCache->SetOwnerKeyValue(kFALSE,kFALSE);
98 AliInfo(Form("%d cache entries have been loaded",fEntryCache.GetEntries()));
101 //_____________________________________________________________________________
102 void AliCDBManager::Destroy() {
103 // delete ALCDBManager instance and active storages
106 //fgInstance->Delete();
112 //_____________________________________________________________________________
113 AliCDBManager::AliCDBManager():
122 fDefaultStorage(NULL),
130 fStartRunLHCPeriod(-1),
131 fEndRunLHCPeriod(-1),
134 // default constuctor
135 fFactories.SetOwner(1);
136 fActiveStorages.SetOwner(1);
137 fSpecificStorages.SetOwner(1);
138 fEntryCache.SetName("CDBEntryCache");
139 fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
141 fStorageMap = new TMap();
142 fStorageMap->SetOwner(1);
147 //_____________________________________________________________________________
148 AliCDBManager::~AliCDBManager() {
151 DestroyActiveStorages();
154 fDefaultStorage = 0x0;
155 delete fStorageMap; fStorageMap = 0;
156 delete fIds; fIds = 0;
159 delete fShortLived; fShortLived = 0x0;
162 //_____________________________________________________________________________
163 void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){
164 // put a storage object into the list of active storages
166 fActiveStorages.Add(param, storage);
167 AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries()));
170 //_____________________________________________________________________________
171 void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) {
172 // add a storage factory to the list of registerd factories
174 if (!fFactories.Contains(factory)) {
175 fFactories.Add(factory);
179 //_____________________________________________________________________________
180 Bool_t AliCDBManager::HasStorage(const char* dbString) const {
181 // check if dbString is a URI valid for one of the registered factories
183 TIter iter(&fFactories);
185 AliCDBStorageFactory* factory=0;
186 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
188 if (factory->Validate(dbString)) {
196 //_____________________________________________________________________________
197 AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
198 // create AliCDBParam object from URI string
200 TIter iter(&fFactories);
202 AliCDBStorageFactory* factory=0;
203 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
204 AliCDBParam* param = factory->CreateParameter(dbString);
205 if(param) return param;
211 //_____________________________________________________________________________
212 AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) {
213 // get storage object from URI string
215 AliCDBParam* param = CreateParameter(dbString);
217 AliError(Form("Failed to activate requested storage! Check URI: %s", dbString));
221 AliCDBStorage* aStorage = GetStorage(param);
227 //_____________________________________________________________________________
228 AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) {
229 // get storage object from AliCDBParam object
231 // if the list of active storages already contains
232 // the requested storage, return it
233 AliCDBStorage* aStorage = GetActiveStorage(param);
238 // if lock is ON, cannot activate more storages!
240 if (fDefaultStorage) {
241 AliFatal("Lock is ON, and default storage is already set: "
242 "cannot reset it or activate more storages!");
246 TIter iter(&fFactories);
248 AliCDBStorageFactory* factory=0;
250 // loop on the list of registered factories
251 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
253 // each factory tries to create its storage from the parameter
254 aStorage = factory->Create(param);
256 PutActiveStorage(param->CloneParam(), aStorage);
257 aStorage->SetURI(param->GetURI());
259 if(aStorage->GetType() == "alien"){
260 aStorage->QueryCDB(fRun);
263 "Skipping query for valid files, it is used only in grid...");
270 AliError(Form("Failed to activate requested storage! Check URI: %s", param->GetURI().Data()));
275 //_____________________________________________________________________________
276 AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) {
277 // get a storage object from the list of active storages
279 return dynamic_cast<AliCDBStorage*> (fActiveStorages.GetValue(param));
282 //_____________________________________________________________________________
283 TList* AliCDBManager::GetActiveStorages() {
284 // return list of active storages
285 // user has responsibility to delete returned object
287 TList* result = new TList();
289 TIter iter(fActiveStorages.GetTable());
291 while ((aPair = (TPair*) iter.Next())) {
292 result->Add(aPair->Value());
298 //_____________________________________________________________________________
299 void AliCDBManager::SetDrain(const char* dbString) {
300 // set drain storage from URI string
302 fDrainStorage = GetStorage(dbString);
305 //_____________________________________________________________________________
306 void AliCDBManager::SetDrain(const AliCDBParam* param) {
307 // set drain storage from AliCDBParam
309 fDrainStorage = GetStorage(param);
312 //_____________________________________________________________________________
313 void AliCDBManager::SetDrain(AliCDBStorage* storage) {
314 // set drain storage from another active storage
316 fDrainStorage = storage;
319 //_____________________________________________________________________________
320 Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
321 // drain retrieved object to drain storage
323 AliDebug(2, "Draining into drain storage...");
324 return fDrainStorage->Put(entry);
327 //____________________________________________________________________________
328 void AliCDBManager::SetDefaultStorage(const char* dbString) {
329 // sets default storage from URI string
331 AliInfo(Form("Setting Default storage to: %s",dbString));
333 // checking whether we are in the raw case
334 TString dbStringTemp(dbString);
335 if (dbStringTemp == "raw://") fRaw = kTRUE;
337 AliCDBStorage* bckStorage = fDefaultStorage;
339 fDefaultStorage = GetStorage(dbString);
341 if(!fDefaultStorage) return;
343 if(bckStorage && (fDefaultStorage != bckStorage)){
344 AliWarning("Existing default storage replaced: clearing cache!");
348 if (fStorageMap->Contains("default")) {
349 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
351 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
353 //_____________________________________________________________________________
354 void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
355 // set default storage from AliCDBParam object
357 AliCDBStorage* bckStorage = fDefaultStorage;
359 fDefaultStorage = GetStorage(param);
361 if(!fDefaultStorage) return;
363 if(bckStorage && (fDefaultStorage != bckStorage)){
364 AliWarning("Existing default storage replaced: clearing cache!");
368 if (fStorageMap->Contains("default")) {
369 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
371 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
374 //_____________________________________________________________________________
375 void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
376 // set default storage from another active storage
378 // if lock is ON, cannot activate more storages!
380 if (fDefaultStorage) {
381 AliFatal("Lock is ON, and default storage is already set: "
382 "cannot reset it or activate more storages!");
387 UnsetDefaultStorage();
391 AliCDBStorage* bckStorage = fDefaultStorage;
393 fDefaultStorage = storage;
395 if(bckStorage && (fDefaultStorage != bckStorage)){
396 AliWarning("Existing default storage replaced: clearing cache!");
400 if (fStorageMap->Contains("default")) {
401 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
403 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
406 //_____________________________________________________________________________
407 void AliCDBManager::SetDefaultStorage(const char* mcString, const char* simType) {
408 // sets default storage for MC data
409 // mcString MUST be "MC",
410 // simType can be "Ideal","Residual","Full"
412 TString strmcString(mcString);
413 TString strsimType(simType);
415 if (strmcString != "MC"){
416 AliFatal("Method requires first string to be MC!");
419 if (strsimType == "Ideal"){
420 dbString = fgkMCIdealStorage;
422 else if (strsimType == "Full"){
423 dbString = fgkMCFullStorage;
425 else if (strsimType == "Residual"){
426 dbString = fgkMCResidualStorage;
429 AliFatal("Error in setting the storage for MC data, second argument MUST be either \"Ideal\" or \"Full\" or \"Residual\".");
432 SetDefaultStorage(dbString.Data());
433 if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",fLHCPeriod.Data()));
436 //_____________________________________________________________________________
437 void AliCDBManager::SetDefaultStorageFromRun(Int_t run) {
438 // set default storage from the run number - to be used only with raw data
440 // if lock is ON, cannot activate more storages!
442 if (fDefaultStorage) {
443 AliFatal("Lock is ON, and default storage is already set: "
444 "cannot activate default storage from run number");
448 // retrieve XML file from alien
450 TString rndname = "/tmp/";
451 rndname += "OCDBFolderXML.";
452 rndname += uuid.AsString();
454 AliDebug(2, Form("file to be copied = %s", fgkOCDBFolderXMLfile.Data()));
455 if (!TFile::Cp(fgkOCDBFolderXMLfile.Data(), rndname.Data())) {
456 AliFatal(Form("Cannot make a local copy of OCDBFolder xml file in %s",rndname.Data()));
458 AliCDBHandler* saxcdb = new AliCDBHandler();
460 TSAXParser *saxParser = new TSAXParser();
461 saxParser->ConnectToHandler("AliCDBHandler", saxcdb);
462 saxParser->ParseFile(rndname.Data());
463 AliInfo(Form(" LHC folder = %s", saxcdb->GetOCDBFolder().Data()));
464 AliInfo(Form(" LHC period start run = %d", saxcdb->GetStartRunRange()));
465 AliInfo(Form(" LHC period end run = %d", saxcdb->GetEndRunRange()));
466 fLHCPeriod = saxcdb->GetOCDBFolder();
467 fStartRunLHCPeriod = saxcdb->GetStartRunRange();
468 fEndRunLHCPeriod = saxcdb->GetEndRunRange();
470 SetDefaultStorage(fLHCPeriod.Data());
471 if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",fLHCPeriod.Data()));
475 //_____________________________________________________________________________
476 void AliCDBManager::UnsetDefaultStorage() {
477 // Unset default storage
479 // if lock is ON, action is forbidden!
481 if (fDefaultStorage) {
482 AliFatal("Lock is ON: cannot unset default storage!");
486 if (fDefaultStorage) {
487 AliWarning("Clearing cache!");
491 fDefaultStorage = 0x0;
494 //_____________________________________________________________________________
495 void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) {
496 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
498 AliCDBParam *aPar = CreateParameter(dbString);
500 SetSpecificStorage(calibType, aPar);
504 //_____________________________________________________________________________
505 void AliCDBManager::SetSpecificStorage(const char* calibType, AliCDBParam* param) {
506 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
507 // Default storage should be defined prior to any specific storages, e.g.:
508 // AliCDBManager::instance()->SetDefaultStorage("alien://");
509 // AliCDBManager::instance()->SetSpecificStorage("TPC/*","local://DB_TPC");
510 // AliCDBManager::instance()->SetSpecificStorage("*/Align/*","local://DB_TPCAlign");
511 // calibType must be a valid CDB path! (3 level folder structure)
514 if(!fDefaultStorage) {
515 AliError("Please activate a default storage first!");
520 AliCDBPath aPath(calibType);
521 if(!aPath.IsValid()){
522 AliError(Form("Not a valid path: %s", calibType));
526 TObjString *objCalibType = new TObjString(aPath.GetPath());
527 if(fSpecificStorages.Contains(objCalibType)){
528 AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one",
530 AliCDBParam *checkPar = dynamic_cast<AliCDBParam*> (fSpecificStorages.GetValue(calibType));
531 if(checkPar) delete checkPar;
532 delete fSpecificStorages.Remove(objCalibType);
534 AliCDBStorage *aStorage = GetStorage(param);
535 if(!aStorage) return;
537 fSpecificStorages.Add(objCalibType, param->CloneParam());
539 if(fStorageMap->Contains(objCalibType)){
540 delete fStorageMap->Remove(objCalibType);
542 fStorageMap->Add(objCalibType->Clone(), new TObjString(param->GetURI()));
546 //_____________________________________________________________________________
547 AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) {
548 // get storage specific for detector or calibration type
550 AliCDBPath calibPath(calibType);
551 if(!calibPath.IsValid()) return NULL;
553 AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibPath.GetPath());
555 AliError(Form("%s storage not found!", calibType));
558 return GetStorage(checkPar);
563 //_____________________________________________________________________________
564 AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) {
565 // select storage valid for path from the list of specific storages
567 AliCDBPath aPath(path);
568 if(!aPath.IsValid()) return NULL;
570 TIter iter(&fSpecificStorages);
571 TObjString *aCalibType=0;
572 AliCDBPath tmpPath("null/null/null");
574 while((aCalibType = (TObjString*) iter.Next())){
575 AliCDBPath calibTypePath(aCalibType->GetName());
576 if(calibTypePath.Comprises(aPath)) {
577 if(calibTypePath.Comprises(tmpPath)) continue;
578 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
579 tmpPath.SetPath(calibTypePath.GetPath());
585 //_____________________________________________________________________________
586 AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber,
587 Int_t version, Int_t subVersion) {
588 // get an AliCDBEntry object from the database
591 // RunNumber is not specified. Try with fRun
593 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
599 return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
602 //_____________________________________________________________________________
603 AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path,
604 const AliCDBRunRange& runRange, Int_t version,
606 // get an AliCDBEntry object from the database!
608 return Get(AliCDBId(path, runRange, version, subVersion));
611 //_____________________________________________________________________________
612 AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) {
613 // get an AliCDBEntry object from the database
615 // check if query's path and runRange are valid
616 // query is invalid also if version is not specified and subversion is!
617 if (!query.IsValid()) {
618 AliError(Form("Invalid query: %s", query.ToString().Data()));
622 // query is not specified if path contains wildcard or run range= [-1,-1]
623 if (!query.IsSpecified()) {
624 AliError(Form("Unspecified query: %s",
625 query.ToString().Data()));
629 if(fLock && query.GetFirstRun() != fRun)
630 AliFatal("Lock is ON: cannot use different run number than the internal one!");
632 if(fCache && query.GetFirstRun() != fRun)
633 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
635 AliCDBEntry *entry=0;
637 // first look into map of cached objects
638 if(fCache && query.GetFirstRun() == fRun)
639 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
642 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
646 if(!fDefaultStorage) {
647 AliError("No storage set!");
650 // Entry is not in cache -> retrieve it from CDB and cache it!!
651 AliCDBStorage *aStorage=0;
652 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
653 // Bool_t usedDefStorage=kTRUE;
656 aStorage=GetStorage(aPar);
657 TString str = aPar->GetURI();
658 AliDebug(2,Form("Looking into storage: %s",str.Data()));
659 // usedDefStorage=kFALSE;
662 aStorage=GetDefaultStorage();
663 AliDebug(2,"Looking into default storage");
666 entry = aStorage->Get(query);
668 if(entry && fCache && (query.GetFirstRun() == fRun)){
669 CacheEntry(query.GetPath(), entry);
672 if(entry && !fIds->Contains(&entry->GetId())){
673 fIds->Add(entry->GetId().Clone());
681 //_____________________________________________________________________________
682 const char* AliCDBManager::GetURI(const char* path) {
683 // return the URI of the storage where to look for path
685 if(!IsDefaultStorageSet()) return 0;
687 AliCDBParam *aPar=SelectSpecificStorage(path);
690 return aPar->GetURI().Data();
693 return GetDefaultStorage()->GetURI().Data();
699 //_____________________________________________________________________________
700 AliCDBId* AliCDBManager::GetId(const AliCDBPath& path, Int_t runNumber,
701 Int_t version, Int_t subVersion) {
702 // get the AliCDBId of the valid object from the database (does not retrieve the object)
703 // User must delete returned object!
706 // RunNumber is not specified. Try with fRun
708 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
714 return GetId(AliCDBId(path, runNumber, runNumber, version, subVersion));
717 //_____________________________________________________________________________
718 AliCDBId* AliCDBManager::GetId(const AliCDBPath& path,
719 const AliCDBRunRange& runRange, Int_t version,
721 // get the AliCDBId of the valid object from the database (does not retrieve the object)
722 // User must delete returned object!
724 return GetId(AliCDBId(path, runRange, version, subVersion));
727 //_____________________________________________________________________________
728 AliCDBId* AliCDBManager::GetId(const AliCDBId& query) {
729 // get the AliCDBId of the valid object from the database (does not retrieve the object)
730 // User must delete returned object!
732 if(!fDefaultStorage) {
733 AliError("No storage set!");
737 // check if query's path and runRange are valid
738 // query is invalid also if version is not specified and subversion is!
739 if (!query.IsValid()) {
740 AliError(Form("Invalid query: %s", query.ToString().Data()));
744 // query is not specified if path contains wildcard or run range= [-1,-1]
745 if (!query.IsSpecified()) {
746 AliError(Form("Unspecified query: %s",
747 query.ToString().Data()));
751 if(fCache && query.GetFirstRun() != fRun)
752 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
754 AliCDBEntry* entry = 0;
756 // first look into map of cached objects
757 if(fCache && query.GetFirstRun() == fRun)
758 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
761 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
762 return dynamic_cast<AliCDBId*> (entry->GetId().Clone());
765 // Entry is not in cache -> retrieve it from CDB and cache it!!
766 AliCDBStorage *aStorage=0;
767 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
770 aStorage=GetStorage(aPar);
771 TString str = aPar->GetURI();
772 AliDebug(2,Form("Looking into storage: %s",str.Data()));
775 aStorage=GetDefaultStorage();
776 AliDebug(2,"Looking into default storage");
779 return aStorage->GetId(query);
783 //_____________________________________________________________________________
784 TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber,
785 Int_t version, Int_t subVersion) {
786 // get multiple AliCDBEntry objects from the database
789 // RunNumber is not specified. Try with fRun
791 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
797 return GetAll(AliCDBId(path, runNumber, runNumber, version,
801 //_____________________________________________________________________________
802 TList* AliCDBManager::GetAll(const AliCDBPath& path,
803 const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
804 // get multiple AliCDBEntry objects from the database
806 return GetAll(AliCDBId(path, runRange, version, subVersion));
809 //_____________________________________________________________________________
810 TList* AliCDBManager::GetAll(const AliCDBId& query) {
811 // get multiple AliCDBEntry objects from the database
812 // Warning: this method works correctly only for queries of the type "Detector/*"
813 // and not for more specific queries e.g. "Detector/Calib/*" !
814 // Warning #2: Entries are cached, but GetAll will keep on retrieving objects from OCDB!
815 // To get an object from cache use Get() function
817 if(!fDefaultStorage) {
818 AliError("No storage set!");
822 if (!query.IsValid()) {
823 AliError(Form("Invalid query: %s", query.ToString().Data()));
827 if((fSpecificStorages.GetEntries()>0) && query.GetPath().BeginsWith('*')){
828 // if specific storages are active a query with "*" is ambiguous
829 AliError("Query too generic in this context!");
833 if (query.IsAnyRange()) {
834 AliError(Form("Unspecified run or runrange: %s",
835 query.ToString().Data()));
839 if(fLock && query.GetFirstRun() != fRun)
840 AliFatal("Lock is ON: cannot use different run number than the internal one!");
842 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
844 AliCDBStorage *aStorage;
846 aStorage=GetStorage(aPar);
847 AliDebug(2,Form("Looking into storage: %s", aPar->GetURI().Data()));
850 aStorage=GetDefaultStorage();
851 AliDebug(2,"Looking into default storage");
855 if(aStorage) result = aStorage->GetAll(query);
856 if(!result) return 0;
858 // loop on result to check whether entries should be re-queried with specific storages
859 if(fSpecificStorages.GetEntries()>0 && ! (fSpecificStorages.GetEntries() == 1 && aPar)) {
860 AliInfo("Now look into all other specific storages...");
863 AliCDBEntry* chkEntry=0;
865 while((chkEntry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
866 AliCDBId& chkId = chkEntry->GetId();
867 AliDebug(2, Form("Checking id %s ", chkId.GetPath().Data()));
868 AliCDBParam *chkPar=SelectSpecificStorage(chkId.GetPath());
869 if (!chkPar || aPar == chkPar) continue;
870 AliCDBStorage *chkStorage = GetStorage(chkPar);
871 AliDebug(2, Form("Found specific storage! %s", chkPar->GetURI().Data()));
873 AliCDBEntry *newEntry=0;
874 chkId.SetRunRange(query.GetFirstRun(), query.GetLastRun());
875 chkId.SetVersion(query.GetVersion());
876 chkId.SetSubVersion(query.GetSubVersion());
878 if(chkStorage) newEntry = chkStorage->Get(chkId);
879 if(!newEntry) continue;
881 // object is found in specific storage: replace entry in the result list!
882 chkEntry->SetOwner(1);
883 delete result->Remove(chkEntry);
884 result->AddFirst(newEntry);
887 Int_t nEntries = result->GetEntries();
888 AliInfo("After look into other specific storages, result list is:");
889 for(int i=0; i<nEntries;i++){
890 AliCDBEntry *entry = (AliCDBEntry*) result->At(i);
891 AliInfo(Form("%s",entry->GetId().ToString().Data()));
897 AliCDBEntry* entry=0;
898 while((entry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
900 if(!fIds->Contains(&entry->GetId())){
901 fIds->Add(entry->GetId().Clone());
903 if(fCache && (query.GetFirstRun() == fRun)){
904 CacheEntry(entry->GetId().GetPath(), entry);
912 //_____________________________________________________________________________
913 Bool_t AliCDBManager::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData, DataType type){
914 // store an AliCDBEntry object into the database
917 AliError("Null Entry! No storage will be done!");
921 AliCDBEntry anEntry(object, id, metaData);
922 return Put(&anEntry, type);
927 //_____________________________________________________________________________
928 Bool_t AliCDBManager::Put(AliCDBEntry* entry, DataType type){
929 // store an AliCDBEntry object into the database
931 if(type == kPrivate && !fDefaultStorage) {
932 AliError("No storage set!");
936 if (entry->GetObject()==0x0){
937 AliError("No valid object in CDB entry!");
942 AliError("No entry!");
946 if (!entry->GetId().IsValid()) {
947 AliError(Form("Invalid entry ID: %s",
948 entry->GetId().ToString().Data()));
952 if (!entry->GetId().IsSpecified()) {
953 AliError(Form("Unspecified entry ID: %s",
954 entry->GetId().ToString().Data()));
958 AliCDBId id = entry->GetId();
959 AliCDBParam *aPar = SelectSpecificStorage(id.GetPath());
961 AliCDBStorage *aStorage=0;
964 aStorage=GetStorage(aPar);
968 aStorage = GetStorage(fCondParam);
971 aStorage = GetStorage(fRefParam);
974 aStorage = GetDefaultStorage();
979 AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data()));
981 Bool_t result = aStorage->Put(entry, type);
983 if(fRun >= 0) QueryCDB();
990 //_____________________________________________________________________________
991 void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry)
993 // cache AliCDBEntry. Cache is valid until run number is changed.
995 AliCDBEntry *chkEntry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(path));
998 AliDebug(2, Form("Object %s already in cache !!", path));
1001 AliDebug(2,Form("Caching entry %s", path));
1004 fEntryCache.Add(new TObjString(path), entry);
1005 AliDebug(2,Form("Cache entries: %d", fEntryCache.GetEntries()));
1009 //_____________________________________________________________________________
1010 void AliCDBManager::Print(Option_t* /*option*/) const
1012 // Print list of active storages and their URIs
1014 TString output=Form("Run number = %d; ",fRun);
1015 output += "Cache is ";
1016 if(!fCache) output += "NOT ";
1017 output += Form("ACTIVE; Number of active storages: %d\n",fActiveStorages.GetEntries());
1019 if(fDefaultStorage) {
1020 output += Form("\t*** Default Storage URI: \"%s\"\n",fDefaultStorage->GetURI().Data());
1021 // AliInfo(output.Data());
1023 if(fSpecificStorages.GetEntries()>0) {
1024 TIter iter(fSpecificStorages.GetTable());
1027 while((aPair = (TPair*) iter.Next())){
1028 output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n",
1029 i++, ((TObjString*) aPair->Key())->GetName(),
1030 ((AliCDBParam*) aPair->Value())->GetURI().Data());
1034 output += Form("*** Drain Storage URI: %s\n",fDrainStorage->GetURI().Data());
1036 AliInfo(output.Data());
1039 //_____________________________________________________________________________
1040 void AliCDBManager::SetRun(Int_t run)
1042 // Sets current run number.
1043 // When the run number changes the caching is cleared.
1048 if(fLock && fRun >= 0) {
1049 AliFatal("Lock is ON, cannot reset run number!");
1054 // here the LHCPeriod xml file is parsed; the string containing the correct period is returned; the default storage is set
1055 if (fStartRunLHCPeriod <= run && fEndRunLHCPeriod >= run){
1056 AliInfo("LHCPeriod alien folder for current run already in memory");
1059 SetDefaultStorageFromRun(run);
1066 //_____________________________________________________________________________
1067 void AliCDBManager::ClearCache(){
1068 // clear AliCDBEntry cache
1070 AliDebug(2, Form("Cache entries to be deleted: %d",fEntryCache.GetEntries()));
1073 // To clean entries one by one
1074 TIter iter(fEntryCache.GetTable());
1076 while((pair= dynamic_cast<TPair*> (iter.Next()))){
1078 TObjString* key = dynamic_cast<TObjString*> (pair->Key());
1079 AliCDBEntry* entry = dynamic_cast<AliCDBEntry*> (pair->Value());
1080 AliDebug(2, Form("Deleting entry: %s", key->GetName()));
1081 if (entry) delete entry;
1082 delete fEntryCache.Remove(key);
1085 fEntryCache.DeleteAll();
1086 AliDebug(2, Form("After deleting - Cache entries: %d",fEntryCache.GetEntries()));
1089 //_____________________________________________________________________________
1090 void AliCDBManager::UnloadFromCache(const char* path){
1091 // unload cached object
1093 AliCDBPath queryPath(path);
1094 if(!queryPath.IsValid()) return;
1096 if(!queryPath.IsWildcard()) { // path is not wildcard, get it directly from the cache and unload it!
1097 if(fEntryCache.Contains(path)){
1098 AliDebug(2, Form("Unloading object \"%s\" from cache", path));
1099 TObjString pathStr(path);
1100 delete fEntryCache.Remove(&pathStr);
1102 AliError(Form("Cache does not contain object \"%s\"!", path))
1104 AliDebug(2, Form("Cache entries: %d",fEntryCache.GetEntries()));
1108 // path is wildcard: loop on the cache and unload all comprised objects!
1109 TIter iter(fEntryCache.GetTable());
1112 while((pair = dynamic_cast<TPair*> (iter.Next()))){
1113 AliCDBPath entryPath = pair->Key()->GetName();
1114 if(queryPath.Comprises(entryPath)) {
1115 AliDebug(2, Form("Unloading object \"%s\" from cache", entryPath.GetPath().Data()));
1116 TObjString pathStr(entryPath.GetPath().Data());
1117 delete fEntryCache.Remove(&pathStr);
1120 AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries()));
1123 //_____________________________________________________________________________
1124 void AliCDBManager::DestroyActiveStorages() {
1125 // delete list of active storages
1127 fActiveStorages.DeleteAll();
1128 fSpecificStorages.DeleteAll();
1131 //_____________________________________________________________________________
1132 void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
1133 // destroys active storage
1136 TIter iter(fActiveStorages.GetTable());
1138 while ((aPair = (TPair*) iter.Next())) {
1139 if(storage == (AliCDBStorage*) aPair->Value())
1140 delete fActiveStorages.Remove(aPair->Key());
1141 storage->Delete(); storage=0x0;
1147 //_____________________________________________________________________________
1148 void AliCDBManager::QueryCDB() {
1149 // query default and specific storages for files valid for fRun. Every storage loads the Ids into its list.
1152 AliError("Run number not yet set! Use AliCDBManager::SetRun.");
1155 if (!fDefaultStorage){
1156 AliError("Default storage is not set! Use AliCDBManager::SetDefaultStorage");
1159 if(fDefaultStorage->GetType() == "alien"){
1160 fDefaultStorage->QueryCDB(fRun);
1162 AliDebug(2,"Skipping query for valid files, it used only in grid...");
1165 TIter iter(&fSpecificStorages);
1166 TObjString *aCalibType=0;
1167 AliCDBParam* aPar=0;
1168 while((aCalibType = dynamic_cast<TObjString*> (iter.Next()))){
1169 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
1171 AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName()));
1172 AliCDBStorage *aStorage = GetStorage(aPar);
1173 if(aStorage->GetType() == "alien"){
1174 aStorage->QueryCDB(fRun,aCalibType->GetName());
1177 "Skipping query for valid files, it is used only in grid...");
1183 //______________________________________________________________________________________________
1184 const char* AliCDBManager::GetDataTypeName(DataType type)
1186 // returns the name (string) of the data type
1189 case kCondition: return "Conditions";
1190 case kReference: return "Reference";
1191 case kPrivate: return "Private";
1197 //______________________________________________________________________________________________
1198 void AliCDBManager::InitShortLived()
1200 // Init the list of short-lived objects
1201 // currently disabled
1205 // fShortLived = new TList();
1206 // fShortLived->SetOwner(1);
1208 // fShortLived->Add(new TObjString("EMCAL/Calib/Data"));
1210 // fShortLived->Add(new TObjString("HMPID/Calib/Nmean"));
1211 // fShortLived->Add(new TObjString("HMPID/Calib/Qthre"));
1213 // fShortLived->Add(new TObjString("ITS/Calib/CalibSPD"));
1215 // fShortLived->Add(new TObjString("MUON/Calib/Gains"));
1216 // fShortLived->Add(new TObjString("MUON/Calib/HV"));
1217 // fShortLived->Add(new TObjString("MUON/Calib/Pedestals"));
1219 // fShortLived->Add(new TObjString("PHOS/Calib/CpvGainPedestals"));
1220 // fShortLived->Add(new TObjString("PHOS/Calib/EmcGainPedestals"));
1222 // fShortLived->Add(new TObjString("PMD/Calib/Data"));
1224 // fShortLived->Add(new TObjString("TRD/Calib/ChamberGainFactor"));
1225 // fShortLived->Add(new TObjString("TRD/Calib/LocalGainFactor"));
1226 // fShortLived->Add(new TObjString("TRD/Calib/ChamberT0"));
1227 // fShortLived->Add(new TObjString("TRD/Calib/LocalT0"));
1228 // fShortLived->Add(new TObjString("TRD/Calib/ChamberVdrift"));
1229 // fShortLived->Add(new TObjString("TRD/Calib/LocalVdrift"));
1231 // fShortLived->Add(new TObjString("ZDC/Calib/Data"));
1235 //______________________________________________________________________________________________
1236 Bool_t AliCDBManager::IsShortLived(const char* path)
1238 // returns the name (string) of the data type
1240 if(!fShortLived) return kFALSE;
1242 AliCDBPath aPath(path);
1243 if(!aPath.IsValid()){
1244 AliError(Form("Not a valid path: %s", path));
1248 return fShortLived->Contains(path);
1252 //______________________________________________________________________________________________
1253 void AliCDBManager::SetLock(Bool_t lock){
1255 if(fLock == kTRUE && lock == kFALSE) {
1256 AliFatal("Lock is ON: cannot reset it!");
1262 ///////////////////////////////////////////////////////////
1263 // AliCDBManager Parameter class //
1264 // interface to specific AliCDBParameter class //
1265 // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) //
1266 ///////////////////////////////////////////////////////////
1268 AliCDBParam::AliCDBParam():
1276 //_____________________________________________________________________________
1277 AliCDBParam::~AliCDBParam() {