LCOV - code coverage report
Current view: top level - STEER/CDB - AliCDBManager.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 339 987 34.3 %
Date: 2016-06-14 17:26:59 Functions: 40 86 46.5 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       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             : //-------------------------------------------------------------------------
      20             : 
      21             : #include <fstream>
      22             : 
      23             : #include "AliCDBManager.h"
      24             : #include "AliCDBStorage.h"
      25             : #include "AliLog.h"
      26             : #include "AliCDBDump.h"
      27             : #include "AliCDBLocal.h"
      28             : #include "AliCDBGrid.h"
      29             : #include "AliCDBEntry.h"
      30             : #include "AliCDBHandler.h"
      31             : 
      32             : #include <TObjString.h>
      33             : #include <TSAXParser.h>
      34             : #include <TFile.h>
      35             : #include <TKey.h>
      36             : #include <TUUID.h>
      37             : #include <TGrid.h>
      38             : #include "TMessage.h"
      39             : #include "TObject.h"
      40             : #include "TRegexp.h"
      41             : 
      42         128 : ClassImp(AliCDBParam)
      43             : 
      44         128 : ClassImp(AliCDBManager)
      45             : 
      46             : //TODO OCDB and Reference folder should not be fully hardcoded but built from run number (or year/LHC period)
      47         128 : TString AliCDBManager::fgkCondUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/CDB?user=aliprod");
      48         128 : TString AliCDBManager::fgkRefUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/Reference?user=aliprod");
      49         128 : TString AliCDBManager::fgkMCIdealStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Ideal");
      50         128 : TString AliCDBManager::fgkMCFullStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Full");
      51         128 : TString AliCDBManager::fgkMCResidualStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Residual");
      52         128 : TString AliCDBManager::fgkOCDBFolderXMLfile("alien:///alice/data/OCDBFoldervsRunRange.xml");
      53             : AliCDBManager* AliCDBManager::fgInstance = 0x0;
      54             : 
      55             : //_____________________________________________________________________________
      56             : AliCDBManager* AliCDBManager::Instance(TMap *entryCache, Int_t run) {
      57             : // returns AliCDBManager instance (singleton)
      58             : 
      59        7142 :   if (!fgInstance) {
      60          10 :     fgInstance = new AliCDBManager();
      61           5 :     if (!entryCache)
      62           5 :       fgInstance->Init();
      63             :     else
      64           0 :       fgInstance->InitFromCache(entryCache,run);
      65             :   }
      66             : 
      67        3571 :   return fgInstance;
      68           0 : }
      69             : 
      70             : //_____________________________________________________________________________
      71             : void AliCDBManager::Init() {
      72             : // factory registering
      73             : 
      74          24 :   RegisterFactory(new AliCDBDumpFactory());
      75          16 :   RegisterFactory(new AliCDBLocalFactory());
      76             :   // AliCDBGridFactory is registered only if AliEn libraries are enabled in Root
      77           8 :   if(!gSystem->Exec("root-config --has-alien 2>/dev/null |grep yes 2>&1 > /dev/null")){ // returns 0 if yes
      78           8 :     AliInfo("AliEn classes enabled in Root. AliCDBGrid factory registered.");
      79          16 :     RegisterFactory(new AliCDBGridFactory());
      80           8 :     fCondParam = CreateParameter(fgkCondUri);
      81           8 :     fRefParam = CreateParameter(fgkRefUri);
      82           8 :   }
      83             : 
      84           8 :   InitShortLived();
      85           8 : }
      86             : 
      87             : //_____________________________________________________________________________
      88             : void AliCDBManager::InitFromCache(TMap *entryCache, Int_t run) {
      89             : // initialize manager from existing cache
      90             : // used on the slaves in case of parallel reconstruction
      91           0 :   SetRun(run);
      92             : 
      93           0 :   TIter iter(entryCache->GetTable());
      94             :   TPair* pair = 0;
      95             : 
      96           0 :   while((pair = dynamic_cast<TPair*> (iter.Next()))){
      97           0 :     fEntryCache.Add(pair->Key(),pair->Value());
      98             :   }
      99             :   // fEntry is the new owner of the cache
     100           0 :   fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
     101           0 :   entryCache->SetOwnerKeyValue(kFALSE,kFALSE);
     102           0 :   AliInfo(Form("%d cache entries have been loaded",fEntryCache.GetEntries()));
     103           0 : }
     104             : 
     105             : //_____________________________________________________________________________
     106             : void  AliCDBManager::DumpToSnapshotFile(const char* snapshotFileName, Bool_t singleKeys) const {
     107             : //
     108             : // If singleKeys is true, dump the entries map and the ids list to the snapshot file
     109             : // (provided mostly for historical reasons, the file is then read with InitFromSnapshot),
     110             : // otherwise write to file each AliCDBEntry separately (the is the preferred way, the file
     111             : // is then read with SetSnapshotMode).
     112             : 
     113             :   // open the file
     114           0 :   TFile *f = TFile::Open(snapshotFileName,"RECREATE");
     115           0 :   if (!f || f->IsZombie()){
     116           0 :     AliError(Form("Cannot open file %s",snapshotFileName));
     117           0 :     return;
     118             :   }
     119             : 
     120           0 :   AliInfo(Form("Dumping entriesMap (entries'cache) with %d entries!\n", fEntryCache.GetEntries()));
     121           0 :   AliInfo(Form("Dumping entriesList with %d entries!\n", fIds->GetEntries()));
     122             : 
     123           0 :   f->cd();
     124           0 :   if(singleKeys){
     125           0 :     f->WriteObject(&fEntryCache,"CDBentriesMap");
     126           0 :     f->WriteObject(fIds,"CDBidsList");
     127           0 :   }else{
     128             :     // We write the entries one by one named by their calibration path
     129           0 :     TIter iter(fEntryCache.GetTable());
     130             :     TPair* pair = 0;
     131           0 :     while((pair = dynamic_cast<TPair*> (iter.Next()))){
     132           0 :       TObjString *os = dynamic_cast<TObjString*>(pair->Key());
     133           0 :       if (!os) continue;
     134           0 :       TString path = os->GetString();
     135           0 :       AliCDBEntry *entry = dynamic_cast<AliCDBEntry*>(pair->Value());
     136           0 :       if (!entry) continue;
     137           0 :       path.ReplaceAll("/","*");
     138           0 :       entry->Write(path.Data());
     139           0 :     }
     140           0 :   }
     141           0 :   f->Close();
     142           0 :   delete f;
     143           0 : }
     144             : 
     145             : //_____________________________________________________________________________
     146             : void  AliCDBManager::DumpToLightSnapshotFile(const char* lightSnapshotFileName) const {
     147             : // The light snapshot does not contain the CDB objects (AliCDBEntries) but
     148             : // only the information identifying them, that is the map of storages and
     149             : // the list of AliCDBIds, as in the UserInfo of AliESDs.root
     150             : 
     151             :   // open the file
     152           0 :   TFile *f = TFile::Open(lightSnapshotFileName,"RECREATE");
     153           0 :   if (!f || f->IsZombie()){
     154           0 :     AliError(Form("Cannot open file %s",lightSnapshotFileName));
     155           0 :     return;
     156             :   }
     157             : 
     158           0 :   AliInfo(Form("Dumping map of storages with %d entries!\n", fStorageMap->GetEntries()));
     159           0 :   AliInfo(Form("Dumping entriesList with %d entries!\n", fIds->GetEntries()));
     160           0 :   f->WriteObject(fStorageMap,"cdbStoragesMap");
     161           0 :   f->WriteObject(fIds,"CDBidsList");
     162             : 
     163           0 :   f->Close();
     164           0 :   delete f;
     165           0 : }
     166             : 
     167             : //_____________________________________________________________________________
     168             : Bool_t AliCDBManager::InitFromSnapshot(const char* snapshotFileName, Bool_t overwrite){
     169             : // initialize manager from a CDB snapshot, that is add the entries
     170             : // to the entries map and the ids to the ids list taking them from
     171             : // the map and the list found in the input file
     172             : 
     173             :   // if the manager is locked it cannot initialize from a snapshot
     174           0 :   if(fLock) {
     175           0 :     AliError("Being locked I cannot initialize from the snapshot!");
     176           0 :     return kFALSE;
     177             :   }     
     178             : 
     179             :   // open the file
     180           0 :   TString snapshotFile(snapshotFileName);
     181           0 :   if(snapshotFile.BeginsWith("alien://")){
     182           0 :     if(!gGrid) {
     183           0 :       TGrid::Connect("alien://","");
     184           0 :       if(!gGrid) {
     185           0 :         AliError("Connection to alien failed!");
     186           0 :         return kFALSE;
     187             :       }
     188             :     }
     189             :   }
     190             : 
     191           0 :   TFile *f = TFile::Open(snapshotFileName);
     192           0 :   if (!f || f->IsZombie()){
     193           0 :     AliError(Form("Cannot open file %s",snapshotFileName));
     194           0 :     return kFALSE;
     195             :   }
     196             : 
     197             :   // retrieve entries' map from snapshot file
     198             :   TMap *entriesMap = 0;
     199           0 :   TIter next(f->GetListOfKeys());
     200             :   TKey *key;
     201           0 :   while ((key = (TKey*)next())) {
     202           0 :     if (strcmp(key->GetClassName(),"TMap") != 0) continue;
     203           0 :     entriesMap = (TMap*)key->ReadObj();
     204           0 :     break;
     205             :   }
     206           0 :   if (!entriesMap || entriesMap->GetEntries()==0){
     207           0 :     AliError("Cannot get valid map of CDB entries from snapshot file");
     208           0 :     return kFALSE;
     209             :   }
     210             : 
     211             :   // retrieve ids' list from snapshot file
     212             :   TList *idsList = 0;
     213           0 :   TIter nextKey(f->GetListOfKeys());
     214             :   TKey *keyN;
     215           0 :   while ((keyN = (TKey*)nextKey())) {
     216           0 :     if (strcmp(keyN->GetClassName(),"TList") != 0) continue;
     217           0 :     idsList = (TList*)keyN->ReadObj();
     218           0 :     break;
     219             :   }
     220           0 :   if (!idsList || idsList->GetEntries()==0){
     221           0 :     AliError("Cannot get valid list of CDB entries from snapshot file");
     222           0 :     return kFALSE;
     223             :   }
     224             : 
     225             :   // Add each (entry,id) from the snapshot to the memory: entry to the cache, id to the list of ids.
     226             :   // If "overwrite" is false: add the entry to the cache and its id to the list of ids
     227             :   // only if neither of them is already there.
     228             :   // If "overwrite" is true: write the snapshot entry,id in any case. If something
     229             :   // was already there for that calibration type, remove it and issue a warning
     230           0 :   TIter iterObj(entriesMap->GetTable());
     231             :   TPair* pair = 0;
     232             :   Int_t nAdded=0;
     233           0 :   while((pair = dynamic_cast<TPair*> (iterObj.Next()))){
     234           0 :     TObjString* os = (TObjString*) pair->Key();
     235           0 :     TString path = os->GetString();
     236           0 :     TIter iterId(idsList);
     237             :     AliCDBId* id=0;
     238             :     AliCDBId* correspondingId=0;
     239           0 :     while((id = dynamic_cast<AliCDBId*> (iterId.Next()))){
     240           0 :       TString idpath(id->GetPath());
     241           0 :       if(idpath==path){
     242             :         correspondingId=id;
     243           0 :         break;
     244             :       }
     245           0 :     }
     246           0 :     if(!correspondingId){
     247           0 :       AliError(Form("id for \"%s\" not found in the snapshot (while entry was). This entry is skipped!",path.Data()));
     248           0 :       break;
     249             :     }
     250           0 :     Bool_t cached = fEntryCache.Contains(path.Data());
     251             :     Bool_t registeredId = kFALSE;
     252           0 :     TIter iter(fIds);
     253             :     AliCDBId *idT = 0;
     254           0 :     while((idT = dynamic_cast<AliCDBId*> (iter.Next()))){
     255           0 :       if(idT->GetPath()==path){
     256             :         registeredId = kTRUE;
     257           0 :         break;
     258             :       }
     259             :     }
     260             : 
     261           0 :     if(overwrite){
     262           0 :       if(cached || registeredId){
     263           0 :         AliWarning(Form("An entry was already cached for \"%s\". Removing it before caching from snapshot",path.Data()));
     264           0 :         UnloadFromCache(path.Data());
     265             :       }
     266           0 :       fEntryCache.Add(pair->Key(),pair->Value());
     267           0 :       fIds->Add(id);
     268           0 :       nAdded++;
     269           0 :     }else{
     270           0 :       if(cached || registeredId){
     271           0 :         AliWarning(Form("An entry was already cached for \"%s\". Not adding this object from snapshot",path.Data()));
     272             :       }else{
     273           0 :         fEntryCache.Add(pair->Key(),pair->Value());
     274           0 :         fIds->Add(id);
     275           0 :         nAdded++;
     276             :       }
     277             :     }
     278           0 :   }
     279             : 
     280             :   // fEntry is the new owner of the cache
     281           0 :   fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
     282           0 :   entriesMap->SetOwnerKeyValue(kFALSE,kFALSE);
     283           0 :   fIds->SetOwner(kTRUE);
     284           0 :   idsList->SetOwner(kFALSE);
     285           0 :   AliInfo(Form("%d new (entry,id) cached. Total number %d",nAdded,fEntryCache.GetEntries()));
     286             : 
     287           0 :   f->Close();
     288           0 :   delete f;
     289             : 
     290             :   return kTRUE;
     291           0 : }
     292             : 
     293             : //_____________________________________________________________________________
     294             : void AliCDBManager::Destroy() {
     295             : // delete ALCDBManager instance and active storages
     296             : 
     297           0 :   if (fgInstance) {
     298             :     //fgInstance->Delete();
     299           0 :     delete fgInstance;
     300           0 :     fgInstance = 0x0;
     301           0 :   }
     302           0 : }
     303             : 
     304             : //_____________________________________________________________________________
     305             : AliCDBManager::AliCDBManager():
     306           8 :   TObject(),
     307           8 :   fFactories(),
     308           8 :   fActiveStorages(),
     309           8 :   fSpecificStorages(),
     310           8 :   fEntryCache(),
     311           8 :   fPromptEntryCache(),
     312           8 :   fIds(0),
     313           8 :   fStorageMap(0),
     314           8 :   fShortLived(0),
     315           8 :   fDefaultStorage(NULL),
     316           8 :   fDrainStorage(NULL),
     317           8 :   fCondParam(0),
     318           8 :   fRefParam(0),
     319           8 :   fRun(-1),
     320           8 :   fCache(kTRUE),
     321           8 :   fPromptCache(kFALSE),
     322           8 :   fLock(kFALSE),
     323           8 :   fSnapshotMode(kFALSE),
     324           8 :   fSnapshotFile(0),
     325           8 :   fOCDBUploadMode(kFALSE),
     326           8 :   fRaw(kFALSE),
     327           8 :   fCvmfsOcdb(""),
     328           8 :   fStartRunLHCPeriod(-1),
     329           8 :   fEndRunLHCPeriod(-1),
     330           8 :   fLHCPeriod(""),
     331           8 :   fKey(0)
     332          34 : {
     333             :   // default constuctor
     334           8 :   fFactories.SetOwner(1);
     335           8 :   fActiveStorages.SetOwner(1);
     336           8 :   fSpecificStorages.SetOwner(1);
     337           8 :   fEntryCache.SetName("CDBEntryCache");
     338           8 :   fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
     339           8 :   fPromptEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
     340             : 
     341          24 :   fStorageMap = new TMap();
     342           8 :   fStorageMap->SetOwner(1);
     343          24 :   fIds = new TList();
     344           8 :   fIds->SetOwner(1);
     345          13 : }
     346             : 
     347             : //_____________________________________________________________________________
     348           2 : AliCDBManager::~AliCDBManager() {
     349             : // destructor
     350           1 :   ClearCache();
     351           1 :   ClearPromptCache();
     352           1 :   DestroyActiveStorages();
     353           1 :   fFactories.Delete();
     354           1 :   fDrainStorage = 0x0;
     355           1 :   fDefaultStorage = 0x0;
     356           3 :   delete fStorageMap; fStorageMap = 0;
     357           3 :   delete fIds; fIds = 0;
     358           2 :   delete fCondParam;
     359           2 :   delete fRefParam;
     360           2 :   delete fShortLived; fShortLived = 0x0;
     361             :   //fSnapshotCache = 0;
     362             :   //fSnapshotIdsList = 0;
     363           1 :   if(fSnapshotMode){
     364           0 :     fSnapshotFile->Close();
     365           0 :     fSnapshotFile = 0;
     366           0 :   }
     367           1 : }
     368             : 
     369             : //_____________________________________________________________________________
     370             : void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){
     371             : // put a storage object into the list of active storages
     372             : 
     373          24 :   fActiveStorages.Add(param, storage);
     374          36 :   AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries()));
     375          12 : }
     376             : 
     377             : //_____________________________________________________________________________
     378             : void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) {
     379             : // add a storage factory to the list of registerd factories
     380             : 
     381          48 :   if (!fFactories.Contains(factory)) {
     382          24 :     fFactories.Add(factory);
     383          24 :   }
     384          24 : }
     385             : 
     386             : //_____________________________________________________________________________
     387             : Bool_t AliCDBManager::HasStorage(const char* dbString) const {
     388             : // check if dbString is a URI valid for one of the registered factories
     389             : 
     390           0 :   TIter iter(&fFactories);
     391             : 
     392             :   AliCDBStorageFactory* factory=0;
     393           0 :   while ((factory = (AliCDBStorageFactory*) iter.Next())) {
     394             : 
     395           0 :     if (factory->Validate(dbString)) {
     396           0 :       return kTRUE;
     397             :     }
     398             :   }
     399             : 
     400           0 :   return kFALSE;
     401           0 : }
     402             : 
     403             : //_____________________________________________________________________________
     404             : AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
     405             : // create AliCDBParam object from URI string
     406             : 
     407          58 :   TString uriString(dbString);
     408             : 
     409          58 :   if ( !fCvmfsOcdb.IsNull() && uriString.BeginsWith("alien://")) {
     410           0 :     AlienToCvmfsUri(uriString);
     411             :   }
     412             : 
     413          29 :   TIter iter(&fFactories);
     414             : 
     415             :   AliCDBStorageFactory* factory=0;
     416         177 :   while ((factory = (AliCDBStorageFactory*) iter.Next())) {
     417         148 :     AliCDBParam* param = factory->CreateParameter(uriString);
     418         103 :     if(param) return param;
     419          45 :   }
     420             : 
     421           0 :   return NULL;
     422          29 : }
     423             : 
     424             : //_____________________________________________________________________________
     425             : void AliCDBManager::AlienToCvmfsUri(TString& uriString) const {
     426             : // convert alien storage uri to local:///cvmfs storage uri (called when OCDB_PATH is set)
     427             : 
     428           0 :   TObjArray *arr = uriString.Tokenize('?');
     429           0 :   TIter iter(arr);
     430             :   TObjString *str = 0;
     431           0 :   TString entryKey = "";
     432           0 :   TString entryValue  = "";
     433           0 :   TString newUriString = "";
     434           0 :   while((str = (TObjString*) iter.Next())){
     435           0 :     TString entry(str->String());
     436           0 :     Int_t indeq = entry.Index('=');
     437           0 :     entryKey = entry(0, indeq+1);
     438           0 :     entryValue = entry(indeq+1, entry.Length()-indeq);
     439             : 
     440           0 :     if ( entryKey.Contains("folder", TString::kIgnoreCase) )
     441             :     {
     442             : 
     443           0 :       TRegexp re_RawFolder("^/alice/data/20[0-9]+/OCDB");
     444           0 :       TRegexp re_MCFolder("^/alice/simulation/2008/v4-15-Release");
     445           0 :       TString rawFolder = entryValue(re_RawFolder);
     446           0 :       TString mcFolder = entryValue(re_MCFolder);
     447           0 :       if ( !rawFolder.IsNull() ){
     448           0 :         entryValue.Replace(0, 6, "/cvmfs/alice-ocdb.cern.ch/calibration");
     449             :         //entryValue.Replace(entryValue.Length()-4, entryValue.Length(), "");
     450           0 :       } else if ( !mcFolder.IsNull() ){
     451           0 :         entryValue.Replace(0,36,"/cvmfs/alice-ocdb.cern.ch/calibration/MC");
     452             :       } else {
     453           0 :         AliFatal(Form("Environment variable for cvmfs OCDB folder set for an invalid OCDB storage:\n   %s", entryValue.Data()));
     454             :       }
     455           0 :     } else {
     456           0 :       newUriString += entryKey;
     457             :     }
     458           0 :     newUriString += entryValue;
     459           0 :     newUriString += '?';
     460           0 :   }
     461           0 :   newUriString.Prepend("local://");
     462           0 :   newUriString.Remove(TString::kTrailing, '?');
     463           0 :   uriString = newUriString;
     464           0 : }
     465             : 
     466             : //_____________________________________________________________________________
     467             : AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) {
     468             : // Get the CDB storage corresponding to the URI string passed as argument
     469             : // If "raw://" is passed, get the storage for the raw OCDB for the current run (fRun)
     470             : 
     471          16 :   TString uriString(dbString);
     472          16 :   if (uriString.EqualTo("raw://")) {
     473           0 :     if (!fLHCPeriod.IsNull() && !fLHCPeriod.IsWhitespace()) {
     474           0 :       return GetDefaultStorage();
     475             :     } else {
     476           0 :       TString lhcPeriod("");
     477           0 :       Int_t startRun = -1, endRun = -1;
     478           0 :       GetLHCPeriodAgainstAlienFile(fRun, lhcPeriod, startRun, endRun);
     479           0 :       return GetStorage(lhcPeriod.Data());
     480           0 :     }
     481             :   }
     482             : 
     483           8 :   AliCDBParam* param = CreateParameter(dbString);
     484           8 :   if (!param) {
     485           0 :     AliError(Form("Failed to activate requested storage! Check URI: %s", dbString));
     486           0 :     return NULL;
     487             :   }
     488             : 
     489           8 :   AliCDBStorage* aStorage = GetStorage(param);
     490             : 
     491          16 :   delete param;
     492             :   return aStorage;
     493           8 : }
     494             : 
     495             : //_____________________________________________________________________________
     496             : AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) {
     497             : // get storage object from AliCDBParam object
     498             : 
     499             :   // if the list of active storages already contains
     500             :   // the requested storage, return it
     501          70 :   AliCDBStorage* aStorage = GetActiveStorage(param);
     502          35 :   if (aStorage) {
     503          23 :     return aStorage;
     504             :   }
     505             : 
     506             :   // if lock is ON, cannot activate more storages!
     507          12 :   if(fLock) {
     508           0 :     if (fDefaultStorage) {
     509           0 :       AliFatal("Lock is ON, and default storage is already set: "
     510             :           "cannot reset it or activate more storages!");
     511           0 :     }
     512             :   }     
     513             : 
     514             :   // loop on the list of registered factories
     515          12 :   TIter iter(&fFactories);
     516             :   AliCDBStorageFactory* factory=0;
     517          60 :   while ((factory = (AliCDBStorageFactory*) iter.Next())) {
     518             : 
     519             :     // each factory tries to create its storage from the parameter
     520          24 :     aStorage = factory->Create(param);
     521          24 :     if (aStorage) {
     522          24 :       PutActiveStorage(param->CloneParam(), aStorage);
     523          12 :       aStorage->SetURI(param->GetURI());
     524          12 :       if(fRun >= 0) {
     525           0 :         if( aStorage->GetType() == "alien" || aStorage->GetType() == "local" )
     526           0 :           aStorage->QueryCDB(fRun);
     527             :       }
     528          12 :       return aStorage;
     529             :     }
     530             :   }
     531             : 
     532           0 :   AliError(Form("Failed to activate requested storage! Check URI: %s", param->GetURI().Data()));
     533             : 
     534           0 :   return NULL;
     535          47 : }
     536             : 
     537             : //_____________________________________________________________________________
     538             : AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) {
     539             : // get a storage object from the list of active storages
     540             : 
     541         128 :   return dynamic_cast<AliCDBStorage*> (fActiveStorages.GetValue(param));
     542             : }
     543             : 
     544             : //_____________________________________________________________________________
     545             : TList* AliCDBManager::GetActiveStorages() {
     546             : // return list of active storages
     547             : // user has responsibility to delete returned object
     548             : 
     549           0 :   TList* result = new TList();
     550             : 
     551           0 :   TIter iter(fActiveStorages.GetTable());
     552             :   TPair* aPair=0;
     553           0 :   while ((aPair = (TPair*) iter.Next())) {
     554           0 :     result->Add(aPair->Value());
     555             :   }
     556             : 
     557             :   return result;
     558           0 : }
     559             : 
     560             : //_____________________________________________________________________________
     561             : void AliCDBManager::SetDrain(const char* dbString) {
     562             : // set drain storage from URI string
     563             : 
     564           0 :   fDrainStorage = GetStorage(dbString); 
     565           0 : }
     566             : 
     567             : //_____________________________________________________________________________
     568             : void AliCDBManager::SetDrain(const AliCDBParam* param) {
     569             : // set drain storage from AliCDBParam
     570             : 
     571           0 :   fDrainStorage = GetStorage(param);
     572           0 : }
     573             : 
     574             : //_____________________________________________________________________________
     575             : void AliCDBManager::SetDrain(AliCDBStorage* storage) {
     576             : // set drain storage from another active storage
     577             : 
     578           0 :   fDrainStorage = storage;
     579           0 : }
     580             : 
     581             : //_____________________________________________________________________________
     582             : Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
     583             : // drain retrieved object to drain storage
     584             : 
     585           0 :   AliDebug(2, "Draining into drain storage...");
     586           0 :   return fDrainStorage->Put(entry);
     587             : }
     588             : 
     589             : //____________________________________________________________________________
     590             : Bool_t AliCDBManager::SetOCDBUploadMode() {
     591             : // Set the framework in official upload mode. This tells the framework to upload
     592             : // objects to cvmfs after they have been uploaded to AliEn OCDBs.
     593             : // It return false if the executable to upload to cvmfs is not found.
     594             : 
     595           0 :   TString cvmfsUploadExecutable("$HOME/bin/ocdb-cvmfs");
     596           0 :   gSystem->ExpandPathName(cvmfsUploadExecutable);
     597           0 :   if ( gSystem->AccessPathName(cvmfsUploadExecutable) )
     598           0 :     return kFALSE;
     599           0 :   fOCDBUploadMode = kTRUE;
     600           0 :   return kTRUE;
     601           0 : }
     602             : 
     603             : //____________________________________________________________________________
     604             : void AliCDBManager::SetDefaultStorage(const char* storageUri) {
     605             : // sets default storage from URI string
     606             : 
     607             :   // if in the cvmfs case (triggered by environment variable) check for path validity
     608             :   // and modify Uri if it is "raw://"
     609          14 :   TString cvmfsOcdb(gSystem->Getenv("OCDB_PATH"));
     610          14 :   if (! cvmfsOcdb.IsNull()){
     611           0 :     fCvmfsOcdb = cvmfsOcdb;
     612           0 :     ValidateCvmfsCase();
     613             :   }
     614             : 
     615             :   // checking whether we are in the raw case
     616           7 :   TString uriTemp(storageUri);
     617          14 :   if (uriTemp == "raw://") {
     618           0 :     fRaw = kTRUE; // read then by SetRun to check if the method has to be called again with expanded uri
     619           0 :     AliInfo("Setting the run-number will set the corresponding OCDB for raw data reconstruction.");
     620           0 :     return;
     621             :   }
     622             : 
     623           7 :   AliCDBStorage* bckStorage = fDefaultStorage;
     624             : 
     625          14 :   fDefaultStorage = GetStorage(storageUri);
     626             : 
     627           7 :   if(!fDefaultStorage) return;
     628             : 
     629           7 :   if(bckStorage && (fDefaultStorage != bckStorage)){
     630           0 :     AliWarning("Existing default storage replaced: clearing cache!");
     631           0 :     ClearCache();
     632             :   }
     633             : 
     634          14 :   if (fStorageMap->Contains("default")) {
     635           0 :     delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
     636             :   }
     637          42 :   fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
     638          14 : }
     639             : 
     640             : //_____________________________________________________________________________
     641             : void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
     642             : // set default storage from AliCDBParam object
     643             : 
     644           0 :   AliCDBStorage* bckStorage = fDefaultStorage;
     645             : 
     646           0 :   fDefaultStorage = GetStorage(param);
     647             : 
     648           0 :   if(!fDefaultStorage) return;
     649             : 
     650           0 :   if(bckStorage && (fDefaultStorage != bckStorage)){
     651           0 :     AliWarning("Existing default storage replaced: clearing cache!");
     652           0 :     ClearCache();
     653           0 :   }
     654             : 
     655           0 :   if (fStorageMap->Contains("default")) {
     656           0 :     delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
     657             :   }
     658           0 :   fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
     659           0 : }
     660             : 
     661             : //_____________________________________________________________________________
     662             : void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
     663             : // set default storage from another active storage
     664             : 
     665             :   // if lock is ON, cannot activate more storages!
     666           0 :   if(fLock) {
     667           0 :     if (fDefaultStorage) {
     668           0 :       AliFatal("Lock is ON, and default storage is already set: "
     669             :           "cannot reset it or activate more storages!");
     670           0 :     }
     671             :   }     
     672             : 
     673           0 :   if (!storage) {
     674           0 :     UnsetDefaultStorage();
     675           0 :     return;
     676             :   }
     677             : 
     678           0 :   AliCDBStorage* bckStorage = fDefaultStorage;
     679             : 
     680           0 :   fDefaultStorage = storage;
     681             : 
     682           0 :   if(bckStorage && (fDefaultStorage != bckStorage)){
     683           0 :     AliWarning("Existing default storage replaced: clearing cache!");
     684           0 :     ClearCache();
     685           0 :   }
     686             : 
     687           0 :   if (fStorageMap->Contains("default")) {
     688           0 :     delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
     689             :   }
     690           0 :   fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
     691           0 : }
     692             : 
     693             : //_____________________________________________________________________________
     694             : void AliCDBManager::SetDefaultStorage(const char* mcString, const char* simType) {
     695             : // sets default storage for MC data
     696             : // mcString MUST be "MC",
     697             : // simType can be "Ideal","Residual","Full"
     698             : 
     699           0 :   TString strmcString(mcString);
     700           0 :   TString strsimType(simType);
     701           0 :   TString dbString;
     702           0 :   if (strmcString != "MC"){
     703           0 :     AliFatal("Method requires first string to be MC!");
     704             :   }
     705             :   else {
     706           0 :     if (strsimType == "Ideal"){
     707           0 :       dbString = fgkMCIdealStorage;
     708             :     }
     709           0 :     else if (strsimType == "Full"){
     710           0 :       dbString = fgkMCFullStorage;
     711             :     }
     712           0 :     else if (strsimType == "Residual"){
     713           0 :       dbString = fgkMCResidualStorage;
     714             :     }
     715             :     else {
     716           0 :       AliFatal("Error in setting the storage for MC data, second argument MUST be either \"Ideal\" or \"Full\" or \"Residual\".");
     717             :     }
     718             : 
     719           0 :     SetDefaultStorage(dbString.Data());
     720           0 :     fStartRunLHCPeriod=0;
     721           0 :     fEndRunLHCPeriod=AliCDBRunRange::Infinity();
     722           0 :     if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",dbString.Data()));
     723             :   }
     724           0 : }
     725             : 
     726             : //_____________________________________________________________________________
     727             : void AliCDBManager::ValidateCvmfsCase() const {
     728             :   // The OCDB_PATH variable contains the path to the directory in /cvmfs/ which is
     729             :   // an AliRoot tag based snapshot of the AliEn file catalogue (e.g. 
     730             :   // /cvmfs/alice.cern.ch/x86_64-2.6-gnu-4.1.2/Packages/OCDB/v5-05-76-AN).
     731             :   // The directory has to contain:
     732             :   // 1) <data|MC>/20??.list.gz gzipped text files listing the OCDB files (seen by that AliRoot tag)
     733             :   // 2) bin/getOCDBFilesPerRun.sh   (shell+awk) script extracting from 1) the list
     734             :   //    of valid files for the given run.
     735             : 
     736           0 :     if (! fCvmfsOcdb.BeginsWith("/cvmfs"))  //!!!! to be commented out for testing
     737           0 :       AliFatal(Form("OCDB_PATH set to an invalid path: %s", fCvmfsOcdb.Data()));
     738             : 
     739           0 :     TString cvmfsUri(fCvmfsOcdb);
     740           0 :     gSystem->ExpandPathName(cvmfsUri);
     741           0 :     if (gSystem->AccessPathName(cvmfsUri))
     742           0 :       AliFatal(Form("OCDB_PATH set to an invalid path: %s", cvmfsUri.Data()));
     743             :     
     744             :     // check that we find the two scripts we need
     745             : 
     746           0 :     AliDebug(3, "OCDB_PATH envvar is set. Changing OCDB storage from alien:// to local:///cvmfs type.");
     747           0 :     cvmfsUri = cvmfsUri.Strip(TString::kTrailing, '/');
     748           0 :     cvmfsUri.Append("/bin/getOCDBFilesPerRun.sh");
     749           0 :     if (gSystem->AccessPathName(cvmfsUri))
     750           0 :       AliFatal(Form("Cannot find valid script: %s", cvmfsUri.Data()));
     751           0 : }
     752             : 
     753             : //_____________________________________________________________________________
     754             : void AliCDBManager::SetDefaultStorageFromRun(Int_t run) {
     755             : // set default storage from the run number - to be used only with raw data      
     756             : 
     757             :   // if lock is ON, cannot activate more storages!
     758           0 :   if(fLock) {
     759           0 :     if (fDefaultStorage) {
     760           0 :       AliFatal("Lock is ON, and default storage is already set: "
     761             :           "cannot activate default storage from run number");
     762           0 :     }
     763             :   }     
     764             : 
     765           0 :   TString lhcPeriod("");
     766           0 :   Int_t startRun = 0, endRun = 0;
     767           0 :   if (! fCvmfsOcdb.IsNull()) { // fRaw and cvmfs case: set LHC period from cvmfs file
     768           0 :     GetLHCPeriodAgainstCvmfsFile(run, lhcPeriod, startRun, endRun);
     769             :   } else {                     // fRaw: set LHC period from AliEn XML file
     770           0 :     GetLHCPeriodAgainstAlienFile(run, lhcPeriod, startRun, endRun);
     771             :   }
     772             : 
     773           0 :   fLHCPeriod = lhcPeriod;
     774           0 :   fStartRunLHCPeriod = startRun;
     775           0 :   fEndRunLHCPeriod = endRun;
     776             : 
     777           0 :   SetDefaultStorage(fLHCPeriod.Data());
     778           0 :   if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",fLHCPeriod.Data()));
     779             : 
     780           0 : }
     781             : 
     782             : //_____________________________________________________________________________
     783             : void AliCDBManager::GetLHCPeriodAgainstAlienFile(Int_t run, TString& lhcPeriod, Int_t& startRun, Int_t& endRun) {
     784             : // set LHC period (year + first, last run) comparing run number and AliEn XML file
     785             :  
     786             : // retrieve XML file from alien
     787           0 :   if(!gGrid) {
     788           0 :     TGrid::Connect("alien://","");
     789           0 :     if(!gGrid) {
     790           0 :       AliError("Connection to alien failed!");
     791           0 :       return;
     792             :     }
     793             :   }
     794           0 :   TUUID uuid;
     795           0 :   TString rndname = gSystem->TempDirectory(); // "/tmp/";
     796           0 :   rndname += "/";
     797           0 :   rndname += "OCDBFolderXML.";
     798           0 :   rndname += uuid.AsString();
     799           0 :   rndname += ".xml";
     800           0 :   AliDebug(2, Form("file to be copied = %s", fgkOCDBFolderXMLfile.Data()));
     801           0 :   if (!TFile::Cp(fgkOCDBFolderXMLfile.Data(), rndname.Data())) {
     802           0 :     AliFatal(Form("Cannot make a local copy of OCDBFolder xml file in %s",rndname.Data()));
     803             :   }
     804           0 :   AliCDBHandler* saxcdb = new AliCDBHandler();
     805           0 :   saxcdb->SetRun(run);
     806           0 :   TSAXParser *saxParser = new TSAXParser();
     807           0 :   saxParser->ConnectToHandler("AliCDBHandler", saxcdb);
     808           0 :   saxParser->ParseFile(rndname.Data());
     809           0 :   AliInfo(Form(" LHC folder = %s", saxcdb->GetOCDBFolder().Data()));
     810           0 :   AliInfo(Form(" LHC period start run = %d", saxcdb->GetStartRunRange()));
     811           0 :   AliInfo(Form(" LHC period end run = %d", saxcdb->GetEndRunRange()));
     812           0 :   lhcPeriod = saxcdb->GetOCDBFolder();
     813           0 :   startRun = saxcdb->GetStartRunRange();
     814           0 :   endRun = saxcdb->GetEndRunRange();
     815           0 : }
     816             : 
     817             : //_____________________________________________________________________________
     818             : void AliCDBManager::GetLHCPeriodAgainstCvmfsFile(Int_t run, TString& lhcPeriod, Int_t& startRun, Int_t& endRun) {
     819             : // set LHC period (year + first, last run) comparing run number and CVMFS file
     820             : // We don't want to connect to AliEn just to set the uri from the runnumber
     821             : // for that we use the script getUriFromYear.sh in the cvmfs AliRoot package
     822             : 
     823           0 :   TString getYearScript(fCvmfsOcdb);
     824           0 :   getYearScript = getYearScript.Strip(TString::kTrailing, '/');
     825           0 :   getYearScript.Append("/bin/getUriFromYear.sh");
     826           0 :   if (gSystem->AccessPathName(getYearScript))
     827           0 :     AliFatal(Form("Cannot find valid script: %s", getYearScript.Data()));
     828           0 :   TString inoutFile(gSystem->WorkingDirectory());
     829           0 :   inoutFile += "/uri_range_";
     830           0 :   inoutFile += TString::Itoa(run,10);
     831           0 :   TString command(getYearScript);
     832           0 :   command += ' ';
     833           0 :   command += TString::Itoa(run,10);
     834           0 :   command += Form(" > %s", inoutFile.Data());
     835           0 :   AliDebug(3, Form("Running command: \"%s\"",command.Data()));
     836           0 :   Int_t result = gSystem->Exec(command.Data());
     837           0 :   if(result != 0) {
     838           0 :     AliFatal(Form("Was not able to execute \"%s\"", command.Data()));
     839             :   }
     840             : 
     841             :   // now read the file with the uri and first and last run
     842           0 :   std::ifstream file(inoutFile.Data());
     843           0 :   if (!file.is_open()) {
     844           0 :     AliFatal(Form("Error opening file \"%s\"!", inoutFile.Data()));
     845             :   }
     846           0 :   TString line;
     847             :   TObjArray* oStringsArray = 0;
     848           0 :   while (line.ReadLine(file)){
     849           0 :     oStringsArray = line.Tokenize(' ');
     850             :   }
     851           0 :   TObjString *oStrUri = dynamic_cast<TObjString*> (oStringsArray->At(0));
     852           0 :   TObjString *oStrFirst = dynamic_cast<TObjString*> (oStringsArray->At(1));
     853           0 :   TString firstRun = oStrFirst->GetString();
     854           0 :   TObjString *oStrLast = dynamic_cast<TObjString*> (oStringsArray->At(2));
     855           0 :   TString lastRun = oStrLast->GetString();
     856             : 
     857           0 :   lhcPeriod = oStrUri->GetString();
     858           0 :   startRun = firstRun.Atoi();
     859           0 :   endRun = lastRun.Atoi();
     860             : 
     861           0 :   file.close();
     862           0 : }
     863             : 
     864             : //_____________________________________________________________________________
     865             : void AliCDBManager::UnsetDefaultStorage() {
     866             : // Unset default storage
     867             : 
     868             :   // if lock is ON, action is forbidden!
     869           0 :   if(fLock) {
     870           0 :     if (fDefaultStorage) {
     871           0 :       AliFatal("Lock is ON: cannot unset default storage!");
     872           0 :     }
     873             :   }
     874             : 
     875           0 :   if (fDefaultStorage) {
     876           0 :     AliWarning("Clearing cache!");
     877           0 :     ClearCache();
     878           0 :   }
     879             : 
     880           0 :   fRun = fStartRunLHCPeriod = fEndRunLHCPeriod = -1;
     881           0 :   fRaw = kFALSE;
     882             : 
     883           0 :   fDefaultStorage = 0x0;
     884           0 : }
     885             : 
     886             : //_____________________________________________________________________________
     887             : void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString, Int_t version, Int_t subVersion) {
     888             : // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
     889             : 
     890          10 :   AliCDBParam *aPar = CreateParameter(dbString);
     891           5 :   if(!aPar) return;
     892           5 :   SetSpecificStorage(calibType, aPar, version, subVersion);
     893          10 :   delete aPar;
     894          10 : }
     895             : 
     896             : //_____________________________________________________________________________
     897             : void AliCDBManager::SetSpecificStorage(const char* calibType, const AliCDBParam* param, Int_t version, Int_t subVersion) {
     898             : // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
     899             : // Default storage should be defined prior to any specific storages, e.g.:
     900             : // AliCDBManager::instance()->SetDefaultStorage("alien://");
     901             : // AliCDBManager::instance()->SetSpecificStorage("TPC/*","local://DB_TPC");
     902             : // AliCDBManager::instance()->SetSpecificStorage("*/Align/*","local://DB_TPCAlign");
     903             : // calibType must be a valid CDB path! (3 level folder structure)
     904             : // Specific version/subversion is set in the uniqueid of the AliCDBParam value stored in the
     905             : // specific storages map
     906             : 
     907          10 :   if(!fDefaultStorage && !fRaw) {
     908           0 :     AliError("Please activate a default storage first!");
     909           0 :     return;
     910             :   }
     911             : 
     912           5 :   AliCDBPath aPath(calibType);
     913           5 :   if(!aPath.IsValid()){
     914           0 :     AliError(Form("Not a valid path: %s", calibType));
     915           0 :     return;
     916             :   }
     917             : 
     918          15 :   TObjString *objCalibType = new TObjString(aPath.GetPath());
     919          10 :   if(fSpecificStorages.Contains(objCalibType)){
     920           0 :     AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one",
     921             :           calibType));
     922           0 :     AliCDBParam *checkPar = dynamic_cast<AliCDBParam*> (fSpecificStorages.GetValue(calibType));
     923           0 :     if(checkPar) delete checkPar;
     924           0 :     delete fSpecificStorages.Remove(objCalibType);
     925           0 :   }
     926           5 :   AliCDBStorage *aStorage = GetStorage(param);
     927           5 :   if(!aStorage) return;
     928             : 
     929             :   // Set the unique id of the AliCDBParam stored in the map to store specific version/subversion
     930           5 :   UInt_t uId = ((subVersion+1)<<16) + (version+1);
     931           5 :   AliCDBParam *specificParam = param->CloneParam();
     932           5 :   specificParam->SetUniqueID(uId);
     933           5 :   fSpecificStorages.Add(objCalibType, specificParam);
     934             : 
     935          10 :   if(fStorageMap->Contains(objCalibType)){
     936           0 :     delete fStorageMap->Remove(objCalibType);
     937             :   }
     938          25 :   fStorageMap->Add(objCalibType->Clone(), new TObjString(param->GetURI()));
     939             : 
     940          15 : }
     941             : 
     942             : //_____________________________________________________________________________
     943             : AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) {
     944             : // get storage specific for detector or calibration type
     945             : 
     946           0 :   AliCDBPath calibPath(calibType);
     947           0 :   if(!calibPath.IsValid()) return NULL;
     948             : 
     949           0 :   AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibPath.GetPath());
     950           0 :   if(!checkPar){
     951           0 :     AliError(Form("%s storage not found!", calibType));
     952           0 :     return NULL;
     953             :   } else {
     954           0 :     return GetStorage(checkPar);
     955             :   }
     956             : 
     957           0 : }
     958             : 
     959             : //_____________________________________________________________________________
     960             : AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) {
     961             : // select storage valid for path from the list of specific storages
     962             : 
     963        1612 :   AliCDBPath aPath(path);
     964         806 :   if(!aPath.IsValid()) return NULL;
     965             : 
     966         806 :   TIter iter(&fSpecificStorages);
     967             :   TObjString *aCalibType=0;
     968         806 :   AliCDBPath tmpPath("null/null/null");
     969             :   AliCDBParam* aPar=0;
     970        4030 :   while((aCalibType = (TObjString*) iter.Next())){
     971        1612 :     AliCDBPath calibTypePath(aCalibType->GetName());
     972        1612 :     if(calibTypePath.Comprises(aPath)) {
     973          34 :       if(calibTypePath.Comprises(tmpPath)) continue;
     974          34 :       aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
     975          34 :       tmpPath.SetPath(calibTypePath.GetPath());
     976             :     }
     977        1612 :   }
     978             :   return aPar;
     979        1612 : }
     980             : 
     981             : //_____________________________________________________________________________
     982             : AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber,
     983             :     Int_t version, Int_t subVersion) {
     984             :   // get an AliCDBEntry object from the database
     985             : 
     986        1306 :   if(runNumber < 0){
     987             :     // RunNumber is not specified. Try with fRun
     988         508 :     if (fRun < 0){
     989           3 :       AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
     990           3 :       return NULL;
     991             :     }
     992             :     runNumber = fRun;
     993         505 :   }
     994             : 
     995        1300 :   return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
     996         653 : }
     997             : 
     998             : //_____________________________________________________________________________
     999             : AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path,
    1000             :     const AliCDBRunRange& runRange, Int_t version,
    1001             :     Int_t subVersion) {
    1002             :   // get an AliCDBEntry object from the database!
    1003             : 
    1004           0 :   return Get(AliCDBId(path, runRange, version, subVersion));
    1005           0 : }
    1006             : 
    1007             : //_____________________________________________________________________________
    1008             : AliCDBEntry* AliCDBManager::Get(const AliCDBId& queryId, Bool_t forceCaching) {
    1009             : // get an AliCDBEntry object from the database
    1010             : 
    1011             :   // check if queryId's path and runRange are valid
    1012             :   // queryId is invalid also if version is not specified and subversion is!
    1013         650 :   if (!queryId.IsValid()) {
    1014           1 :     AliError(Form("Invalid query: %s", queryId.ToString().Data()));
    1015           0 :     return NULL;
    1016             :   }
    1017             : 
    1018             :   // queryId is not specified if path contains wildcard or run range= [-1,-1]
    1019         650 :   if (!queryId.IsSpecified()) {
    1020           0 :     AliError(Form("Unspecified query: %s",
    1021             :           queryId.ToString().Data()));
    1022           0 :     return NULL;
    1023             :   }
    1024             : 
    1025        1948 :   if(fLock && !(fRun >= queryId.GetFirstRun() && fRun <= queryId.GetLastRun()))
    1026           0 :     AliFatal("Lock is ON: cannot use different run number than the internal one!");
    1027             : 
    1028        1950 :   if(fCache && !(fRun >= queryId.GetFirstRun() && fRun <= queryId.GetLastRun()))
    1029           0 :     AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
    1030             : 
    1031             :   AliCDBEntry *entry=0;
    1032             : 
    1033             :   //first of all, look in the prompt cache, for online overrides
    1034         650 :   if(fPromptCache && queryId.GetFirstRun() == fRun)
    1035           0 :     entry = (AliCDBEntry*) fPromptEntryCache.GetValue(queryId.GetPath());
    1036         650 :   if(entry) {
    1037           0 :     AliDebug(2, Form("Object %s retrieved from PROMPT cache !!",queryId.GetPath().Data()));
    1038           0 :     return entry;
    1039             :   }
    1040             : 
    1041             :   // first look into map of cached objects
    1042        1300 :   if(fCache && queryId.GetFirstRun() == fRun)
    1043         650 :     entry = (AliCDBEntry*) fEntryCache.GetValue(queryId.GetPath());
    1044         650 :   if(entry) {
    1045        1338 :     AliDebug(2, Form("Object %s retrieved from cache !!",queryId.GetPath().Data()));
    1046         446 :     return entry;
    1047             :   }
    1048             : 
    1049             :   // if snapshot flag is set, try getting from the snapshot
    1050             :   // but in the case a specific storage is specified for this path
    1051         204 :   AliCDBParam *aPar=SelectSpecificStorage(queryId.GetPath());
    1052         204 :   if(!aPar){
    1053         187 :     if(fSnapshotMode && queryId.GetFirstRun() == fRun)
    1054             :     {
    1055           0 :       entry = GetEntryFromSnapshot(queryId.GetPath());
    1056           0 :       if(entry) {
    1057           0 :         AliInfo(Form("Object \"%s\" retrieved from the snapshot.",queryId.GetPath().Data()));
    1058           0 :         if(queryId.GetFirstRun() == fRun) // no need to check fCache, fSnapshotMode not possible otherwise
    1059           0 :           CacheEntry(queryId.GetPath(), entry);
    1060             : 
    1061           0 :         if(!fIds->Contains(&entry->GetId()))
    1062           0 :           fIds->Add(entry->GetId().Clone());
    1063             : 
    1064           0 :         return entry;
    1065             :       }
    1066             :     }
    1067             :   }
    1068             : 
    1069             :   // Entry is not in cache (and, in case we are in snapshot mode, not in the snapshot either)
    1070             :   // => retrieve it from the storage and cache it!!
    1071         204 :   if(!fDefaultStorage) {
    1072           0 :     AliError("No storage set!");
    1073           0 :     return NULL;
    1074             :   }
    1075             : 
    1076             :   Int_t version = -1, subVersion = -1;
    1077             :   AliCDBStorage *aStorage=0;
    1078         204 :   if(aPar) {
    1079          17 :     aStorage=GetStorage(aPar);
    1080          17 :     TString str = aPar->GetURI();
    1081          17 :     UInt_t uId = aPar->GetUniqueID();
    1082          17 :     version = Int_t(uId&0xffff) - 1;
    1083          17 :     subVersion = Int_t(uId>>16) - 1;
    1084          85 :     AliDebug(2,Form("Looking into storage: %s",str.Data()));
    1085          17 :   } else {
    1086         187 :     aStorage=GetDefaultStorage();
    1087         561 :     AliDebug(2,"Looking into default storage");
    1088             :   }
    1089             : 
    1090         204 :   AliCDBId finalQueryId(queryId);
    1091         204 :   if(version >= 0) {
    1092           0 :     AliDebug(2,Form("Specific version set to: %d", version));
    1093           0 :     finalQueryId.SetVersion(version);
    1094           0 :   }
    1095         204 :   if(subVersion >= 0) {
    1096           0 :     AliDebug(2,Form("Specific subversion set to: %d", subVersion));
    1097           0 :     finalQueryId.SetSubVersion(subVersion);
    1098           0 :   }
    1099         204 :   entry = aStorage->Get(finalQueryId);
    1100             : 
    1101         812 :   if(entry && fCache && (queryId.GetFirstRun()==fRun || forceCaching)){
    1102         609 :     CacheEntry(queryId.GetPath(), entry);
    1103             :   }
    1104             : 
    1105         609 :   if(entry && !fIds->Contains(&entry->GetId())){
    1106         380 :     fIds->Add(entry->GetId().Clone());
    1107             :   }
    1108             : 
    1109             :   return entry;
    1110         853 : }
    1111             : 
    1112             : //_____________________________________________________________________________
    1113             : AliCDBEntry* AliCDBManager::GetEntryFromSnapshot(const char* path) {
    1114             : // get the entry from the open snapshot file
    1115             : 
    1116           0 :   TString sPath(path);
    1117           0 :   sPath.ReplaceAll("/","*");
    1118           0 :   if(!fSnapshotFile){
    1119           0 :     AliError("No snapshot file is open!");
    1120           0 :     return 0;
    1121             :   }
    1122           0 :   AliCDBEntry *entry = dynamic_cast<AliCDBEntry*>(fSnapshotFile->Get(sPath.Data()));
    1123           0 :   if(!entry){
    1124           0 :     AliDebug(2,Form("Cannot get a CDB entry for \"%s\" from snapshot file",path));
    1125           0 :     return 0;
    1126             :   }
    1127             : 
    1128           0 :   return entry;
    1129           0 : }
    1130             : 
    1131             : //_____________________________________________________________________________
    1132             : Bool_t AliCDBManager::SetSnapshotMode(const char* snapshotFileName) {
    1133             : // set the manager in snapshot mode
    1134             : 
    1135           0 :   if(!fCache){
    1136           0 :     AliError("Cannot set the CDB manage in snapshot mode if the cache is not active!");
    1137           0 :     return kFALSE;
    1138             :   }
    1139             : 
    1140             :   //open snapshot file
    1141           0 :   TString snapshotFile(snapshotFileName);
    1142           0 :   if(snapshotFile.BeginsWith("alien://")){
    1143           0 :     if(!gGrid) {
    1144           0 :       TGrid::Connect("alien://","");
    1145           0 :       if(!gGrid) {
    1146           0 :         AliError("Connection to alien failed!");
    1147           0 :         return kFALSE;
    1148             :       }
    1149             :     }
    1150             :   }
    1151             : 
    1152           0 :   fSnapshotFile = TFile::Open(snapshotFileName);
    1153           0 :   if (!fSnapshotFile || fSnapshotFile->IsZombie()){
    1154           0 :     AliError(Form("Cannot open file %s",snapshotFileName));
    1155           0 :     return kFALSE;
    1156             :   }
    1157             : 
    1158           0 :   AliInfo("The CDB manager is set in snapshot mode!");
    1159           0 :   fSnapshotMode = kTRUE;
    1160           0 :   return kTRUE;
    1161             : 
    1162           0 : }
    1163             : 
    1164             : //_____________________________________________________________________________
    1165             : const char* AliCDBManager::GetURI(const char* path) {
    1166             : // return the URI of the storage where to look for path
    1167             : 
    1168           4 :   if(!IsDefaultStorageSet()) return 0;
    1169             : 
    1170           4 :   AliCDBParam *aPar=SelectSpecificStorage(path);
    1171             : 
    1172           2 :   if(aPar) {
    1173           0 :     return aPar->GetURI().Data();
    1174             : 
    1175             :   } else {
    1176           2 :     return GetDefaultStorage()->GetURI().Data();
    1177             :   }
    1178             : 
    1179             :   return 0;
    1180           2 : }
    1181             : 
    1182             : //_____________________________________________________________________________
    1183             : Int_t AliCDBManager::GetStartRunLHCPeriod(){
    1184             : // get the first run of validity
    1185             : // for the current period
    1186             : // if set
    1187           0 :   if(fStartRunLHCPeriod==-1)
    1188           0 :     AliWarning("Run-range not yet set for the current LHC period.");
    1189           0 :   return fStartRunLHCPeriod;
    1190             : }
    1191             : 
    1192             : //_____________________________________________________________________________
    1193             : Int_t AliCDBManager::GetEndRunLHCPeriod(){
    1194             : // get the last run of validity
    1195             : // for the current period
    1196             : // if set
    1197           0 :   if(fEndRunLHCPeriod==-1)
    1198           0 :     AliWarning("Run-range not yet set for the current LHC period.");
    1199           0 :   return fEndRunLHCPeriod;
    1200             : }
    1201             : 
    1202             : //_____________________________________________________________________________
    1203             : TString AliCDBManager::GetLHCPeriod(){
    1204             : // get the current LHC period string
    1205             : //
    1206           0 :   if(fLHCPeriod.IsWhitespace() || fLHCPeriod.IsNull())
    1207           0 :     AliWarning("LHC period (OCDB folder) not yet set");
    1208           0 :   return fLHCPeriod;
    1209             : }
    1210             : 
    1211             : //_____________________________________________________________________________
    1212             : AliCDBId* AliCDBManager::GetId(const AliCDBPath& path, Int_t runNumber,
    1213             :     Int_t version, Int_t subVersion) {
    1214             :   // get the AliCDBId of the valid object from the database (does not retrieve the object)
    1215             :   // User must delete returned object!
    1216             : 
    1217           0 :   if(runNumber < 0){
    1218             :     // RunNumber is not specified. Try with fRun
    1219           0 :     if (fRun < 0){
    1220           0 :       AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
    1221           0 :       return NULL;
    1222             :     }
    1223             :     runNumber = fRun;
    1224           0 :   }
    1225             : 
    1226           0 :   return GetId(AliCDBId(path, runNumber, runNumber, version, subVersion));
    1227           0 : }
    1228             : 
    1229             : //_____________________________________________________________________________
    1230             : AliCDBId* AliCDBManager::GetId(const AliCDBPath& path,
    1231             :     const AliCDBRunRange& runRange, Int_t version,
    1232             :     Int_t subVersion) {
    1233             :   // get the AliCDBId of the valid object from the database (does not retrieve the object)
    1234             :   // User must delete returned object!
    1235             : 
    1236           0 :   return GetId(AliCDBId(path, runRange, version, subVersion));
    1237           0 : }
    1238             : 
    1239             : //_____________________________________________________________________________
    1240             : AliCDBId* AliCDBManager::GetId(const AliCDBId& query) {
    1241             : // get the AliCDBId of the valid object from the database (does not retrieve the object)
    1242             : // User must delete returned object!
    1243             : 
    1244           0 :   if(!fDefaultStorage) {
    1245           0 :     AliError("No storage set!");
    1246           0 :     return NULL;
    1247             :   }
    1248             : 
    1249             :   // check if query's path and runRange are valid
    1250             :   // query is invalid also if version is not specified and subversion is!
    1251           0 :   if (!query.IsValid()) {
    1252           0 :     AliError(Form("Invalid query: %s", query.ToString().Data()));
    1253           0 :     return NULL;
    1254             :   }
    1255             : 
    1256             :   // query is not specified if path contains wildcard or run range= [-1,-1]
    1257           0 :   if (!query.IsSpecified()) {
    1258           0 :     AliError(Form("Unspecified query: %s",
    1259             :           query.ToString().Data()));
    1260           0 :     return NULL;
    1261             :   }
    1262             : 
    1263           0 :   if(fCache && query.GetFirstRun() != fRun)
    1264           0 :     AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
    1265             : 
    1266             :   AliCDBEntry* entry = 0;
    1267             : 
    1268             :   // first look into map of cached objects
    1269           0 :   if(fCache && query.GetFirstRun() == fRun)
    1270           0 :     entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
    1271             : 
    1272           0 :   if(entry) {
    1273           0 :     AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
    1274           0 :     return dynamic_cast<AliCDBId*> (entry->GetId().Clone());
    1275             :   }
    1276             : 
    1277             :   // Entry is not in cache -> retrieve it from CDB and cache it!!
    1278             :   AliCDBStorage *aStorage=0;
    1279           0 :   AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
    1280             : 
    1281           0 :   if(aPar) {
    1282           0 :     aStorage=GetStorage(aPar);
    1283           0 :     TString str = aPar->GetURI();
    1284           0 :     AliDebug(2,Form("Looking into storage: %s",str.Data()));
    1285             : 
    1286           0 :   } else {
    1287           0 :     aStorage=GetDefaultStorage();
    1288           0 :     AliDebug(2,"Looking into default storage");
    1289             :   }
    1290             : 
    1291           0 :   return aStorage->GetId(query);
    1292             : 
    1293           0 : }
    1294             : 
    1295             : //_____________________________________________________________________________
    1296             : TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber,
    1297             :     Int_t version, Int_t subVersion) {
    1298             :   // get multiple AliCDBEntry objects from the database
    1299             : 
    1300         128 :   if(runNumber < 0){
    1301             :     // RunNumber is not specified. Try with fRun
    1302          64 :     if (fRun < 0){
    1303           0 :       AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
    1304           0 :       return NULL;
    1305             :     }
    1306             :     runNumber = fRun;
    1307          64 :   }
    1308             : 
    1309         128 :   return GetAll(AliCDBId(path, runNumber, runNumber, version,   
    1310             :         subVersion));
    1311          64 : }
    1312             : 
    1313             : //_____________________________________________________________________________
    1314             : TList* AliCDBManager::GetAll(const AliCDBPath& path,
    1315             :     const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
    1316             :   // get multiple AliCDBEntry objects from the database
    1317             : 
    1318           0 :   return GetAll(AliCDBId(path, runRange, version, subVersion));
    1319           0 : }
    1320             : 
    1321             : //_____________________________________________________________________________
    1322             : TList* AliCDBManager::GetAll(const AliCDBId& query) {
    1323             : // get multiple AliCDBEntry objects from the database
    1324             : // Warning: this method works correctly only for queries of the type "Detector/*"
    1325             : //              and not for more specific queries e.g. "Detector/Calib/*" !
    1326             : // Warning #2: Entries are cached, but GetAll will keep on retrieving objects from OCDB!
    1327             : //              To get an object from cache use Get() function
    1328             : 
    1329         128 :   if(!fDefaultStorage) {
    1330           0 :     AliError("No storage set!");
    1331           0 :     return NULL;
    1332             :   }
    1333             : 
    1334          64 :   if (!query.IsValid()) {
    1335           0 :     AliError(Form("Invalid query: %s", query.ToString().Data()));
    1336           0 :     return NULL;
    1337             :   }
    1338             : 
    1339         320 :   if((fSpecificStorages.GetEntries()>0) && query.GetPath().BeginsWith('*')){
    1340             :     // if specific storages are active a query with "*" is ambiguous
    1341           0 :     AliError("Query too generic in this context!");
    1342           0 :     return NULL;
    1343             :   }
    1344             : 
    1345          64 :   if (query.IsAnyRange()) {
    1346           0 :     AliError(Form("Unspecified run or runrange: %s",
    1347             :           query.ToString().Data()));
    1348           0 :     return NULL;
    1349             :   }
    1350             : 
    1351         128 :   if(fLock && query.GetFirstRun() != fRun)
    1352           0 :     AliFatal("Lock is ON: cannot use different run number than the internal one!");
    1353             : 
    1354          64 :   AliCDBParam *aPar = SelectSpecificStorage(query.GetPath());
    1355             : 
    1356             :   AliCDBStorage *aStorage;
    1357          64 :   if(aPar) {
    1358           0 :     aStorage=GetStorage(aPar);
    1359           0 :     AliDebug(2,Form("Looking into storage: %s", aPar->GetURI().Data()));
    1360             : 
    1361             :   } else {
    1362          64 :     aStorage=GetDefaultStorage();
    1363         192 :     AliDebug(2,Form("Looking into default storage: %s", aStorage->GetURI().Data()));
    1364             :   }
    1365             : 
    1366             :   TList *result = 0;
    1367         128 :   if(aStorage) result = aStorage->GetAll(query);
    1368          64 :   if(!result) return 0;
    1369             : 
    1370             :   // loop on result to check whether entries should be re-queried with specific storages
    1371         128 :   if(fSpecificStorages.GetEntries()>0 && ! (fSpecificStorages.GetEntries() == 1 && aPar)) {
    1372          64 :     AliInfo("Now look into all other specific storages...");
    1373             : 
    1374          64 :     TIter iter(result);
    1375             :     AliCDBEntry* chkEntry=0;
    1376             : 
    1377        2400 :     while((chkEntry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
    1378         536 :       AliCDBId& chkId = chkEntry->GetId();
    1379        2680 :       AliDebug(2, Form("Checking id %s ", chkId.GetPath().Data()));
    1380        1072 :       AliCDBParam *chkPar=SelectSpecificStorage(chkId.GetPath());
    1381        1072 :       if (!chkPar || aPar == chkPar) continue;
    1382           0 :       AliCDBStorage *chkStorage = GetStorage(chkPar);
    1383           0 :       AliDebug(2, Form("Found specific storage! %s", chkPar->GetURI().Data()));
    1384             : 
    1385           0 :       chkId.SetRunRange(query.GetFirstRun(), query.GetLastRun());
    1386           0 :       UInt_t uId = chkPar->GetUniqueID();
    1387             :       Int_t version = -1, subVersion = -1;
    1388           0 :       version = Int_t(uId&0xffff) - 1;
    1389           0 :       subVersion = Int_t(uId>>16) - 1;
    1390           0 :       if(version!=-1){
    1391           0 :         chkId.SetVersion(version);
    1392           0 :       }else{
    1393           0 :         chkId.SetVersion(query.GetVersion());
    1394             :       }
    1395           0 :       if(subVersion!=-1){
    1396           0 :         chkId.SetSubVersion(subVersion);
    1397           0 :       }else{
    1398           0 :         chkId.SetSubVersion(query.GetSubVersion());
    1399             :       }
    1400             : 
    1401             :       AliCDBEntry *newEntry=0;
    1402           0 :       if(chkStorage) newEntry = chkStorage->Get(chkId);
    1403           0 :       if(!newEntry) continue;
    1404             : 
    1405             :       // object is found in specific storage: replace entry in the result list!
    1406           0 :       chkEntry->SetOwner(1);
    1407           0 :       delete result->Remove(chkEntry);
    1408           0 :       result->AddFirst(newEntry);
    1409           0 :     }
    1410             : 
    1411          64 :     Int_t nEntries = result->GetEntries();
    1412         128 :     AliInfo("After look into other specific storages, result list is:");
    1413        1200 :     for(int i=0; i<nEntries;i++){
    1414        1072 :       AliCDBEntry *entry = (AliCDBEntry*) result->At(i);
    1415        3216 :       AliInfo(Form("%s",entry->GetId().ToString().Data()));
    1416             :     }
    1417          64 :   }
    1418             : 
    1419             :   // caching entries
    1420          64 :   TIter iter(result);
    1421             :   AliCDBEntry* entry=0;
    1422        2400 :   while((entry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
    1423             : 
    1424        1072 :     if(!fIds->Contains(&entry->GetId())){
    1425        1060 :       fIds->Add(entry->GetId().Clone());
    1426             :     }
    1427        1608 :     if(fCache && (query.GetFirstRun() == fRun)){
    1428        1608 :       CacheEntry(entry->GetId().GetPath(), entry);
    1429             :     }
    1430             :   }
    1431             : 
    1432             : 
    1433             :   return result;
    1434         128 : }
    1435             : 
    1436             : //_____________________________________________________________________________
    1437             : Bool_t AliCDBManager::Put(TObject* object, const AliCDBId& id, AliCDBMetaData* metaData, const char* mirrors, DataType type){
    1438             : // store an AliCDBEntry object into the database
    1439             : 
    1440           0 :   if (object==0x0) {
    1441           0 :     AliError("Null Entry! No storage will be done!");
    1442           0 :     return kFALSE;
    1443             :   }
    1444             : 
    1445           0 :   AliCDBEntry anEntry(object, id, metaData);
    1446           0 :   return Put(&anEntry, mirrors, type);
    1447             : 
    1448           0 : }
    1449             : 
    1450             : 
    1451             : //_____________________________________________________________________________
    1452             : Bool_t AliCDBManager::Put(AliCDBEntry* entry, const char* mirrors, DataType type){
    1453             : // store an AliCDBEntry object into the database
    1454             : 
    1455           0 :   if(type == kPrivate && !fDefaultStorage) {
    1456           0 :     AliError("No storage set!");
    1457           0 :     return kFALSE;
    1458             :   }
    1459             : 
    1460           0 :   if (!entry){
    1461           0 :     AliError("No entry!");
    1462           0 :     return kFALSE;
    1463             :   }
    1464             : 
    1465           0 :   if (entry->GetObject()==0x0){
    1466           0 :     AliError("No valid object in CDB entry!");
    1467           0 :     return kFALSE;
    1468             :   }
    1469             : 
    1470           0 :   if (!entry->GetId().IsValid()) {
    1471           0 :     AliError(Form("Invalid entry ID: %s",
    1472             :           entry->GetId().ToString().Data()));
    1473           0 :     return kFALSE;
    1474             :   }     
    1475             : 
    1476           0 :   if (!entry->GetId().IsSpecified()) {
    1477           0 :     AliError(Form("Unspecified entry ID: %s",
    1478             :           entry->GetId().ToString().Data()));
    1479           0 :     return kFALSE;
    1480             :   }
    1481             : 
    1482           0 :   AliCDBId id = entry->GetId();
    1483           0 :   AliCDBParam *aPar = SelectSpecificStorage(id.GetPath());
    1484             : 
    1485             :   AliCDBStorage *aStorage=0;
    1486             : 
    1487           0 :   if(aPar) {
    1488           0 :     aStorage=GetStorage(aPar);
    1489           0 :   } else {
    1490           0 :     switch(type){
    1491             :       case kCondition:
    1492           0 :         aStorage = GetStorage(fCondParam);
    1493           0 :         break;
    1494             :       case kReference:
    1495           0 :         aStorage = GetStorage(fRefParam);
    1496           0 :         break;
    1497             :       case kPrivate:
    1498           0 :         aStorage = GetDefaultStorage();
    1499           0 :         break;
    1500             :     }
    1501             :   }
    1502             : 
    1503           0 :   AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data()));
    1504             : 
    1505           0 :   TString strMirrors(mirrors);
    1506             :   Bool_t result = kFALSE;
    1507           0 :   if(!strMirrors.IsNull() && !strMirrors.IsWhitespace())
    1508           0 :     result = aStorage->Put(entry, mirrors, type);
    1509             :   else
    1510           0 :     result = aStorage->Put(entry, "", type);
    1511             : 
    1512           0 :   if(fRun >= 0) QueryCDB();
    1513             : 
    1514           0 :   return result;
    1515             : 
    1516             : 
    1517           0 : }
    1518             : 
    1519             : //_____________________________________________________________________________
    1520             : void AliCDBManager::SetMirrorSEs(const char* mirrors) {
    1521             : // set mirror Storage Elements for the default storage, if it is of type "alien"
    1522           0 :   if(fDefaultStorage->GetType() != "alien"){
    1523           0 :     AliInfo("The default storage is not of type \"alien\". Settings for Storage Elements are not taken into account!");
    1524           0 :     return;
    1525             :   }
    1526           0 :   fDefaultStorage->SetMirrorSEs(mirrors);
    1527           0 : }
    1528             : 
    1529             : //_____________________________________________________________________________
    1530             : const char* AliCDBManager::GetMirrorSEs() const {
    1531             : // get mirror Storage Elements for the default storage, if it is of type "alien"
    1532           0 :   if(fDefaultStorage->GetType() != "alien"){
    1533           0 :     AliInfo("The default storage is not of type \"alien\". Settings for Storage Elements are not taken into account!");
    1534           0 :     return "";
    1535             :   }
    1536           0 :   return fDefaultStorage->GetMirrorSEs();
    1537           0 : }
    1538             : 
    1539             : //_____________________________________________________________________________
    1540             : void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry) {
    1541             : // cache AliCDBEntry. Cache is valid until run number is changed.
    1542             : 
    1543        2223 :   AliCDBEntry *chkEntry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(path));
    1544             : 
    1545        1478 :   if(chkEntry) {
    1546         757 :     AliDebug(2, Form("Object %s already in cache !!", path));
    1547           6 :     return;
    1548             :   } else {
    1549        2199 :     AliDebug(2,Form("Caching entry %s", path));
    1550             :   }
    1551             : 
    1552        1466 :   fEntryCache.Add(new TObjString(path), entry);
    1553        2199 :   AliDebug(2,Form("Cache entries: %d", fEntryCache.GetEntries()));
    1554             : 
    1555        1472 : }
    1556             : 
    1557             : //_____________________________________________________________________________
    1558             : void AliCDBManager::Print(Option_t* /*option*/) const {
    1559             : // Print list of active storages and their URIs
    1560             : 
    1561           8 :   TString output=Form("Run number = %d; ",fRun);
    1562           4 :   output += "Cache is ";
    1563           4 :   if(!fCache) output += "NOT ";
    1564          12 :   output += Form("ACTIVE; Number of active storages: %d\n",fActiveStorages.GetEntries());
    1565             : 
    1566           4 :   if(fDefaultStorage) {
    1567          12 :     output += Form("\t*** Default Storage URI: \"%s\"\n",fDefaultStorage->GetURI().Data());
    1568             :     //          AliInfo(output.Data());
    1569             :   }
    1570           8 :   if(fSpecificStorages.GetEntries()>0) {
    1571           4 :     TIter iter(fSpecificStorages.GetTable());
    1572             :     TPair *aPair=0;
    1573             :     Int_t i=1;
    1574          20 :     while((aPair = (TPair*) iter.Next())){
    1575           8 :       output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n",
    1576           4 :           i++, ((TObjString*) aPair->Key())->GetName(),
    1577           4 :           ((AliCDBParam*) aPair->Value())->GetURI().Data());
    1578             :     }
    1579           4 :   }
    1580           4 :   if(fDrainStorage) {
    1581           0 :     output += Form("*** Drain Storage URI: %s\n",fDrainStorage->GetURI().Data());
    1582             :   }
    1583          12 :   AliInfo(output.Data());
    1584           4 : }
    1585             : 
    1586             : //_____________________________________________________________________________
    1587             : void AliCDBManager::SetRun(Int_t run) {
    1588             : // Sets current run number.
    1589             : // When the run number changes the caching is cleared.
    1590             : 
    1591          12 :   if(fRun == run)
    1592             :     return;
    1593             : 
    1594           5 :   if(fLock && fRun >= 0) {
    1595           0 :     AliFatal("Lock is ON, cannot reset run number!");
    1596           0 :   }     
    1597             : 
    1598           5 :   fRun = run;
    1599             : 
    1600           5 :   if (fRaw) {
    1601             :     // here the LHCPeriod xml file is parsed; the string containing the correct period is returned; the default storage is set
    1602           0 :     if (fStartRunLHCPeriod <= run && fEndRunLHCPeriod >= run){
    1603           0 :       AliInfo("LHCPeriod alien folder for current run already in memory");
    1604             :     }else{
    1605           0 :       SetDefaultStorageFromRun(fRun);
    1606           0 :       if(fEntryCache.GetEntries()!=0) ClearCache();
    1607             :       return;
    1608             :     }
    1609           0 :   }
    1610           5 :   ClearCache();
    1611           5 :   QueryCDB();
    1612          11 : }
    1613             : 
    1614             : //_____________________________________________________________________________
    1615             : void AliCDBManager::ClearPromptCache(){
    1616             : // clear AliCDBEntry prompt cache
    1617             : 
    1618           4 :   AliDebug(2, Form("PROMPT cache entries to be deleted: %d",fPromptEntryCache.GetEntries()));
    1619             : 
    1620           1 :   fPromptEntryCache.DeleteAll();
    1621             : 
    1622           3 :   AliDebug(2, Form("After deleting - PROMPT cache entries: %d",fPromptEntryCache.GetEntries()));
    1623           1 : }
    1624             : 
    1625             : //_____________________________________________________________________________
    1626             : void AliCDBManager::ClearCache(){
    1627             : // clear AliCDBEntry cache
    1628             : 
    1629          36 :   AliDebug(2, Form("Cache entries to be deleted: %d",fEntryCache.GetEntries()));
    1630             : 
    1631             :   /*
    1632             :   // To clean entries one by one
    1633             :   TIter iter(fEntryCache.GetTable());
    1634             :   TPair* pair=0;
    1635             :   while((pair= dynamic_cast<TPair*> (iter.Next()))){
    1636             : 
    1637             :   TObjString* key = dynamic_cast<TObjString*> (pair->Key());
    1638             :   AliCDBEntry* entry = dynamic_cast<AliCDBEntry*> (pair->Value());
    1639             :   AliDebug(2, Form("Deleting entry: %s", key->GetName()));
    1640             :   if (entry) delete entry;
    1641             :   delete fEntryCache.Remove(key);
    1642             :   }
    1643             :   */
    1644           9 :   fEntryCache.DeleteAll();
    1645          27 :   AliDebug(2, Form("After deleting - Cache entries: %d",fEntryCache.GetEntries()));
    1646           9 : }
    1647             : 
    1648             : //_____________________________________________________________________________
    1649             : void AliCDBManager::UnloadFromCache(const char* path){
    1650             : // unload cached object
    1651             : // that is remove the entry from the cache and the id from the list of ids
    1652             : //
    1653          40 :   if(!fActiveStorages.GetEntries()) {
    1654           0 :     AliDebug(2, Form("No active storages. Object \"%s\" is not unloaded from cache", path));
    1655             :     return;
    1656             :   }
    1657             : 
    1658          20 :   AliCDBPath queryPath(path);
    1659          20 :   if(!queryPath.IsValid()) return;
    1660             : 
    1661          20 :   if(!queryPath.IsWildcard()) { // path is not wildcard, get it directly from the cache and unload it!
    1662          36 :     if(fEntryCache.Contains(path)){
    1663          85 :       AliDebug(2, Form("Unloading object \"%s\" from cache and from list of ids", path));
    1664          17 :       TObjString pathStr(path);
    1665          51 :       delete fEntryCache.Remove(&pathStr);
    1666             :       // we do not remove from the list of Id's (it's not very coherent but we leave the
    1667             :       // id for the benefit of the userinfo)
    1668             :       /*
    1669             :          TIter iter(fIds);
    1670             :          AliCDBId *id = 0;
    1671             :          while((id = dynamic_cast<AliCDBId*> (iter.Next()))){
    1672             :          if(queryPath.Comprises(id->GetPath()))
    1673             :          delete fIds->Remove(id);
    1674             :          }*/
    1675          17 :     } else {
    1676           3 :       AliWarning(Form("Cache does not contain object \"%s\"!", path));
    1677             :     }
    1678          90 :     AliDebug(2, Form("Cache entries: %d",fEntryCache.GetEntries()));
    1679          18 :     return;
    1680             :   }
    1681             : 
    1682             :   // path is wildcard: loop on the cache and unload all comprised objects!
    1683           2 :   TIter iter(fEntryCache.GetTable());
    1684             :   TPair* pair = 0;
    1685             :   Int_t removed=0;
    1686             : 
    1687         168 :   while((pair = dynamic_cast<TPair*> (iter.Next()))){
    1688          64 :     AliCDBPath entryPath = pair->Key()->GetName();
    1689          64 :     if(queryPath.Comprises(entryPath)) {
    1690         155 :       AliDebug(2, Form("Unloading object \"%s\" from cache and from list of ids", entryPath.GetPath().Data()));
    1691          62 :       TObjString pathStr(entryPath.GetPath());
    1692          93 :       delete fEntryCache.Remove(&pathStr);
    1693          31 :       removed++;
    1694             : 
    1695             :       // we do not remove from the list of Id's (it's not very coherent but we leave the
    1696             :       // id for the benefit of the userinfo)
    1697             :       /*
    1698             :          TIter iterids(fIds);
    1699             :          AliCDBId *anId = 0;
    1700             :          while((anId = dynamic_cast<AliCDBId*> (iterids.Next()))){
    1701             :          AliCDBPath aPath = anId->GetPath();
    1702             :          TString aPathStr = aPath.GetPath();
    1703             :          if(queryPath.Comprises(aPath)) {
    1704             :          delete fIds->Remove(anId);
    1705             :          }
    1706             :          }*/
    1707          31 :     }
    1708          32 :   }
    1709          10 :   AliDebug(2,Form("Cache entries and ids removed: %d   Remaining: %d",removed,fEntryCache.GetEntries()));
    1710          42 : }
    1711             : 
    1712             : //_____________________________________________________________________________
    1713             : void AliCDBManager::DestroyActiveStorages() {
    1714             : // delete list of active storages
    1715             : 
    1716           2 :   fActiveStorages.DeleteAll();
    1717           1 :   fSpecificStorages.DeleteAll();
    1718           1 : }
    1719             : 
    1720             : //_____________________________________________________________________________
    1721             : void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
    1722             : // destroys active storage
    1723             : 
    1724             :   /*
    1725             :      TIter iter(fActiveStorages.GetTable());
    1726             :      TPair* aPair;
    1727             :      while ((aPair = (TPair*) iter.Next())) {
    1728             :      if(storage == (AliCDBStorage*) aPair->Value())
    1729             :      delete fActiveStorages.Remove(aPair->Key());
    1730             :      storage->Delete(); storage=0x0;
    1731             :      }
    1732             :      */
    1733             : 
    1734           0 : }
    1735             : 
    1736             : //_____________________________________________________________________________
    1737             : void AliCDBManager::QueryCDB() {
    1738             : // query default and specific storages for files valid for fRun. Every storage loads the Ids into its list.
    1739             : 
    1740          10 :   if (fRun < 0){
    1741           0 :     AliError("Run number not yet set! Use AliCDBManager::SetRun.");
    1742           0 :     return;
    1743             :   }
    1744           5 :   if (!fDefaultStorage){
    1745           0 :     AliError("Default storage is not set! Use AliCDBManager::SetDefaultStorage");
    1746           0 :     return;
    1747             :   }
    1748          10 :   if(fDefaultStorage->GetType() == "alien" || fDefaultStorage->GetType() == "local"){
    1749           5 :     fDefaultStorage->QueryCDB(fRun);
    1750             :   //} else {
    1751             :   //    AliDebug(2,"Skipping query for valid files, it used only in grid...");
    1752           5 :   }
    1753             : 
    1754           5 :   TIter iter(&fSpecificStorages);
    1755             :   TObjString *aCalibType=0;
    1756             :   AliCDBParam* aPar=0;
    1757          40 :   while((aCalibType = dynamic_cast<TObjString*> (iter.Next()))){
    1758          10 :     aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
    1759           5 :     if(aPar) {
    1760          25 :       AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName()));
    1761           5 :       AliCDBStorage *aStorage = GetStorage(aPar);
    1762          20 :       if(aStorage->GetType() == "alien" || aStorage->GetType() == "local"){
    1763          10 :         aStorage->QueryCDB(fRun, aCalibType->GetName());
    1764             :       } else {
    1765           0 :         AliDebug(2,
    1766             :             "Skipping query for valid files, it is used only in grid...");
    1767             :       }
    1768           5 :     }
    1769             :   }
    1770          10 : }
    1771             : 
    1772             : //______________________________________________________________________________________________
    1773             : const char* AliCDBManager::GetDataTypeName(DataType type) {
    1774             : // returns the name (string) of the data type
    1775             : 
    1776           0 :   switch (type){
    1777           0 :     case kCondition: return "Conditions";
    1778           0 :     case kReference: return "Reference";
    1779           0 :     case kPrivate: return "Private";
    1780             :   }
    1781           0 :   return 0;
    1782             : 
    1783           0 : }
    1784             : 
    1785             : //______________________________________________________________________________________________
    1786             : Bool_t AliCDBManager::DiffObjects(const char *cdbFile1, const char *cdbFile2) const {
    1787             : // Compare byte-by-byte the objects contained in the CDB entry in two different files,
    1788             : // whose name is passed as input
    1789             : // Return value:
    1790             : //   kTRUE - in case the content of the OCDB object (persistent part) is exactly the same
    1791             : //   kFALSE - otherwise
    1792             : 
    1793           0 :   TString f1Str(cdbFile1);
    1794           0 :   TString f2Str(cdbFile2);
    1795           0 :   if (!gGrid && ( f1Str.BeginsWith("alien://") || f2Str.BeginsWith("alien://") ))
    1796           0 :     TGrid::Connect("alien://");
    1797             : 
    1798           0 :   TFile * f1 = TFile::Open(cdbFile1);
    1799           0 :   if (!f1){
    1800           0 :     Printf("Cannot open file \"%s\"",cdbFile1);
    1801           0 :     return kFALSE;
    1802             :   }
    1803           0 :   TFile * f2 = TFile::Open(cdbFile2);
    1804           0 :   if (!f2){
    1805           0 :     Printf("Cannot open file \"%s\"",cdbFile2);
    1806           0 :     return kFALSE;
    1807             :   }
    1808             : 
    1809           0 :   AliCDBEntry * entry1 = (AliCDBEntry*)f1->Get("AliCDBEntry");
    1810           0 :   if (!entry1){
    1811           0 :     Printf("Cannot get CDB entry from file \"%s\"",cdbFile1);
    1812           0 :     return kFALSE;
    1813             :   }
    1814           0 :   AliCDBEntry * entry2 = (AliCDBEntry*)f2->Get("AliCDBEntry");
    1815           0 :   if (!entry2){
    1816           0 :     Printf("Cannot get CDB entry from file \"%s\"",cdbFile2);
    1817           0 :     return kFALSE;
    1818             :   }
    1819             : 
    1820             :   // stream the two objects in the buffer of two TMessages
    1821           0 :   TObject* object1 = entry1->GetObject();
    1822           0 :   TObject* object2 = entry2->GetObject();
    1823           0 :   TMessage * file1 = new TMessage(TBuffer::kWrite);
    1824           0 :   file1->WriteObject(object1);
    1825           0 :   Int_t size1 = file1->Length();
    1826           0 :   TMessage * file2 = new TMessage(TBuffer::kWrite);
    1827           0 :   file2->WriteObject(object2);
    1828           0 :   Int_t size2 = file2->Length();
    1829           0 :   if (size1!=size2){
    1830           0 :     Printf("Problem 2:  OCDB entry of different size (%d,%d)",size1,size2);
    1831           0 :     return kFALSE;
    1832             :   }
    1833             : 
    1834             :   // if the two buffers have the same size, check that they are the same byte-by-byte
    1835             :   Int_t countDiff=0;
    1836           0 :   char* buf1 = file1->Buffer();
    1837           0 :   char* buf2 = file2->Buffer();
    1838             :   //for (Int_t i=0; i<size1; i++)    if (file1->Buffer()[i]!=file2->Buffer()[i]) countDiff++;
    1839           0 :   for(Int_t i=0; i<size1; i++)
    1840           0 :     if (buf1[i]!=buf2[i]) countDiff++;
    1841             : 
    1842           0 :   if (countDiff>0){
    1843           0 :     Printf("The CDB objects differ by %d bytes.", countDiff);
    1844           0 :     return kFALSE;
    1845             :   }
    1846             : 
    1847           0 :   Printf("The CDB objects are the same in the two files.");
    1848           0 :   return kTRUE;
    1849           0 : }
    1850             : 
    1851             : //______________________________________________________________________________________________
    1852             : void AliCDBManager::InitShortLived() {
    1853             : // Init the list of short-lived objects
    1854             : // currently disabled
    1855             : 
    1856          16 :   fShortLived=0x0;
    1857             : 
    1858             :   //    fShortLived = new TList();
    1859             :   //    fShortLived->SetOwner(1);
    1860             :   //
    1861             :   //    fShortLived->Add(new TObjString("EMCAL/Calib/Data"));
    1862             :   //
    1863             :   //    fShortLived->Add(new TObjString("HMPID/Calib/Nmean"));
    1864             :   //    fShortLived->Add(new TObjString("HMPID/Calib/Qthre"));
    1865             :   //
    1866             :   //    fShortLived->Add(new TObjString("ITS/Calib/CalibSPD"));
    1867             :   //
    1868             :   //    fShortLived->Add(new TObjString("MUON/Calib/Gains"));
    1869             :   //    fShortLived->Add(new TObjString("MUON/Calib/HV"));
    1870             :   //    fShortLived->Add(new TObjString("MUON/Calib/Pedestals"));
    1871             :   //
    1872             :   //    fShortLived->Add(new TObjString("PHOS/Calib/CpvGainPedestals"));
    1873             :   //    fShortLived->Add(new TObjString("PHOS/Calib/EmcGainPedestals"));
    1874             :   //
    1875             :   //    fShortLived->Add(new TObjString("PMD/Calib/Data"));
    1876             :   //
    1877             :   //    fShortLived->Add(new TObjString("TRD/Calib/ChamberGainFactor"));
    1878             :   //    fShortLived->Add(new TObjString("TRD/Calib/LocalGainFactor"));
    1879             :   //    fShortLived->Add(new TObjString("TRD/Calib/ChamberT0"));
    1880             :   //    fShortLived->Add(new TObjString("TRD/Calib/LocalT0"));
    1881             :   //    fShortLived->Add(new TObjString("TRD/Calib/ChamberVdrift"));
    1882             :   //    fShortLived->Add(new TObjString("TRD/Calib/LocalVdrift"));
    1883             :   //
    1884             :   //    fShortLived->Add(new TObjString("ZDC/Calib/Data"));
    1885             : 
    1886           8 : }
    1887             : 
    1888             : //______________________________________________________________________________________________
    1889             : Bool_t AliCDBManager::IsShortLived(const char* path) {
    1890             : // returns the name (string) of the data type
    1891             : 
    1892           0 :   if(!fShortLived) return kFALSE;
    1893             : 
    1894           0 :   AliCDBPath aPath(path);
    1895           0 :   if(!aPath.IsValid()){
    1896           0 :     AliError(Form("Not a valid path: %s", path));
    1897           0 :     return kFALSE;
    1898             :   }
    1899             : 
    1900           0 :   return fShortLived->Contains(path);
    1901             : 
    1902           0 : }
    1903             : 
    1904             : //______________________________________________________________________________________________
    1905             : ULong64_t AliCDBManager::SetLock(Bool_t lock, ULong64_t key){
    1906             : // To lock/unlock user must provide the key. A new key is provided after
    1907             : // each successful lock. User should always backup the returned key and
    1908             : // use it on next access.
    1909             :   ULong64_t msk=0x0000000ffffffff;
    1910          25 :   if (fLock == lock) return 0;  // nothing to be done
    1911           7 :   if (lock) {
    1912             :     // User wants to lock - check his identity
    1913           6 :     if (fKey) {
    1914             :       // Lock has a user - check his key
    1915           1 :       if (fKey != key) {
    1916           0 :         AliFatal("Wrong key provided to lock CDB. Please remove CDB lock access from your code !");
    1917           0 :         return 0;
    1918             :       }
    1919             :     }
    1920             :     // Provide new key
    1921           6 :     fKey = gSystem->Now();
    1922           6 :     fLock = kTRUE;
    1923             :     // give to experts possibility to unlock the CDB
    1924           6 :     SetUniqueID(UInt_t(fKey&msk));
    1925           6 :     return fKey;
    1926             :   }
    1927             :   // User wants to unlock - check the provided key
    1928           1 :   if (key != fKey) {
    1929           0 :     AliFatal("Lock is ON: wrong key provided");
    1930           0 :     return 0;
    1931             :   }
    1932           1 :   fLock = kFALSE;
    1933           1 :   return key;
    1934          16 : }
    1935             : 
    1936             : ///////////////////////////////////////////////////////////
    1937             : // AliCDBManager Parameter class                         //
    1938             : // interface to specific AliCDBParameter class           //
    1939             : // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam)  //
    1940             : ///////////////////////////////////////////////////////////
    1941             : 
    1942          46 : AliCDBParam::AliCDBParam():
    1943          46 :   fType(),
    1944          46 :   fURI()
    1945         138 : {
    1946             :   // constructor
    1947             : 
    1948          46 : }
    1949             : 
    1950             : //_____________________________________________________________________________
    1951          30 : AliCDBParam::~AliCDBParam() {
    1952             :   // destructor
    1953             : 
    1954          15 : }
    1955             : 
    1956             : void AliCDBManager::ExtractBaseFolder(TString& url)
    1957             : {
    1958             :   // TBD RS
    1959             :   // remove everything but the url - 
    1960             :   // Exact copy of the AliReconstuction::Rectify.... (to be removed)
    1961             :   // 
    1962             :   //
    1963           0 :   TString sbs;
    1964           0 :   if (!(sbs=url("\\?User=[^?]*")).IsNull())                url.ReplaceAll(sbs,"");
    1965           0 :   if (!(sbs=url("\\?DBFolder=[^?]*")).IsNull())            url.ReplaceAll("?DB","");
    1966           0 :   if (!(sbs=url("\\?SE=[^?]*")).IsNull())                  url.ReplaceAll(sbs,"");
    1967           0 :   if (!(sbs=url("\\?CacheFolder=[^?]*")).IsNull())         url.ReplaceAll(sbs,"");
    1968           0 :   if (!(sbs=url("\\?OperateDisconnected=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
    1969           0 :   if (!(sbs=url("\\?CacheSize=[^?]*")).IsNull())           url.ReplaceAll(sbs,"");  
    1970           0 :   if (!(sbs=url("\\?CleanupInterval=[^?]*")).IsNull())     url.ReplaceAll(sbs,"");  
    1971             :   Bool_t slash=kFALSE,space=kFALSE;
    1972           0 :   while ( (slash=url.EndsWith("/")) || (space=url.EndsWith(" ")) ) {
    1973           0 :     if (slash) url = url.Strip(TString::kTrailing,'/');
    1974           0 :     if (space) url = url.Strip(TString::kTrailing,' ');
    1975             :   }
    1976             :   //url.ToLower();
    1977             :   //
    1978           0 : }
    1979             : 
    1980             : //_____________________________________________________________________________
    1981             : void AliCDBManager::PromptCacheEntry(const char* path, AliCDBEntry* entry)
    1982             : {
    1983             :   //put (or replace) a CDB entry in the prompt cache, and enable the cache
    1984             :   //this is owner of object, so old entry is destroyed
    1985             : 
    1986           0 :   TPair* pair = static_cast<TPair*>(fEntryCache.FindObject(path));
    1987           0 :   if (pair)
    1988             :   {
    1989           0 :     AliDebug(2, Form("Object %s already in cache, replacing!!", path));
    1990           0 :     TObject* key = pair->Key();
    1991           0 :     TObject* value = pair->Value();
    1992           0 :     fEntryCache.Remove(key);
    1993           0 :     delete key;
    1994             :     //delete value; //We must not delete this here. Actually, the CDB Manager CANNOT take ownership. If some function has querried that Object, it might still have a pointer to it and we DO NOT know.
    1995           0 :   }
    1996           0 :   AliDebug(2,Form("Caching entry %s", path));
    1997           0 :   fPromptEntryCache.Add(new TObjString(path), entry);
    1998           0 :   SetPromptCacheFlag(kTRUE);
    1999           0 : }
    2000             : 

Generated by: LCOV version 1.11