]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/CDB/AliCDBManager.cxx
initial version/subversion should be set to -1 to load last object if special version...
[u/mrichter/AliRoot.git] / STEER / CDB / AliCDBManager.cxx
index 642b2f9a5ab0504ea8a77abd003f581aa941fa64..489164e2c8523973dd4982e02479039bb71d43d3 100644 (file)
@@ -18,7 +18,6 @@
 //   e-mail: Alberto.Colla@cern.ch
 //-------------------------------------------------------------------------
 
-#include <stdlib.h>
 #include <fstream>
 
 #include "AliCDBManager.h"
@@ -104,10 +103,12 @@ void AliCDBManager::InitFromCache(TMap *entryCache, Int_t run) {
 }
 
 //_____________________________________________________________________________
-void  AliCDBManager::DumpToSnapshotFile(const char* snapshotFileName, Bool_t singleKeys){
+void  AliCDBManager::DumpToSnapshotFile(const char* snapshotFileName, Bool_t singleKeys) const {
 //
-// dump the entries map and the ids list to
-// the output file
+// If singleKeys is true, dump the entries map and the ids list to the snapshot file
+// (provided mostly for historical reasons, the file is then read with InitFromSnapshot),
+// otherwise write to file each AliCDBEntry separately (the is the preferred way, the file
+// is then read with SetSnapshotMode).
 
   // open the file
   TFile *f = TFile::Open(snapshotFileName,"RECREATE");
@@ -120,16 +121,11 @@ void  AliCDBManager::DumpToSnapshotFile(const char* snapshotFileName, Bool_t sin
   AliInfo(Form("Dumping entriesList with %d entries!\n", fIds->GetEntries()));
 
   f->cd();
-
   if(singleKeys){
     f->WriteObject(&fEntryCache,"CDBentriesMap");
     f->WriteObject(fIds,"CDBidsList");
   }else{
     // We write the entries one by one named by their calibration path
-    /*
-       fEntryCache.Write("CDBentriesMap");
-       fIds->Write("CDBidsList");
-       */
     TIter iter(fEntryCache.GetTable());
     TPair* pair = 0;
     while((pair = dynamic_cast<TPair*> (iter.Next()))){
@@ -144,8 +140,28 @@ void  AliCDBManager::DumpToSnapshotFile(const char* snapshotFileName, Bool_t sin
   }
   f->Close();
   delete f;
+}
+
+//_____________________________________________________________________________
+void  AliCDBManager::DumpToLightSnapshotFile(const char* lightSnapshotFileName) const {
+// The light snapshot does not contain the CDB objects (AliCDBEntries) but
+// only the information identifying them, that is the map of storages and
+// the list of AliCDBIds, as in the UserInfo of AliESDs.root
+
+  // open the file
+  TFile *f = TFile::Open(lightSnapshotFileName,"RECREATE");
+  if (!f || f->IsZombie()){
+    AliError(Form("Cannot open file %s",lightSnapshotFileName));
+    return;
+  }
+
+  AliInfo(Form("Dumping map of storages with %d entries!\n", fStorageMap->GetEntries()));
+  AliInfo(Form("Dumping entriesList with %d entries!\n", fIds->GetEntries()));
+  f->WriteObject(fStorageMap,"cdbStoragesMap");
+  f->WriteObject(fIds,"CDBidsList");
 
-  exit(0);
+  f->Close();
+  delete f;
 }
 
 //_____________________________________________________________________________
@@ -304,6 +320,7 @@ AliCDBManager::AliCDBManager():
   fLock(kFALSE),
   fSnapshotMode(kFALSE),
   fSnapshotFile(0),
+  fOCDBUploadMode(kFALSE),
   fRaw(kFALSE),
   fCvmfsOcdb(""),
   fStartRunLHCPeriod(-1),
@@ -385,7 +402,7 @@ AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
 
   TString uriString(dbString);
 
-  if (! fCvmfsOcdb.IsNull()) {
+  if ( !fCvmfsOcdb.IsNull() && uriString.BeginsWith("alien://")) {
     AlienToCvmfsUri(uriString);
   }
 
@@ -393,7 +410,6 @@ AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
 
   AliCDBStorageFactory* factory=0;
   while ((factory = (AliCDBStorageFactory*) iter.Next())) {
-    //AliCDBParam* param = factory->CreateParameter(dbString);
     AliCDBParam* param = factory->CreateParameter(uriString);
     if(param) return param;
   }
@@ -405,9 +421,6 @@ AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
 void AliCDBManager::AlienToCvmfsUri(TString& uriString) const {
 // convert alien storage uri to local:///cvmfs storage uri (called when OCDB_PATH is set)
 
-  if (! uriString.BeginsWith("alien://") && !fCvmfsOcdb.IsNull())
-    AliFatal("Cannot set local://cvmfs storage for a non alien uri");
-
   TObjArray *arr = uriString.Tokenize('?');
   TIter iter(arr);
   TObjString *str = 0;
@@ -448,15 +461,20 @@ void AliCDBManager::AlienToCvmfsUri(TString& uriString) const {
 
 //_____________________________________________________________________________
 AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) {
-// get storage object from URI string
+// Get the CDB storage corresponding to the URI string passed as argument
+// If "raw://" is passed, get the storage for the raw OCDB for the current run (fRun)
 
-  // Check environment variable OCDB_PATH. It is set in case the user (job) expects
-  // to find in the local /cvmfs the required OCDB tag. The OCDB_PATH variable
-  // contains the path to the directory in /cvmfs/ which is an AliRoot tag based snapshot
-  // of the AliEn file catalogue. The directory has to contain:
-  // 1) catalogue/20??.list.gz gzipped text files listing the OCDB files (seen by that AliRoot tag)
-  // 2) bin/getOCDBperRun.sh   (shell+awk) script extracting from 1) the list
-  // of valid files for the given run.
+  TString uriString(dbString);
+  if (uriString.EqualTo("raw://")) {
+    if (!fLHCPeriod.IsNull() && !fLHCPeriod.IsWhitespace()) {
+      return GetDefaultStorage();
+    } else {
+      TString lhcPeriod("");
+      Int_t startRun = -1, endRun = -1;
+      GetLHCPeriodAgainstAlienFile(fRun, lhcPeriod, startRun, endRun);
+      return GetStorage(lhcPeriod.Data());
+    }
+  }
 
   AliCDBParam* param = CreateParameter(dbString);
   if (!param) {
@@ -564,6 +582,20 @@ Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
   return fDrainStorage->Put(entry);
 }
 
+//____________________________________________________________________________
+Bool_t AliCDBManager::SetOCDBUploadMode() {
+// Set the framework in official upload mode. This tells the framework to upload
+// objects to cvmfs after they have been uploaded to AliEn OCDBs.
+// It return false if the executable to upload to cvmfs is not found.
+
+  TString cvmfsUploadExecutable("$HOME/bin/ocdb-cvmfs");
+  gSystem->ExpandPathName(cvmfsUploadExecutable);
+  if ( gSystem->AccessPathName(cvmfsUploadExecutable) )
+    return kFALSE;
+  fOCDBUploadMode = kTRUE;
+  return kTRUE;
+}
+
 //____________________________________________________________________________
 void AliCDBManager::SetDefaultStorage(const char* storageUri) {
 // sets default storage from URI string
@@ -689,6 +721,14 @@ void AliCDBManager::SetDefaultStorage(const char* mcString, const char* simType)
 
 //_____________________________________________________________________________
 void AliCDBManager::ValidateCvmfsCase() const {
+  // The OCDB_PATH variable contains the path to the directory in /cvmfs/ which is
+  // an AliRoot tag based snapshot of the AliEn file catalogue (e.g. 
+  // /cvmfs/alice.cern.ch/x86_64-2.6-gnu-4.1.2/Packages/OCDB/v5-05-76-AN).
+  // The directory has to contain:
+  // 1) <data|MC>/20??.list.gz gzipped text files listing the OCDB files (seen by that AliRoot tag)
+  // 2) bin/getOCDBFilesPerRun.sh   (shell+awk) script extracting from 1) the list
+  //    of valid files for the given run.
+
     if (! fCvmfsOcdb.BeginsWith("/cvmfs"))  //!!!! to be commented out for testing
       AliFatal(Form("OCDB_PATH set to an invalid path: %s", fCvmfsOcdb.Data()));
 
@@ -718,86 +758,102 @@ void AliCDBManager::SetDefaultStorageFromRun(Int_t run) {
     }
   }    
 
-  // fRaw and cvmfs case
-  if (! fCvmfsOcdb.IsNull()) {
-    // we don't want to connect to AliEn just to set the uri from the runnumber
-    // for that we use the script getUriFromYear.sh in the cvmfs AliRoot package
-    // check that we find the two scripts we need
-    TString getYearScript(fCvmfsOcdb);
-    getYearScript = getYearScript.Strip(TString::kTrailing, '/');
-    getYearScript.Append("/bin/getUriFromYear.sh");
-    if (gSystem->AccessPathName(getYearScript))
-      AliFatal(Form("Cannot find valid script: %s", getYearScript.Data()));
-    TString inoutFile(gSystem->WorkingDirectory());
-    inoutFile += "/uri_range_";
-    inoutFile += TString::Itoa(fRun,10);
-    TString command(getYearScript);
-    command += ' ';
-    command += TString::Itoa(fRun,10);
-    command += Form(" > %s", inoutFile.Data());
-    AliDebug(3, Form("Running command: \"%s\"",command.Data()));
-    Int_t result = gSystem->Exec(command.Data());
-    if(result != 0) {
-      AliFatal(Form("Was not able to execute \"%s\"", command.Data()));
-    }
+  TString lhcPeriod("");
+  Int_t startRun = 0, endRun = 0;
+  if (! fCvmfsOcdb.IsNull()) { // fRaw and cvmfs case: set LHC period from cvmfs file
+    GetLHCPeriodAgainstCvmfsFile(run, lhcPeriod, startRun, endRun);
+  } else {                     // fRaw: set LHC period from AliEn XML file
+    GetLHCPeriodAgainstAlienFile(run, lhcPeriod, startRun, endRun);
+  }
 
-    // now read the file with the uri and first and last run
-    ifstream *file = new ifstream(inoutFile.Data());
-    if (!*file) {
-      AliFatal(Form("Error opening file \"%s\"!", inoutFile.Data()));
-    }
-    TString lhcPeriod;
-    TObjArray* oStringsArray = 0;
-    while (lhcPeriod.ReadLine(*file)){
-      oStringsArray = lhcPeriod.Tokenize(' ');
-    }
-    TObjString *oStrUri = dynamic_cast<TObjString*> (oStringsArray->At(0));
-    TObjString *oStrFirst = dynamic_cast<TObjString*> (oStringsArray->At(1));
-    TString firstRun = oStrFirst->GetString();
-    TObjString *oStrLast = dynamic_cast<TObjString*> (oStringsArray->At(2));
-    TString lastRun = oStrLast->GetString();
+  fLHCPeriod = lhcPeriod;
+  fStartRunLHCPeriod = startRun;
+  fEndRunLHCPeriod = endRun;
 
-    fLHCPeriod = oStrUri->GetString();
-    fStartRunLHCPeriod = firstRun.Atoi();
-    fEndRunLHCPeriod = lastRun.Atoi();
+  SetDefaultStorage(fLHCPeriod.Data());
+  if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",fLHCPeriod.Data()));
 
-    file->close();
-    delete file;
+}
 
-  } else { // if not cvmfs case, "plain" AliEn case
-    // retrieve XML file from alien
+//_____________________________________________________________________________
+void AliCDBManager::GetLHCPeriodAgainstAlienFile(Int_t run, TString& lhcPeriod, Int_t& startRun, Int_t& endRun) {
+// set LHC period (year + first, last run) comparing run number and AliEn XML file
+// retrieve XML file from alien
+  if(!gGrid) {
+    TGrid::Connect("alien://","");
     if(!gGrid) {
-      TGrid::Connect("alien://","");
-      if(!gGrid) {
-        AliError("Connection to alien failed!");
-        return;
-      }
-    }
-    TUUID uuid;
-    TString rndname = "/tmp/";
-    rndname += "OCDBFolderXML.";
-    rndname += uuid.AsString();
-    rndname += ".xml";
-    AliDebug(2, Form("file to be copied = %s", fgkOCDBFolderXMLfile.Data()));
-    if (!TFile::Cp(fgkOCDBFolderXMLfile.Data(), rndname.Data())) {
-      AliFatal(Form("Cannot make a local copy of OCDBFolder xml file in %s",rndname.Data()));
+      AliError("Connection to alien failed!");
+      return;
     }
-    AliCDBHandler* saxcdb = new AliCDBHandler();
-    saxcdb->SetRun(run);
-    TSAXParser *saxParser = new TSAXParser();
-    saxParser->ConnectToHandler("AliCDBHandler", saxcdb);
-    saxParser->ParseFile(rndname.Data());
-    AliInfo(Form(" LHC folder = %s", saxcdb->GetOCDBFolder().Data()));
-    AliInfo(Form(" LHC period start run = %d", saxcdb->GetStartRunRange()));
-    AliInfo(Form(" LHC period end run = %d", saxcdb->GetEndRunRange()));
-    fLHCPeriod = saxcdb->GetOCDBFolder();
-    fStartRunLHCPeriod = saxcdb->GetStartRunRange();
-    fEndRunLHCPeriod = saxcdb->GetEndRunRange();
   }
+  TUUID uuid;
+  TString rndname = "/tmp/";
+  rndname += "OCDBFolderXML.";
+  rndname += uuid.AsString();
+  rndname += ".xml";
+  AliDebug(2, Form("file to be copied = %s", fgkOCDBFolderXMLfile.Data()));
+  if (!TFile::Cp(fgkOCDBFolderXMLfile.Data(), rndname.Data())) {
+    AliFatal(Form("Cannot make a local copy of OCDBFolder xml file in %s",rndname.Data()));
+  }
+  AliCDBHandler* saxcdb = new AliCDBHandler();
+  saxcdb->SetRun(run);
+  TSAXParser *saxParser = new TSAXParser();
+  saxParser->ConnectToHandler("AliCDBHandler", saxcdb);
+  saxParser->ParseFile(rndname.Data());
+  AliInfo(Form(" LHC folder = %s", saxcdb->GetOCDBFolder().Data()));
+  AliInfo(Form(" LHC period start run = %d", saxcdb->GetStartRunRange()));
+  AliInfo(Form(" LHC period end run = %d", saxcdb->GetEndRunRange()));
+  lhcPeriod = saxcdb->GetOCDBFolder();
+  startRun = saxcdb->GetStartRunRange();
+  endRun = saxcdb->GetEndRunRange();
+}
 
-  SetDefaultStorage(fLHCPeriod.Data());
-  if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",fLHCPeriod.Data()));
-
+//_____________________________________________________________________________
+void AliCDBManager::GetLHCPeriodAgainstCvmfsFile(Int_t run, TString& lhcPeriod, Int_t& startRun, Int_t& endRun) {
+// set LHC period (year + first, last run) comparing run number and CVMFS file
+// We don't want to connect to AliEn just to set the uri from the runnumber
+// for that we use the script getUriFromYear.sh in the cvmfs AliRoot package
+
+  TString getYearScript(fCvmfsOcdb);
+  getYearScript = getYearScript.Strip(TString::kTrailing, '/');
+  getYearScript.Append("/bin/getUriFromYear.sh");
+  if (gSystem->AccessPathName(getYearScript))
+    AliFatal(Form("Cannot find valid script: %s", getYearScript.Data()));
+  TString inoutFile(gSystem->WorkingDirectory());
+  inoutFile += "/uri_range_";
+  inoutFile += TString::Itoa(run,10);
+  TString command(getYearScript);
+  command += ' ';
+  command += TString::Itoa(run,10);
+  command += Form(" > %s", inoutFile.Data());
+  AliDebug(3, Form("Running command: \"%s\"",command.Data()));
+  Int_t result = gSystem->Exec(command.Data());
+  if(result != 0) {
+    AliFatal(Form("Was not able to execute \"%s\"", command.Data()));
+  }
+
+  // now read the file with the uri and first and last run
+  std::ifstream file(inoutFile.Data());
+  if (!file.is_open()) {
+    AliFatal(Form("Error opening file \"%s\"!", inoutFile.Data()));
+  }
+  TString line;
+  TObjArray* oStringsArray = 0;
+  while (line.ReadLine(file)){
+    oStringsArray = line.Tokenize(' ');
+  }
+  TObjString *oStrUri = dynamic_cast<TObjString*> (oStringsArray->At(0));
+  TObjString *oStrFirst = dynamic_cast<TObjString*> (oStringsArray->At(1));
+  TString firstRun = oStrFirst->GetString();
+  TObjString *oStrLast = dynamic_cast<TObjString*> (oStringsArray->At(2));
+  TString lastRun = oStrLast->GetString();
+
+  lhcPeriod = oStrUri->GetString();
+  startRun = firstRun.Atoi();
+  endRun = lastRun.Atoi();
+
+  file.close();
 }
 
 //_____________________________________________________________________________
@@ -823,24 +879,25 @@ void AliCDBManager::UnsetDefaultStorage() {
 }
 
 //_____________________________________________________________________________
-void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) {
+void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString, Int_t version, Int_t subVersion) {
 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
 
   AliCDBParam *aPar = CreateParameter(dbString);
   if(!aPar) return;
-  SetSpecificStorage(calibType, aPar);
+  SetSpecificStorage(calibType, aPar, version, subVersion);
   delete aPar;
 }
 
 //_____________________________________________________________________________
-void AliCDBManager::SetSpecificStorage(const char* calibType, const AliCDBParam* param) {
+void AliCDBManager::SetSpecificStorage(const char* calibType, const AliCDBParam* param, Int_t version, Int_t subVersion) {
 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
 // Default storage should be defined prior to any specific storages, e.g.:
 // AliCDBManager::instance()->SetDefaultStorage("alien://");
 // AliCDBManager::instance()->SetSpecificStorage("TPC/*","local://DB_TPC");
 // AliCDBManager::instance()->SetSpecificStorage("*/Align/*","local://DB_TPCAlign");
 // calibType must be a valid CDB path! (3 level folder structure)
-
+// Specific version/subversion is set in the uniqueid of the AliCDBParam value stored in the
+// specific storages map
 
   if(!fDefaultStorage && !fRaw) {
     AliError("Please activate a default storage first!");
@@ -864,7 +921,11 @@ void AliCDBManager::SetSpecificStorage(const char* calibType, const AliCDBParam*
   AliCDBStorage *aStorage = GetStorage(param);
   if(!aStorage) return;
 
-  fSpecificStorages.Add(objCalibType, param->CloneParam());
+  // Set the unique id of the AliCDBParam stored in the map to store specific version/subversion
+  UInt_t uId = ((subVersion+1)<<16) + (version+1);
+  AliCDBParam *specificParam = param->CloneParam();
+  specificParam->SetUniqueID(uId);
+  fSpecificStorages.Add(objCalibType, specificParam);
 
   if(fStorageMap->Contains(objCalibType)){
     delete fStorageMap->Remove(objCalibType);
@@ -939,50 +1000,50 @@ AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path,
 }
 
 //_____________________________________________________________________________
-AliCDBEntry* AliCDBManager::Get(const AliCDBId& query, Bool_t forceCaching) {
+AliCDBEntry* AliCDBManager::Get(const AliCDBId& queryId, Bool_t forceCaching) {
 // get an AliCDBEntry object from the database
 
-  // check if query's path and runRange are valid
-  // query is invalid also if version is not specified and subversion is!
-  if (!query.IsValid()) {
-    AliError(Form("Invalid query: %s", query.ToString().Data()));
+  // check if queryId's path and runRange are valid
+  // queryId is invalid also if version is not specified and subversion is!
+  if (!queryId.IsValid()) {
+    AliError(Form("Invalid query: %s", queryId.ToString().Data()));
     return NULL;
   }
 
-  // query is not specified if path contains wildcard or run range= [-1,-1]
-  if (!query.IsSpecified()) {
+  // queryId is not specified if path contains wildcard or run range= [-1,-1]
+  if (!queryId.IsSpecified()) {
     AliError(Form("Unspecified query: %s",
-          query.ToString().Data()));
+          queryId.ToString().Data()));
     return NULL;
   }
 
-  if(fLock && !(fRun >= query.GetFirstRun() && fRun <= query.GetLastRun()))
+  if(fLock && !(fRun >= queryId.GetFirstRun() && fRun <= queryId.GetLastRun()))
     AliFatal("Lock is ON: cannot use different run number than the internal one!");
 
-  if(fCache && !(fRun >= query.GetFirstRun() && fRun <= query.GetLastRun()))
+  if(fCache && !(fRun >= queryId.GetFirstRun() && fRun <= queryId.GetLastRun()))
     AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
 
   AliCDBEntry *entry=0;
 
   // first look into map of cached objects
-  if(fCache && query.GetFirstRun() == fRun)
-    entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
+  if(fCache && queryId.GetFirstRun() == fRun)
+    entry = (AliCDBEntry*) fEntryCache.GetValue(queryId.GetPath());
   if(entry) {
-    AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
+    AliDebug(2, Form("Object %s retrieved from cache !!",queryId.GetPath().Data()));
     return entry;
   }
 
   // if snapshot flag is set, try getting from the snapshot
   // but in the case a specific storage is specified for this path
-  AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
+  AliCDBParam *aPar=SelectSpecificStorage(queryId.GetPath());
   if(!aPar){
-    if(fSnapshotMode && query.GetFirstRun() == fRun)
+    if(fSnapshotMode && queryId.GetFirstRun() == fRun)
     {
-      entry = GetEntryFromSnapshot(query.GetPath());
+      entry = GetEntryFromSnapshot(queryId.GetPath());
       if(entry) {
-        AliInfo(Form("Object \"%s\" retrieved from the snapshot.",query.GetPath().Data()));
-        if(query.GetFirstRun() == fRun) // no need to check fCache, fSnapshotMode not possible otherwise
-          CacheEntry(query.GetPath(), entry);
+        AliInfo(Form("Object \"%s\" retrieved from the snapshot.",queryId.GetPath().Data()));
+        if(queryId.GetFirstRun() == fRun) // no need to check fCache, fSnapshotMode not possible otherwise
+          CacheEntry(queryId.GetPath(), entry);
 
         if(!fIds->Contains(&entry->GetId()))
           fIds->Add(entry->GetId().Clone());
@@ -999,29 +1060,40 @@ AliCDBEntry* AliCDBManager::Get(const AliCDBId& query, Bool_t forceCaching) {
     return NULL;
   }
 
+  Int_t version = -1, subVersion = -1;
   AliCDBStorage *aStorage=0;
   if(aPar) {
     aStorage=GetStorage(aPar);
     TString str = aPar->GetURI();
+    UInt_t uId = aPar->GetUniqueID();
+    version = Int_t(uId&0xffff) - 1;
+    subVersion = Int_t(uId>>16) - 1;
     AliDebug(2,Form("Looking into storage: %s",str.Data()));
   } else {
     aStorage=GetDefaultStorage();
     AliDebug(2,"Looking into default storage");
   }
 
-  entry = aStorage->Get(query);
+  AliCDBId finalQueryId(queryId);
+  if(version >= 0) {
+    AliDebug(2,Form("Specific version set to: %d", version));
+    finalQueryId.SetVersion(version);
+  }
+  if(subVersion >= 0) {
+    AliDebug(2,Form("Specific subversion set to: %d", subVersion));
+    finalQueryId.SetSubVersion(subVersion);
+  }
+  entry = aStorage->Get(finalQueryId);
 
-  if(entry && fCache && (query.GetFirstRun()==fRun || forceCaching)){
-    CacheEntry(query.GetPath(), entry);
+  if(entry && fCache && (queryId.GetFirstRun()==fRun || forceCaching)){
+    CacheEntry(queryId.GetPath(), entry);
   }
 
   if(entry && !fIds->Contains(&entry->GetId())){
     fIds->Add(entry->GetId().Clone());
   }
 
-
   return entry;
-
 }
 
 //_____________________________________________________________________________
@@ -1505,7 +1577,7 @@ void AliCDBManager::SetRun(Int_t run) {
     if (fStartRunLHCPeriod <= run && fEndRunLHCPeriod >= run){
       AliInfo("LHCPeriod alien folder for current run already in memory");
     }else{
-      SetDefaultStorageFromRun(run);
+      SetDefaultStorageFromRun(fRun);
       if(fEntryCache.GetEntries()!=0) ClearCache();
       return;
     }
@@ -1842,3 +1914,26 @@ AliCDBParam::~AliCDBParam() {
 
 }
 
+void AliCDBManager::ExtractBaseFolder(TString& url)
+{
+  // TBD RS
+  // remove everything but the url - 
+  // Exact copy of the AliReconstuction::Rectify.... (to be removed)
+  // 
+  //
+  TString sbs;
+  if (!(sbs=url("\\?User=[^?]*")).IsNull())                url.ReplaceAll(sbs,"");
+  if (!(sbs=url("\\?DBFolder=[^?]*")).IsNull())            url.ReplaceAll("?DB","");
+  if (!(sbs=url("\\?SE=[^?]*")).IsNull())                  url.ReplaceAll(sbs,"");
+  if (!(sbs=url("\\?CacheFolder=[^?]*")).IsNull())         url.ReplaceAll(sbs,"");
+  if (!(sbs=url("\\?OperateDisconnected=[^?]*")).IsNull()) url.ReplaceAll(sbs,"");
+  if (!(sbs=url("\\?CacheSize=[^?]*")).IsNull())           url.ReplaceAll(sbs,"");  
+  if (!(sbs=url("\\?CleanupInterval=[^?]*")).IsNull())     url.ReplaceAll(sbs,"");  
+  Bool_t slash=kFALSE,space=kFALSE;
+  while ( (slash=url.EndsWith("/")) || (space=url.EndsWith(" ")) ) {
+    if (slash) url = url.Strip(TString::kTrailing,'/');
+    if (space) url = url.Strip(TString::kTrailing,' ');
+  }
+  //url.ToLower();
+  //
+}