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),
135 // default constuctor
136 fFactories.SetOwner(1);
137 fActiveStorages.SetOwner(1);
138 fSpecificStorages.SetOwner(1);
139 fEntryCache.SetName("CDBEntryCache");
140 fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
142 fStorageMap = new TMap();
143 fStorageMap->SetOwner(1);
148 //_____________________________________________________________________________
149 AliCDBManager::~AliCDBManager() {
152 DestroyActiveStorages();
155 fDefaultStorage = 0x0;
156 delete fStorageMap; fStorageMap = 0;
157 delete fIds; fIds = 0;
160 delete fShortLived; fShortLived = 0x0;
163 //_____________________________________________________________________________
164 void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){
165 // put a storage object into the list of active storages
167 fActiveStorages.Add(param, storage);
168 AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries()));
171 //_____________________________________________________________________________
172 void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) {
173 // add a storage factory to the list of registerd factories
175 if (!fFactories.Contains(factory)) {
176 fFactories.Add(factory);
180 //_____________________________________________________________________________
181 Bool_t AliCDBManager::HasStorage(const char* dbString) const {
182 // check if dbString is a URI valid for one of the registered factories
184 TIter iter(&fFactories);
186 AliCDBStorageFactory* factory=0;
187 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
189 if (factory->Validate(dbString)) {
197 //_____________________________________________________________________________
198 AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
199 // create AliCDBParam object from URI string
201 TIter iter(&fFactories);
203 AliCDBStorageFactory* factory=0;
204 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
205 AliCDBParam* param = factory->CreateParameter(dbString);
206 if(param) return param;
212 //_____________________________________________________________________________
213 AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) {
214 // get storage object from URI string
216 AliCDBParam* param = CreateParameter(dbString);
218 AliError(Form("Failed to activate requested storage! Check URI: %s", dbString));
222 AliCDBStorage* aStorage = GetStorage(param);
228 //_____________________________________________________________________________
229 AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) {
230 // get storage object from AliCDBParam object
232 // if the list of active storages already contains
233 // the requested storage, return it
234 AliCDBStorage* aStorage = GetActiveStorage(param);
239 // if lock is ON, cannot activate more storages!
241 if (fDefaultStorage) {
242 AliFatal("Lock is ON, and default storage is already set: "
243 "cannot reset it or activate more storages!");
247 TIter iter(&fFactories);
249 AliCDBStorageFactory* factory=0;
251 // loop on the list of registered factories
252 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
254 // each factory tries to create its storage from the parameter
255 aStorage = factory->Create(param);
257 PutActiveStorage(param->CloneParam(), aStorage);
258 aStorage->SetURI(param->GetURI());
260 if(aStorage->GetType() == "alien"){
261 aStorage->QueryCDB(fRun);
264 "Skipping query for valid files, it is used only in grid...");
271 AliError(Form("Failed to activate requested storage! Check URI: %s", param->GetURI().Data()));
276 //_____________________________________________________________________________
277 AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) {
278 // get a storage object from the list of active storages
280 return dynamic_cast<AliCDBStorage*> (fActiveStorages.GetValue(param));
283 //_____________________________________________________________________________
284 TList* AliCDBManager::GetActiveStorages() {
285 // return list of active storages
286 // user has responsibility to delete returned object
288 TList* result = new TList();
290 TIter iter(fActiveStorages.GetTable());
292 while ((aPair = (TPair*) iter.Next())) {
293 result->Add(aPair->Value());
299 //_____________________________________________________________________________
300 void AliCDBManager::SetDrain(const char* dbString) {
301 // set drain storage from URI string
303 fDrainStorage = GetStorage(dbString);
306 //_____________________________________________________________________________
307 void AliCDBManager::SetDrain(const AliCDBParam* param) {
308 // set drain storage from AliCDBParam
310 fDrainStorage = GetStorage(param);
313 //_____________________________________________________________________________
314 void AliCDBManager::SetDrain(AliCDBStorage* storage) {
315 // set drain storage from another active storage
317 fDrainStorage = storage;
320 //_____________________________________________________________________________
321 Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
322 // drain retrieved object to drain storage
324 AliDebug(2, "Draining into drain storage...");
325 return fDrainStorage->Put(entry);
328 //____________________________________________________________________________
329 void AliCDBManager::SetDefaultStorage(const char* dbString) {
330 // sets default storage from URI string
332 AliInfo(Form("Setting Default storage to: %s",dbString));
334 // checking whether we are in the raw case
335 TString dbStringTemp(dbString);
336 if (dbStringTemp == "raw://") fRaw = kTRUE;
338 AliCDBStorage* bckStorage = fDefaultStorage;
340 fDefaultStorage = GetStorage(dbString);
342 if(!fDefaultStorage) return;
344 if(bckStorage && (fDefaultStorage != bckStorage)){
345 AliWarning("Existing default storage replaced: clearing cache!");
349 if (fStorageMap->Contains("default")) {
350 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
352 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
354 //_____________________________________________________________________________
355 void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
356 // set default storage from AliCDBParam object
358 AliCDBStorage* bckStorage = fDefaultStorage;
360 fDefaultStorage = GetStorage(param);
362 if(!fDefaultStorage) return;
364 if(bckStorage && (fDefaultStorage != bckStorage)){
365 AliWarning("Existing default storage replaced: clearing cache!");
369 if (fStorageMap->Contains("default")) {
370 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
372 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
375 //_____________________________________________________________________________
376 void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
377 // set default storage from another active storage
379 // if lock is ON, cannot activate more storages!
381 if (fDefaultStorage) {
382 AliFatal("Lock is ON, and default storage is already set: "
383 "cannot reset it or activate more storages!");
388 UnsetDefaultStorage();
392 AliCDBStorage* bckStorage = fDefaultStorage;
394 fDefaultStorage = storage;
396 if(bckStorage && (fDefaultStorage != bckStorage)){
397 AliWarning("Existing default storage replaced: clearing cache!");
401 if (fStorageMap->Contains("default")) {
402 delete fStorageMap->Remove(fStorageMap->GetValue("default"));
404 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
407 //_____________________________________________________________________________
408 void AliCDBManager::SetDefaultStorage(const char* mcString, const char* simType) {
409 // sets default storage for MC data
410 // mcString MUST be "MC",
411 // simType can be "Ideal","Residual","Full"
413 TString strmcString(mcString);
414 TString strsimType(simType);
416 if (strmcString != "MC"){
417 AliFatal("Method requires first string to be MC!");
420 if (strsimType == "Ideal"){
421 dbString = fgkMCIdealStorage;
423 else if (strsimType == "Full"){
424 dbString = fgkMCFullStorage;
426 else if (strsimType == "Residual"){
427 dbString = fgkMCResidualStorage;
430 AliFatal("Error in setting the storage for MC data, second argument MUST be either \"Ideal\" or \"Full\" or \"Residual\".");
433 SetDefaultStorage(dbString.Data());
434 if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",fLHCPeriod.Data()));
437 //_____________________________________________________________________________
438 void AliCDBManager::SetDefaultStorageFromRun(Int_t run) {
439 // set default storage from the run number - to be used only with raw data
441 // if lock is ON, cannot activate more storages!
443 if (fDefaultStorage) {
444 AliFatal("Lock is ON, and default storage is already set: "
445 "cannot activate default storage from run number");
449 // retrieve XML file from alien
451 TString rndname = "/tmp/";
452 rndname += "OCDBFolderXML.";
453 rndname += uuid.AsString();
455 AliDebug(2, Form("file to be copied = %s", fgkOCDBFolderXMLfile.Data()));
456 if (!TFile::Cp(fgkOCDBFolderXMLfile.Data(), rndname.Data())) {
457 AliFatal(Form("Cannot make a local copy of OCDBFolder xml file in %s",rndname.Data()));
459 AliCDBHandler* saxcdb = new AliCDBHandler();
461 TSAXParser *saxParser = new TSAXParser();
462 saxParser->ConnectToHandler("AliCDBHandler", saxcdb);
463 saxParser->ParseFile(rndname.Data());
464 AliInfo(Form(" LHC folder = %s", saxcdb->GetOCDBFolder().Data()));
465 AliInfo(Form(" LHC period start run = %d", saxcdb->GetStartRunRange()));
466 AliInfo(Form(" LHC period end run = %d", saxcdb->GetEndRunRange()));
467 fLHCPeriod = saxcdb->GetOCDBFolder();
468 fStartRunLHCPeriod = saxcdb->GetStartRunRange();
469 fEndRunLHCPeriod = saxcdb->GetEndRunRange();
471 SetDefaultStorage(fLHCPeriod.Data());
472 if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",fLHCPeriod.Data()));
476 //_____________________________________________________________________________
477 void AliCDBManager::UnsetDefaultStorage() {
478 // Unset default storage
480 // if lock is ON, action is forbidden!
482 if (fDefaultStorage) {
483 AliFatal("Lock is ON: cannot unset default storage!");
487 if (fDefaultStorage) {
488 AliWarning("Clearing cache!");
492 fDefaultStorage = 0x0;
495 //_____________________________________________________________________________
496 void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) {
497 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
499 AliCDBParam *aPar = CreateParameter(dbString);
501 SetSpecificStorage(calibType, aPar);
505 //_____________________________________________________________________________
506 void AliCDBManager::SetSpecificStorage(const char* calibType, AliCDBParam* param) {
507 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
508 // Default storage should be defined prior to any specific storages, e.g.:
509 // AliCDBManager::instance()->SetDefaultStorage("alien://");
510 // AliCDBManager::instance()->SetSpecificStorage("TPC/*","local://DB_TPC");
511 // AliCDBManager::instance()->SetSpecificStorage("*/Align/*","local://DB_TPCAlign");
512 // calibType must be a valid CDB path! (3 level folder structure)
515 if(!fDefaultStorage) {
516 AliError("Please activate a default storage first!");
521 AliCDBPath aPath(calibType);
522 if(!aPath.IsValid()){
523 AliError(Form("Not a valid path: %s", calibType));
527 TObjString *objCalibType = new TObjString(aPath.GetPath());
528 if(fSpecificStorages.Contains(objCalibType)){
529 AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one",
531 AliCDBParam *checkPar = dynamic_cast<AliCDBParam*> (fSpecificStorages.GetValue(calibType));
532 if(checkPar) delete checkPar;
533 delete fSpecificStorages.Remove(objCalibType);
535 AliCDBStorage *aStorage = GetStorage(param);
536 if(!aStorage) return;
538 fSpecificStorages.Add(objCalibType, param->CloneParam());
540 if(fStorageMap->Contains(objCalibType)){
541 delete fStorageMap->Remove(objCalibType);
543 fStorageMap->Add(objCalibType->Clone(), new TObjString(param->GetURI()));
547 //_____________________________________________________________________________
548 AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) {
549 // get storage specific for detector or calibration type
551 AliCDBPath calibPath(calibType);
552 if(!calibPath.IsValid()) return NULL;
554 AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibPath.GetPath());
556 AliError(Form("%s storage not found!", calibType));
559 return GetStorage(checkPar);
564 //_____________________________________________________________________________
565 AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) {
566 // select storage valid for path from the list of specific storages
568 AliCDBPath aPath(path);
569 if(!aPath.IsValid()) return NULL;
571 TIter iter(&fSpecificStorages);
572 TObjString *aCalibType=0;
573 AliCDBPath tmpPath("null/null/null");
575 while((aCalibType = (TObjString*) iter.Next())){
576 AliCDBPath calibTypePath(aCalibType->GetName());
577 if(calibTypePath.Comprises(aPath)) {
578 if(calibTypePath.Comprises(tmpPath)) continue;
579 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
580 tmpPath.SetPath(calibTypePath.GetPath());
586 //_____________________________________________________________________________
587 AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber,
588 Int_t version, Int_t subVersion) {
589 // get an AliCDBEntry object from the database
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 Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
603 //_____________________________________________________________________________
604 AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path,
605 const AliCDBRunRange& runRange, Int_t version,
607 // get an AliCDBEntry object from the database!
609 return Get(AliCDBId(path, runRange, version, subVersion));
612 //_____________________________________________________________________________
613 AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) {
614 // get an AliCDBEntry object from the database
616 // check if query's path and runRange are valid
617 // query is invalid also if version is not specified and subversion is!
618 if (!query.IsValid()) {
619 AliError(Form("Invalid query: %s", query.ToString().Data()));
623 // query is not specified if path contains wildcard or run range= [-1,-1]
624 if (!query.IsSpecified()) {
625 AliError(Form("Unspecified query: %s",
626 query.ToString().Data()));
630 if(fLock && query.GetFirstRun() != fRun)
631 AliFatal("Lock is ON: cannot use different run number than the internal one!");
633 if(fCache && query.GetFirstRun() != fRun)
634 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
636 AliCDBEntry *entry=0;
638 // first look into map of cached objects
639 if(fCache && query.GetFirstRun() == fRun)
640 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
643 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
647 if(!fDefaultStorage) {
648 AliError("No storage set!");
651 // Entry is not in cache -> retrieve it from CDB and cache it!!
652 AliCDBStorage *aStorage=0;
653 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
654 // Bool_t usedDefStorage=kTRUE;
657 aStorage=GetStorage(aPar);
658 TString str = aPar->GetURI();
659 AliDebug(2,Form("Looking into storage: %s",str.Data()));
660 // usedDefStorage=kFALSE;
663 aStorage=GetDefaultStorage();
664 AliDebug(2,"Looking into default storage");
667 entry = aStorage->Get(query);
669 if(entry && fCache && (query.GetFirstRun() == fRun)){
670 CacheEntry(query.GetPath(), entry);
673 if(entry && !fIds->Contains(&entry->GetId())){
674 fIds->Add(entry->GetId().Clone());
682 //_____________________________________________________________________________
683 const char* AliCDBManager::GetURI(const char* path) {
684 // return the URI of the storage where to look for path
686 if(!IsDefaultStorageSet()) return 0;
688 AliCDBParam *aPar=SelectSpecificStorage(path);
691 return aPar->GetURI().Data();
694 return GetDefaultStorage()->GetURI().Data();
700 //_____________________________________________________________________________
701 AliCDBId* AliCDBManager::GetId(const AliCDBPath& path, Int_t runNumber,
702 Int_t version, Int_t subVersion) {
703 // get the AliCDBId of the valid object from the database (does not retrieve the object)
704 // User must delete returned object!
707 // RunNumber is not specified. Try with fRun
709 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
715 return GetId(AliCDBId(path, runNumber, runNumber, version, subVersion));
718 //_____________________________________________________________________________
719 AliCDBId* AliCDBManager::GetId(const AliCDBPath& path,
720 const AliCDBRunRange& runRange, Int_t version,
722 // get the AliCDBId of the valid object from the database (does not retrieve the object)
723 // User must delete returned object!
725 return GetId(AliCDBId(path, runRange, version, subVersion));
728 //_____________________________________________________________________________
729 AliCDBId* AliCDBManager::GetId(const AliCDBId& query) {
730 // get the AliCDBId of the valid object from the database (does not retrieve the object)
731 // User must delete returned object!
733 if(!fDefaultStorage) {
734 AliError("No storage set!");
738 // check if query's path and runRange are valid
739 // query is invalid also if version is not specified and subversion is!
740 if (!query.IsValid()) {
741 AliError(Form("Invalid query: %s", query.ToString().Data()));
745 // query is not specified if path contains wildcard or run range= [-1,-1]
746 if (!query.IsSpecified()) {
747 AliError(Form("Unspecified query: %s",
748 query.ToString().Data()));
752 if(fCache && query.GetFirstRun() != fRun)
753 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
755 AliCDBEntry* entry = 0;
757 // first look into map of cached objects
758 if(fCache && query.GetFirstRun() == fRun)
759 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
762 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
763 return dynamic_cast<AliCDBId*> (entry->GetId().Clone());
766 // Entry is not in cache -> retrieve it from CDB and cache it!!
767 AliCDBStorage *aStorage=0;
768 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
771 aStorage=GetStorage(aPar);
772 TString str = aPar->GetURI();
773 AliDebug(2,Form("Looking into storage: %s",str.Data()));
776 aStorage=GetDefaultStorage();
777 AliDebug(2,"Looking into default storage");
780 return aStorage->GetId(query);
784 //_____________________________________________________________________________
785 TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber,
786 Int_t version, Int_t subVersion) {
787 // get multiple AliCDBEntry objects from the database
790 // RunNumber is not specified. Try with fRun
792 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
798 return GetAll(AliCDBId(path, runNumber, runNumber, version,
802 //_____________________________________________________________________________
803 TList* AliCDBManager::GetAll(const AliCDBPath& path,
804 const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
805 // get multiple AliCDBEntry objects from the database
807 return GetAll(AliCDBId(path, runRange, version, subVersion));
810 //_____________________________________________________________________________
811 TList* AliCDBManager::GetAll(const AliCDBId& query) {
812 // get multiple AliCDBEntry objects from the database
813 // Warning: this method works correctly only for queries of the type "Detector/*"
814 // and not for more specific queries e.g. "Detector/Calib/*" !
815 // Warning #2: Entries are cached, but GetAll will keep on retrieving objects from OCDB!
816 // To get an object from cache use Get() function
818 if(!fDefaultStorage) {
819 AliError("No storage set!");
823 if (!query.IsValid()) {
824 AliError(Form("Invalid query: %s", query.ToString().Data()));
828 if((fSpecificStorages.GetEntries()>0) && query.GetPath().BeginsWith('*')){
829 // if specific storages are active a query with "*" is ambiguous
830 AliError("Query too generic in this context!");
834 if (query.IsAnyRange()) {
835 AliError(Form("Unspecified run or runrange: %s",
836 query.ToString().Data()));
840 if(fLock && query.GetFirstRun() != fRun)
841 AliFatal("Lock is ON: cannot use different run number than the internal one!");
843 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
845 AliCDBStorage *aStorage;
847 aStorage=GetStorage(aPar);
848 AliDebug(2,Form("Looking into storage: %s", aPar->GetURI().Data()));
851 aStorage=GetDefaultStorage();
852 AliDebug(2,"Looking into default storage");
856 if(aStorage) result = aStorage->GetAll(query);
857 if(!result) return 0;
859 // loop on result to check whether entries should be re-queried with specific storages
860 if(fSpecificStorages.GetEntries()>0 && ! (fSpecificStorages.GetEntries() == 1 && aPar)) {
861 AliInfo("Now look into all other specific storages...");
864 AliCDBEntry* chkEntry=0;
866 while((chkEntry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
867 AliCDBId& chkId = chkEntry->GetId();
868 AliDebug(2, Form("Checking id %s ", chkId.GetPath().Data()));
869 AliCDBParam *chkPar=SelectSpecificStorage(chkId.GetPath());
870 if (!chkPar || aPar == chkPar) continue;
871 AliCDBStorage *chkStorage = GetStorage(chkPar);
872 AliDebug(2, Form("Found specific storage! %s", chkPar->GetURI().Data()));
874 AliCDBEntry *newEntry=0;
875 chkId.SetRunRange(query.GetFirstRun(), query.GetLastRun());
876 chkId.SetVersion(query.GetVersion());
877 chkId.SetSubVersion(query.GetSubVersion());
879 if(chkStorage) newEntry = chkStorage->Get(chkId);
880 if(!newEntry) continue;
882 // object is found in specific storage: replace entry in the result list!
883 chkEntry->SetOwner(1);
884 delete result->Remove(chkEntry);
885 result->AddFirst(newEntry);
888 Int_t nEntries = result->GetEntries();
889 AliInfo("After look into other specific storages, result list is:");
890 for(int i=0; i<nEntries;i++){
891 AliCDBEntry *entry = (AliCDBEntry*) result->At(i);
892 AliInfo(Form("%s",entry->GetId().ToString().Data()));
898 AliCDBEntry* entry=0;
899 while((entry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
901 if(!fIds->Contains(&entry->GetId())){
902 fIds->Add(entry->GetId().Clone());
904 if(fCache && (query.GetFirstRun() == fRun)){
905 CacheEntry(entry->GetId().GetPath(), entry);
913 //_____________________________________________________________________________
914 Bool_t AliCDBManager::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData, DataType type){
915 // store an AliCDBEntry object into the database
918 AliError("Null Entry! No storage will be done!");
922 AliCDBEntry anEntry(object, id, metaData);
923 return Put(&anEntry, type);
928 //_____________________________________________________________________________
929 Bool_t AliCDBManager::Put(AliCDBEntry* entry, DataType type){
930 // store an AliCDBEntry object into the database
932 if(type == kPrivate && !fDefaultStorage) {
933 AliError("No storage set!");
937 if (entry->GetObject()==0x0){
938 AliError("No valid object in CDB entry!");
943 AliError("No entry!");
947 if (!entry->GetId().IsValid()) {
948 AliError(Form("Invalid entry ID: %s",
949 entry->GetId().ToString().Data()));
953 if (!entry->GetId().IsSpecified()) {
954 AliError(Form("Unspecified entry ID: %s",
955 entry->GetId().ToString().Data()));
959 AliCDBId id = entry->GetId();
960 AliCDBParam *aPar = SelectSpecificStorage(id.GetPath());
962 AliCDBStorage *aStorage=0;
965 aStorage=GetStorage(aPar);
969 aStorage = GetStorage(fCondParam);
972 aStorage = GetStorage(fRefParam);
975 aStorage = GetDefaultStorage();
980 AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data()));
982 Bool_t result = aStorage->Put(entry, type);
984 if(fRun >= 0) QueryCDB();
991 //_____________________________________________________________________________
992 void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry)
994 // cache AliCDBEntry. Cache is valid until run number is changed.
996 AliCDBEntry *chkEntry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(path));
999 AliDebug(2, Form("Object %s already in cache !!", path));
1002 AliDebug(2,Form("Caching entry %s", path));
1005 fEntryCache.Add(new TObjString(path), entry);
1006 AliDebug(2,Form("Cache entries: %d", fEntryCache.GetEntries()));
1010 //_____________________________________________________________________________
1011 void AliCDBManager::Print(Option_t* /*option*/) const
1013 // Print list of active storages and their URIs
1015 TString output=Form("Run number = %d; ",fRun);
1016 output += "Cache is ";
1017 if(!fCache) output += "NOT ";
1018 output += Form("ACTIVE; Number of active storages: %d\n",fActiveStorages.GetEntries());
1020 if(fDefaultStorage) {
1021 output += Form("\t*** Default Storage URI: \"%s\"\n",fDefaultStorage->GetURI().Data());
1022 // AliInfo(output.Data());
1024 if(fSpecificStorages.GetEntries()>0) {
1025 TIter iter(fSpecificStorages.GetTable());
1028 while((aPair = (TPair*) iter.Next())){
1029 output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n",
1030 i++, ((TObjString*) aPair->Key())->GetName(),
1031 ((AliCDBParam*) aPair->Value())->GetURI().Data());
1035 output += Form("*** Drain Storage URI: %s\n",fDrainStorage->GetURI().Data());
1037 AliInfo(output.Data());
1040 //_____________________________________________________________________________
1041 void AliCDBManager::SetRun(Int_t run)
1043 // Sets current run number.
1044 // When the run number changes the caching is cleared.
1049 if(fLock && fRun >= 0) {
1050 AliFatal("Lock is ON, cannot reset run number!");
1055 // here the LHCPeriod xml file is parsed; the string containing the correct period is returned; the default storage is set
1056 if (fStartRunLHCPeriod <= run && fEndRunLHCPeriod >= run){
1057 AliInfo("LHCPeriod alien folder for current run already in memory");
1060 SetDefaultStorageFromRun(run);
1067 //_____________________________________________________________________________
1068 void AliCDBManager::ClearCache(){
1069 // clear AliCDBEntry cache
1071 AliDebug(2, Form("Cache entries to be deleted: %d",fEntryCache.GetEntries()));
1074 // To clean entries one by one
1075 TIter iter(fEntryCache.GetTable());
1077 while((pair= dynamic_cast<TPair*> (iter.Next()))){
1079 TObjString* key = dynamic_cast<TObjString*> (pair->Key());
1080 AliCDBEntry* entry = dynamic_cast<AliCDBEntry*> (pair->Value());
1081 AliDebug(2, Form("Deleting entry: %s", key->GetName()));
1082 if (entry) delete entry;
1083 delete fEntryCache.Remove(key);
1086 fEntryCache.DeleteAll();
1087 AliDebug(2, Form("After deleting - Cache entries: %d",fEntryCache.GetEntries()));
1090 //_____________________________________________________________________________
1091 void AliCDBManager::UnloadFromCache(const char* path){
1092 // unload cached object
1094 AliCDBPath queryPath(path);
1095 if(!queryPath.IsValid()) return;
1097 if(!queryPath.IsWildcard()) { // path is not wildcard, get it directly from the cache and unload it!
1098 if(fEntryCache.Contains(path)){
1099 AliDebug(2, Form("Unloading object \"%s\" from cache", path));
1100 TObjString pathStr(path);
1101 delete fEntryCache.Remove(&pathStr);
1103 AliError(Form("Cache does not contain object \"%s\"!", path))
1105 AliDebug(2, Form("Cache entries: %d",fEntryCache.GetEntries()));
1109 // path is wildcard: loop on the cache and unload all comprised objects!
1110 TIter iter(fEntryCache.GetTable());
1113 while((pair = dynamic_cast<TPair*> (iter.Next()))){
1114 AliCDBPath entryPath = pair->Key()->GetName();
1115 if(queryPath.Comprises(entryPath)) {
1116 AliDebug(2, Form("Unloading object \"%s\" from cache", entryPath.GetPath().Data()));
1117 TObjString pathStr(entryPath.GetPath().Data());
1118 delete fEntryCache.Remove(&pathStr);
1121 AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries()));
1124 //_____________________________________________________________________________
1125 void AliCDBManager::DestroyActiveStorages() {
1126 // delete list of active storages
1128 fActiveStorages.DeleteAll();
1129 fSpecificStorages.DeleteAll();
1132 //_____________________________________________________________________________
1133 void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
1134 // destroys active storage
1137 TIter iter(fActiveStorages.GetTable());
1139 while ((aPair = (TPair*) iter.Next())) {
1140 if(storage == (AliCDBStorage*) aPair->Value())
1141 delete fActiveStorages.Remove(aPair->Key());
1142 storage->Delete(); storage=0x0;
1148 //_____________________________________________________________________________
1149 void AliCDBManager::QueryCDB() {
1150 // query default and specific storages for files valid for fRun. Every storage loads the Ids into its list.
1153 AliError("Run number not yet set! Use AliCDBManager::SetRun.");
1156 if (!fDefaultStorage){
1157 AliError("Default storage is not set! Use AliCDBManager::SetDefaultStorage");
1160 if(fDefaultStorage->GetType() == "alien"){
1161 fDefaultStorage->QueryCDB(fRun);
1163 AliDebug(2,"Skipping query for valid files, it used only in grid...");
1166 TIter iter(&fSpecificStorages);
1167 TObjString *aCalibType=0;
1168 AliCDBParam* aPar=0;
1169 while((aCalibType = dynamic_cast<TObjString*> (iter.Next()))){
1170 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
1172 AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName()));
1173 AliCDBStorage *aStorage = GetStorage(aPar);
1174 if(aStorage->GetType() == "alien"){
1175 aStorage->QueryCDB(fRun,aCalibType->GetName());
1178 "Skipping query for valid files, it is used only in grid...");
1184 //______________________________________________________________________________________________
1185 const char* AliCDBManager::GetDataTypeName(DataType type)
1187 // returns the name (string) of the data type
1190 case kCondition: return "Conditions";
1191 case kReference: return "Reference";
1192 case kPrivate: return "Private";
1198 //______________________________________________________________________________________________
1199 void AliCDBManager::InitShortLived()
1201 // Init the list of short-lived objects
1202 // currently disabled
1206 // fShortLived = new TList();
1207 // fShortLived->SetOwner(1);
1209 // fShortLived->Add(new TObjString("EMCAL/Calib/Data"));
1211 // fShortLived->Add(new TObjString("HMPID/Calib/Nmean"));
1212 // fShortLived->Add(new TObjString("HMPID/Calib/Qthre"));
1214 // fShortLived->Add(new TObjString("ITS/Calib/CalibSPD"));
1216 // fShortLived->Add(new TObjString("MUON/Calib/Gains"));
1217 // fShortLived->Add(new TObjString("MUON/Calib/HV"));
1218 // fShortLived->Add(new TObjString("MUON/Calib/Pedestals"));
1220 // fShortLived->Add(new TObjString("PHOS/Calib/CpvGainPedestals"));
1221 // fShortLived->Add(new TObjString("PHOS/Calib/EmcGainPedestals"));
1223 // fShortLived->Add(new TObjString("PMD/Calib/Data"));
1225 // fShortLived->Add(new TObjString("TRD/Calib/ChamberGainFactor"));
1226 // fShortLived->Add(new TObjString("TRD/Calib/LocalGainFactor"));
1227 // fShortLived->Add(new TObjString("TRD/Calib/ChamberT0"));
1228 // fShortLived->Add(new TObjString("TRD/Calib/LocalT0"));
1229 // fShortLived->Add(new TObjString("TRD/Calib/ChamberVdrift"));
1230 // fShortLived->Add(new TObjString("TRD/Calib/LocalVdrift"));
1232 // fShortLived->Add(new TObjString("ZDC/Calib/Data"));
1236 //______________________________________________________________________________________________
1237 Bool_t AliCDBManager::IsShortLived(const char* path)
1239 // returns the name (string) of the data type
1241 if(!fShortLived) return kFALSE;
1243 AliCDBPath aPath(path);
1244 if(!aPath.IsValid()){
1245 AliError(Form("Not a valid path: %s", path));
1249 return fShortLived->Contains(path);
1253 //______________________________________________________________________________________________
1254 ULong_t AliCDBManager::SetLock(Bool_t lock, ULong_t key){
1255 // To lock/unlock user must provide the key. A new key is provided after
1256 // each successful lock. User should always backup the returned key and
1257 // use it on next access.
1258 if (fLock == lock) return 0; // nothing to be done
1260 // User wants to lock - check his identity
1262 // Lock has a user - check his key
1264 AliFatal("Wrong key provided to lock CDB. Please remove CDB lock access from your code !");
1269 fKey = gSystem->Now();
1273 // User wants to unlock - check the provided key
1275 AliFatal("Lock is ON: wrong key provided");
1282 ///////////////////////////////////////////////////////////
1283 // AliCDBManager Parameter class //
1284 // interface to specific AliCDBParameter class //
1285 // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) //
1286 ///////////////////////////////////////////////////////////
1288 AliCDBParam::AliCDBParam():
1296 //_____________________________________________________________________________
1297 AliCDBParam::~AliCDBParam() {