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()) {
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 if (! uriString.BeginsWith("alien://") && !fCvmfsOcdb.IsNull())
409 AliFatal("Cannot set local://cvmfs storage for a non alien uri");
411 TObjArray *arr = uriString.Tokenize('?');
414 TString entryKey = "";
415 TString entryValue = "";
416 TString newUriString = "";
417 while((str = (TObjString*) iter.Next())){
418 TString entry(str->String());
419 Int_t indeq = entry.Index('=');
420 entryKey = entry(0, indeq+1);
421 entryValue = entry(indeq+1, entry.Length()-indeq);
423 if ( entryKey.Contains("folder", TString::kIgnoreCase) )
426 TRegexp re_RawFolder("^/alice/data/20[0-9]+/OCDB");
427 TRegexp re_MCFolder("^/alice/simulation/2008/v4-15-Release");
428 TString rawFolder = entryValue(re_RawFolder);
429 TString mcFolder = entryValue(re_MCFolder);
430 if ( !rawFolder.IsNull() ){
431 entryValue.Replace(0, 6, "/cvmfs/alice.cern.ch/calibration");
432 //entryValue.Replace(entryValue.Length()-4, entryValue.Length(), "");
433 } else if ( !mcFolder.IsNull() ){
434 entryValue.Replace(0,36,"/cvmfs/alice.cern.ch/calibration/MC");
436 AliFatal(Form("Environment variable for cvmfs OCDB folder set for an invalid OCDB storage:\n %s", entryValue.Data()));
439 newUriString += entryKey;
441 newUriString += entryValue;
444 newUriString.Prepend("local://");
445 newUriString.Remove(TString::kTrailing, '?');
446 uriString = newUriString;
449 //_____________________________________________________________________________
450 AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) {
451 // get storage object from URI string
453 // Check environment variable OCDB_PATH. It is set in case the user (job) expects
454 // to find in the local /cvmfs the required OCDB tag. The OCDB_PATH variable
455 // contains the path to the directory in /cvmfs/ which is an AliRoot tag based snapshot
456 // of the AliEn file catalogue. The directory has to contain:
457 // 1) catalogue/20??.list.gz gzipped text files listing the OCDB files (seen by that AliRoot tag)
458 // 2) bin/getOCDBperRun.sh (shell+awk) script extracting from 1) the list
459 // of valid files for the given run.
461 AliCDBParam* param = CreateParameter(dbString);
463 AliError(Form("Failed to activate requested storage! Check URI: %s", dbString));
467 AliCDBStorage* aStorage = GetStorage(param);
473 //_____________________________________________________________________________
474 AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) {
475 // get storage object from AliCDBParam object
477 // if the list of active storages already contains
478 // the requested storage, return it
479 AliCDBStorage* aStorage = GetActiveStorage(param);
484 // if lock is ON, cannot activate more storages!
486 if (fDefaultStorage) {
487 AliFatal("Lock is ON, and default storage is already set: "
488 "cannot reset it or activate more storages!");
492 // loop on the list of registered factories
493 TIter iter(&fFactories);
494 AliCDBStorageFactory* factory=0;
495 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
497 // each factory tries to create its storage from the parameter
498 aStorage = factory->Create(param);
500 PutActiveStorage(param->CloneParam(), aStorage);
501 aStorage->SetURI(param->GetURI());
503 if( aStorage->GetType() == "alien" || aStorage->GetType() == "local" )
504 aStorage->QueryCDB(fRun);
510 AliError(Form("Failed to activate requested storage! Check URI: %s", param->GetURI().Data()));
515 //_____________________________________________________________________________
516 AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) {
517 // get a storage object from the list of active storages
519 return dynamic_cast<AliCDBStorage*> (fActiveStorages.GetValue(param));
522 //_____________________________________________________________________________
523 TList* AliCDBManager::GetActiveStorages() {
524 // return list of active storages
525 // user has responsibility to delete returned object
527 TList* result = new TList();
529 TIter iter(fActiveStorages.GetTable());
531 while ((aPair = (TPair*) iter.Next())) {
532 result->Add(aPair->Value());
538 //_____________________________________________________________________________
539 void AliCDBManager::SetDrain(const char* dbString) {
540 // set drain storage from URI string
542 fDrainStorage = GetStorage(dbString);
545 //_____________________________________________________________________________
546 void AliCDBManager::SetDrain(const AliCDBParam* param) {
547 // set drain storage from AliCDBParam
549 fDrainStorage = GetStorage(param);
552 //_____________________________________________________________________________
553 void AliCDBManager::SetDrain(AliCDBStorage* storage) {
554 // set drain storage from another active storage
556 fDrainStorage = storage;
559 //_____________________________________________________________________________
560 Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
561 // drain retrieved object to drain storage
563 AliDebug(2, "Draining into drain storage...");
564 return fDrainStorage->Put(entry);
567 //____________________________________________________________________________
568 void AliCDBManager::SetDefaultStorage(const char* storageUri) {
569 // sets default storage from URI string
571 // if in the cvmfs case (triggered by environment variable) check for path validity
572 // and modify Uri if it is "raw://"
573 TString cvmfsOcdb(gSystem->Getenv("OCDB_PATH"));
574 if (! cvmfsOcdb.IsNull()){
575 fCvmfsOcdb = cvmfsOcdb;
579 // checking whether we are in the raw case
580 TString uriTemp(storageUri);
581 if (uriTemp == "raw://") {
582 fRaw = kTRUE; // read then by SetRun to check if the method has to be called again with expanded uri
583 AliInfo("Setting the run-number will set the corresponding OCDB for raw data reconstruction.");
587 AliCDBStorage* bckStorage = fDefaultStorage;
589 fDefaultStorage = GetStorage(storageUri);
591 if(!fDefaultStorage) return;
593 if(bckStorage && (fDefaultStorage != bckStorage)){
594 AliWarning("Existing default storage replaced: clearing cache!");
598 if (fStorageMap->Contains("default")) {
599 delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
601 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
604 //_____________________________________________________________________________
605 void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
606 // set default storage from AliCDBParam object
608 AliCDBStorage* bckStorage = fDefaultStorage;
610 fDefaultStorage = GetStorage(param);
612 if(!fDefaultStorage) return;
614 if(bckStorage && (fDefaultStorage != bckStorage)){
615 AliWarning("Existing default storage replaced: clearing cache!");
619 if (fStorageMap->Contains("default")) {
620 delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
622 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
625 //_____________________________________________________________________________
626 void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
627 // set default storage from another active storage
629 // if lock is ON, cannot activate more storages!
631 if (fDefaultStorage) {
632 AliFatal("Lock is ON, and default storage is already set: "
633 "cannot reset it or activate more storages!");
638 UnsetDefaultStorage();
642 AliCDBStorage* bckStorage = fDefaultStorage;
644 fDefaultStorage = storage;
646 if(bckStorage && (fDefaultStorage != bckStorage)){
647 AliWarning("Existing default storage replaced: clearing cache!");
651 if (fStorageMap->Contains("default")) {
652 delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
654 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
657 //_____________________________________________________________________________
658 void AliCDBManager::SetDefaultStorage(const char* mcString, const char* simType) {
659 // sets default storage for MC data
660 // mcString MUST be "MC",
661 // simType can be "Ideal","Residual","Full"
663 TString strmcString(mcString);
664 TString strsimType(simType);
666 if (strmcString != "MC"){
667 AliFatal("Method requires first string to be MC!");
670 if (strsimType == "Ideal"){
671 dbString = fgkMCIdealStorage;
673 else if (strsimType == "Full"){
674 dbString = fgkMCFullStorage;
676 else if (strsimType == "Residual"){
677 dbString = fgkMCResidualStorage;
680 AliFatal("Error in setting the storage for MC data, second argument MUST be either \"Ideal\" or \"Full\" or \"Residual\".");
683 SetDefaultStorage(dbString.Data());
684 fStartRunLHCPeriod=0;
685 fEndRunLHCPeriod=AliCDBRunRange::Infinity();
686 if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",dbString.Data()));
690 //_____________________________________________________________________________
691 void AliCDBManager::ValidateCvmfsCase() const {
692 if (! fCvmfsOcdb.BeginsWith("/cvmfs")) //!!!! to be commented out for testing
693 AliFatal(Form("OCDB_PATH set to an invalid path: %s", fCvmfsOcdb.Data()));
695 TString cvmfsUri(fCvmfsOcdb);
696 gSystem->ExpandPathName(cvmfsUri);
697 if (gSystem->AccessPathName(cvmfsUri))
698 AliFatal(Form("OCDB_PATH set to an invalid path: %s", cvmfsUri.Data()));
700 // check that we find the two scripts we need
702 AliDebug(3, "OCDB_PATH envvar is set. Changing OCDB storage from alien:// to local:///cvmfs type.");
703 cvmfsUri = cvmfsUri.Strip(TString::kTrailing, '/');
704 cvmfsUri.Append("/bin/getOCDBFilesPerRun.sh");
705 if (gSystem->AccessPathName(cvmfsUri))
706 AliFatal(Form("Cannot find valid script: %s", cvmfsUri.Data()));
709 //_____________________________________________________________________________
710 void AliCDBManager::SetDefaultStorageFromRun(Int_t run) {
711 // set default storage from the run number - to be used only with raw data
713 // if lock is ON, cannot activate more storages!
715 if (fDefaultStorage) {
716 AliFatal("Lock is ON, and default storage is already set: "
717 "cannot activate default storage from run number");
721 // fRaw and cvmfs case
722 if (! fCvmfsOcdb.IsNull()) {
723 // we don't want to connect to AliEn just to set the uri from the runnumber
724 // for that we use the script getUriFromYear.sh in the cvmfs AliRoot package
725 // check that we find the two scripts we need
726 TString getYearScript(fCvmfsOcdb);
727 getYearScript = getYearScript.Strip(TString::kTrailing, '/');
728 getYearScript.Append("/bin/getUriFromYear.sh");
729 if (gSystem->AccessPathName(getYearScript))
730 AliFatal(Form("Cannot find valid script: %s", getYearScript.Data()));
731 TString inoutFile(gSystem->WorkingDirectory());
732 inoutFile += "/uri_range_";
733 inoutFile += TString::Itoa(fRun,10);
734 TString command(getYearScript);
736 command += TString::Itoa(fRun,10);
737 command += Form(" > %s", inoutFile.Data());
738 AliDebug(3, Form("Running command: \"%s\"",command.Data()));
739 Int_t result = gSystem->Exec(command.Data());
741 AliFatal(Form("Was not able to execute \"%s\"", command.Data()));
744 // now read the file with the uri and first and last run
745 ifstream *file = new ifstream(inoutFile.Data());
747 AliFatal(Form("Error opening file \"%s\"!", inoutFile.Data()));
752 TObjArray* oStringsArray = 0;
753 while (lhcPeriod.ReadLine(*file)){
754 oStringsArray = lhcPeriod.Tokenize(' ');
756 TObjString *oStrUri = dynamic_cast<TObjString*> (oStringsArray->At(0));
757 TObjString *oStrFirst = dynamic_cast<TObjString*> (oStringsArray->At(1));
758 TString firstRun = oStrFirst->GetString();
759 TObjString *oStrLast = dynamic_cast<TObjString*> (oStringsArray->At(2));
760 TString lastRun = oStrLast->GetString();
762 fLHCPeriod = oStrUri->GetString();
763 fStartRunLHCPeriod = firstRun.Atoi();
764 fEndRunLHCPeriod = lastRun.Atoi();
769 } else { // if not cvmfs case, "plain" AliEn case
770 // retrieve XML file from alien
772 TGrid::Connect("alien://","");
774 AliError("Connection to alien failed!");
779 TString rndname = "/tmp/";
780 rndname += "OCDBFolderXML.";
781 rndname += uuid.AsString();
783 AliDebug(2, Form("file to be copied = %s", fgkOCDBFolderXMLfile.Data()));
784 if (!TFile::Cp(fgkOCDBFolderXMLfile.Data(), rndname.Data())) {
785 AliFatal(Form("Cannot make a local copy of OCDBFolder xml file in %s",rndname.Data()));
787 AliCDBHandler* saxcdb = new AliCDBHandler();
789 TSAXParser *saxParser = new TSAXParser();
790 saxParser->ConnectToHandler("AliCDBHandler", saxcdb);
791 saxParser->ParseFile(rndname.Data());
792 AliInfo(Form(" LHC folder = %s", saxcdb->GetOCDBFolder().Data()));
793 AliInfo(Form(" LHC period start run = %d", saxcdb->GetStartRunRange()));
794 AliInfo(Form(" LHC period end run = %d", saxcdb->GetEndRunRange()));
795 fLHCPeriod = saxcdb->GetOCDBFolder();
796 fStartRunLHCPeriod = saxcdb->GetStartRunRange();
797 fEndRunLHCPeriod = saxcdb->GetEndRunRange();
800 SetDefaultStorage(fLHCPeriod.Data());
801 if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",fLHCPeriod.Data()));
805 //_____________________________________________________________________________
806 void AliCDBManager::UnsetDefaultStorage() {
807 // Unset default storage
809 // if lock is ON, action is forbidden!
811 if (fDefaultStorage) {
812 AliFatal("Lock is ON: cannot unset default storage!");
816 if (fDefaultStorage) {
817 AliWarning("Clearing cache!");
821 fRun = fStartRunLHCPeriod = fEndRunLHCPeriod = -1;
824 fDefaultStorage = 0x0;
827 //_____________________________________________________________________________
828 void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) {
829 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
831 AliCDBParam *aPar = CreateParameter(dbString);
833 SetSpecificStorage(calibType, aPar);
837 //_____________________________________________________________________________
838 void AliCDBManager::SetSpecificStorage(const char* calibType, const AliCDBParam* param) {
839 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
840 // Default storage should be defined prior to any specific storages, e.g.:
841 // AliCDBManager::instance()->SetDefaultStorage("alien://");
842 // AliCDBManager::instance()->SetSpecificStorage("TPC/*","local://DB_TPC");
843 // AliCDBManager::instance()->SetSpecificStorage("*/Align/*","local://DB_TPCAlign");
844 // calibType must be a valid CDB path! (3 level folder structure)
847 if(!fDefaultStorage && !fRaw) {
848 AliError("Please activate a default storage first!");
853 AliCDBPath aPath(calibType);
854 if(!aPath.IsValid()){
855 AliError(Form("Not a valid path: %s", calibType));
859 TObjString *objCalibType = new TObjString(aPath.GetPath());
860 if(fSpecificStorages.Contains(objCalibType)){
861 AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one",
863 AliCDBParam *checkPar = dynamic_cast<AliCDBParam*> (fSpecificStorages.GetValue(calibType));
864 if(checkPar) delete checkPar;
865 delete fSpecificStorages.Remove(objCalibType);
867 AliCDBStorage *aStorage = GetStorage(param);
868 if(!aStorage) return;
870 fSpecificStorages.Add(objCalibType, param->CloneParam());
872 if(fStorageMap->Contains(objCalibType)){
873 delete fStorageMap->Remove(objCalibType);
875 fStorageMap->Add(objCalibType->Clone(), new TObjString(param->GetURI()));
879 //_____________________________________________________________________________
880 AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) {
881 // get storage specific for detector or calibration type
883 AliCDBPath calibPath(calibType);
884 if(!calibPath.IsValid()) return NULL;
886 AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibPath.GetPath());
888 AliError(Form("%s storage not found!", calibType));
891 return GetStorage(checkPar);
896 //_____________________________________________________________________________
897 AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) {
898 // select storage valid for path from the list of specific storages
900 AliCDBPath aPath(path);
901 if(!aPath.IsValid()) return NULL;
903 TIter iter(&fSpecificStorages);
904 TObjString *aCalibType=0;
905 AliCDBPath tmpPath("null/null/null");
907 while((aCalibType = (TObjString*) iter.Next())){
908 AliCDBPath calibTypePath(aCalibType->GetName());
909 if(calibTypePath.Comprises(aPath)) {
910 if(calibTypePath.Comprises(tmpPath)) continue;
911 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
912 tmpPath.SetPath(calibTypePath.GetPath());
918 //_____________________________________________________________________________
919 AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber,
920 Int_t version, Int_t subVersion) {
921 // get an AliCDBEntry object from the database
924 // RunNumber is not specified. Try with fRun
926 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
932 return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
935 //_____________________________________________________________________________
936 AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path,
937 const AliCDBRunRange& runRange, Int_t version,
939 // get an AliCDBEntry object from the database!
941 return Get(AliCDBId(path, runRange, version, subVersion));
944 //_____________________________________________________________________________
945 AliCDBEntry* AliCDBManager::Get(const AliCDBId& query, Bool_t forceCaching) {
946 // get an AliCDBEntry object from the database
948 // check if query's path and runRange are valid
949 // query is invalid also if version is not specified and subversion is!
950 if (!query.IsValid()) {
951 AliError(Form("Invalid query: %s", query.ToString().Data()));
955 // query is not specified if path contains wildcard or run range= [-1,-1]
956 if (!query.IsSpecified()) {
957 AliError(Form("Unspecified query: %s",
958 query.ToString().Data()));
962 if(fLock && !(fRun >= query.GetFirstRun() && fRun <= query.GetLastRun()))
963 AliFatal("Lock is ON: cannot use different run number than the internal one!");
965 if(fCache && !(fRun >= query.GetFirstRun() && fRun <= query.GetLastRun()))
966 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
968 AliCDBEntry *entry=0;
970 // first look into map of cached objects
971 if(fCache && query.GetFirstRun() == fRun)
972 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
974 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
978 // if snapshot flag is set, try getting from the snapshot
979 // but in the case a specific storage is specified for this path
980 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
982 if(fSnapshotMode && query.GetFirstRun() == fRun)
984 entry = GetEntryFromSnapshot(query.GetPath());
986 AliInfo(Form("Object \"%s\" retrieved from the snapshot.",query.GetPath().Data()));
987 if(query.GetFirstRun() == fRun) // no need to check fCache, fSnapshotMode not possible otherwise
988 CacheEntry(query.GetPath(), entry);
990 if(!fIds->Contains(&entry->GetId()))
991 fIds->Add(entry->GetId().Clone());
998 // Entry is not in cache (and, in case we are in snapshot mode, not in the snapshot either)
999 // => retrieve it from the storage and cache it!!
1000 if(!fDefaultStorage) {
1001 AliError("No storage set!");
1005 AliCDBStorage *aStorage=0;
1007 aStorage=GetStorage(aPar);
1008 TString str = aPar->GetURI();
1009 AliDebug(2,Form("Looking into storage: %s",str.Data()));
1011 aStorage=GetDefaultStorage();
1012 AliDebug(2,"Looking into default storage");
1015 entry = aStorage->Get(query);
1017 if(entry && fCache && (query.GetFirstRun()==fRun || forceCaching)){
1018 CacheEntry(query.GetPath(), entry);
1021 if(entry && !fIds->Contains(&entry->GetId())){
1022 fIds->Add(entry->GetId().Clone());
1030 //_____________________________________________________________________________
1031 AliCDBEntry* AliCDBManager::GetEntryFromSnapshot(const char* path) {
1032 // get the entry from the open snapshot file
1034 TString sPath(path);
1035 sPath.ReplaceAll("/","*");
1037 AliError("No snapshot file is open!");
1040 AliCDBEntry *entry = dynamic_cast<AliCDBEntry*>(fSnapshotFile->Get(sPath.Data()));
1042 AliDebug(2,Form("Cannot get a CDB entry for \"%s\" from snapshot file",path));
1049 //_____________________________________________________________________________
1050 Bool_t AliCDBManager::SetSnapshotMode(const char* snapshotFileName) {
1051 // set the manager in snapshot mode
1054 AliError("Cannot set the CDB manage in snapshot mode if the cache is not active!");
1058 //open snapshot file
1059 TString snapshotFile(snapshotFileName);
1060 if(snapshotFile.BeginsWith("alien://")){
1062 TGrid::Connect("alien://","");
1064 AliError("Connection to alien failed!");
1070 fSnapshotFile = TFile::Open(snapshotFileName);
1071 if (!fSnapshotFile || fSnapshotFile->IsZombie()){
1072 AliError(Form("Cannot open file %s",snapshotFileName));
1076 AliInfo("The CDB manager is set in snapshot mode!");
1077 fSnapshotMode = kTRUE;
1082 //_____________________________________________________________________________
1083 const char* AliCDBManager::GetURI(const char* path) {
1084 // return the URI of the storage where to look for path
1086 if(!IsDefaultStorageSet()) return 0;
1088 AliCDBParam *aPar=SelectSpecificStorage(path);
1091 return aPar->GetURI().Data();
1094 return GetDefaultStorage()->GetURI().Data();
1100 //_____________________________________________________________________________
1101 Int_t AliCDBManager::GetStartRunLHCPeriod(){
1102 // get the first run of validity
1103 // for the current period
1105 if(fStartRunLHCPeriod==-1)
1106 AliWarning("Run-range not yet set for the current LHC period.");
1107 return fStartRunLHCPeriod;
1110 //_____________________________________________________________________________
1111 Int_t AliCDBManager::GetEndRunLHCPeriod(){
1112 // get the last run of validity
1113 // for the current period
1115 if(fEndRunLHCPeriod==-1)
1116 AliWarning("Run-range not yet set for the current LHC period.");
1117 return fEndRunLHCPeriod;
1120 //_____________________________________________________________________________
1121 TString AliCDBManager::GetLHCPeriod(){
1122 // get the current LHC period string
1124 if(fLHCPeriod.IsWhitespace() || fLHCPeriod.IsNull())
1125 AliWarning("LHC period (OCDB folder) not yet set");
1129 //_____________________________________________________________________________
1130 AliCDBId* AliCDBManager::GetId(const AliCDBPath& path, Int_t runNumber,
1131 Int_t version, Int_t subVersion) {
1132 // get the AliCDBId of the valid object from the database (does not retrieve the object)
1133 // User must delete returned object!
1136 // RunNumber is not specified. Try with fRun
1138 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
1144 return GetId(AliCDBId(path, runNumber, runNumber, version, subVersion));
1147 //_____________________________________________________________________________
1148 AliCDBId* AliCDBManager::GetId(const AliCDBPath& path,
1149 const AliCDBRunRange& runRange, Int_t version,
1151 // get the AliCDBId of the valid object from the database (does not retrieve the object)
1152 // User must delete returned object!
1154 return GetId(AliCDBId(path, runRange, version, subVersion));
1157 //_____________________________________________________________________________
1158 AliCDBId* AliCDBManager::GetId(const AliCDBId& query) {
1159 // get the AliCDBId of the valid object from the database (does not retrieve the object)
1160 // User must delete returned object!
1162 if(!fDefaultStorage) {
1163 AliError("No storage set!");
1167 // check if query's path and runRange are valid
1168 // query is invalid also if version is not specified and subversion is!
1169 if (!query.IsValid()) {
1170 AliError(Form("Invalid query: %s", query.ToString().Data()));
1174 // query is not specified if path contains wildcard or run range= [-1,-1]
1175 if (!query.IsSpecified()) {
1176 AliError(Form("Unspecified query: %s",
1177 query.ToString().Data()));
1181 if(fCache && query.GetFirstRun() != fRun)
1182 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
1184 AliCDBEntry* entry = 0;
1186 // first look into map of cached objects
1187 if(fCache && query.GetFirstRun() == fRun)
1188 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
1191 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
1192 return dynamic_cast<AliCDBId*> (entry->GetId().Clone());
1195 // Entry is not in cache -> retrieve it from CDB and cache it!!
1196 AliCDBStorage *aStorage=0;
1197 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
1200 aStorage=GetStorage(aPar);
1201 TString str = aPar->GetURI();
1202 AliDebug(2,Form("Looking into storage: %s",str.Data()));
1205 aStorage=GetDefaultStorage();
1206 AliDebug(2,"Looking into default storage");
1209 return aStorage->GetId(query);
1213 //_____________________________________________________________________________
1214 TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber,
1215 Int_t version, Int_t subVersion) {
1216 // get multiple AliCDBEntry objects from the database
1219 // RunNumber is not specified. Try with fRun
1221 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
1227 return GetAll(AliCDBId(path, runNumber, runNumber, version,
1231 //_____________________________________________________________________________
1232 TList* AliCDBManager::GetAll(const AliCDBPath& path,
1233 const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
1234 // get multiple AliCDBEntry objects from the database
1236 return GetAll(AliCDBId(path, runRange, version, subVersion));
1239 //_____________________________________________________________________________
1240 TList* AliCDBManager::GetAll(const AliCDBId& query) {
1241 // get multiple AliCDBEntry objects from the database
1242 // Warning: this method works correctly only for queries of the type "Detector/*"
1243 // and not for more specific queries e.g. "Detector/Calib/*" !
1244 // Warning #2: Entries are cached, but GetAll will keep on retrieving objects from OCDB!
1245 // To get an object from cache use Get() function
1247 if(!fDefaultStorage) {
1248 AliError("No storage set!");
1252 if (!query.IsValid()) {
1253 AliError(Form("Invalid query: %s", query.ToString().Data()));
1257 if((fSpecificStorages.GetEntries()>0) && query.GetPath().BeginsWith('*')){
1258 // if specific storages are active a query with "*" is ambiguous
1259 AliError("Query too generic in this context!");
1263 if (query.IsAnyRange()) {
1264 AliError(Form("Unspecified run or runrange: %s",
1265 query.ToString().Data()));
1269 if(fLock && query.GetFirstRun() != fRun)
1270 AliFatal("Lock is ON: cannot use different run number than the internal one!");
1272 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
1274 AliCDBStorage *aStorage;
1276 aStorage=GetStorage(aPar);
1277 AliDebug(2,Form("Looking into storage: %s", aPar->GetURI().Data()));
1280 aStorage=GetDefaultStorage();
1281 AliDebug(2,Form("Looking into default storage: %s", aStorage->GetURI().Data()));
1285 if(aStorage) result = aStorage->GetAll(query);
1286 if(!result) return 0;
1288 // loop on result to check whether entries should be re-queried with specific storages
1289 if(fSpecificStorages.GetEntries()>0 && ! (fSpecificStorages.GetEntries() == 1 && aPar)) {
1290 AliInfo("Now look into all other specific storages...");
1293 AliCDBEntry* chkEntry=0;
1295 while((chkEntry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
1296 AliCDBId& chkId = chkEntry->GetId();
1297 AliDebug(2, Form("Checking id %s ", chkId.GetPath().Data()));
1298 AliCDBParam *chkPar=SelectSpecificStorage(chkId.GetPath());
1299 if (!chkPar || aPar == chkPar) continue;
1300 AliCDBStorage *chkStorage = GetStorage(chkPar);
1301 AliDebug(2, Form("Found specific storage! %s", chkPar->GetURI().Data()));
1303 AliCDBEntry *newEntry=0;
1304 chkId.SetRunRange(query.GetFirstRun(), query.GetLastRun());
1305 chkId.SetVersion(query.GetVersion());
1306 chkId.SetSubVersion(query.GetSubVersion());
1308 if(chkStorage) newEntry = chkStorage->Get(chkId);
1309 if(!newEntry) continue;
1311 // object is found in specific storage: replace entry in the result list!
1312 chkEntry->SetOwner(1);
1313 delete result->Remove(chkEntry);
1314 result->AddFirst(newEntry);
1317 Int_t nEntries = result->GetEntries();
1318 AliInfo("After look into other specific storages, result list is:");
1319 for(int i=0; i<nEntries;i++){
1320 AliCDBEntry *entry = (AliCDBEntry*) result->At(i);
1321 AliInfo(Form("%s",entry->GetId().ToString().Data()));
1327 AliCDBEntry* entry=0;
1328 while((entry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
1330 if(!fIds->Contains(&entry->GetId())){
1331 fIds->Add(entry->GetId().Clone());
1333 if(fCache && (query.GetFirstRun() == fRun)){
1334 CacheEntry(entry->GetId().GetPath(), entry);
1342 //_____________________________________________________________________________
1343 Bool_t AliCDBManager::Put(TObject* object, const AliCDBId& id, AliCDBMetaData* metaData, const char* mirrors, DataType type){
1344 // store an AliCDBEntry object into the database
1347 AliError("Null Entry! No storage will be done!");
1351 AliCDBEntry anEntry(object, id, metaData);
1352 return Put(&anEntry, mirrors, type);
1357 //_____________________________________________________________________________
1358 Bool_t AliCDBManager::Put(AliCDBEntry* entry, const char* mirrors, DataType type){
1359 // store an AliCDBEntry object into the database
1361 if(type == kPrivate && !fDefaultStorage) {
1362 AliError("No storage set!");
1367 AliError("No entry!");
1371 if (entry->GetObject()==0x0){
1372 AliError("No valid object in CDB entry!");
1376 if (!entry->GetId().IsValid()) {
1377 AliError(Form("Invalid entry ID: %s",
1378 entry->GetId().ToString().Data()));
1382 if (!entry->GetId().IsSpecified()) {
1383 AliError(Form("Unspecified entry ID: %s",
1384 entry->GetId().ToString().Data()));
1388 AliCDBId id = entry->GetId();
1389 AliCDBParam *aPar = SelectSpecificStorage(id.GetPath());
1391 AliCDBStorage *aStorage=0;
1394 aStorage=GetStorage(aPar);
1398 aStorage = GetStorage(fCondParam);
1401 aStorage = GetStorage(fRefParam);
1404 aStorage = GetDefaultStorage();
1409 AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data()));
1411 TString strMirrors(mirrors);
1412 Bool_t result = kFALSE;
1413 if(!strMirrors.IsNull() && !strMirrors.IsWhitespace())
1414 result = aStorage->Put(entry, mirrors, type);
1416 result = aStorage->Put(entry, "", type);
1418 if(fRun >= 0) QueryCDB();
1425 //_____________________________________________________________________________
1426 void AliCDBManager::SetMirrorSEs(const char* mirrors) {
1427 // set mirror Storage Elements for the default storage, if it is of type "alien"
1428 if(fDefaultStorage->GetType() != "alien"){
1429 AliInfo("The default storage is not of type \"alien\". Settings for Storage Elements are not taken into account!");
1432 fDefaultStorage->SetMirrorSEs(mirrors);
1435 //_____________________________________________________________________________
1436 const char* AliCDBManager::GetMirrorSEs() const {
1437 // get mirror Storage Elements for the default storage, if it is of type "alien"
1438 if(fDefaultStorage->GetType() != "alien"){
1439 AliInfo("The default storage is not of type \"alien\". Settings for Storage Elements are not taken into account!");
1442 return fDefaultStorage->GetMirrorSEs();
1445 //_____________________________________________________________________________
1446 void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry) {
1447 // cache AliCDBEntry. Cache is valid until run number is changed.
1449 AliCDBEntry *chkEntry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(path));
1452 AliDebug(2, Form("Object %s already in cache !!", path));
1455 AliDebug(2,Form("Caching entry %s", path));
1458 fEntryCache.Add(new TObjString(path), entry);
1459 AliDebug(2,Form("Cache entries: %d", fEntryCache.GetEntries()));
1463 //_____________________________________________________________________________
1464 void AliCDBManager::Print(Option_t* /*option*/) const {
1465 // Print list of active storages and their URIs
1467 TString output=Form("Run number = %d; ",fRun);
1468 output += "Cache is ";
1469 if(!fCache) output += "NOT ";
1470 output += Form("ACTIVE; Number of active storages: %d\n",fActiveStorages.GetEntries());
1472 if(fDefaultStorage) {
1473 output += Form("\t*** Default Storage URI: \"%s\"\n",fDefaultStorage->GetURI().Data());
1474 // AliInfo(output.Data());
1476 if(fSpecificStorages.GetEntries()>0) {
1477 TIter iter(fSpecificStorages.GetTable());
1480 while((aPair = (TPair*) iter.Next())){
1481 output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n",
1482 i++, ((TObjString*) aPair->Key())->GetName(),
1483 ((AliCDBParam*) aPair->Value())->GetURI().Data());
1487 output += Form("*** Drain Storage URI: %s\n",fDrainStorage->GetURI().Data());
1489 AliInfo(output.Data());
1492 //_____________________________________________________________________________
1493 void AliCDBManager::SetRun(Int_t run) {
1494 // Sets current run number.
1495 // When the run number changes the caching is cleared.
1500 if(fLock && fRun >= 0) {
1501 AliFatal("Lock is ON, cannot reset run number!");
1507 // here the LHCPeriod xml file is parsed; the string containing the correct period is returned; the default storage is set
1508 if (fStartRunLHCPeriod <= run && fEndRunLHCPeriod >= run){
1509 AliInfo("LHCPeriod alien folder for current run already in memory");
1511 SetDefaultStorageFromRun(run);
1512 if(fEntryCache.GetEntries()!=0) ClearCache();
1520 //_____________________________________________________________________________
1521 void AliCDBManager::ClearCache(){
1522 // clear AliCDBEntry cache
1524 AliDebug(2, Form("Cache entries to be deleted: %d",fEntryCache.GetEntries()));
1527 // To clean entries one by one
1528 TIter iter(fEntryCache.GetTable());
1530 while((pair= dynamic_cast<TPair*> (iter.Next()))){
1532 TObjString* key = dynamic_cast<TObjString*> (pair->Key());
1533 AliCDBEntry* entry = dynamic_cast<AliCDBEntry*> (pair->Value());
1534 AliDebug(2, Form("Deleting entry: %s", key->GetName()));
1535 if (entry) delete entry;
1536 delete fEntryCache.Remove(key);
1539 fEntryCache.DeleteAll();
1540 AliDebug(2, Form("After deleting - Cache entries: %d",fEntryCache.GetEntries()));
1543 //_____________________________________________________________________________
1544 void AliCDBManager::UnloadFromCache(const char* path){
1545 // unload cached object
1546 // that is remove the entry from the cache and the id from the list of ids
1548 if(!fActiveStorages.GetEntries()) {
1549 AliDebug(2, Form("No active storages. Object \"%s\" is not unloaded from cache", path));
1553 AliCDBPath queryPath(path);
1554 if(!queryPath.IsValid()) return;
1556 if(!queryPath.IsWildcard()) { // path is not wildcard, get it directly from the cache and unload it!
1557 if(fEntryCache.Contains(path)){
1558 AliDebug(2, Form("Unloading object \"%s\" from cache and from list of ids", path));
1559 TObjString pathStr(path);
1560 delete fEntryCache.Remove(&pathStr);
1561 // we do not remove from the list of Id's (it's not very coherent but we leave the
1562 // id for the benefit of the userinfo)
1566 while((id = dynamic_cast<AliCDBId*> (iter.Next()))){
1567 if(queryPath.Comprises(id->GetPath()))
1568 delete fIds->Remove(id);
1571 AliWarning(Form("Cache does not contain object \"%s\"!", path));
1573 AliDebug(2, Form("Cache entries: %d",fEntryCache.GetEntries()));
1577 // path is wildcard: loop on the cache and unload all comprised objects!
1578 TIter iter(fEntryCache.GetTable());
1582 while((pair = dynamic_cast<TPair*> (iter.Next()))){
1583 AliCDBPath entryPath = pair->Key()->GetName();
1584 if(queryPath.Comprises(entryPath)) {
1585 AliDebug(2, Form("Unloading object \"%s\" from cache and from list of ids", entryPath.GetPath().Data()));
1586 TObjString pathStr(entryPath.GetPath());
1587 delete fEntryCache.Remove(&pathStr);
1590 // we do not remove from the list of Id's (it's not very coherent but we leave the
1591 // id for the benefit of the userinfo)
1593 TIter iterids(fIds);
1595 while((anId = dynamic_cast<AliCDBId*> (iterids.Next()))){
1596 AliCDBPath aPath = anId->GetPath();
1597 TString aPathStr = aPath.GetPath();
1598 if(queryPath.Comprises(aPath)) {
1599 delete fIds->Remove(anId);
1604 AliDebug(2,Form("Cache entries and ids removed: %d Remaining: %d",removed,fEntryCache.GetEntries()));
1607 //_____________________________________________________________________________
1608 void AliCDBManager::DestroyActiveStorages() {
1609 // delete list of active storages
1611 fActiveStorages.DeleteAll();
1612 fSpecificStorages.DeleteAll();
1615 //_____________________________________________________________________________
1616 void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
1617 // destroys active storage
1620 TIter iter(fActiveStorages.GetTable());
1622 while ((aPair = (TPair*) iter.Next())) {
1623 if(storage == (AliCDBStorage*) aPair->Value())
1624 delete fActiveStorages.Remove(aPair->Key());
1625 storage->Delete(); storage=0x0;
1631 //_____________________________________________________________________________
1632 void AliCDBManager::QueryCDB() {
1633 // query default and specific storages for files valid for fRun. Every storage loads the Ids into its list.
1636 AliError("Run number not yet set! Use AliCDBManager::SetRun.");
1639 if (!fDefaultStorage){
1640 AliError("Default storage is not set! Use AliCDBManager::SetDefaultStorage");
1643 if(fDefaultStorage->GetType() == "alien" || fDefaultStorage->GetType() == "local"){
1644 fDefaultStorage->QueryCDB(fRun);
1646 // AliDebug(2,"Skipping query for valid files, it used only in grid...");
1649 TIter iter(&fSpecificStorages);
1650 TObjString *aCalibType=0;
1651 AliCDBParam* aPar=0;
1652 while((aCalibType = dynamic_cast<TObjString*> (iter.Next()))){
1653 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
1655 AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName()));
1656 AliCDBStorage *aStorage = GetStorage(aPar);
1657 if(aStorage->GetType() == "alien" || aStorage->GetType() == "local"){
1658 aStorage->QueryCDB(fRun,aCalibType->GetName());
1661 "Skipping query for valid files, it is used only in grid...");
1667 //______________________________________________________________________________________________
1668 const char* AliCDBManager::GetDataTypeName(DataType type) {
1669 // returns the name (string) of the data type
1672 case kCondition: return "Conditions";
1673 case kReference: return "Reference";
1674 case kPrivate: return "Private";
1680 //______________________________________________________________________________________________
1681 Bool_t AliCDBManager::DiffObjects(const char *cdbFile1, const char *cdbFile2) const {
1682 // Compare byte-by-byte the objects contained in the CDB entry in two different files,
1683 // whose name is passed as input
1685 // kTRUE - in case the content of the OCDB object (persistent part) is exactly the same
1686 // kFALSE - otherwise
1688 TString f1Str(cdbFile1);
1689 TString f2Str(cdbFile2);
1690 if (!gGrid && ( f1Str.BeginsWith("alien://") || f2Str.BeginsWith("alien://") ))
1691 TGrid::Connect("alien://");
1693 TFile * f1 = TFile::Open(cdbFile1);
1695 Printf("Cannot open file \"%s\"",cdbFile1);
1698 TFile * f2 = TFile::Open(cdbFile2);
1700 Printf("Cannot open file \"%s\"",cdbFile2);
1704 AliCDBEntry * entry1 = (AliCDBEntry*)f1->Get("AliCDBEntry");
1706 Printf("Cannot get CDB entry from file \"%s\"",cdbFile1);
1709 AliCDBEntry * entry2 = (AliCDBEntry*)f2->Get("AliCDBEntry");
1711 Printf("Cannot get CDB entry from file \"%s\"",cdbFile2);
1715 // stream the two objects in the buffer of two TMessages
1716 TObject* object1 = entry1->GetObject();
1717 TObject* object2 = entry2->GetObject();
1718 TMessage * file1 = new TMessage(TBuffer::kWrite);
1719 file1->WriteObject(object1);
1720 Int_t size1 = file1->Length();
1721 TMessage * file2 = new TMessage(TBuffer::kWrite);
1722 file2->WriteObject(object2);
1723 Int_t size2 = file2->Length();
1725 Printf("Problem 2: OCDB entry of different size (%d,%d)",size1,size2);
1729 // if the two buffers have the same size, check that they are the same byte-by-byte
1731 char* buf1 = file1->Buffer();
1732 char* buf2 = file2->Buffer();
1733 //for (Int_t i=0; i<size1; i++) if (file1->Buffer()[i]!=file2->Buffer()[i]) countDiff++;
1734 for(Int_t i=0; i<size1; i++)
1735 if (buf1[i]!=buf2[i]) countDiff++;
1738 Printf("The CDB objects differ by %d bytes.", countDiff);
1742 Printf("The CDB objects are the same in the two files.");
1746 //______________________________________________________________________________________________
1747 void AliCDBManager::InitShortLived() {
1748 // Init the list of short-lived objects
1749 // currently disabled
1753 // fShortLived = new TList();
1754 // fShortLived->SetOwner(1);
1756 // fShortLived->Add(new TObjString("EMCAL/Calib/Data"));
1758 // fShortLived->Add(new TObjString("HMPID/Calib/Nmean"));
1759 // fShortLived->Add(new TObjString("HMPID/Calib/Qthre"));
1761 // fShortLived->Add(new TObjString("ITS/Calib/CalibSPD"));
1763 // fShortLived->Add(new TObjString("MUON/Calib/Gains"));
1764 // fShortLived->Add(new TObjString("MUON/Calib/HV"));
1765 // fShortLived->Add(new TObjString("MUON/Calib/Pedestals"));
1767 // fShortLived->Add(new TObjString("PHOS/Calib/CpvGainPedestals"));
1768 // fShortLived->Add(new TObjString("PHOS/Calib/EmcGainPedestals"));
1770 // fShortLived->Add(new TObjString("PMD/Calib/Data"));
1772 // fShortLived->Add(new TObjString("TRD/Calib/ChamberGainFactor"));
1773 // fShortLived->Add(new TObjString("TRD/Calib/LocalGainFactor"));
1774 // fShortLived->Add(new TObjString("TRD/Calib/ChamberT0"));
1775 // fShortLived->Add(new TObjString("TRD/Calib/LocalT0"));
1776 // fShortLived->Add(new TObjString("TRD/Calib/ChamberVdrift"));
1777 // fShortLived->Add(new TObjString("TRD/Calib/LocalVdrift"));
1779 // fShortLived->Add(new TObjString("ZDC/Calib/Data"));
1783 //______________________________________________________________________________________________
1784 Bool_t AliCDBManager::IsShortLived(const char* path) {
1785 // returns the name (string) of the data type
1787 if(!fShortLived) return kFALSE;
1789 AliCDBPath aPath(path);
1790 if(!aPath.IsValid()){
1791 AliError(Form("Not a valid path: %s", path));
1795 return fShortLived->Contains(path);
1799 //______________________________________________________________________________________________
1800 ULong64_t AliCDBManager::SetLock(Bool_t lock, ULong64_t key){
1801 // To lock/unlock user must provide the key. A new key is provided after
1802 // each successful lock. User should always backup the returned key and
1803 // use it on next access.
1804 if (fLock == lock) return 0; // nothing to be done
1806 // User wants to lock - check his identity
1808 // Lock has a user - check his key
1810 AliFatal("Wrong key provided to lock CDB. Please remove CDB lock access from your code !");
1815 fKey = gSystem->Now();
1819 // User wants to unlock - check the provided key
1821 AliFatal("Lock is ON: wrong key provided");
1828 ///////////////////////////////////////////////////////////
1829 // AliCDBManager Parameter class //
1830 // interface to specific AliCDBParameter class //
1831 // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) //
1832 ///////////////////////////////////////////////////////////
1834 AliCDBParam::AliCDBParam():
1842 //_____________________________________________________________________________
1843 AliCDBParam::~AliCDBParam() {