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 //-------------------------------------------------------------------------
24 #include "AliCDBManager.h"
25 #include "AliCDBStorage.h"
27 #include "AliCDBDump.h"
28 #include "AliCDBLocal.h"
29 #include "AliCDBGrid.h"
30 #include "AliCDBEntry.h"
31 #include "AliCDBHandler.h"
33 #include <TObjString.h>
34 #include <TSAXParser.h>
45 ClassImp(AliCDBManager)
47 //TODO OCDB and Reference folder should not be fully hardcoded but built from run number (or year/LHC period)
48 TString AliCDBManager::fgkCondUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/CDB?user=aliprod");
49 TString AliCDBManager::fgkRefUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/Reference?user=aliprod");
50 TString AliCDBManager::fgkMCIdealStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Ideal");
51 TString AliCDBManager::fgkMCFullStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Full");
52 TString AliCDBManager::fgkMCResidualStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Residual");
53 TString AliCDBManager::fgkOCDBFolderXMLfile("alien:///alice/data/OCDBFoldervsRunRange.xml");
54 AliCDBManager* AliCDBManager::fgInstance = 0x0;
56 //_____________________________________________________________________________
57 AliCDBManager* AliCDBManager::Instance(TMap *entryCache, Int_t run) {
58 // returns AliCDBManager instance (singleton)
61 fgInstance = new AliCDBManager();
65 fgInstance->InitFromCache(entryCache,run);
71 //_____________________________________________________________________________
72 void AliCDBManager::Init() {
73 // factory registering
75 RegisterFactory(new AliCDBDumpFactory());
76 RegisterFactory(new AliCDBLocalFactory());
77 // AliCDBGridFactory is registered only if AliEn libraries are enabled in Root
78 if(!gSystem->Exec("root-config --has-alien 2>/dev/null |grep yes 2>&1 > /dev/null")){ // returns 0 if yes
79 AliInfo("AliEn classes enabled in Root. AliCDBGrid factory registered.");
80 RegisterFactory(new AliCDBGridFactory());
81 fCondParam = CreateParameter(fgkCondUri);
82 fRefParam = CreateParameter(fgkRefUri);
88 //_____________________________________________________________________________
89 void AliCDBManager::InitFromCache(TMap *entryCache, Int_t run) {
90 // initialize manager from existing cache
91 // used on the slaves in case of parallel reconstruction
94 TIter iter(entryCache->GetTable());
97 while((pair = dynamic_cast<TPair*> (iter.Next()))){
98 fEntryCache.Add(pair->Key(),pair->Value());
100 // fEntry is the new owner of the cache
101 fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
102 entryCache->SetOwnerKeyValue(kFALSE,kFALSE);
103 AliInfo(Form("%d cache entries have been loaded",fEntryCache.GetEntries()));
106 //_____________________________________________________________________________
107 void AliCDBManager::DumpToSnapshotFile(const char* snapshotFileName, Bool_t singleKeys){
109 // dump the entries map and the ids list to
113 TFile *f = TFile::Open(snapshotFileName,"RECREATE");
114 if (!f || f->IsZombie()){
115 AliError(Form("Cannot open file %s",snapshotFileName));
119 AliInfo(Form("Dumping entriesMap (entries'cache) with %d entries!\n", fEntryCache.GetEntries()));
120 AliInfo(Form("Dumping entriesList with %d entries!\n", fIds->GetEntries()));
125 f->WriteObject(&fEntryCache,"CDBentriesMap");
126 f->WriteObject(fIds,"CDBidsList");
128 // We write the entries one by one named by their calibration path
130 fEntryCache.Write("CDBentriesMap");
131 fIds->Write("CDBidsList");
133 TIter iter(fEntryCache.GetTable());
135 while((pair = dynamic_cast<TPair*> (iter.Next()))){
136 TObjString *os = dynamic_cast<TObjString*>(pair->Key());
138 TString path = os->GetString();
139 AliCDBEntry *entry = dynamic_cast<AliCDBEntry*>(pair->Value());
140 if (!entry) continue;
141 path.ReplaceAll("/","*");
142 entry->Write(path.Data());
151 //_____________________________________________________________________________
152 Bool_t AliCDBManager::InitFromSnapshot(const char* snapshotFileName, Bool_t overwrite){
153 // initialize manager from a CDB snapshot, that is add the entries
154 // to the entries map and the ids to the ids list taking them from
155 // the map and the list found in the input file
157 // if the manager is locked it cannot initialize from a snapshot
159 AliError("Being locked I cannot initialize from the snapshot!");
164 TString snapshotFile(snapshotFileName);
165 if(snapshotFile.BeginsWith("alien://")){
167 TGrid::Connect("alien://","");
169 AliError("Connection to alien failed!");
175 TFile *f = TFile::Open(snapshotFileName);
176 if (!f || f->IsZombie()){
177 AliError(Form("Cannot open file %s",snapshotFileName));
181 // retrieve entries' map from snapshot file
182 TMap *entriesMap = 0;
183 TIter next(f->GetListOfKeys());
185 while ((key = (TKey*)next())) {
186 if (strcmp(key->GetClassName(),"TMap") != 0) continue;
187 entriesMap = (TMap*)key->ReadObj();
190 if (!entriesMap || entriesMap->GetEntries()==0){
191 AliError("Cannot get valid map of CDB entries from snapshot file");
195 // retrieve ids' list from snapshot file
197 TIter nextKey(f->GetListOfKeys());
199 while ((keyN = (TKey*)nextKey())) {
200 if (strcmp(keyN->GetClassName(),"TList") != 0) continue;
201 idsList = (TList*)keyN->ReadObj();
204 if (!idsList || idsList->GetEntries()==0){
205 AliError("Cannot get valid list of CDB entries from snapshot file");
209 // Add each (entry,id) from the snapshot to the memory: entry to the cache, id to the list of ids.
210 // If "overwrite" is false: add the entry to the cache and its id to the list of ids
211 // only if neither of them is already there.
212 // If "overwrite" is true: write the snapshot entry,id in any case. If something
213 // was already there for that calibration type, remove it and issue a warning
214 TIter iterObj(entriesMap->GetTable());
217 while((pair = dynamic_cast<TPair*> (iterObj.Next()))){
218 TObjString* os = (TObjString*) pair->Key();
219 TString path = os->GetString();
220 TIter iterId(idsList);
222 AliCDBId* correspondingId=0;
223 while((id = dynamic_cast<AliCDBId*> (iterId.Next()))){
224 TString idpath(id->GetPath());
230 if(!correspondingId){
231 AliError(Form("id for \"%s\" not found in the snapshot (while entry was). This entry is skipped!",path.Data()));
234 Bool_t cached = fEntryCache.Contains(path.Data());
235 Bool_t registeredId = kFALSE;
238 while((idT = dynamic_cast<AliCDBId*> (iter.Next()))){
239 if(idT->GetPath()==path){
240 registeredId = kTRUE;
246 if(cached || registeredId){
247 AliWarning(Form("An entry was already cached for \"%s\". Removing it before caching from snapshot",path.Data()));
248 UnloadFromCache(path.Data());
250 fEntryCache.Add(pair->Key(),pair->Value());
254 if(cached || registeredId){
255 AliWarning(Form("An entry was already cached for \"%s\". Not adding this object from snapshot",path.Data()));
257 fEntryCache.Add(pair->Key(),pair->Value());
264 // fEntry is the new owner of the cache
265 fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
266 entriesMap->SetOwnerKeyValue(kFALSE,kFALSE);
267 fIds->SetOwner(kTRUE);
268 idsList->SetOwner(kFALSE);
269 AliInfo(Form("%d new (entry,id) cached. Total number %d",nAdded,fEntryCache.GetEntries()));
277 //_____________________________________________________________________________
278 void AliCDBManager::Destroy() {
279 // delete ALCDBManager instance and active storages
282 //fgInstance->Delete();
288 //_____________________________________________________________________________
289 AliCDBManager::AliCDBManager():
298 fDefaultStorage(NULL),
305 fSnapshotMode(kFALSE),
309 fStartRunLHCPeriod(-1),
310 fEndRunLHCPeriod(-1),
314 // default constuctor
315 fFactories.SetOwner(1);
316 fActiveStorages.SetOwner(1);
317 fSpecificStorages.SetOwner(1);
318 fEntryCache.SetName("CDBEntryCache");
319 fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
321 fStorageMap = new TMap();
322 fStorageMap->SetOwner(1);
327 //_____________________________________________________________________________
328 AliCDBManager::~AliCDBManager() {
331 DestroyActiveStorages();
334 fDefaultStorage = 0x0;
335 delete fStorageMap; fStorageMap = 0;
336 delete fIds; fIds = 0;
339 delete fShortLived; fShortLived = 0x0;
340 //fSnapshotCache = 0;
341 //fSnapshotIdsList = 0;
343 fSnapshotFile->Close();
348 //_____________________________________________________________________________
349 void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){
350 // put a storage object into the list of active storages
352 fActiveStorages.Add(param, storage);
353 AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries()));
356 //_____________________________________________________________________________
357 void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) {
358 // add a storage factory to the list of registerd factories
360 if (!fFactories.Contains(factory)) {
361 fFactories.Add(factory);
365 //_____________________________________________________________________________
366 Bool_t AliCDBManager::HasStorage(const char* dbString) const {
367 // check if dbString is a URI valid for one of the registered factories
369 TIter iter(&fFactories);
371 AliCDBStorageFactory* factory=0;
372 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
374 if (factory->Validate(dbString)) {
382 //_____________________________________________________________________________
383 AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
384 // create AliCDBParam object from URI string
386 TString uriString(dbString);
388 if ( !fCvmfsOcdb.IsNull() && uriString.BeginsWith("alien://")) {
389 AlienToCvmfsUri(uriString);
392 TIter iter(&fFactories);
394 AliCDBStorageFactory* factory=0;
395 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
396 //AliCDBParam* param = factory->CreateParameter(dbString);
397 AliCDBParam* param = factory->CreateParameter(uriString);
398 if(param) return param;
404 //_____________________________________________________________________________
405 void AliCDBManager::AlienToCvmfsUri(TString& uriString) const {
406 // convert alien storage uri to local:///cvmfs storage uri (called when OCDB_PATH is set)
408 TObjArray *arr = uriString.Tokenize('?');
411 TString entryKey = "";
412 TString entryValue = "";
413 TString newUriString = "";
414 while((str = (TObjString*) iter.Next())){
415 TString entry(str->String());
416 Int_t indeq = entry.Index('=');
417 entryKey = entry(0, indeq+1);
418 entryValue = entry(indeq+1, entry.Length()-indeq);
420 if ( entryKey.Contains("folder", TString::kIgnoreCase) )
423 TRegexp re_RawFolder("^/alice/data/20[0-9]+/OCDB");
424 TRegexp re_MCFolder("^/alice/simulation/2008/v4-15-Release");
425 TString rawFolder = entryValue(re_RawFolder);
426 TString mcFolder = entryValue(re_MCFolder);
427 if ( !rawFolder.IsNull() ){
428 entryValue.Replace(0, 6, "/cvmfs/alice-ocdb.cern.ch/calibration");
429 //entryValue.Replace(entryValue.Length()-4, entryValue.Length(), "");
430 } else if ( !mcFolder.IsNull() ){
431 entryValue.Replace(0,36,"/cvmfs/alice-ocdb.cern.ch/calibration/MC");
433 AliFatal(Form("Environment variable for cvmfs OCDB folder set for an invalid OCDB storage:\n %s", entryValue.Data()));
436 newUriString += entryKey;
438 newUriString += entryValue;
441 newUriString.Prepend("local://");
442 newUriString.Remove(TString::kTrailing, '?');
443 uriString = newUriString;
446 //_____________________________________________________________________________
447 AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) {
448 // get storage object from URI string
450 // Check environment variable OCDB_PATH. It is set in case the user (job) expects
451 // to find in the local /cvmfs the required OCDB tag. The OCDB_PATH variable
452 // contains the path to the directory in /cvmfs/ which is an AliRoot tag based snapshot
453 // of the AliEn file catalogue. The directory has to contain:
454 // 1) catalogue/20??.list.gz gzipped text files listing the OCDB files (seen by that AliRoot tag)
455 // 2) bin/getOCDBperRun.sh (shell+awk) script extracting from 1) the list
456 // of valid files for the given run.
458 AliCDBParam* param = CreateParameter(dbString);
460 AliError(Form("Failed to activate requested storage! Check URI: %s", dbString));
464 AliCDBStorage* aStorage = GetStorage(param);
470 //_____________________________________________________________________________
471 AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) {
472 // get storage object from AliCDBParam object
474 // if the list of active storages already contains
475 // the requested storage, return it
476 AliCDBStorage* aStorage = GetActiveStorage(param);
481 // if lock is ON, cannot activate more storages!
483 if (fDefaultStorage) {
484 AliFatal("Lock is ON, and default storage is already set: "
485 "cannot reset it or activate more storages!");
489 // loop on the list of registered factories
490 TIter iter(&fFactories);
491 AliCDBStorageFactory* factory=0;
492 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
494 // each factory tries to create its storage from the parameter
495 aStorage = factory->Create(param);
497 PutActiveStorage(param->CloneParam(), aStorage);
498 aStorage->SetURI(param->GetURI());
500 if( aStorage->GetType() == "alien" || aStorage->GetType() == "local" )
501 aStorage->QueryCDB(fRun);
507 AliError(Form("Failed to activate requested storage! Check URI: %s", param->GetURI().Data()));
512 //_____________________________________________________________________________
513 AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) {
514 // get a storage object from the list of active storages
516 return dynamic_cast<AliCDBStorage*> (fActiveStorages.GetValue(param));
519 //_____________________________________________________________________________
520 TList* AliCDBManager::GetActiveStorages() {
521 // return list of active storages
522 // user has responsibility to delete returned object
524 TList* result = new TList();
526 TIter iter(fActiveStorages.GetTable());
528 while ((aPair = (TPair*) iter.Next())) {
529 result->Add(aPair->Value());
535 //_____________________________________________________________________________
536 void AliCDBManager::SetDrain(const char* dbString) {
537 // set drain storage from URI string
539 fDrainStorage = GetStorage(dbString);
542 //_____________________________________________________________________________
543 void AliCDBManager::SetDrain(const AliCDBParam* param) {
544 // set drain storage from AliCDBParam
546 fDrainStorage = GetStorage(param);
549 //_____________________________________________________________________________
550 void AliCDBManager::SetDrain(AliCDBStorage* storage) {
551 // set drain storage from another active storage
553 fDrainStorage = storage;
556 //_____________________________________________________________________________
557 Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
558 // drain retrieved object to drain storage
560 AliDebug(2, "Draining into drain storage...");
561 return fDrainStorage->Put(entry);
564 //____________________________________________________________________________
565 void AliCDBManager::SetDefaultStorage(const char* storageUri) {
566 // sets default storage from URI string
568 // if in the cvmfs case (triggered by environment variable) check for path validity
569 // and modify Uri if it is "raw://"
570 TString cvmfsOcdb(gSystem->Getenv("OCDB_PATH"));
571 if (! cvmfsOcdb.IsNull()){
572 fCvmfsOcdb = cvmfsOcdb;
576 // checking whether we are in the raw case
577 TString uriTemp(storageUri);
578 if (uriTemp == "raw://") {
579 fRaw = kTRUE; // read then by SetRun to check if the method has to be called again with expanded uri
580 AliInfo("Setting the run-number will set the corresponding OCDB for raw data reconstruction.");
584 AliCDBStorage* bckStorage = fDefaultStorage;
586 fDefaultStorage = GetStorage(storageUri);
588 if(!fDefaultStorage) return;
590 if(bckStorage && (fDefaultStorage != bckStorage)){
591 AliWarning("Existing default storage replaced: clearing cache!");
595 if (fStorageMap->Contains("default")) {
596 delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
598 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
601 //_____________________________________________________________________________
602 void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
603 // set default storage from AliCDBParam object
605 AliCDBStorage* bckStorage = fDefaultStorage;
607 fDefaultStorage = GetStorage(param);
609 if(!fDefaultStorage) return;
611 if(bckStorage && (fDefaultStorage != bckStorage)){
612 AliWarning("Existing default storage replaced: clearing cache!");
616 if (fStorageMap->Contains("default")) {
617 delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
619 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
622 //_____________________________________________________________________________
623 void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
624 // set default storage from another active storage
626 // if lock is ON, cannot activate more storages!
628 if (fDefaultStorage) {
629 AliFatal("Lock is ON, and default storage is already set: "
630 "cannot reset it or activate more storages!");
635 UnsetDefaultStorage();
639 AliCDBStorage* bckStorage = fDefaultStorage;
641 fDefaultStorage = storage;
643 if(bckStorage && (fDefaultStorage != bckStorage)){
644 AliWarning("Existing default storage replaced: clearing cache!");
648 if (fStorageMap->Contains("default")) {
649 delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
651 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
654 //_____________________________________________________________________________
655 void AliCDBManager::SetDefaultStorage(const char* mcString, const char* simType) {
656 // sets default storage for MC data
657 // mcString MUST be "MC",
658 // simType can be "Ideal","Residual","Full"
660 TString strmcString(mcString);
661 TString strsimType(simType);
663 if (strmcString != "MC"){
664 AliFatal("Method requires first string to be MC!");
667 if (strsimType == "Ideal"){
668 dbString = fgkMCIdealStorage;
670 else if (strsimType == "Full"){
671 dbString = fgkMCFullStorage;
673 else if (strsimType == "Residual"){
674 dbString = fgkMCResidualStorage;
677 AliFatal("Error in setting the storage for MC data, second argument MUST be either \"Ideal\" or \"Full\" or \"Residual\".");
680 SetDefaultStorage(dbString.Data());
681 fStartRunLHCPeriod=0;
682 fEndRunLHCPeriod=AliCDBRunRange::Infinity();
683 if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",dbString.Data()));
687 //_____________________________________________________________________________
688 void AliCDBManager::ValidateCvmfsCase() const {
689 if (! fCvmfsOcdb.BeginsWith("/cvmfs")) //!!!! to be commented out for testing
690 AliFatal(Form("OCDB_PATH set to an invalid path: %s", fCvmfsOcdb.Data()));
692 TString cvmfsUri(fCvmfsOcdb);
693 gSystem->ExpandPathName(cvmfsUri);
694 if (gSystem->AccessPathName(cvmfsUri))
695 AliFatal(Form("OCDB_PATH set to an invalid path: %s", cvmfsUri.Data()));
697 // check that we find the two scripts we need
699 AliDebug(3, "OCDB_PATH envvar is set. Changing OCDB storage from alien:// to local:///cvmfs type.");
700 cvmfsUri = cvmfsUri.Strip(TString::kTrailing, '/');
701 cvmfsUri.Append("/bin/getOCDBFilesPerRun.sh");
702 if (gSystem->AccessPathName(cvmfsUri))
703 AliFatal(Form("Cannot find valid script: %s", cvmfsUri.Data()));
706 //_____________________________________________________________________________
707 void AliCDBManager::SetDefaultStorageFromRun(Int_t run) {
708 // set default storage from the run number - to be used only with raw data
710 // if lock is ON, cannot activate more storages!
712 if (fDefaultStorage) {
713 AliFatal("Lock is ON, and default storage is already set: "
714 "cannot activate default storage from run number");
718 // fRaw and cvmfs case
719 if (! fCvmfsOcdb.IsNull()) {
720 // we don't want to connect to AliEn just to set the uri from the runnumber
721 // for that we use the script getUriFromYear.sh in the cvmfs AliRoot package
722 // check that we find the two scripts we need
723 TString getYearScript(fCvmfsOcdb);
724 getYearScript = getYearScript.Strip(TString::kTrailing, '/');
725 getYearScript.Append("/bin/getUriFromYear.sh");
726 if (gSystem->AccessPathName(getYearScript))
727 AliFatal(Form("Cannot find valid script: %s", getYearScript.Data()));
728 TString inoutFile(gSystem->WorkingDirectory());
729 inoutFile += "/uri_range_";
730 inoutFile += TString::Itoa(fRun,10);
731 TString command(getYearScript);
733 command += TString::Itoa(fRun,10);
734 command += Form(" > %s", inoutFile.Data());
735 AliDebug(3, Form("Running command: \"%s\"",command.Data()));
736 Int_t result = gSystem->Exec(command.Data());
738 AliFatal(Form("Was not able to execute \"%s\"", command.Data()));
741 // now read the file with the uri and first and last run
742 std::ifstream file(inoutFile.Data());
743 if (!file.is_open()) {
744 AliFatal(Form("Error opening file \"%s\"!", inoutFile.Data()));
747 TObjArray* oStringsArray = 0;
748 while (lhcPeriod.ReadLine(file)){
749 oStringsArray = lhcPeriod.Tokenize(' ');
751 TObjString *oStrUri = dynamic_cast<TObjString*> (oStringsArray->At(0));
752 TObjString *oStrFirst = dynamic_cast<TObjString*> (oStringsArray->At(1));
753 TString firstRun = oStrFirst->GetString();
754 TObjString *oStrLast = dynamic_cast<TObjString*> (oStringsArray->At(2));
755 TString lastRun = oStrLast->GetString();
757 fLHCPeriod = oStrUri->GetString();
758 fStartRunLHCPeriod = firstRun.Atoi();
759 fEndRunLHCPeriod = lastRun.Atoi();
763 } else { // if not cvmfs case, "plain" AliEn case
764 // retrieve XML file from alien
766 TGrid::Connect("alien://","");
768 AliError("Connection to alien failed!");
773 TString rndname = "/tmp/";
774 rndname += "OCDBFolderXML.";
775 rndname += uuid.AsString();
777 AliDebug(2, Form("file to be copied = %s", fgkOCDBFolderXMLfile.Data()));
778 if (!TFile::Cp(fgkOCDBFolderXMLfile.Data(), rndname.Data())) {
779 AliFatal(Form("Cannot make a local copy of OCDBFolder xml file in %s",rndname.Data()));
781 AliCDBHandler* saxcdb = new AliCDBHandler();
783 TSAXParser *saxParser = new TSAXParser();
784 saxParser->ConnectToHandler("AliCDBHandler", saxcdb);
785 saxParser->ParseFile(rndname.Data());
786 AliInfo(Form(" LHC folder = %s", saxcdb->GetOCDBFolder().Data()));
787 AliInfo(Form(" LHC period start run = %d", saxcdb->GetStartRunRange()));
788 AliInfo(Form(" LHC period end run = %d", saxcdb->GetEndRunRange()));
789 fLHCPeriod = saxcdb->GetOCDBFolder();
790 fStartRunLHCPeriod = saxcdb->GetStartRunRange();
791 fEndRunLHCPeriod = saxcdb->GetEndRunRange();
794 SetDefaultStorage(fLHCPeriod.Data());
795 if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",fLHCPeriod.Data()));
799 //_____________________________________________________________________________
800 void AliCDBManager::UnsetDefaultStorage() {
801 // Unset default storage
803 // if lock is ON, action is forbidden!
805 if (fDefaultStorage) {
806 AliFatal("Lock is ON: cannot unset default storage!");
810 if (fDefaultStorage) {
811 AliWarning("Clearing cache!");
815 fRun = fStartRunLHCPeriod = fEndRunLHCPeriod = -1;
818 fDefaultStorage = 0x0;
821 //_____________________________________________________________________________
822 void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) {
823 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
825 AliCDBParam *aPar = CreateParameter(dbString);
827 SetSpecificStorage(calibType, aPar);
831 //_____________________________________________________________________________
832 void AliCDBManager::SetSpecificStorage(const char* calibType, const AliCDBParam* param) {
833 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
834 // Default storage should be defined prior to any specific storages, e.g.:
835 // AliCDBManager::instance()->SetDefaultStorage("alien://");
836 // AliCDBManager::instance()->SetSpecificStorage("TPC/*","local://DB_TPC");
837 // AliCDBManager::instance()->SetSpecificStorage("*/Align/*","local://DB_TPCAlign");
838 // calibType must be a valid CDB path! (3 level folder structure)
841 if(!fDefaultStorage && !fRaw) {
842 AliError("Please activate a default storage first!");
846 AliCDBPath aPath(calibType);
847 if(!aPath.IsValid()){
848 AliError(Form("Not a valid path: %s", calibType));
852 TObjString *objCalibType = new TObjString(aPath.GetPath());
853 if(fSpecificStorages.Contains(objCalibType)){
854 AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one",
856 AliCDBParam *checkPar = dynamic_cast<AliCDBParam*> (fSpecificStorages.GetValue(calibType));
857 if(checkPar) delete checkPar;
858 delete fSpecificStorages.Remove(objCalibType);
860 AliCDBStorage *aStorage = GetStorage(param);
861 if(!aStorage) return;
863 fSpecificStorages.Add(objCalibType, param->CloneParam());
865 if(fStorageMap->Contains(objCalibType)){
866 delete fStorageMap->Remove(objCalibType);
868 fStorageMap->Add(objCalibType->Clone(), new TObjString(param->GetURI()));
872 //_____________________________________________________________________________
873 AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) {
874 // get storage specific for detector or calibration type
876 AliCDBPath calibPath(calibType);
877 if(!calibPath.IsValid()) return NULL;
879 AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibPath.GetPath());
881 AliError(Form("%s storage not found!", calibType));
884 return GetStorage(checkPar);
889 //_____________________________________________________________________________
890 AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) {
891 // select storage valid for path from the list of specific storages
893 AliCDBPath aPath(path);
894 if(!aPath.IsValid()) return NULL;
896 TIter iter(&fSpecificStorages);
897 TObjString *aCalibType=0;
898 AliCDBPath tmpPath("null/null/null");
900 while((aCalibType = (TObjString*) iter.Next())){
901 AliCDBPath calibTypePath(aCalibType->GetName());
902 if(calibTypePath.Comprises(aPath)) {
903 if(calibTypePath.Comprises(tmpPath)) continue;
904 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
905 tmpPath.SetPath(calibTypePath.GetPath());
911 //_____________________________________________________________________________
912 AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber,
913 Int_t version, Int_t subVersion) {
914 // get an AliCDBEntry object from the database
917 // RunNumber is not specified. Try with fRun
919 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
925 return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
928 //_____________________________________________________________________________
929 AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path,
930 const AliCDBRunRange& runRange, Int_t version,
932 // get an AliCDBEntry object from the database!
934 return Get(AliCDBId(path, runRange, version, subVersion));
937 //_____________________________________________________________________________
938 AliCDBEntry* AliCDBManager::Get(const AliCDBId& query, Bool_t forceCaching) {
939 // get an AliCDBEntry object from the database
941 // check if query's path and runRange are valid
942 // query is invalid also if version is not specified and subversion is!
943 if (!query.IsValid()) {
944 AliError(Form("Invalid query: %s", query.ToString().Data()));
948 // query is not specified if path contains wildcard or run range= [-1,-1]
949 if (!query.IsSpecified()) {
950 AliError(Form("Unspecified query: %s",
951 query.ToString().Data()));
955 if(fLock && !(fRun >= query.GetFirstRun() && fRun <= query.GetLastRun()))
956 AliFatal("Lock is ON: cannot use different run number than the internal one!");
958 if(fCache && !(fRun >= query.GetFirstRun() && fRun <= query.GetLastRun()))
959 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
961 AliCDBEntry *entry=0;
963 // first look into map of cached objects
964 if(fCache && query.GetFirstRun() == fRun)
965 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
967 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
971 // if snapshot flag is set, try getting from the snapshot
972 // but in the case a specific storage is specified for this path
973 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
975 if(fSnapshotMode && query.GetFirstRun() == fRun)
977 entry = GetEntryFromSnapshot(query.GetPath());
979 AliInfo(Form("Object \"%s\" retrieved from the snapshot.",query.GetPath().Data()));
980 if(query.GetFirstRun() == fRun) // no need to check fCache, fSnapshotMode not possible otherwise
981 CacheEntry(query.GetPath(), entry);
983 if(!fIds->Contains(&entry->GetId()))
984 fIds->Add(entry->GetId().Clone());
991 // Entry is not in cache (and, in case we are in snapshot mode, not in the snapshot either)
992 // => retrieve it from the storage and cache it!!
993 if(!fDefaultStorage) {
994 AliError("No storage set!");
998 AliCDBStorage *aStorage=0;
1000 aStorage=GetStorage(aPar);
1001 TString str = aPar->GetURI();
1002 AliDebug(2,Form("Looking into storage: %s",str.Data()));
1004 aStorage=GetDefaultStorage();
1005 AliDebug(2,"Looking into default storage");
1008 entry = aStorage->Get(query);
1010 if(entry && fCache && (query.GetFirstRun()==fRun || forceCaching)){
1011 CacheEntry(query.GetPath(), entry);
1014 if(entry && !fIds->Contains(&entry->GetId())){
1015 fIds->Add(entry->GetId().Clone());
1023 //_____________________________________________________________________________
1024 AliCDBEntry* AliCDBManager::GetEntryFromSnapshot(const char* path) {
1025 // get the entry from the open snapshot file
1027 TString sPath(path);
1028 sPath.ReplaceAll("/","*");
1030 AliError("No snapshot file is open!");
1033 AliCDBEntry *entry = dynamic_cast<AliCDBEntry*>(fSnapshotFile->Get(sPath.Data()));
1035 AliDebug(2,Form("Cannot get a CDB entry for \"%s\" from snapshot file",path));
1042 //_____________________________________________________________________________
1043 Bool_t AliCDBManager::SetSnapshotMode(const char* snapshotFileName) {
1044 // set the manager in snapshot mode
1047 AliError("Cannot set the CDB manage in snapshot mode if the cache is not active!");
1051 //open snapshot file
1052 TString snapshotFile(snapshotFileName);
1053 if(snapshotFile.BeginsWith("alien://")){
1055 TGrid::Connect("alien://","");
1057 AliError("Connection to alien failed!");
1063 fSnapshotFile = TFile::Open(snapshotFileName);
1064 if (!fSnapshotFile || fSnapshotFile->IsZombie()){
1065 AliError(Form("Cannot open file %s",snapshotFileName));
1069 AliInfo("The CDB manager is set in snapshot mode!");
1070 fSnapshotMode = kTRUE;
1075 //_____________________________________________________________________________
1076 const char* AliCDBManager::GetURI(const char* path) {
1077 // return the URI of the storage where to look for path
1079 if(!IsDefaultStorageSet()) return 0;
1081 AliCDBParam *aPar=SelectSpecificStorage(path);
1084 return aPar->GetURI().Data();
1087 return GetDefaultStorage()->GetURI().Data();
1093 //_____________________________________________________________________________
1094 Int_t AliCDBManager::GetStartRunLHCPeriod(){
1095 // get the first run of validity
1096 // for the current period
1098 if(fStartRunLHCPeriod==-1)
1099 AliWarning("Run-range not yet set for the current LHC period.");
1100 return fStartRunLHCPeriod;
1103 //_____________________________________________________________________________
1104 Int_t AliCDBManager::GetEndRunLHCPeriod(){
1105 // get the last run of validity
1106 // for the current period
1108 if(fEndRunLHCPeriod==-1)
1109 AliWarning("Run-range not yet set for the current LHC period.");
1110 return fEndRunLHCPeriod;
1113 //_____________________________________________________________________________
1114 TString AliCDBManager::GetLHCPeriod(){
1115 // get the current LHC period string
1117 if(fLHCPeriod.IsWhitespace() || fLHCPeriod.IsNull())
1118 AliWarning("LHC period (OCDB folder) not yet set");
1122 //_____________________________________________________________________________
1123 AliCDBId* AliCDBManager::GetId(const AliCDBPath& path, Int_t runNumber,
1124 Int_t version, Int_t subVersion) {
1125 // get the AliCDBId of the valid object from the database (does not retrieve the object)
1126 // User must delete returned object!
1129 // RunNumber is not specified. Try with fRun
1131 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
1137 return GetId(AliCDBId(path, runNumber, runNumber, version, subVersion));
1140 //_____________________________________________________________________________
1141 AliCDBId* AliCDBManager::GetId(const AliCDBPath& path,
1142 const AliCDBRunRange& runRange, Int_t version,
1144 // get the AliCDBId of the valid object from the database (does not retrieve the object)
1145 // User must delete returned object!
1147 return GetId(AliCDBId(path, runRange, version, subVersion));
1150 //_____________________________________________________________________________
1151 AliCDBId* AliCDBManager::GetId(const AliCDBId& query) {
1152 // get the AliCDBId of the valid object from the database (does not retrieve the object)
1153 // User must delete returned object!
1155 if(!fDefaultStorage) {
1156 AliError("No storage set!");
1160 // check if query's path and runRange are valid
1161 // query is invalid also if version is not specified and subversion is!
1162 if (!query.IsValid()) {
1163 AliError(Form("Invalid query: %s", query.ToString().Data()));
1167 // query is not specified if path contains wildcard or run range= [-1,-1]
1168 if (!query.IsSpecified()) {
1169 AliError(Form("Unspecified query: %s",
1170 query.ToString().Data()));
1174 if(fCache && query.GetFirstRun() != fRun)
1175 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
1177 AliCDBEntry* entry = 0;
1179 // first look into map of cached objects
1180 if(fCache && query.GetFirstRun() == fRun)
1181 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
1184 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
1185 return dynamic_cast<AliCDBId*> (entry->GetId().Clone());
1188 // Entry is not in cache -> retrieve it from CDB and cache it!!
1189 AliCDBStorage *aStorage=0;
1190 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
1193 aStorage=GetStorage(aPar);
1194 TString str = aPar->GetURI();
1195 AliDebug(2,Form("Looking into storage: %s",str.Data()));
1198 aStorage=GetDefaultStorage();
1199 AliDebug(2,"Looking into default storage");
1202 return aStorage->GetId(query);
1206 //_____________________________________________________________________________
1207 TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber,
1208 Int_t version, Int_t subVersion) {
1209 // get multiple AliCDBEntry objects from the database
1212 // RunNumber is not specified. Try with fRun
1214 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
1220 return GetAll(AliCDBId(path, runNumber, runNumber, version,
1224 //_____________________________________________________________________________
1225 TList* AliCDBManager::GetAll(const AliCDBPath& path,
1226 const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
1227 // get multiple AliCDBEntry objects from the database
1229 return GetAll(AliCDBId(path, runRange, version, subVersion));
1232 //_____________________________________________________________________________
1233 TList* AliCDBManager::GetAll(const AliCDBId& query) {
1234 // get multiple AliCDBEntry objects from the database
1235 // Warning: this method works correctly only for queries of the type "Detector/*"
1236 // and not for more specific queries e.g. "Detector/Calib/*" !
1237 // Warning #2: Entries are cached, but GetAll will keep on retrieving objects from OCDB!
1238 // To get an object from cache use Get() function
1240 if(!fDefaultStorage) {
1241 AliError("No storage set!");
1245 if (!query.IsValid()) {
1246 AliError(Form("Invalid query: %s", query.ToString().Data()));
1250 if((fSpecificStorages.GetEntries()>0) && query.GetPath().BeginsWith('*')){
1251 // if specific storages are active a query with "*" is ambiguous
1252 AliError("Query too generic in this context!");
1256 if (query.IsAnyRange()) {
1257 AliError(Form("Unspecified run or runrange: %s",
1258 query.ToString().Data()));
1262 if(fLock && query.GetFirstRun() != fRun)
1263 AliFatal("Lock is ON: cannot use different run number than the internal one!");
1265 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
1267 AliCDBStorage *aStorage;
1269 aStorage=GetStorage(aPar);
1270 AliDebug(2,Form("Looking into storage: %s", aPar->GetURI().Data()));
1273 aStorage=GetDefaultStorage();
1274 AliDebug(2,Form("Looking into default storage: %s", aStorage->GetURI().Data()));
1278 if(aStorage) result = aStorage->GetAll(query);
1279 if(!result) return 0;
1281 // loop on result to check whether entries should be re-queried with specific storages
1282 if(fSpecificStorages.GetEntries()>0 && ! (fSpecificStorages.GetEntries() == 1 && aPar)) {
1283 AliInfo("Now look into all other specific storages...");
1286 AliCDBEntry* chkEntry=0;
1288 while((chkEntry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
1289 AliCDBId& chkId = chkEntry->GetId();
1290 AliDebug(2, Form("Checking id %s ", chkId.GetPath().Data()));
1291 AliCDBParam *chkPar=SelectSpecificStorage(chkId.GetPath());
1292 if (!chkPar || aPar == chkPar) continue;
1293 AliCDBStorage *chkStorage = GetStorage(chkPar);
1294 AliDebug(2, Form("Found specific storage! %s", chkPar->GetURI().Data()));
1296 AliCDBEntry *newEntry=0;
1297 chkId.SetRunRange(query.GetFirstRun(), query.GetLastRun());
1298 chkId.SetVersion(query.GetVersion());
1299 chkId.SetSubVersion(query.GetSubVersion());
1301 if(chkStorage) newEntry = chkStorage->Get(chkId);
1302 if(!newEntry) continue;
1304 // object is found in specific storage: replace entry in the result list!
1305 chkEntry->SetOwner(1);
1306 delete result->Remove(chkEntry);
1307 result->AddFirst(newEntry);
1310 Int_t nEntries = result->GetEntries();
1311 AliInfo("After look into other specific storages, result list is:");
1312 for(int i=0; i<nEntries;i++){
1313 AliCDBEntry *entry = (AliCDBEntry*) result->At(i);
1314 AliInfo(Form("%s",entry->GetId().ToString().Data()));
1320 AliCDBEntry* entry=0;
1321 while((entry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
1323 if(!fIds->Contains(&entry->GetId())){
1324 fIds->Add(entry->GetId().Clone());
1326 if(fCache && (query.GetFirstRun() == fRun)){
1327 CacheEntry(entry->GetId().GetPath(), entry);
1335 //_____________________________________________________________________________
1336 Bool_t AliCDBManager::Put(TObject* object, const AliCDBId& id, AliCDBMetaData* metaData, const char* mirrors, DataType type){
1337 // store an AliCDBEntry object into the database
1340 AliError("Null Entry! No storage will be done!");
1344 AliCDBEntry anEntry(object, id, metaData);
1345 return Put(&anEntry, mirrors, type);
1350 //_____________________________________________________________________________
1351 Bool_t AliCDBManager::Put(AliCDBEntry* entry, const char* mirrors, DataType type){
1352 // store an AliCDBEntry object into the database
1354 if(type == kPrivate && !fDefaultStorage) {
1355 AliError("No storage set!");
1360 AliError("No entry!");
1364 if (entry->GetObject()==0x0){
1365 AliError("No valid object in CDB entry!");
1369 if (!entry->GetId().IsValid()) {
1370 AliError(Form("Invalid entry ID: %s",
1371 entry->GetId().ToString().Data()));
1375 if (!entry->GetId().IsSpecified()) {
1376 AliError(Form("Unspecified entry ID: %s",
1377 entry->GetId().ToString().Data()));
1381 AliCDBId id = entry->GetId();
1382 AliCDBParam *aPar = SelectSpecificStorage(id.GetPath());
1384 AliCDBStorage *aStorage=0;
1387 aStorage=GetStorage(aPar);
1391 aStorage = GetStorage(fCondParam);
1394 aStorage = GetStorage(fRefParam);
1397 aStorage = GetDefaultStorage();
1402 AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data()));
1404 TString strMirrors(mirrors);
1405 Bool_t result = kFALSE;
1406 if(!strMirrors.IsNull() && !strMirrors.IsWhitespace())
1407 result = aStorage->Put(entry, mirrors, type);
1409 result = aStorage->Put(entry, "", type);
1411 if(fRun >= 0) QueryCDB();
1418 //_____________________________________________________________________________
1419 void AliCDBManager::SetMirrorSEs(const char* mirrors) {
1420 // set mirror Storage Elements for the default storage, if it is of type "alien"
1421 if(fDefaultStorage->GetType() != "alien"){
1422 AliInfo("The default storage is not of type \"alien\". Settings for Storage Elements are not taken into account!");
1425 fDefaultStorage->SetMirrorSEs(mirrors);
1428 //_____________________________________________________________________________
1429 const char* AliCDBManager::GetMirrorSEs() const {
1430 // get mirror Storage Elements for the default storage, if it is of type "alien"
1431 if(fDefaultStorage->GetType() != "alien"){
1432 AliInfo("The default storage is not of type \"alien\". Settings for Storage Elements are not taken into account!");
1435 return fDefaultStorage->GetMirrorSEs();
1438 //_____________________________________________________________________________
1439 void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry) {
1440 // cache AliCDBEntry. Cache is valid until run number is changed.
1442 AliCDBEntry *chkEntry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(path));
1445 AliDebug(2, Form("Object %s already in cache !!", path));
1448 AliDebug(2,Form("Caching entry %s", path));
1451 fEntryCache.Add(new TObjString(path), entry);
1452 AliDebug(2,Form("Cache entries: %d", fEntryCache.GetEntries()));
1456 //_____________________________________________________________________________
1457 void AliCDBManager::Print(Option_t* /*option*/) const {
1458 // Print list of active storages and their URIs
1460 TString output=Form("Run number = %d; ",fRun);
1461 output += "Cache is ";
1462 if(!fCache) output += "NOT ";
1463 output += Form("ACTIVE; Number of active storages: %d\n",fActiveStorages.GetEntries());
1465 if(fDefaultStorage) {
1466 output += Form("\t*** Default Storage URI: \"%s\"\n",fDefaultStorage->GetURI().Data());
1467 // AliInfo(output.Data());
1469 if(fSpecificStorages.GetEntries()>0) {
1470 TIter iter(fSpecificStorages.GetTable());
1473 while((aPair = (TPair*) iter.Next())){
1474 output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n",
1475 i++, ((TObjString*) aPair->Key())->GetName(),
1476 ((AliCDBParam*) aPair->Value())->GetURI().Data());
1480 output += Form("*** Drain Storage URI: %s\n",fDrainStorage->GetURI().Data());
1482 AliInfo(output.Data());
1485 //_____________________________________________________________________________
1486 void AliCDBManager::SetRun(Int_t run) {
1487 // Sets current run number.
1488 // When the run number changes the caching is cleared.
1493 if(fLock && fRun >= 0) {
1494 AliFatal("Lock is ON, cannot reset run number!");
1500 // here the LHCPeriod xml file is parsed; the string containing the correct period is returned; the default storage is set
1501 if (fStartRunLHCPeriod <= run && fEndRunLHCPeriod >= run){
1502 AliInfo("LHCPeriod alien folder for current run already in memory");
1504 SetDefaultStorageFromRun(run);
1505 if(fEntryCache.GetEntries()!=0) ClearCache();
1513 //_____________________________________________________________________________
1514 void AliCDBManager::ClearCache(){
1515 // clear AliCDBEntry cache
1517 AliDebug(2, Form("Cache entries to be deleted: %d",fEntryCache.GetEntries()));
1520 // To clean entries one by one
1521 TIter iter(fEntryCache.GetTable());
1523 while((pair= dynamic_cast<TPair*> (iter.Next()))){
1525 TObjString* key = dynamic_cast<TObjString*> (pair->Key());
1526 AliCDBEntry* entry = dynamic_cast<AliCDBEntry*> (pair->Value());
1527 AliDebug(2, Form("Deleting entry: %s", key->GetName()));
1528 if (entry) delete entry;
1529 delete fEntryCache.Remove(key);
1532 fEntryCache.DeleteAll();
1533 AliDebug(2, Form("After deleting - Cache entries: %d",fEntryCache.GetEntries()));
1536 //_____________________________________________________________________________
1537 void AliCDBManager::UnloadFromCache(const char* path){
1538 // unload cached object
1539 // that is remove the entry from the cache and the id from the list of ids
1541 if(!fActiveStorages.GetEntries()) {
1542 AliDebug(2, Form("No active storages. Object \"%s\" is not unloaded from cache", path));
1546 AliCDBPath queryPath(path);
1547 if(!queryPath.IsValid()) return;
1549 if(!queryPath.IsWildcard()) { // path is not wildcard, get it directly from the cache and unload it!
1550 if(fEntryCache.Contains(path)){
1551 AliDebug(2, Form("Unloading object \"%s\" from cache and from list of ids", path));
1552 TObjString pathStr(path);
1553 delete fEntryCache.Remove(&pathStr);
1554 // we do not remove from the list of Id's (it's not very coherent but we leave the
1555 // id for the benefit of the userinfo)
1559 while((id = dynamic_cast<AliCDBId*> (iter.Next()))){
1560 if(queryPath.Comprises(id->GetPath()))
1561 delete fIds->Remove(id);
1564 AliWarning(Form("Cache does not contain object \"%s\"!", path));
1566 AliDebug(2, Form("Cache entries: %d",fEntryCache.GetEntries()));
1570 // path is wildcard: loop on the cache and unload all comprised objects!
1571 TIter iter(fEntryCache.GetTable());
1575 while((pair = dynamic_cast<TPair*> (iter.Next()))){
1576 AliCDBPath entryPath = pair->Key()->GetName();
1577 if(queryPath.Comprises(entryPath)) {
1578 AliDebug(2, Form("Unloading object \"%s\" from cache and from list of ids", entryPath.GetPath().Data()));
1579 TObjString pathStr(entryPath.GetPath());
1580 delete fEntryCache.Remove(&pathStr);
1583 // we do not remove from the list of Id's (it's not very coherent but we leave the
1584 // id for the benefit of the userinfo)
1586 TIter iterids(fIds);
1588 while((anId = dynamic_cast<AliCDBId*> (iterids.Next()))){
1589 AliCDBPath aPath = anId->GetPath();
1590 TString aPathStr = aPath.GetPath();
1591 if(queryPath.Comprises(aPath)) {
1592 delete fIds->Remove(anId);
1597 AliDebug(2,Form("Cache entries and ids removed: %d Remaining: %d",removed,fEntryCache.GetEntries()));
1600 //_____________________________________________________________________________
1601 void AliCDBManager::DestroyActiveStorages() {
1602 // delete list of active storages
1604 fActiveStorages.DeleteAll();
1605 fSpecificStorages.DeleteAll();
1608 //_____________________________________________________________________________
1609 void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
1610 // destroys active storage
1613 TIter iter(fActiveStorages.GetTable());
1615 while ((aPair = (TPair*) iter.Next())) {
1616 if(storage == (AliCDBStorage*) aPair->Value())
1617 delete fActiveStorages.Remove(aPair->Key());
1618 storage->Delete(); storage=0x0;
1624 //_____________________________________________________________________________
1625 void AliCDBManager::QueryCDB() {
1626 // query default and specific storages for files valid for fRun. Every storage loads the Ids into its list.
1629 AliError("Run number not yet set! Use AliCDBManager::SetRun.");
1632 if (!fDefaultStorage){
1633 AliError("Default storage is not set! Use AliCDBManager::SetDefaultStorage");
1636 if(fDefaultStorage->GetType() == "alien" || fDefaultStorage->GetType() == "local"){
1637 fDefaultStorage->QueryCDB(fRun);
1639 // AliDebug(2,"Skipping query for valid files, it used only in grid...");
1642 TIter iter(&fSpecificStorages);
1643 TObjString *aCalibType=0;
1644 AliCDBParam* aPar=0;
1645 while((aCalibType = dynamic_cast<TObjString*> (iter.Next()))){
1646 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
1648 AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName()));
1649 AliCDBStorage *aStorage = GetStorage(aPar);
1650 if(aStorage->GetType() == "alien" || aStorage->GetType() == "local"){
1651 aStorage->QueryCDB(fRun, aCalibType->GetName());
1654 "Skipping query for valid files, it is used only in grid...");
1660 //______________________________________________________________________________________________
1661 const char* AliCDBManager::GetDataTypeName(DataType type) {
1662 // returns the name (string) of the data type
1665 case kCondition: return "Conditions";
1666 case kReference: return "Reference";
1667 case kPrivate: return "Private";
1673 //______________________________________________________________________________________________
1674 Bool_t AliCDBManager::DiffObjects(const char *cdbFile1, const char *cdbFile2) const {
1675 // Compare byte-by-byte the objects contained in the CDB entry in two different files,
1676 // whose name is passed as input
1678 // kTRUE - in case the content of the OCDB object (persistent part) is exactly the same
1679 // kFALSE - otherwise
1681 TString f1Str(cdbFile1);
1682 TString f2Str(cdbFile2);
1683 if (!gGrid && ( f1Str.BeginsWith("alien://") || f2Str.BeginsWith("alien://") ))
1684 TGrid::Connect("alien://");
1686 TFile * f1 = TFile::Open(cdbFile1);
1688 Printf("Cannot open file \"%s\"",cdbFile1);
1691 TFile * f2 = TFile::Open(cdbFile2);
1693 Printf("Cannot open file \"%s\"",cdbFile2);
1697 AliCDBEntry * entry1 = (AliCDBEntry*)f1->Get("AliCDBEntry");
1699 Printf("Cannot get CDB entry from file \"%s\"",cdbFile1);
1702 AliCDBEntry * entry2 = (AliCDBEntry*)f2->Get("AliCDBEntry");
1704 Printf("Cannot get CDB entry from file \"%s\"",cdbFile2);
1708 // stream the two objects in the buffer of two TMessages
1709 TObject* object1 = entry1->GetObject();
1710 TObject* object2 = entry2->GetObject();
1711 TMessage * file1 = new TMessage(TBuffer::kWrite);
1712 file1->WriteObject(object1);
1713 Int_t size1 = file1->Length();
1714 TMessage * file2 = new TMessage(TBuffer::kWrite);
1715 file2->WriteObject(object2);
1716 Int_t size2 = file2->Length();
1718 Printf("Problem 2: OCDB entry of different size (%d,%d)",size1,size2);
1722 // if the two buffers have the same size, check that they are the same byte-by-byte
1724 char* buf1 = file1->Buffer();
1725 char* buf2 = file2->Buffer();
1726 //for (Int_t i=0; i<size1; i++) if (file1->Buffer()[i]!=file2->Buffer()[i]) countDiff++;
1727 for(Int_t i=0; i<size1; i++)
1728 if (buf1[i]!=buf2[i]) countDiff++;
1731 Printf("The CDB objects differ by %d bytes.", countDiff);
1735 Printf("The CDB objects are the same in the two files.");
1739 //______________________________________________________________________________________________
1740 void AliCDBManager::InitShortLived() {
1741 // Init the list of short-lived objects
1742 // currently disabled
1746 // fShortLived = new TList();
1747 // fShortLived->SetOwner(1);
1749 // fShortLived->Add(new TObjString("EMCAL/Calib/Data"));
1751 // fShortLived->Add(new TObjString("HMPID/Calib/Nmean"));
1752 // fShortLived->Add(new TObjString("HMPID/Calib/Qthre"));
1754 // fShortLived->Add(new TObjString("ITS/Calib/CalibSPD"));
1756 // fShortLived->Add(new TObjString("MUON/Calib/Gains"));
1757 // fShortLived->Add(new TObjString("MUON/Calib/HV"));
1758 // fShortLived->Add(new TObjString("MUON/Calib/Pedestals"));
1760 // fShortLived->Add(new TObjString("PHOS/Calib/CpvGainPedestals"));
1761 // fShortLived->Add(new TObjString("PHOS/Calib/EmcGainPedestals"));
1763 // fShortLived->Add(new TObjString("PMD/Calib/Data"));
1765 // fShortLived->Add(new TObjString("TRD/Calib/ChamberGainFactor"));
1766 // fShortLived->Add(new TObjString("TRD/Calib/LocalGainFactor"));
1767 // fShortLived->Add(new TObjString("TRD/Calib/ChamberT0"));
1768 // fShortLived->Add(new TObjString("TRD/Calib/LocalT0"));
1769 // fShortLived->Add(new TObjString("TRD/Calib/ChamberVdrift"));
1770 // fShortLived->Add(new TObjString("TRD/Calib/LocalVdrift"));
1772 // fShortLived->Add(new TObjString("ZDC/Calib/Data"));
1776 //______________________________________________________________________________________________
1777 Bool_t AliCDBManager::IsShortLived(const char* path) {
1778 // returns the name (string) of the data type
1780 if(!fShortLived) return kFALSE;
1782 AliCDBPath aPath(path);
1783 if(!aPath.IsValid()){
1784 AliError(Form("Not a valid path: %s", path));
1788 return fShortLived->Contains(path);
1792 //______________________________________________________________________________________________
1793 ULong64_t AliCDBManager::SetLock(Bool_t lock, ULong64_t key){
1794 // To lock/unlock user must provide the key. A new key is provided after
1795 // each successful lock. User should always backup the returned key and
1796 // use it on next access.
1797 if (fLock == lock) return 0; // nothing to be done
1799 // User wants to lock - check his identity
1801 // Lock has a user - check his key
1803 AliFatal("Wrong key provided to lock CDB. Please remove CDB lock access from your code !");
1808 fKey = gSystem->Now();
1812 // User wants to unlock - check the provided key
1814 AliFatal("Lock is ON: wrong key provided");
1821 ///////////////////////////////////////////////////////////
1822 // AliCDBManager Parameter class //
1823 // interface to specific AliCDBParameter class //
1824 // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) //
1825 ///////////////////////////////////////////////////////////
1827 AliCDBParam::AliCDBParam():
1835 //_____________________________________________________________________________
1836 AliCDBParam::~AliCDBParam() {