Implementation of the local caching of the OCDB set required some upgrade of the...
authoracolla <acolla@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 4 Sep 2007 17:38:39 +0000 (17:38 +0000)
committeracolla <acolla@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 4 Sep 2007 17:38:39 +0000 (17:38 +0000)
framework

Main changes:

- Public method GetId(AliCDBId& query) added to AliCDBManager and AliCDBStorage. It is used to retrieve the Id of the valid object
without retieving the object itself.
- "Remote storage" added to AliCDBManager's possible storages. Remote storage is used if it
is activated and if object is not found in the default storage. This is used in case an
object in the local cache is lost before the job is executed.

13 files changed:
STEER/AliCDBDump.cxx
STEER/AliCDBDump.h
STEER/AliCDBGrid.cxx
STEER/AliCDBGrid.h
STEER/AliCDBId.h
STEER/AliCDBLocal.cxx
STEER/AliCDBLocal.h
STEER/AliCDBManager.cxx
STEER/AliCDBManager.h
STEER/AliCDBPath.cxx
STEER/AliCDBPath.h
STEER/AliCDBStorage.cxx
STEER/AliCDBStorage.h

index d40bb51..49b97af 100644 (file)
@@ -251,9 +251,119 @@ Bool_t AliCDBDump::PrepareId(AliCDBId& id) {
 
 }
 
+// //_____________________________________________________________________________
+// Bool_t AliCDBDump::GetId(const AliCDBId& query, AliCDBId& result) {
+// // look for filename matching query (called by GetEntry)
+// 
+// 
+//         AliCDBRunRange aRunRange; // the runRange got from filename
+//         Int_t aVersion, aSubVersion; // the version and subVersion got from filename
+// 
+//     TIter iter(gDirectory->GetListOfKeys());
+//     TKey* key;
+// 
+//     if (!query.HasVersion()) { // neither version and subversion specified -> look for highest version and subVersion
+// 
+//                 while ((key = (TKey*) iter.Next())) { // loop on the keys
+// 
+//                     if (!KeyNameToId(key->GetName(), aRunRange, aVersion, aSubVersion)) continue;
+//                         // aRunRange, aVersion, aSubVersion filled from filename
+// 
+//                     if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
+//                     // aRunRange contains requested run!
+// 
+//                     if (result.GetVersion() < aVersion) {
+//                             result.SetVersion(aVersion);
+//                             result.SetSubVersion(aSubVersion);
+// 
+//                             result.SetFirstRun(
+//                                     aRunRange.GetFirstRun());
+//                             result.SetLastRun(
+//                                     aRunRange.GetLastRun());
+// 
+//                     } else if (result.GetVersion() == aVersion
+//                             && result.GetSubVersion()
+//                                     < aSubVersion) {
+// 
+//                             result.SetSubVersion(aSubVersion);
+// 
+//                             result.SetFirstRun(
+//                                     aRunRange.GetFirstRun());
+//                             result.SetLastRun(
+//                                     aRunRange.GetLastRun());
+//                     } else if (result.GetVersion() == aVersion
+//                             && result.GetSubVersion() == aSubVersion){
+//                                     AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
+//                                     query.GetFirstRun(), aVersion, aSubVersion));
+//                             result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
+//                             return kFALSE;
+//                             }
+//             }
+// 
+//     } else if (!query.HasSubVersion()) { // version specified but not subversion -> look for highest subVersion
+// 
+//             result.SetVersion(query.GetVersion());
+// 
+//                 while ((key = (TKey*) iter.Next())) { // loop on the keys
+// 
+//                     if (!KeyNameToId(key->GetName(), aRunRange, aVersion, aSubVersion)) continue;
+//                         // aRunRange, aVersion, aSubVersion filled from filename
+// 
+//                        if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
+//                     // aRunRange contains requested run!
+//                     
+//                     if(query.GetVersion() != aVersion) continue;
+//                     // aVersion is requested version!
+// 
+//                     if(result.GetSubVersion() == aSubVersion){
+//                                     AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
+//                                     query.GetFirstRun(), aVersion, aSubVersion));
+//                             result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
+//                             return kFALSE;
+//                     }
+//                     if( result.GetSubVersion() < aSubVersion) {
+// 
+//                                 result.SetSubVersion(aSubVersion);
+// 
+//                                 result.SetFirstRun(
+//                                     aRunRange.GetFirstRun());
+//                                 result.SetLastRun(
+//                                     aRunRange.GetLastRun());
+//                     }
+//                 }
+// 
+//     } else { // both version and subversion specified
+// 
+//                 while ((key = (TKey*) iter.Next())) { // loop on the keys
+// 
+//                     if (!KeyNameToId(key->GetName(), aRunRange, aVersion, aSubVersion)) continue;
+//                         // aRunRange, aVersion, aSubVersion filled from filename
+// 
+//                     if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
+//                     // aRunRange contains requested run!
+// 
+//                     if(query.GetVersion() != aVersion || query.GetSubVersion() != aSubVersion) continue;
+//                     // aVersion and aSubVersion are requested version and subVersion!
+// 
+//                     if(result.GetVersion() == aVersion && result.GetSubVersion() == aSubVersion){
+//                                     AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
+//                                     query.GetFirstRun(), aVersion, aSubVersion));
+//                             result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
+//                             return kFALSE; 
+//                     }
+//                     result.SetVersion(aVersion);
+//                     result.SetSubVersion(aSubVersion);
+//                     result.SetFirstRun(aRunRange.GetFirstRun());
+//                     result.SetLastRun(aRunRange.GetLastRun());
+// 
+//             }
+//     }
+// 
+//     return kTRUE;
+// }
 
 //_____________________________________________________________________________
-Bool_t AliCDBDump::GetId(const AliCDBId& query, AliCDBId& result) {
+AliCDBId* AliCDBDump::GetId(const AliCDBId& query) {
 // look for filename matching query (called by GetEntry)
 
 
@@ -263,8 +373,11 @@ Bool_t AliCDBDump::GetId(const AliCDBId& query, AliCDBId& result) {
        TIter iter(gDirectory->GetListOfKeys());
        TKey* key;
 
+       AliCDBId* result = new AliCDBId();
+       result->SetPath(query.GetPath());
+
        if (!query.HasVersion()) { // neither version and subversion specified -> look for highest version and subVersion
-               
+
                 while ((key = (TKey*) iter.Next())) { // loop on the keys
                        
                        if (!KeyNameToId(key->GetName(), aRunRange, aVersion, aSubVersion)) continue;
@@ -272,41 +385,41 @@ Bool_t AliCDBDump::GetId(const AliCDBId& query, AliCDBId& result) {
 
                        if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
                        // aRunRange contains requested run!
-                       
-                       if (result.GetVersion() < aVersion) {
-                               result.SetVersion(aVersion);
-                               result.SetSubVersion(aSubVersion);
 
-                               result.SetFirstRun(
+                       if (result->GetVersion() < aVersion) {
+                               result->SetVersion(aVersion);
+                               result->SetSubVersion(aSubVersion);
+
+                               result->SetFirstRun(
                                        aRunRange.GetFirstRun());
-                               result.SetLastRun(
+                               result->SetLastRun(
                                        aRunRange.GetLastRun());
 
-                       } else if (result.GetVersion() == aVersion 
-                               && result.GetSubVersion() 
+                       } else if (result->GetVersion() == aVersion
+                               && result->GetSubVersion()
                                        < aSubVersion) {
 
-                               result.SetSubVersion(aSubVersion);
+                               result->SetSubVersion(aSubVersion);
 
-                               result.SetFirstRun(
+                               result->SetFirstRun(
                                        aRunRange.GetFirstRun());
-                               result.SetLastRun(
+                               result->SetLastRun(
                                        aRunRange.GetLastRun());
-                       } else if (result.GetVersion() == aVersion
-                               && result.GetSubVersion() == aSubVersion){
-                               AliDebug(2,Form("More than one object valid for run %d, version %d_%d!", 
+                       } else if (result->GetVersion() == aVersion
+                               && result->GetSubVersion() == aSubVersion){
+                               AliError(Form("More than one object valid for run %d, version %d_%d!",
                                        query.GetFirstRun(), aVersion, aSubVersion));
-                               result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
-                               return kFALSE; 
+                               delete result;
+                               return NULL;
                                }
                }
-               
+
        } else if (!query.HasSubVersion()) { // version specified but not subversion -> look for highest subVersion
 
-               result.SetVersion(query.GetVersion());
+               result->SetVersion(query.GetVersion());
 
                 while ((key = (TKey*) iter.Next())) { // loop on the keys
-                       
+
                        if (!KeyNameToId(key->GetName(), aRunRange, aVersion, aSubVersion)) continue;
                         // aRunRange, aVersion, aSubVersion filled from filename
 
@@ -315,20 +428,20 @@ Bool_t AliCDBDump::GetId(const AliCDBId& query, AliCDBId& result) {
                        
                        if(query.GetVersion() != aVersion) continue;
                        // aVersion is requested version!
-                       
-                       if(result.GetSubVersion() == aSubVersion){
-                               AliDebug(2,Form("More than one object valid for run %d, version %d_%d!", 
+
+                       if(result->GetSubVersion() == aSubVersion){
+                               AliError(Form("More than one object valid for run %d, version %d_%d!",
                                        query.GetFirstRun(), aVersion, aSubVersion));
-                               result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
-                               return kFALSE; 
+                               delete result;
+                               return NULL;
                        }
-                       if( result.GetSubVersion() < aSubVersion) {
+                       if( result->GetSubVersion() < aSubVersion) {
 
-                                result.SetSubVersion(aSubVersion);
+                                result->SetSubVersion(aSubVersion);
 
-                                result.SetFirstRun(
+                                result->SetFirstRun(
                                        aRunRange.GetFirstRun());
-                                result.SetLastRun(
+                                result->SetLastRun(
                                        aRunRange.GetLastRun());
                        } 
                 }
@@ -339,28 +452,28 @@ Bool_t AliCDBDump::GetId(const AliCDBId& query, AliCDBId& result) {
                        
                        if (!KeyNameToId(key->GetName(), aRunRange, aVersion, aSubVersion)) continue;
                         // aRunRange, aVersion, aSubVersion filled from filename
-                       
+
                        if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
                        // aRunRange contains requested run!
 
-                       if(query.GetVersion() != aVersion || query.GetSubVersion() != aSubVersion) continue; 
+                       if(query.GetVersion() != aVersion || query.GetSubVersion() != aSubVersion) continue;
                        // aVersion and aSubVersion are requested version and subVersion!
 
-                       if(result.GetVersion() == aVersion && result.GetSubVersion() == aSubVersion){
-                               AliDebug(2,Form("More than one object valid for run %d, version %d_%d!", 
+                       if(result->GetVersion() == aVersion && result->GetSubVersion() == aSubVersion){
+                               AliError(Form("More than one object valid for run %d, version %d_%d!",
                                        query.GetFirstRun(), aVersion, aSubVersion));
-                               result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
-                               return kFALSE; 
+                               delete result;
+                               return NULL;
                        }
-                       result.SetVersion(aVersion);
-                       result.SetSubVersion(aSubVersion);
-                       result.SetFirstRun(aRunRange.GetFirstRun());
-                       result.SetLastRun(aRunRange.GetLastRun());
+                       result->SetVersion(aVersion);
+                       result->SetSubVersion(aSubVersion);
+                       result->SetFirstRun(aRunRange.GetFirstRun());
+                       result->SetLastRun(aRunRange.GetLastRun());
                        
                }
        }
 
-       return kTRUE;
+       return result;
 }
 
 //_____________________________________________________________________________
@@ -378,51 +491,80 @@ AliCDBEntry* AliCDBDump::GetEntry(const AliCDBId& queryId) {
                 return NULL;
         }
 
-       AliCDBId dataId(queryId.GetAliCDBPath(), -1, -1, -1, -1);
-        Bool_t result;
+       AliCDBId *dataId = GetEntryId(queryId);
 
-       // look for a filename matching query requests (path, runRange, version, subVersion)
-       if (!queryId.HasVersion()) {
-               // if version is not specified, first check the selection criteria list
-               AliCDBId selectedId(queryId);
-               GetSelection(&selectedId);
-               result = GetId(selectedId, dataId);
-       } else {
-               result = GetId(queryId, dataId);
-       }
-
-       if (!result || !dataId.IsSpecified()) {
+       if (!dataId || !dataId->IsSpecified()) {
+               if(dataId) delete dataId;
                return NULL;
        }
-       
+
        TString keyname;
-       if (!IdToKeyName(dataId.GetAliCDBRunRange(), dataId.GetVersion(), 
-               dataId.GetSubVersion(), keyname)) {
+       if (!IdToKeyName(dataId->GetAliCDBRunRange(), dataId->GetVersion(),
+               dataId->GetSubVersion(), keyname)) {
                AliDebug(2,Form("Bad ID encountered! Subnormal error!"));
+               delete dataId;
                return NULL;
        }
 
        // get the only AliCDBEntry object from the file
-       // the object in the file is an AliCDBEntry entry named keyname 
+       // the object in the file is an AliCDBEntry entry named keyname
        // keyName = Run#firstRun_#lastRun_v#version_s#subVersion
 
        TObject* anObject = gDirectory->Get(keyname);
        if (!anObject) {
                AliDebug(2,Form("Bad storage data: NULL entry object!"));
+               delete dataId;
                return NULL;
        } 
 
        if (AliCDBEntry::Class() != anObject->IsA()) {
                AliDebug(2,Form("Bad storage data: Invalid entry object!"));
+               delete dataId;
                return NULL;
        }
 
        ((AliCDBEntry*) anObject)->SetLastStorage("dump");
-       
+
+       delete dataId;
        return (AliCDBEntry*) anObject;
 }
 
 //_____________________________________________________________________________
+AliCDBId* AliCDBDump::GetEntryId(const AliCDBId& queryId) {
+// get AliCDBEntry from the database
+
+       TDirectory::TContext context(gDirectory, fFile);
+
+       if (!(fFile && fFile->IsOpen())) {
+                AliError("AliCDBDump storage is not initialized properly");
+                return NULL;
+        }
+
+        if (!gDirectory->cd(queryId.GetPath())) {
+                return NULL;
+        }
+
+       AliCDBId* dataId = 0;
+
+       // look for a filename matching query requests (path, runRange, version, subVersion)
+       if (!queryId.HasVersion()) {
+               // if version is not specified, first check the selection criteria list
+               AliCDBId selectedId(queryId);
+               GetSelection(&selectedId);
+               dataId = GetId(queryId);
+       } else {
+               dataId = GetId(queryId);
+       }
+
+       if (dataId && !dataId->IsSpecified()) {
+               delete dataId;
+               return NULL;
+       }
+
+       return dataId;
+}
+
+//_____________________________________________________________________________
 void AliCDBDump::GetEntriesForLevel0(const AliCDBId& queryId, TList* result) {
 // multiple request (AliCDBStorage::GetAll)
 
@@ -432,7 +574,7 @@ void AliCDBDump::GetEntriesForLevel0(const AliCDBId& queryId, TList* result) {
        TKey* key;
 
        while ((key = (TKey*) iter.Next())) {
-               
+
                TString keyNameStr(key->GetName());
                if (queryId.GetAliCDBPath().Level1Comprises(keyNameStr)) {
                        gDirectory->cd(keyNameStr);
@@ -631,11 +773,13 @@ Int_t AliCDBDump::GetLatestVersion(const char* path, Int_t run){
        }
 
        AliCDBId query(path, run, run, -1, -1);
-       AliCDBId dataId;
+       AliCDBId *dataId = GetId(query);
 
-       GetId(query,dataId);
+       if(!dataId) return -1;
+       Int_t version = dataId->GetVersion();
 
-       return dataId.GetVersion();
+       delete dataId;
+       return version;
 }
 
 //_____________________________________________________________________________
@@ -649,11 +793,14 @@ Int_t AliCDBDump::GetLatestSubVersion(const char* path, Int_t run, Int_t version
        }
 
        AliCDBId query(path, run, run, version, -1);
-       AliCDBId dataId;
+       AliCDBId *dataId = GetId(query);
+
+       if(!dataId) return -1;
 
-       GetId(query,dataId);
+       Int_t subVersion = dataId->GetSubVersion();
 
-       return dataId.GetSubVersion();
+       delete dataId;
+       return subVersion;
 
 }
 
@@ -712,7 +859,7 @@ AliCDBStorage* AliCDBDumpFactory::Create(const AliCDBParam* param) {
                 const AliCDBDumpParam* dumpParam = 
                        (const AliCDBDumpParam*) param;
 
-                return new AliCDBDump(dumpParam->GetPath(), 
+                return new AliCDBDump(dumpParam->GetPath(),
                                dumpParam->IsReadOnly());
         }
 
index c8b3369..4c54ae6 100644 (file)
@@ -32,6 +32,7 @@ public:
 protected:
 
        virtual AliCDBEntry*    GetEntry(const AliCDBId& query);
+       virtual AliCDBId*       GetEntryId(const AliCDBId& query);
         virtual TList*                 GetEntries(const AliCDBId& query);
         virtual Bool_t                 PutEntry(AliCDBEntry* entry);
        virtual TList*          GetIdListFromFile(const char* fileName);
@@ -52,7 +53,8 @@ private:
 
 
        Bool_t PrepareId(AliCDBId& id);
-       Bool_t GetId(const AliCDBId& query, AliCDBId& result);
+//     Bool_t GetId(const AliCDBId& query, AliCDBId& result);
+       AliCDBId* GetId(const AliCDBId& query);
 
        virtual void QueryValidFiles();
 
index 1fcd771..962865e 100644 (file)
@@ -26,7 +26,7 @@
 #include <TFile.h>
 #include <TKey.h>
 #include <TROOT.h>
-//#include <TSystem.h>
+#include <TList.h>
 #include <TObjArray.h>
 #include <TObjString.h>
 #include <TRegexp.h>
@@ -34,6 +34,7 @@
 #include "AliLog.h"
 #include "AliCDBEntry.h"
 #include "AliCDBGrid.h"
+#include "AliCDBManager.h"
 
 
 ClassImp(AliCDBGrid)
@@ -49,7 +50,7 @@ fSE(se)
 // constructor //
 
        // if the same Grid is alreay active, skip connection
-       if (!gGrid || fGridUrl != gGrid->GridUrl()  
+       if (!gGrid || fGridUrl != gGrid->GridUrl()
             || (( fUser != "" ) && ( fUser != gGrid->GetUser() )) ) {
                // connection to the Grid
                AliInfo("Connection to the Grid...");
@@ -74,7 +75,7 @@ fSE(se)
        if(!gGrid->Cd(fDBFolder.Data(),0)){
                AliDebug(2,Form("Creating new folder <%s> ...",fDBFolder.Data()));
                if(!gGrid->Mkdir(fDBFolder.Data(),"",0)){
-                       AliError(Form("Cannot create folder <%s> !",fDBFolder.Data())); 
+                       AliError(Form("Cannot create folder <%s> !",fDBFolder.Data()));
                }
        } else {
                AliDebug(2,Form("Folder <%s> found",fDBFolder.Data()));
@@ -184,17 +185,16 @@ Bool_t AliCDBGrid::PrepareId(AliCDBId& id) {
 // prepare id (version) of the object that will be stored (called by PutEntry)
 
        TString initDir(gGrid->Pwd(0));
-       TString pathName= id.GetPath();
 
        TString dirName(fDBFolder);
 
        Bool_t dirExist=kFALSE;
 
+
+
        // go to the path; if directory does not exist, create it
-       TObjArray *arrName=pathName.Tokenize("/");
-       for(int i=0;i<arrName->GetEntries();i++){
-               TString buffer((arrName->At(i))->GetName());
-               dirName+=buffer; dirName+="/";
+       for(int i=0;i<3;i++){
+               dirName+=Form("%s/",id.GetPathLevel(i).Data());
                dirExist=gGrid->Cd(dirName,0);
                if (!dirExist) {
                        AliDebug(2,Form("Creating new folder <%s> ...",dirName.Data()));
@@ -203,9 +203,61 @@ Bool_t AliCDBGrid::PrepareId(AliCDBId& id) {
                                gGrid->Cd(initDir.Data());
                        return kFALSE;
                        }
+
+                       // if folders are new add tags to them
+                       if(i == 1) {
+                               // TODO Currently disabled
+                               // AliInfo("Tagging level 1 folder with \"ShortLived\" tag");
+                               // if(!AddTag(dirName,"ShortLived_try")){
+                               //      AliError(Form("Could not tag folder %s !", dirName.Data()));
+                               //      if(!gGrid->Rmdir(dirName.Data())){
+                               //              AliError(Form("Unexpected: could not remove %s directory!", dirName.Data()));
+                               //      }
+                               //      return 0;
+                               //}
+
+                       } else if(i == 2) {
+                               AliInfo("Tagging level 2 folder with \"CDB\" and \"CDB_MD\" tag");
+                               if(!AddTag(dirName,"CDB")){
+                                       AliError(Form("Could not tag folder %s !", dirName.Data()));
+                                       if(!gGrid->Rmdir(dirName.Data())){
+                                               AliError(Form("Unexpected: could not remove %s directory!", dirName.Data()));
+                                       }
+                                       return 0;
+                               }
+                               if(!AddTag(dirName,"CDB_MD")){
+                                       AliError(Form("Could not tag folder %s !", dirName.Data()));
+                                       if(!gGrid->Rmdir(dirName.Data())){
+                                               AliError(Form("Unexpected: could not remove %s directory!", dirName.Data()));
+                                       }
+                                       return 0;
+                               }
+
+                               // add short lived tag!
+                               // TODO Currently disabled
+                               // TString path=id.GetPath();
+                               // if(AliCDBManager::Instance()->IsShortLived(path.Data())) {
+                               //      AliInfo(Form("Tagging %s as short lived", dirName.Data()));
+                               //      if(!TagShortLived(dirName, kTRUE)){
+                               //              AliError(Form("Could not tag folder %s !", dirName.Data()));
+                               //              if(!gGrid->Rmdir(dirName.Data())){
+                               //                      AliError(Form("Unexpected: could not remove %s directory!", dirName.Data()));
+                               //              }
+                               //              return 0;
+                               //      }
+                               // } else {
+                               //      AliInfo(Form("Tagging %s as long lived", dirName.Data()));
+                               //      if(!TagShortLived(dirName, kFALSE)){
+                               //              AliError(Form("Could not tag folder %s !", dirName.Data()));
+                               //              if(!gGrid->Rmdir(dirName.Data())){
+                               //                      AliError(Form("Unexpected: could not remove %s directory!", dirName.Data()));
+                               //              }
+                               //              return 0;
+                               //      }
+                               // }
+                       }
                }
        }
-       delete arrName;
        gGrid->Cd(initDir,0);
 
        TString filename;
@@ -252,7 +304,7 @@ AliCDBId* AliCDBGrid::GetId(const TObjArray& validFileIds, const AliCDBId& query
        if(validFileIds.GetEntriesFast() < 1) {
                return NULL;
        } else if (validFileIds.GetEntriesFast() == 1) {
-               return dynamic_cast<AliCDBId*> (validFileIds.At(0));
+               return dynamic_cast<AliCDBId*> (validFileIds.At(0)->Clone());
        }
 
        TIter iter(&validFileIds);
@@ -268,7 +320,7 @@ AliCDBId* AliCDBGrid::GetId(const TObjArray& validFileIds, const AliCDBId& query
                if (!query.HasVersion()){ // look for highest version
                        if(result && result->GetVersion() > anIdPtr->GetVersion()) continue;
                        if(result && result->GetVersion() == anIdPtr->GetVersion()) {
-                               AliDebug(2,Form("More than one object valid for run %d, version %d!",
+                               AliError(Form("More than one object valid for run %d, version %d!",
                                        query.GetFirstRun(), anIdPtr->GetVersion()));
                                return NULL;
                        }
@@ -276,7 +328,7 @@ AliCDBId* AliCDBGrid::GetId(const TObjArray& validFileIds, const AliCDBId& query
                } else { // look for specified version
                        if(query.GetVersion() != anIdPtr->GetVersion()) continue;
                        if(result && result->GetVersion() == anIdPtr->GetVersion()){
-                               AliDebug(2,Form("More than one object valid for run %d, version %d!",
+                               AliError(Form("More than one object valid for run %d, version %d!",
                                        query.GetFirstRun(), anIdPtr->GetVersion()));
                                return NULL;
                        }
@@ -285,13 +337,13 @@ AliCDBId* AliCDBGrid::GetId(const TObjArray& validFileIds, const AliCDBId& query
 
        }
 
-
-       return result;
+       return dynamic_cast<AliCDBId*> (result->Clone());
 }
 
 //_____________________________________________________________________________
-AliCDBEntry* AliCDBGrid::GetEntry(const AliCDBId& queryId) {
-// get AliCDBEntry from the database
+AliCDBId* AliCDBGrid::GetEntryId(const AliCDBId& queryId) {
+// get AliCDBId from the database
+// User must delete returned object
 
        AliCDBId* dataId=0;
 
@@ -337,16 +389,27 @@ AliCDBEntry* AliCDBGrid::GetEntry(const AliCDBId& queryId) {
                dataId = GetId(validFileIds, selectedId);
        }
 
+       return dataId;
+}
+
+//_____________________________________________________________________________
+AliCDBEntry* AliCDBGrid::GetEntry(const AliCDBId& queryId) {
+// get AliCDBEntry from the database
+
+       AliCDBId* dataId = GetEntryId(queryId);
+
        if (!dataId) return NULL;
 
        TString filename;
        if (!IdToFilename(*dataId, filename)) {
                AliDebug(2,Form("Bad data ID encountered! Subnormal error!"));
+               delete dataId;
                return NULL;
        }
 
        AliCDBEntry* anEntry = GetEntryFromFile(filename, dataId);
 
+       delete dataId;
        return anEntry;
 }
 
@@ -476,7 +539,7 @@ TList* AliCDBGrid::GetEntries(const AliCDBId& queryId) {
                } else {
                        dataId = GetId(validFileIds, thisId);
                }
-               if(dataId) selectedIds.Add(dataId->Clone());
+               if(dataId) selectedIds.Add(dataId);
        }
 
        delete iter; iter=0;
@@ -521,11 +584,6 @@ Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry) {
                                        fDBFolder.Data(),
                                        id.GetPath().Data());
 
-       // add CDB and CDB_MD tag to folder
-       // TODO how to check that folder has already tags?
-       AddTag(folderToTag,"CDB");
-       AddTag(folderToTag,"CDB_MD");
-
        TDirectory* saveDir = gDirectory;
 
        TString fullFilename = Form("/alien%s", filename.Data());
@@ -598,9 +656,9 @@ Bool_t AliCDBGrid::TagFileId(TString& filename, const AliCDBId* id){
                                        id->GetLastRun(),
                                        id->GetVersion());
        TString addTagValue3 = Form("path_level_0=\"%s\" path_level_1=\"%s\" path_level_2=\"%s\"",
-                                       id->GetLevel0().Data(),
-                                       id->GetLevel1().Data(),
-                                       id->GetLevel2().Data());
+                                       id->GetPathLevel(0).Data(),
+                                       id->GetPathLevel(1).Data(),
+                                       id->GetPathLevel(2).Data());
        TString addTagValue = Form("%s%s%s",
                                        addTagValue1.Data(),
                                        addTagValue2.Data(),
@@ -624,6 +682,28 @@ Bool_t AliCDBGrid::TagFileId(TString& filename, const AliCDBId* id){
 }
 
 //_____________________________________________________________________________
+Bool_t AliCDBGrid::TagShortLived(TString& filename, Bool_t value){
+// tag folder with ShortLived tag
+
+       TString addTagValue = Form("addTagValue %s ShortLived_try value=%d", filename.Data(), value);
+
+       Bool_t result = kFALSE;
+       AliDebug(2, Form("Tagging file. Tag command: %s", addTagValue.Data()));
+       TGridResult* res = gGrid->Command(addTagValue.Data());
+       const char* resCode = res->GetKey(0,"__result__"); // '1' if success
+       if(resCode[0] != '1') {
+               AliError(Form("Couldn't add ShortLived tag value to file %s !", filename.Data()));
+               result = kFALSE;
+       } else {
+               AliInfo("Object successfully tagged.");
+               result = kTRUE;
+       }
+       delete res;
+       return result;
+
+}
+
+//_____________________________________________________________________________
 Bool_t AliCDBGrid::TagFileMetaData(TString& filename, const AliCDBMetaData* md){
 // tag stored object in CDB table using object Id's parameters
 
@@ -778,9 +858,6 @@ void AliCDBGrid::MakeQueryFilter(Int_t firstRun, Int_t lastRun,
 Int_t AliCDBGrid::GetLatestVersion(const char* path, Int_t run){
 // get last version found in the database valid for run and path
 
-       TObjArray validFileIds;
-       validFileIds.SetOwner(1);
-
        AliCDBPath aCDBPath(path);
        if(!aCDBPath.IsValid() || aCDBPath.IsWildcard()) {
                AliError(Form("Invalid path in request: %s", path));
@@ -796,13 +873,18 @@ Int_t AliCDBGrid::GetLatestVersion(const char* path, Int_t run){
                                        run, path));
                dataId = GetId(fValidFileIds, query);
                if (!dataId) return -1;
-               return dataId->GetVersion();
+               Int_t version = dataId->GetVersion();
+               delete dataId;
+               return version;
 
        }
        // List of files valid for reqested run was not loaded. Looking directly into CDB
        AliDebug(2, Form("List of files valid for run %d and for path %s was not loaded. Looking directly into CDB!",
                                run, path));
 
+       TObjArray validFileIds;
+       validFileIds.SetOwner(1);
+
        TString filter;
        MakeQueryFilter(run, run, 0, filter);
 
@@ -822,7 +904,9 @@ Int_t AliCDBGrid::GetLatestVersion(const char* path, Int_t run){
        dataId = GetId(validFileIds, query);
        if (!dataId) return -1;
 
-       return dataId->GetVersion();
+       Int_t version = dataId->GetVersion();
+       delete dataId;
+       return version;
 
 }
 
@@ -867,13 +951,13 @@ AliCDBParam* AliCDBGridFactory::CreateParameter(const char* gridString) {
 
        TString gridUrl         = "alien://";
        TString user            = "";
-       TString dbFolder        = "DBGrid";
+       TString dbFolder        = "";
        TString se              = "default";
 
        TObjArray *arr = buffer.Tokenize('?');
        TIter iter(arr);
        TObjString *str = 0;
-       
+
        while((str = (TObjString*) iter.Next())){
                TString entry(str->String());
                Int_t indeq = entry.Index('=');
@@ -913,6 +997,11 @@ AliCDBParam* AliCDBGridFactory::CreateParameter(const char* gridString) {
        AliDebug(2, Form("dbFolder:     %s",dbFolder.Data()));
        AliDebug(2, Form("s.e.: %s",se.Data()));
 
+       if(dbFolder == ""){
+               AliError("DBFolder must be specified!");
+               return NULL;
+       }
+
        return new AliCDBGridParam(gridUrl.Data(), user.Data(), dbFolder.Data(), se.Data());
 }
 
index 9d03568..40af651 100644 (file)
@@ -30,6 +30,7 @@ public:
 protected:
 
        virtual AliCDBEntry*    GetEntry(const AliCDBId& queryId);
+       virtual AliCDBId*       GetEntryId(const AliCDBId& queryId);
        virtual TList*          GetEntries(const AliCDBId& queryId);
        virtual Bool_t          PutEntry(AliCDBEntry* entry);
        virtual TList*          GetIdListFromFile(const char* fileName);
@@ -49,9 +50,11 @@ private:
        AliCDBId* GetId(const TObjArray& validFileIds, const AliCDBId& query);
        AliCDBEntry* GetEntryFromFile(TString& filename, AliCDBId* dataId);
 
+       // TODO  use AliEnTag classes!
        Bool_t AddTag(TString& foldername, const char* tagname);
        Bool_t TagFileId(TString& filename, const AliCDBId* id);
        Bool_t TagFileMetaData(TString& filename, const AliCDBMetaData* md);
+       Bool_t TagShortLived(TString& filename, Bool_t value);
 
        void MakeQueryFilter(Int_t firstRun, Int_t lastRun, const AliCDBMetaData* md, TString& result) const;
 
@@ -62,7 +65,7 @@ private:
        TString    fDBFolder;   // path of the DB folder
        TString    fSE;         // Storage Element
 
-ClassDef(AliCDBGrid, 0)      // access class to a DataBase in an AliEn storage 
+ClassDef(AliCDBGrid, 0)      // access class to a DataBase in an AliEn storage
 };
 
 /////////////////////////////////////////////////////////////////////
index d3b4ea9..54ae14a 100644 (file)
@@ -34,45 +34,43 @@ public:
 
        virtual ~AliCDBId();
 
-       const AliCDBPath&       GetAliCDBPath() const {return fPath;};
-       const TString&          GetPath() const {return fPath.GetPath();};
-       const TString&          GetLevel0() const {return fPath.GetLevel0();};
-       const TString&          GetLevel1() const {return fPath.GetLevel1();};
-       const TString&          GetLevel2() const {return fPath.GetLevel2();};
-       Bool_t                  IsWildcard() const {return fPath.IsWildcard();};
+       const AliCDBPath&       GetAliCDBPath() const {return fPath;}
+       const TString&          GetPath() const {return fPath.GetPath();}
+       const TString           GetPathLevel(Int_t i) const {return fPath.GetLevel(i);}
+       Bool_t                  IsWildcard() const {return fPath.IsWildcard();}
 
-       void    SetPath(const char* path) {fPath.SetPath(path);};
+       void    SetPath(const char* path) {fPath.SetPath(path);}
 
-       const           AliCDBRunRange& GetAliCDBRunRange() const {return fRunRange;};
-       AliCDBRunRange& GetAliCDBRunRange() {return fRunRange;};
-       Int_t           GetFirstRun() const {return fRunRange.GetFirstRun();};
-       Int_t           GetLastRun() const {return fRunRange.GetLastRun();};    
-       void            SetFirstRun(Int_t firstRun) {fRunRange.SetFirstRun(firstRun);};
-       void            SetLastRun(Int_t lastRun) {fRunRange.SetLastRun(lastRun);};
-       void            SetRunRange(Int_t firstRun, Int_t lastRun) 
-                       {fRunRange.SetRunRange(firstRun, lastRun);};
+       const           AliCDBRunRange& GetAliCDBRunRange() const {return fRunRange;}
+       AliCDBRunRange& GetAliCDBRunRange() {return fRunRange;}
+       Int_t           GetFirstRun() const {return fRunRange.GetFirstRun();}
+       Int_t           GetLastRun() const {return fRunRange.GetLastRun();}
+       void            SetFirstRun(Int_t firstRun) {fRunRange.SetFirstRun(firstRun);}
+       void            SetLastRun(Int_t lastRun) {fRunRange.SetLastRun(lastRun);}
+       void            SetRunRange(Int_t firstRun, Int_t lastRun)
+                       {fRunRange.SetRunRange(firstRun, lastRun);}
 
 
-       Bool_t  IsAnyRange() const {return fRunRange.IsAnyRange();};
+       Bool_t  IsAnyRange() const {return fRunRange.IsAnyRange();}
 
 
-       Int_t   GetVersion() const {return fVersion;};
-       Int_t   GetSubVersion() const {return fSubVersion;};
-       void    SetVersion(Int_t version) {fVersion = version;};        
-       void    SetSubVersion(Int_t subVersion) {fSubVersion = subVersion;};
+       Int_t   GetVersion() const {return fVersion;}
+       Int_t   GetSubVersion() const {return fSubVersion;}
+       void    SetVersion(Int_t version) {fVersion = version;}
+       void    SetSubVersion(Int_t subVersion) {fSubVersion = subVersion;}
 
-       const TString&  GetLastStorage() const {return fLastStorage;};
-       void            SetLastStorage(TString& lastStorage){fLastStorage = lastStorage;};
+       const TString&  GetLastStorage() const {return fLastStorage;}
+       void            SetLastStorage(TString& lastStorage){fLastStorage = lastStorage;}
 
        Bool_t IsValid() const; 
-       Bool_t IsSpecified() const {return !(IsWildcard() || IsAnyRange());};
+       Bool_t IsSpecified() const {return !(IsWildcard() || IsAnyRange());}
 
-       Bool_t HasVersion() const {return fVersion >= 0;};
-       Bool_t HasSubVersion() const {return fSubVersion >= 0;};
+       Bool_t HasVersion() const {return fVersion >= 0;}
+       Bool_t HasSubVersion() const {return fSubVersion >= 0;}
 
        Bool_t Comprises(const AliCDBId& other) const
                {return fPath.Comprises(other.fPath)
-                        && fRunRange.Comprises(other.fRunRange);};
+                        && fRunRange.Comprises(other.fRunRange);}
 
        virtual Bool_t IsEqual(const TObject *obj) const;
 
index f79da4a..28ef719 100644 (file)
@@ -145,7 +145,7 @@ Bool_t AliCDBLocal::PrepareId(AliCDBId& id) {
        }
 
        const char* filename;
-       AliCDBRunRange aRunRange; // the runRange got from filename 
+       AliCDBRunRange aRunRange; // the runRange got from filename
        AliCDBRunRange lastRunRange(-1,-1); // highest runRange found
        Int_t aVersion, aSubVersion; // the version subVersion got from filename
        Int_t lastVersion = 0, lastSubVersion = -1; // highest version and subVersion found
@@ -232,9 +232,138 @@ Bool_t AliCDBLocal::PrepareId(AliCDBId& id) {
        return kTRUE;
 }
 
+// //_____________________________________________________________________________
+// Bool_t AliCDBLocal::GetId(const AliCDBId& query, AliCDBId& result) {
+// // look for filename matching query (called by GetEntry)
+// 
+//     TString dirName = Form("%s/%s", fBaseDirectory.Data(), query.GetPath().Data());
+// 
+//     void* dirPtr = gSystem->OpenDirectory(dirName);
+//     if (!dirPtr) {
+//             AliDebug(2,Form("Directory <%s> not found", (query.GetPath()).Data()));
+//             AliDebug(2,Form("in DB folder %s", fBaseDirectory.Data()));
+//             return kFALSE;
+//     }
+// 
+//     const char* filename;
+// 
+//     AliCDBRunRange aRunRange; // the runRange got from filename
+//     Int_t aVersion, aSubVersion; // the version and subVersion got from filename
+// 
+//     if (!query.HasVersion()) { // neither version and subversion specified -> look for highest version and subVersion
+// 
+//             while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
+// 
+//                     TString aString(filename);
+//                     if (aString == "." || aString == "..") continue;
+// 
+//                     if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
+//                         // aRunRange, aVersion, aSubVersion filled from filename
+// 
+//                     if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
+//                     // aRunRange contains requested run!
+// 
+//                     if (result.GetVersion() < aVersion) {
+//                             result.SetVersion(aVersion);
+//                             result.SetSubVersion(aSubVersion);
+// 
+//                             result.SetFirstRun(
+//                                     aRunRange.GetFirstRun());
+//                             result.SetLastRun(
+//                                     aRunRange.GetLastRun());
+// 
+//                     } else if (result.GetVersion() == aVersion
+//                             && result.GetSubVersion()
+//                                     < aSubVersion) {
+// 
+//                             result.SetSubVersion(aSubVersion);
+// 
+//                             result.SetFirstRun(
+//                                     aRunRange.GetFirstRun());
+//                             result.SetLastRun(
+//                                     aRunRange.GetLastRun());
+//                     } else if (result.GetVersion() == aVersion
+//                             && result.GetSubVersion() == aSubVersion){
+//                                     AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
+//                                     query.GetFirstRun(), aVersion, aSubVersion));
+//                             gSystem->FreeDirectory(dirPtr);
+//                             return kFALSE;
+//                             }
+//             }
+// 
+//     } else if (!query.HasSubVersion()) { // version specified but not subversion -> look for highest subVersion
+// 
+//             result.SetVersion(query.GetVersion());
+// 
+//             while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
+// 
+//                         TString aString(filename);
+//                         if (aString == "." || aString == "..") continue;
+// 
+//                     if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
+//                         // aRunRange, aVersion, aSubVersion filled from filename
+// 
+//                         if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue; 
+//                     // aRunRange contains requested run!
+// 
+//                     if(query.GetVersion() != aVersion) continue;
+//                     // aVersion is requested version!
+// 
+//                     if(result.GetSubVersion() == aSubVersion){
+//                                     AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
+//                                     query.GetFirstRun(), aVersion, aSubVersion));
+//                             gSystem->FreeDirectory(dirPtr);
+//                             return kFALSE; 
+//                     }
+//                     if( result.GetSubVersion() < aSubVersion) {
+// 
+//                                 result.SetSubVersion(aSubVersion);
+// 
+//                                 result.SetFirstRun(
+//                                     aRunRange.GetFirstRun());
+//                                 result.SetLastRun(
+//                                     aRunRange.GetLastRun());
+//                     } 
+//                 }
+// 
+//     } else { // both version and subversion specified
+// 
+//             while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
+// 
+//                         TString aString(filename);
+//                         if (aString == "." || aString == "..") continue;
+// 
+//                         if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
+//                         // aRunRange, aVersion, aSubVersion filled from filename
+// 
+//                     if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
+//                     // aRunRange contains requested run!
+// 
+//                     if(query.GetVersion() != aVersion || query.GetSubVersion() != aSubVersion) continue;
+//                     // aVersion and aSubVersion are requested version and subVersion!
+// 
+//                     if(result.GetVersion() == aVersion && result.GetSubVersion() == aSubVersion){
+//                                     AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
+//                                     query.GetFirstRun(), aVersion, aSubVersion));
+//                             gSystem->FreeDirectory(dirPtr);
+//                             return kFALSE;
+//                     }
+//                     result.SetVersion(aVersion);
+//                     result.SetSubVersion(aSubVersion);
+//                     result.SetFirstRun(aRunRange.GetFirstRun());
+//                     result.SetLastRun(aRunRange.GetLastRun());
+// 
+//             }
+//     }
+// 
+//     gSystem->FreeDirectory(dirPtr);
+// 
+//     return kTRUE;
+// }
+
 //_____________________________________________________________________________
-Bool_t AliCDBLocal::GetId(const AliCDBId& query, AliCDBId& result) {
-// look for filename matching query (called by GetEntry)
+AliCDBId* AliCDBLocal::GetId(const AliCDBId& query) {
+// look for filename matching query (called by GetEntryId)
 
        TString dirName = Form("%s/%s", fBaseDirectory.Data(), query.GetPath().Data());
 
@@ -242,10 +371,12 @@ Bool_t AliCDBLocal::GetId(const AliCDBId& query, AliCDBId& result) {
        if (!dirPtr) {
                AliDebug(2,Form("Directory <%s> not found", (query.GetPath()).Data()));
                AliDebug(2,Form("in DB folder %s", fBaseDirectory.Data()));
-               return kFALSE;
+               return NULL;
        }
 
        const char* filename;
+       AliCDBId *result = new AliCDBId();
+       result->SetPath(query.GetPath());
 
        AliCDBRunRange aRunRange; // the runRange got from filename
        Int_t aVersion, aSubVersion; // the version and subVersion got from filename
@@ -263,157 +394,154 @@ Bool_t AliCDBLocal::GetId(const AliCDBId& query, AliCDBId& result) {
                        if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
                        // aRunRange contains requested run!
 
-                       if (result.GetVersion() < aVersion) {
-                               result.SetVersion(aVersion);
-                               result.SetSubVersion(aSubVersion);
+                       if (result->GetVersion() < aVersion) {
+                               result->SetVersion(aVersion);
+                               result->SetSubVersion(aSubVersion);
 
-                               result.SetFirstRun(
+                               result->SetFirstRun(
                                        aRunRange.GetFirstRun());
-                               result.SetLastRun(
+                               result->SetLastRun(
                                        aRunRange.GetLastRun());
 
-                       } else if (result.GetVersion() == aVersion 
-                               && result.GetSubVersion() 
+                       } else if (result->GetVersion() == aVersion
+                               && result->GetSubVersion()
                                        < aSubVersion) {
 
-                               result.SetSubVersion(aSubVersion);
+                               result->SetSubVersion(aSubVersion);
 
-                               result.SetFirstRun(
+                               result->SetFirstRun(
                                        aRunRange.GetFirstRun());
-                               result.SetLastRun(
+                               result->SetLastRun(
                                        aRunRange.GetLastRun());
-                       } else if (result.GetVersion() == aVersion
-                               && result.GetSubVersion() == aSubVersion){
-                               AliDebug(2,Form("More than one object valid for run %d, version %d_%d!", 
+                       } else if (result->GetVersion() == aVersion
+                               && result->GetSubVersion() == aSubVersion){
+                               AliError(Form("More than one object valid for run %d, version %d_%d!",
                                        query.GetFirstRun(), aVersion, aSubVersion));
                                gSystem->FreeDirectory(dirPtr);
-                               return kFALSE; 
+                               delete result;
+                               return NULL;
                                }
                }
-               
+
        } else if (!query.HasSubVersion()) { // version specified but not subversion -> look for highest subVersion
 
-               result.SetVersion(query.GetVersion());
+               result->SetVersion(query.GetVersion());
 
                while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
 
                         TString aString(filename);
                         if (aString == "." || aString == "..") continue;
 
-                       if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;       
+                       if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
                         // aRunRange, aVersion, aSubVersion filled from filename
 
                         if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue; 
                        // aRunRange contains requested run!
-                       
+
                        if(query.GetVersion() != aVersion) continue;
                        // aVersion is requested version!
-                       
-                       if(result.GetSubVersion() == aSubVersion){
-                               AliDebug(2,Form("More than one object valid for run %d, version %d_%d!", 
+
+                       if(result->GetSubVersion() == aSubVersion){
+                               AliError(Form("More than one object valid for run %d, version %d_%d!",
                                        query.GetFirstRun(), aVersion, aSubVersion));
                                gSystem->FreeDirectory(dirPtr);
-                               return kFALSE; 
+                               delete result;
+                               return NULL;
                        }
-                       if( result.GetSubVersion() < aSubVersion) {
+                       if( result->GetSubVersion() < aSubVersion) {
 
-                                result.SetSubVersion(aSubVersion);
+                                result->SetSubVersion(aSubVersion);
 
-                                result.SetFirstRun(
+                                result->SetFirstRun(
                                        aRunRange.GetFirstRun());
-                                result.SetLastRun(
+                                result->SetLastRun(
                                        aRunRange.GetLastRun());
                        } 
                 }
 
        } else { // both version and subversion specified
 
-               while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
+               //AliCDBId dataId(queryId.GetAliCDBPath(), -1, -1, -1, -1);
+        //Bool_t result;
+       while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
 
                         TString aString(filename);
                         if (aString == "." || aString == "..") continue;
 
                         if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
                         // aRunRange, aVersion, aSubVersion filled from filename
-                       
+
                        if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
                        // aRunRange contains requested run!
 
-                       if(query.GetVersion() != aVersion || query.GetSubVersion() != aSubVersion) continue; 
+                       if(query.GetVersion() != aVersion || query.GetSubVersion() != aSubVersion) continue;
                        // aVersion and aSubVersion are requested version and subVersion!
-                       
-                       if(result.GetVersion() == aVersion && result.GetSubVersion() == aSubVersion){
-                               AliDebug(2,Form("More than one object valid for run %d, version %d_%d!", 
+
+                       if(result->GetVersion() == aVersion && result->GetSubVersion() == aSubVersion){
+                               AliError(Form("More than one object valid for run %d, version %d_%d!",
                                        query.GetFirstRun(), aVersion, aSubVersion));
                                gSystem->FreeDirectory(dirPtr);
-                               return kFALSE; 
+                               delete result;
+                               return NULL;
                        }
-                       result.SetVersion(aVersion);
-                       result.SetSubVersion(aSubVersion);
-                       result.SetFirstRun(aRunRange.GetFirstRun());
-                       result.SetLastRun(aRunRange.GetLastRun());
+                       result->SetVersion(aVersion);
+                       result->SetSubVersion(aSubVersion);
+                       result->SetFirstRun(aRunRange.GetFirstRun());
+                       result->SetLastRun(aRunRange.GetLastRun());
                        
                }
        }
 
        gSystem->FreeDirectory(dirPtr);
 
-       return kTRUE;
+       return result;
 }
 
 //_____________________________________________________________________________
 AliCDBEntry* AliCDBLocal::GetEntry(const AliCDBId& queryId) {
 // get AliCDBEntry from the database
 
-       AliCDBId dataId(queryId.GetAliCDBPath(), -1, -1, -1, -1);
-        Bool_t result;
-
-       // look for a filename matching query requests (path, runRange, version, subVersion)
-       if (!queryId.HasVersion()) {
-               // if version is not specified, first check the selection criteria list
-               AliCDBId selectedId(queryId);
-               GetSelection(&selectedId);
-               result = GetId(selectedId, dataId);
-       } else {
-               result = GetId(queryId, dataId);
-       }
+       AliCDBId* dataId = GetEntryId(queryId);
 
-       if (!result || !dataId.IsSpecified()) return NULL;
+       if (!dataId || !dataId->IsSpecified()) return NULL;
 
        TString filename;
-       if (!IdToFilename(dataId, filename)) {
+       if (!IdToFilename(*dataId, filename)) {
 
                AliDebug(2,Form("Bad data ID encountered! Subnormal error!"));
-                return NULL;
+               delete dataId;
+               return NULL;
        }
 
        TFile file(filename, "READ"); // open file
        if (!file.IsOpen()) {
                AliDebug(2,Form("Can't open file <%s>!", filename.Data()));
-                return NULL;
+               delete dataId;
+               return NULL;
        }
 
        // get the only AliCDBEntry object from the file
        // the object in the file is an AliCDBEntry entry named "AliCDBEntry"
-       
+
        AliCDBEntry* anEntry = dynamic_cast<AliCDBEntry*> (file.Get("AliCDBEntry"));
        if (!anEntry) {
                AliDebug(2,Form("Bad storage data: No AliCDBEntry in file!"));
                file.Close();
+               delete dataId;
                return NULL;
        }
 
-       AliCDBId entryId = anEntry->GetId();
+       AliCDBId& entryId = anEntry->GetId();
 
        // The object's Id are not reset during storage
        // If object's Id runRange or version do not match with filename,
        // it means that someone renamed file by hand. In this case a warning msg is issued.
 
        anEntry-> SetLastStorage("local");
-       if(!entryId.IsEqual(&dataId)){
+
+       if(!entryId.IsEqual(dataId)){
                AliWarning(Form("Mismatch between file name and object's Id!"));
-               AliWarning(Form("File name: %s", dataId.ToString().Data()));
+               AliWarning(Form("File name: %s", dataId->ToString().Data()));
                AliWarning(Form("Object's Id: %s", entryId.ToString().Data()));
         }
 
@@ -422,10 +550,35 @@ AliCDBEntry* AliCDBLocal::GetEntry(const AliCDBId& queryId) {
 
        // close file, return retieved entry
        file.Close();
+       delete dataId;
        return anEntry;
 }
 
 //_____________________________________________________________________________
+AliCDBId* AliCDBLocal::GetEntryId(const AliCDBId& queryId) {
+// get AliCDBId from the database
+
+       AliCDBId* dataId = 0;
+
+       // look for a filename matching query requests (path, runRange, version, subVersion)
+       if (!queryId.HasVersion()) {
+               // if version is not specified, first check the selection criteria list
+               AliCDBId selectedId(queryId);
+               GetSelection(&selectedId);
+               dataId = GetId(selectedId);
+       } else {
+               dataId = GetId(queryId);
+       }
+
+       if (dataId && !dataId->IsSpecified()) {
+               delete dataId;
+               return NULL;
+       }
+
+       return dataId;
+}
+
+//_____________________________________________________________________________
 void AliCDBLocal::GetEntriesForLevel0(const char* level0,
        const AliCDBId& queryId, TList* result) {
 // multiple request (AliCDBStorage::GetAll)
@@ -707,11 +860,14 @@ Int_t AliCDBLocal::GetLatestVersion(const char* path, Int_t run){
        }
 
        AliCDBId query(path, run, run, -1, -1);
-       AliCDBId dataId;
+       AliCDBId* dataId = GetId(query);
+
+       if(!dataId) return -1;
 
-       GetId(query,dataId);
+       Int_t version = dataId->GetVersion();
+       delete dataId;
 
-       return dataId.GetVersion();
+       return version;
 
 }
 
@@ -726,11 +882,14 @@ Int_t AliCDBLocal::GetLatestSubVersion(const char* path, Int_t run, Int_t versio
        }
 
        AliCDBId query(path, run, run, version, -1);
-       AliCDBId dataId;
+       AliCDBId *dataId = GetId(query);
+
+       if(!dataId) return -1;
 
-       GetId(query,dataId);
+       Int_t subVersion = dataId->GetSubVersion();
 
-       return dataId.GetSubVersion();
+       delete dataId;
+       return subVersion;
 
 }
 
@@ -767,7 +926,7 @@ AliCDBParam* AliCDBLocalFactory::CreateParameter(const char* dbString) {
                pathname.Prepend(TString(gSystem->WorkingDirectory()) + '/');
        }
 
-       return new AliCDBLocalParam(pathname);       
+       return new AliCDBLocalParam(pathname);
 }
 
 //_____________________________________________________________________________
index 8997905..3113d47 100644 (file)
@@ -29,6 +29,7 @@ public:
 protected:
 
        virtual AliCDBEntry*    GetEntry(const AliCDBId& queryId);
+       virtual AliCDBId*       GetEntryId(const AliCDBId& queryId);
         virtual TList*                 GetEntries(const AliCDBId& queryId);
         virtual Bool_t                 PutEntry(AliCDBEntry* entry);
        virtual TList*          GetIdListFromFile(const char* fileName);
@@ -44,7 +45,8 @@ private:
                        Int_t& version, Int_t& subVersion);
 
        Bool_t PrepareId(AliCDBId& id);
-       Bool_t GetId(const AliCDBId& query, AliCDBId& result);
+//     Bool_t GetId(const AliCDBId& query, AliCDBId& result);
+       AliCDBId* GetId(const AliCDBId& query);
 
        virtual void QueryValidFiles();
 
index 7bac82c..8309231 100644 (file)
@@ -65,6 +65,8 @@ void AliCDBManager::Init() {
                fCondParam = CreateParameter(fgkCondUri);
                fRefParam = CreateParameter(fgkRefUri);
        }
+
+       InitShortLived();
 }
 //_____________________________________________________________________________
 void AliCDBManager::Destroy() {
@@ -86,10 +88,12 @@ AliCDBManager::AliCDBManager():
   fActiveStorages(),
   fSpecificStorages(),
   fDefaultStorage(NULL),
+  fRemoteStorage(NULL),
   fDrainStorage(NULL),
   fEntryCache(),
   fCache(kTRUE),
-  fRun(-1)
+  fRun(-1),
+  fShortLived(0)
 {
 // default constuctor
        fFactories.SetOwner(1);
@@ -106,8 +110,10 @@ AliCDBManager::~AliCDBManager() {
        fFactories.Delete();
        fDrainStorage = 0x0;
        fDefaultStorage = 0x0;
+       fRemoteStorage = 0x0;
        delete fCondParam;
        delete fRefParam;
+       delete fShortLived; fShortLived = 0x0;
 }
 
 //_____________________________________________________________________________
@@ -278,16 +284,40 @@ void AliCDBManager::SetDefaultStorage(const char* dbString) {
 //_____________________________________________________________________________
 void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
 // set default storage from AliCDBParam object
-       
+
        fDefaultStorage = GetStorage(param);
 }
 
 //_____________________________________________________________________________
 void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
 // set default storage from another active storage
-       
+
        fDefaultStorage = storage;
 }
+//_____________________________________________________________________________
+void AliCDBManager::SetRemoteStorage(const char* dbString) {
+// sets remote storage from URI string
+// Remote storage is queried if it is activated and if object was not found in default storage
+
+       AliInfo(Form("Setting Default storage to: %s",dbString));
+       fRemoteStorage = GetStorage(dbString);
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::SetRemoteStorage(const AliCDBParam* param) {
+// set remote storage from AliCDBParam object
+// Remote storage is queried if it is activated and if object was not found in default storage
+
+       fRemoteStorage = GetStorage(param);
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::SetRemoteStorage(AliCDBStorage* storage) {
+// set remote storage from another active storage
+// Remote storage is queried if it is activated and if object was not found in default storage
+
+       fRemoteStorage = storage;
+}
 
 //_____________________________________________________________________________
 void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) {
@@ -372,7 +402,7 @@ AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) {
 }
 
 //_____________________________________________________________________________
-AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber, 
+AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber,
        Int_t version, Int_t subVersion) {
 // get an AliCDBEntry object from the database
 
@@ -389,7 +419,7 @@ AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber,
 }
 
 //_____________________________________________________________________________
-AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, 
+AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path,
        const AliCDBRunRange& runRange, Int_t version,
        Int_t subVersion) {
 // get an AliCDBEntry object from the database!
@@ -398,7 +428,7 @@ AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path,
 }
 
 //_____________________________________________________________________________
-AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) {       
+AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) {
 // get an AliCDBEntry object from the database
        
        if(!fDefaultStorage) {
@@ -415,12 +445,12 @@ AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) {
        
        // query is not specified if path contains wildcard or run range= [-1,-1]
        if (!query.IsSpecified()) {
-               AliError(Form("Unspecified query: %s", 
+               AliError(Form("Unspecified query: %s",
                                query.ToString().Data()));
                 return NULL;
        }
 
-       if(fCache && query.GetFirstRun() != fRun)
+       if(fCache && query.GetFirstRun() != fRun)
                AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
 
 
@@ -438,26 +468,116 @@ AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) {
        // Entry is not in cache -> retrieve it from CDB and cache it!!
        AliCDBStorage *aStorage=0;
        AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
+       Bool_t usedDefStorage=kTRUE;
 
        if(aPar) {
                aStorage=GetStorage(aPar);
                TString str = aPar->GetURI();
                AliDebug(2,Form("Looking into storage: %s",str.Data()));
-               
+               usedDefStorage=kFALSE;
+
        } else {
                aStorage=GetDefaultStorage();
                AliDebug(2,"Looking into default storage");
        }
-                       
+
        entry = aStorage->Get(query);
-       if (!entry) return NULL;
 
-       if(fCache && (query.GetFirstRun() == fRun)){
+       if (!entry && usedDefStorage && IsRemoteStorageSet()) {
+               AliWarning(Form("Object not found in default storage: Looking into remote storage!"));
+               entry = fRemoteStorage->Get(query);
+       }
+
+       if(entry && fCache && (query.GetFirstRun() == fRun)){
                CacheEntry(query.GetPath(), entry);
        }
 
        return entry;
+
+}
+
+//_____________________________________________________________________________
+AliCDBId* AliCDBManager::GetId(const AliCDBPath& path, Int_t runNumber,
+       Int_t version, Int_t subVersion) {
+// get the AliCDBId of the valid object from the database (does not retrieve the object)
+// User must delete returned object!
+
+       if(runNumber < 0){
+               // RunNumber is not specified. Try with fRun
+               if (fRun < 0){
+                       AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
+                       return NULL;
+               }
+               runNumber = fRun;
+       }
+
+       return GetId(AliCDBId(path, runNumber, runNumber, version, subVersion));
+}
+
+//_____________________________________________________________________________
+AliCDBId* AliCDBManager::GetId(const AliCDBPath& path,
+       const AliCDBRunRange& runRange, Int_t version,
+       Int_t subVersion) {
+// get the AliCDBId of the valid object from the database (does not retrieve the object)
+// User must delete returned object!
+
+       return GetId(AliCDBId(path, runRange, version, subVersion));
+}
+
+//_____________________________________________________________________________
+AliCDBId* AliCDBManager::GetId(const AliCDBId& query) {
+// get the AliCDBId of the valid object from the database (does not retrieve the object)
+// User must delete returned object!
+
+       if(!fDefaultStorage) {
+               AliError("No storage set!");
+               return NULL;
+       }
+
+       // 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()));
+               return NULL;
+       }
+       
+       // query is not specified if path contains wildcard or run range= [-1,-1]
+       if (!query.IsSpecified()) {
+               AliError(Form("Unspecified query: %s",
+                               query.ToString().Data()));
+                return NULL;
+       }
+
+       if(fCache && query.GetFirstRun() != fRun)
+               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(entry) {
+               AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
+               return dynamic_cast<AliCDBId*> (entry->GetId().Clone());
+       }
+
+       // Entry is not in cache -> retrieve it from CDB and cache it!!
+       AliCDBStorage *aStorage=0;
+       AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
+
+       if(aPar) {
+               aStorage=GetStorage(aPar);
+               TString str = aPar->GetURI();
+               AliDebug(2,Form("Looking into storage: %s",str.Data()));
                
+       } else {
+               aStorage=GetDefaultStorage();
+               AliDebug(2,"Looking into default storage");
+       }
+
+       return aStorage->GetId(query);
+
 }
 
 //_____________________________________________________________________________
@@ -835,6 +955,61 @@ const char* AliCDBManager::GetDataTypeName(DataType type)
 
 }
 
+//______________________________________________________________________________________________
+void AliCDBManager::InitShortLived()
+{
+  // Init the list of short-lived objects
+  // currently disabled
+
+       fShortLived=0x0;
+
+//     fShortLived = new TList();
+//     fShortLived->SetOwner(1);
+//
+//     fShortLived->Add(new TObjString("EMCAL/Calib/Data"));
+// 
+//     fShortLived->Add(new TObjString("HMPID/Calib/Nmean"));
+//     fShortLived->Add(new TObjString("HMPID/Calib/Qthre"));
+// 
+//     fShortLived->Add(new TObjString("ITS/Calib/CalibSPD"));
+// 
+//     fShortLived->Add(new TObjString("MUON/Calib/Gains"));
+//     fShortLived->Add(new TObjString("MUON/Calib/HV"));
+//     fShortLived->Add(new TObjString("MUON/Calib/Pedestals"));
+// 
+//     fShortLived->Add(new TObjString("PHOS/Calib/CpvGainPedestals"));
+//     fShortLived->Add(new TObjString("PHOS/Calib/EmcGainPedestals"));
+// 
+//     fShortLived->Add(new TObjString("PMD/Calib/Data"));
+// 
+//     fShortLived->Add(new TObjString("TRD/Calib/ChamberGainFactor"));
+//     fShortLived->Add(new TObjString("TRD/Calib/LocalGainFactor"));
+//     fShortLived->Add(new TObjString("TRD/Calib/ChamberT0"));
+//     fShortLived->Add(new TObjString("TRD/Calib/LocalT0"));
+//     fShortLived->Add(new TObjString("TRD/Calib/ChamberVdrift"));
+//     fShortLived->Add(new TObjString("TRD/Calib/LocalVdrift"));
+// 
+//     fShortLived->Add(new TObjString("ZDC/Calib/Data"));
+
+}
+
+//______________________________________________________________________________________________
+Bool_t AliCDBManager::IsShortLived(const char* path)
+{
+  // returns the name (string) of the data type
+
+       if(!fShortLived) return kFALSE;
+
+       AliCDBPath aPath(path);
+       if(!aPath.IsValid()){
+               AliError(Form("Not a valid path: %s", path));
+               return kFALSE;
+       }
+
+       return fShortLived->Contains(path);
+
+}
+
 ///////////////////////////////////////////////////////////
 // AliCDBManager Parameter class                         //
 // interface to specific AliCDBParameter class           //
index 6ce8efe..a5f72a0 100644 (file)
@@ -45,11 +45,19 @@ class AliCDBManager: public TObject {
        void SetDefaultStorage(const char* dbString);
        void SetDefaultStorage(const AliCDBParam* param);
        void SetDefaultStorage(AliCDBStorage *storage);
-       
+
        Bool_t IsDefaultStorageSet() const {return fDefaultStorage != 0;}
        AliCDBStorage* GetDefaultStorage() const {return fDefaultStorage;}
        void UnsetDefaultStorage() {fDefaultStorage = 0x0;}
 
+       void SetRemoteStorage(const char* dbString);
+       void SetRemoteStorage(const AliCDBParam* param);
+       void SetRemoteStorage(AliCDBStorage *storage);
+
+       Bool_t IsRemoteStorageSet() const {return fRemoteStorage != 0;}
+       AliCDBStorage* GetRemoteStorage() const {return fRemoteStorage;}
+       void UnsetRemoteStorage() {fRemoteStorage = 0x0;}
+
        void SetSpecificStorage(const char* calibType, const char* dbString);
        void SetSpecificStorage(const char* calibType, AliCDBParam* param);
 
@@ -71,6 +79,12 @@ class AliCDBManager: public TObject {
        AliCDBEntry* Get(const AliCDBPath& path, const AliCDBRunRange& runRange,
                                 Int_t version = -1, Int_t subVersion = -1);
 
+       AliCDBId* GetId(const AliCDBId& query);
+       AliCDBId* GetId(const AliCDBPath& path, Int_t runNumber=-1,
+                               Int_t version = -1, Int_t subVersion = -1);
+       AliCDBId* GetId(const AliCDBPath& path, const AliCDBRunRange& runRange,
+                                Int_t version = -1, Int_t subVersion = -1);
+
        TList* GetAll(const AliCDBId& query);
        TList* GetAll(const AliCDBPath& path, Int_t runNumber=-1,
                                Int_t version = -1, Int_t subVersion = -1);
@@ -87,8 +101,6 @@ class AliCDBManager: public TObject {
        void SetRun(Int_t run);
        Int_t GetRun() const {return fRun;}
 
-       // AliCDBEntry* Get(const char* path);
-
        void DestroyActiveStorages();
        void DestroyActiveStorage(AliCDBStorage* storage);
 
@@ -102,6 +114,8 @@ class AliCDBManager: public TObject {
        void ClearCache();
        void UnloadFromCache(const char* path);
 
+       Bool_t IsShortLived(const char* path);
+
        static AliCDBManager* Instance();
 
  private:
@@ -126,12 +140,15 @@ class AliCDBManager: public TObject {
        
 
        void Init();
-       
+       void InitShortLived();
+
+
        TList fFactories;               //! list of registered storage factories
        TMap fActiveStorages;           //! list of active storages
        TMap fSpecificStorages;         //! list of detector-specific storages
 
        AliCDBStorage *fDefaultStorage; //! pointer to default storage
+       AliCDBStorage *fRemoteStorage;  //! pointer to remote storage
        AliCDBStorage *fDrainStorage;   //! pointer to drain storage
 
        TMap fEntryCache;       //! cache of the retrieved objects
@@ -139,6 +156,8 @@ class AliCDBManager: public TObject {
        Bool_t fCache;                  //! The cache flag
        Int_t fRun;                     //! The run number
 
+       TList* fShortLived;     //! List of short lived objects
+
        ClassDef(AliCDBManager, 0);
 };
 
index c0f986f..390fd82 100644 (file)
@@ -251,7 +251,27 @@ Bool_t AliCDBPath::Level2Comprises(const TString& str) const {
 Bool_t AliCDBPath::Comprises(const AliCDBPath& other) const {
 // check if path is wildcard and comprises other
 
-       return Level0Comprises(other.fLevel0) 
+       return Level0Comprises(other.fLevel0)
                && Level1Comprises(other.fLevel1)
                && Level2Comprises(other.fLevel2);
 }
+
+//_____________________________________________________________________________
+const char* AliCDBPath::GetLevel(Int_t i) const {
+// return level i of the path
+
+       switch (i) {
+               case 0:
+                       return fLevel0.Data();
+                       break;
+               case 1:
+                       return fLevel1.Data();
+                       break;
+               case 2:
+                       return fLevel2.Data();
+                       break;
+               default:
+                       return 0;
+       }
+
+}
index 5ca8d32..755f663 100644 (file)
@@ -35,16 +35,14 @@ public:
        virtual ~AliCDBPath();
 
 
-       const TString& GetPath() const {return fPath;};
-       void  SetPath(const char* path) {fPath=path; InitPath();};
+       const TString& GetPath() const {return fPath;}
+       void  SetPath(const char* path) {fPath=path; InitPath();}
 
-       const TString& GetLevel0() const {return fLevel0;};
-       const TString& GetLevel1() const {return fLevel1;};
-       const TString& GetLevel2() const {return fLevel2;};
+       const char* GetLevel(Int_t i) const;
 
-       Bool_t IsValid() const {return fIsValid;};
+       Bool_t IsValid() const {return fIsValid;}
 
-       Bool_t IsWildcard() const {return fIsWildcard;};
+       Bool_t IsWildcard() const {return fIsWildcard;}
 
        Bool_t Level0Comprises(const TString& str) const;
        Bool_t Level1Comprises(const TString& str) const;
index a69e7e5..16283e4 100644 (file)
@@ -203,7 +203,7 @@ void AliCDBStorage::PrintSelectionList(){
 //_____________________________________________________________________________
 AliCDBEntry* AliCDBStorage::Get(const AliCDBId& query) {
 // 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()) {
@@ -211,9 +211,9 @@ AliCDBEntry* AliCDBStorage::Get(const AliCDBId& query) {
                return NULL;
        }
 
-       // query is not specified if path contains wildcard or runrange = [-1,-1] 
+       // query is not specified if path contains wildcard or runrange = [-1,-1]
        if (!query.IsSpecified()) {
-               AliError(Form("Unspecified query: %s", 
+               AliError(Form("Unspecified query: %s",
                                query.ToString().Data()));
                 return NULL;
        }
@@ -245,7 +245,7 @@ AliCDBEntry* AliCDBStorage::Get(const AliCDBId& query) {
 }
 
 //_____________________________________________________________________________
-AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path, Int_t runNumber, 
+AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path, Int_t runNumber,
        Int_t version, Int_t subVersion) {
 // get an AliCDBEntry object from the database
 
@@ -253,7 +253,7 @@ AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path, Int_t runNumber,
 }
 
 //_____________________________________________________________________________
-AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path, 
+AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path,
        const AliCDBRunRange& runRange, Int_t version,
        Int_t subVersion) {
 // get an AliCDBEntry object from the database
@@ -325,6 +325,45 @@ TList* AliCDBStorage::GetAll(const AliCDBPath& path,
        return GetAll(AliCDBId(path, runRange, version, subVersion));
 }
 
+//_____________________________________________________________________________
+AliCDBId* AliCDBStorage::GetId(const AliCDBId& query) {
+// get the Id of the valid object from the database (does not open the file)
+
+       // 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()));
+               return NULL;
+       }
+
+       // query is not specified if path contains wildcard or runrange = [-1,-1]
+       if (!query.IsSpecified()) {
+               AliError(Form("Unspecified query: %s",
+                               query.ToString().Data()));
+                return NULL;
+       }
+
+       AliCDBId* id = GetEntryId(query);
+
+       return id;
+}
+
+//_____________________________________________________________________________
+AliCDBId* AliCDBStorage::GetId(const AliCDBPath& path, Int_t runNumber,
+       Int_t version, Int_t subVersion) {
+// get the Id of the valid object from the database (does not open the file)
+
+       return GetId(AliCDBId(path, runNumber, runNumber, version, subVersion));
+}
+
+//_____________________________________________________________________________
+AliCDBId* AliCDBStorage::GetId(const AliCDBPath& path,
+       const AliCDBRunRange& runRange, Int_t version,
+       Int_t subVersion) {
+// get the Id of the valid object from the database (does not open the file)
+
+       return GetId(AliCDBId(path, runRange, version, subVersion));
+}
 
 //_____________________________________________________________________________
 Bool_t AliCDBStorage::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData, AliCDBManager::DataType type) {
index 312a5f7..d8c3fcf 100644 (file)
@@ -67,7 +67,7 @@ public:
        void PrintSelectionList();
 
        AliCDBEntry* Get(const AliCDBId& query);
-       AliCDBEntry* Get(const AliCDBPath& path, Int_t runNumber, 
+       AliCDBEntry* Get(const AliCDBPath& path, Int_t runNumber,
                                Int_t version = -1, Int_t subVersion = -1);
        AliCDBEntry* Get(const AliCDBPath& path, const AliCDBRunRange& runRange,
                                 Int_t version = -1, Int_t subVersion = -1);
@@ -78,6 +78,12 @@ public:
        TList* GetAll(const AliCDBPath& path, const AliCDBRunRange& runRange,
                                 Int_t version = -1, Int_t subVersion = -1);
        
+       AliCDBId* GetId(const AliCDBId& query);
+       AliCDBId* GetId(const AliCDBPath& path, Int_t runNumber,
+                               Int_t version = -1, Int_t subVersion = -1);
+       AliCDBId* GetId(const AliCDBPath& path, const AliCDBRunRange& runRange,
+                                Int_t version = -1, Int_t subVersion = -1);
+
        Bool_t Put(TObject* object, AliCDBId& id,  AliCDBMetaData* metaData,
                                AliCDBManager::DataType type=AliCDBManager::kPrivate);
        Bool_t Put(AliCDBEntry* entry, AliCDBManager::DataType type=AliCDBManager::kPrivate);
@@ -100,6 +106,7 @@ protected:
        virtual ~AliCDBStorage();
        void    GetSelection(/*const*/ AliCDBId* id);
        virtual AliCDBEntry* GetEntry(const AliCDBId& query) = 0;
+       virtual AliCDBId* GetEntryId(const AliCDBId& query) = 0;
        virtual TList* GetEntries(const AliCDBId& query) = 0;
        virtual Bool_t PutEntry(AliCDBEntry* entry) = 0;
        virtual TList *GetIdListFromFile(const char* fileName)=0;