New version of CDB storage framework (A.Colla)
authorhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 27 Sep 2005 16:08:08 +0000 (16:08 +0000)
committerhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 27 Sep 2005 16:08:08 +0000 (16:08 +0000)
27 files changed:
PHOS/AliPHOSClusterizerv1.cxx
PHOS/AliPHOSGetter.cxx
STEER/AliCDBDump.cxx
STEER/AliCDBDump.h
STEER/AliCDBEntry.cxx
STEER/AliCDBEntry.h
STEER/AliCDBGrid.cxx [new file with mode: 0644]
STEER/AliCDBGrid.h [new file with mode: 0644]
STEER/AliCDBId.cxx [new file with mode: 0644]
STEER/AliCDBId.h [new file with mode: 0644]
STEER/AliCDBLocal.cxx
STEER/AliCDBLocal.h
STEER/AliCDBManager.cxx [new file with mode: 0644]
STEER/AliCDBManager.h [new file with mode: 0644]
STEER/AliCDBMetaData.cxx
STEER/AliCDBMetaData.h
STEER/AliCDBPath.cxx [new file with mode: 0644]
STEER/AliCDBPath.h [new file with mode: 0644]
STEER/AliCDBRunRange.cxx [new file with mode: 0644]
STEER/AliCDBRunRange.h [new file with mode: 0644]
STEER/AliCDBStorage.cxx
STEER/AliCDBStorage.h
STEER/AliRunLoader.cxx
STEER/AliRunLoader.h
STEER/STEERLinkDef.h
STEER/libSTEER.pkg
macros/DBAccessTutorial.C

index d47ad38..fd1818b 100644 (file)
@@ -18,6 +18,9 @@
 /* History of cvs commits:
  *
  * $Log$
+ * Revision 1.84  2005/09/21 10:02:47  kharlov
+ * Reading calibration from CDB (Boris Polichtchouk)
+ *
  * Revision 1.82  2005/09/02 15:43:13  kharlov
  * Add comments in GetCalibrationParameters and Calibrate
  *
@@ -82,8 +85,8 @@
 #include "AliPHOSDigit.h"
 #include "AliPHOSDigitizer.h"
 #include "AliPHOSCalibrationDB.h"
+#include "AliCDBManager.h"
 #include "AliCDBStorage.h"
-#include "AliCDBLocal.h"
 
 ClassImp(AliPHOSClusterizerv1)
   
@@ -320,10 +323,13 @@ void AliPHOSClusterizerv1::GetCalibrationParameters()
 
   AliPHOSGetter * gime = AliPHOSGetter::Instance();
 
-  if(AliCDBStorage::Instance())
-    fCalibData = (AliPHOSCalibData*)AliCDBStorage::Instance()
+  if(AliCDBManager::Instance()->IsDefaultStorageSet()){
+    AliCDBEntry *entry = (AliCDBEntry*) AliCDBManager::Instance()->GetDefaultStorage()
       ->Get("PHOS/Calib/GainFactors_and_Pedestals",gAlice->GetRunNumber());
-
+    fCalibData = (AliPHOSCalibData*) entry->GetObject();
+  }
+  
+  
   if(!fCalibData)
     {
       if ( !gime->Digitizer() ) 
index fb55d24..0a93bec 100644 (file)
@@ -66,6 +66,7 @@
 #include "AliLog.h"
 #include "AliCDBLocal.h"
 #include "AliCDBStorage.h"
+#include "AliCDBManager.h"
 
 ClassImp(AliPHOSGetter)
   
@@ -1075,7 +1076,7 @@ Float_t AliPHOSGetter::BeamEnergy(void) const
 AliPHOSCalibData* AliPHOSGetter::CalibData()
 { 
 
-  if(!AliCDBStorage::Instance()) {
+  if( !(AliCDBManager::Instance()->IsDefaultStorageSet()) ) {
     fCalibData=0x0;
     Warning("CalibData","Calibration DB is not initiated!");
     return fCalibData;
index ff0d675..8aad7d2 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/* $Id$ */
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBDump                                              //
+//  access class to a DataBase in a dump storage (single file)     //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
 
-///////////////////////////////////////////////////////////////////////////////
-//                                                                           //
-// access classes for a data base in a LOCAL file                            //
-//                                                                           //
-///////////////////////////////////////////////////////////////////////////////
-
-
-#include <TFile.h>
+#include <TSystem.h>
 #include <TKey.h>
-#include <TROOT.h>
-#include "AliLog.h"
-#include "AliCDBEntry.h"
-#include "AliCDBMetaData.h"
-#include "AliCDBDump.h"
+#include <TFile.h>
+#include <TRegexp.h>
+#include <TObjString.h>
+#include <TList.h>
 
+#include "AliCDBDump.h"
+#include "AliCDBEntry.h"
+#include "AliLog.h"
 
 ClassImp(AliCDBDump)
 
-
 //_____________________________________________________________________________
-AliCDBDump::AliCDBDump(const char* fileName, Bool_t readOnly) :
-  AliCDBStorage(),
-  fFile(NULL)
-{
+AliCDBDump::AliCDBDump(const char* dbFile, Bool_t readOnly):
+fFile(NULL), fReadOnly(readOnly) {
 // constructor
 
-  if (!fileName) {
-    AliError("no file name given");
-    return;
-  }
-  TDirectory* saveDir = gDirectory;
-  fFile = TFile::Open(fileName, ((readOnly) ? "READ" : "UPDATE"));
-  if (saveDir) saveDir->cd(); else gROOT->cd();
-  if (!fFile || !fFile->IsOpen()) {
-    AliError(Form("could not open file %s", fileName));
-    fFile = NULL;
-  }
+       // opening file
+       fFile = TFile::Open(dbFile, fReadOnly ? "READ" : "UPDATE");     
+       if (!fFile) {
+               AliError(Form("Can't open file <%s>!" , dbFile));
+       } else {
+               AliDebug(2,Form("File <%s> opened",dbFile));
+               if(fReadOnly) AliDebug(2,Form("in read-only mode"));
+       }
 }
 
 //_____________________________________________________________________________
-AliCDBDump::~AliCDBDump()
-{
+AliCDBDump::~AliCDBDump() {
 // destructor
 
-  if (fFile) {
-    fFile->Close();
-    delete fFile;
-  }
+       if (fFile) {
+               fFile->Close();
+               delete fFile;
+       }
 }
 
+
 //_____________________________________________________________________________
-AliCDBDump::AliCDBDump(const AliCDBDump& /*db*/) :
-  AliCDBStorage(),
-  fFile(NULL)
-{
-// copy constructor
+Bool_t AliCDBDump::KeyNameToId(const char* keyname, AliCDBRunRange& runRange,
+// build AliCDBId from keyname numbers
+
+       Int_t& version, Int_t& subVersion) {
+
+        Ssiz_t mSize;
 
-  AliFatal("not implemented");
+       // valid keyname: Run#firstRun_#lastRun_v#version_s#subVersion.root
+        TRegexp keyPattern("^Run[0-9]+_[0-9]+_v[0-9]+_s[0-9]+$");
+        keyPattern.Index(keyname, &mSize);
+        if (!mSize) {
+                AliDebug(2,Form("Bad keyname <%s>.", keyname));
+                return kFALSE;
+        }
+
+        TObjArray* strArray = (TObjArray*) TString(keyname).Tokenize("_");
+
+       TString firstRunString(((TObjString*) strArray->At(0))->GetString());
+       runRange.SetFirstRun(atoi(firstRunString.Data() + 3));
+       runRange.SetLastRun(atoi(((TObjString*) strArray->At(1))->GetString()));
+       
+       TString verString(((TObjString*) strArray->At(2))->GetString());
+       version = atoi(verString.Data() + 1);
+
+       TString subVerString(((TObjString*) strArray->At(3))->GetString());
+        subVersion = atoi(subVerString.Data() + 1);
+
+        delete strArray;
+
+        return kTRUE;
 }
 
 //_____________________________________________________________________________
-AliCDBDump& AliCDBDump::operator = (const AliCDBDump& /*db*/)
-{
-// assignment operator
+Bool_t AliCDBDump::IdToKeyName(const AliCDBRunRange& runRange, Int_t version,
+        Int_t subVersion, TString& keyname) {
+// build key name from AliCDBId data (run range, version, subVersion)
 
-  AliFatal("not implemented");
-  return *this;
+        if (!runRange.IsValid()) {
+                AliWarning(Form("Invalid run range <%d, %d>.",
+                        runRange.GetFirstRun(), runRange.GetLastRun()));
+                return kFALSE;
+        }
+
+        if (version < 0) {
+                AliWarning(Form("Invalid version <%d>.", version));
+                return kFALSE;
+        }
+
+       if (subVersion < 0) {
+               AliWarning(Form("Invalid subversion <%s>.", subVersion));
+               return kFALSE;
+       }
+    
+        keyname += "Run";
+       keyname += runRange.GetFirstRun();
+        keyname += "_";
+        keyname += runRange.GetLastRun();
+        keyname += "_v";
+        keyname += version;
+       keyname += "_s";
+       keyname += subVersion;
+
+        return kTRUE;
 }
 
+//_____________________________________________________________________________
+Bool_t AliCDBDump::MkDir(const TString& path) {
+// descend into TDirectory, making TDirectories if they don't exist 
+       TObjArray* strArray = (TObjArray*) path.Tokenize("/");
+       
+       TIter iter(strArray);
+       TObjString* str;
+
+       while ((str = (TObjString*) iter.Next())) {
+               
+               TString dirName(str->GetString());
+               if (!dirName.Length()) {
+                       continue;
+               }
+
+               if (gDirectory->cd(dirName)) {
+                       continue;
+               }
+
+               TDirectory* aDir = gDirectory->mkdir(dirName, "");
+               if (!aDir) {
+                       AliError(Form("Can't create directory <%s>!", 
+                                       dirName.Data()));
+                       delete strArray;
+
+                       return kFALSE;
+               }
+
+               aDir->cd();
+       }       
+       
+       delete strArray;
+
+       return kTRUE;
+}
 
 //_____________________________________________________________________________
-AliCDBEntry* AliCDBDump::GetEntry(AliCDBMetaDataSelect& selMetaData, Int_t runNumber)
-{
-// get an object from the data base
-
-  // go to the directory
-  TDirectory* saveDir = gDirectory;
-  TDirectory *dir = fFile;
-  TString name(selMetaData.GetName());
-  Int_t last = name.Last('/');
-  if (last < 0) {
-    fFile->cd();
-  } else {
-    TString dirName(name(0, last));
-      if (!dir->cd(dirName)) {
-      AliError(Form("no directory %s found", dirName.Data()));
-      if (saveDir) saveDir->cd(); else gROOT->cd();
-      return NULL;
-    }
-    name.Remove(0, last+1);
-  }
-
-  dir = gDirectory;
-  TKey* key = dir->GetKey(name); 
-  if (!key) {
-    AliError(Form("no object with name %s found", selMetaData.GetName()));
-    if (saveDir) saveDir->cd(); else gROOT->cd();
-    return NULL;
-  }
-  Int_t nCycles = key->GetCycle();
-
-  // find the closest entry
-  AliCDBEntry* closestEntry = NULL;
-  for (Int_t iCycle = nCycles; iCycle > 0; iCycle--) {
-    key = dir->GetKey(name, iCycle);
-    
-    if (!key) continue;
-    AliCDBEntry* entry = (AliCDBEntry*) key->ReadObj();
-    if (!entry) continue;
-    if (!entry->InheritsFrom(AliCDBEntry::Class())) {
-      AliCDBMetaData metaData;
-      entry = new AliCDBEntry(entry, metaData);
-    }
-    if (!entry->GetCDBMetaData().IsStrictlyValid(runNumber, &selMetaData) ||
-       (entry->Compare(closestEntry) <= 0)) {
-      delete entry;
-      continue;
-    }
-    delete closestEntry;
-    closestEntry = entry;
-  }
-  if (saveDir) saveDir->cd(); else gROOT->cd();
-  if(!closestEntry) AliError(Form("No valid entry found for: name %s, version %d, run %d!!!",
-            selMetaData.GetName(),selMetaData.GetVersion(),runNumber));
-  if (!closestEntry) return NULL;
-
-//   if(selMetaData.GetVersion() > -1 && (closestEntry->GetCDBMetaData()).GetVersion() != selMetaData.GetVersion()) 
-//      AliWarning(Form("Warning: selected version (%d) not found, got version %d instead",
-//             selMetaData.GetVersion(),(closestEntry->GetCDBMetaData()).GetVersion()));
-
-  return closestEntry;
-}
-
-//_____________________________________________________________________________
-Bool_t AliCDBDump::PutEntry(AliCDBEntry* entry)
+Bool_t AliCDBDump::PrepareId(AliCDBId& id) {
+// prepare id (version, subVersion) of the object that will be stored (called by PutEntry)
+
+       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
+
+       
+       TIter iter(gDirectory->GetListOfKeys());
+       TKey* key;
+
+       if (!id.HasVersion()) { // version not specified: look for highest version & subVersion 
+                               
+               while ((key = (TKey*) iter.Next())) { // loop on keys
+
+                       const char* keyName = key->GetName();
+       
+                       if (!KeyNameToId(keyName, aRunRange, aVersion, 
+                          aSubVersion)) {
+                               AliWarning(Form(
+                                       "Bad keyname <%s>!I'll skip it.", keyName));
+                               continue;
+                       }
+                       
+                       if (!aRunRange.Overlaps(id.GetAliCDBRunRange())) continue;
+                       if(aVersion < lastVersion) continue;
+                       if(aVersion > lastVersion) lastSubVersion = -1;
+                       if(aSubVersion < lastSubVersion) continue;
+                       lastVersion = aVersion;
+                       lastSubVersion = aSubVersion;
+                       lastRunRange = aRunRange;
+               }
+
+               id.SetVersion(lastVersion);
+               id.SetSubVersion(lastSubVersion + 1);
+
+       } else { // version specified, look for highest subVersion only
+               
+               while ((key = (TKey*) iter.Next())) { // loop on the keys
+
+                       const char* keyName = key->GetName();
+       
+                       if (!KeyNameToId(keyName, aRunRange, aVersion, 
+                          aSubVersion)) {
+                               AliWarning(Form(
+                                       "Bad keyname <%s>!I'll skip it.", keyName));
+                               continue;
+                       }
+
+                       if (aRunRange.Overlaps(id.GetAliCDBRunRange()) 
+                               && aVersion == id.GetVersion()
+                               && aSubVersion > lastSubVersion) {
+                               lastSubVersion = aSubVersion;
+                               lastRunRange = aRunRange;
+                       }
+       
+               }
+               
+               id.SetSubVersion(lastSubVersion + 1);
+       }
+
+       TString lastStorage = id.GetLastStorage();
+       if(lastStorage.Contains(TString("grid"), TString::kIgnoreCase) &&
+          id.GetSubVersion() > 0 ){
+               AliError(Form("Grid to Dump Storage error! local object with version v%d_s%d found:",id.GetVersion(), id.GetSubVersion()-1));
+               AliError(Form("This object has been already transferred from Grid (check v%d_s0)!",id.GetVersion()));
+               return kFALSE;
+       }
+
+       if(lastStorage.Contains(TString("new"), TString::kIgnoreCase) &&
+          id.GetSubVersion() > 0 ){
+               AliWarning(Form("*** WARNING! a NEW object is being stored with version v%d_s%d",
+                                       id.GetVersion(),id.GetSubVersion()));
+               AliWarning(Form("and it will hide previously stored object with v%d_s%d!",
+                                       id.GetVersion(),id.GetSubVersion()-1));
+       }
+
+       if(!lastRunRange.IsAnyRange() && !(lastRunRange.IsEqual(& id.GetAliCDBRunRange()))) 
+               AliWarning(Form("Run range modified w.r.t. previous version (Run%d_%d_v%d_s%d)",
+                       lastRunRange.GetFirstRun(), lastRunRange.GetLastRun(), 
+                       id.GetVersion(), id.GetSubVersion()-1));
+
+       return kTRUE;
+
+}
+
+
+//_____________________________________________________________________________
+AliCDBId AliCDBDump::GetId(const AliCDBId& query) {
+// look for filename matching query (called by GetEntry)
+
+        AliCDBId result(query.GetAliCDBPath(), -1, -1, -1, -1);
+
+        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){
+                               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 result; 
+                               }
+               }
+               
+       } 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){
+                               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 result; 
+                       }
+                       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){
+                               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 result; 
+                       }
+                       result.SetVersion(aVersion);
+                       result.SetSubVersion(aSubVersion);
+                       result.SetFirstRun(aRunRange.GetFirstRun());
+                       result.SetLastRun(aRunRange.GetLastRun());
+                       
+               }
+       }
+
+       return result;
+}
+
+//_____________________________________________________________________________
+AliCDBEntry* AliCDBDump::GetEntry(const AliCDBId& query) {
+// 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(query.GetPath())) {
+                return NULL;
+        }
+
+       AliCDBId dataId;
+
+       // look for a filename matching query requests (path, runRange, version, subVersion)
+       if (!query.HasVersion()) {
+               // if version is not specified, first check the selection criteria list
+               dataId = GetId(GetSelection(query));
+       } else {
+               dataId = GetId(query);
+       }
+
+       if (!dataId.IsSpecified()) {
+               return NULL;
+       }
+       
+       TString keyname;
+       if (!IdToKeyName(dataId.GetAliCDBRunRange(), dataId.GetVersion(), 
+               dataId.GetSubVersion(), keyname)) {
+               AliError("Bad ID encountered! Subnormal error!");
+               return NULL;
+       }
+
+       // get the only AliCDBEntry object from the file
+       // 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) {
+               AliError("Bad storage data: NULL entry object!");
+               return NULL;
+       } 
+
+       if (AliCDBEntry::Class() != anObject->IsA()) {
+               AliError("Bad storage data: Invalid entry object!");
+               return NULL;
+       }
+
+       ((AliCDBEntry*) anObject)->SetLastStorage("dump");
+       
+       return (AliCDBEntry*) anObject;
+}
+
+//_____________________________________________________________________________
+void AliCDBDump::GetEntriesForLevel0(const AliCDBId& queryId, TList* result) {
+// multiple request (AliCDBStorage::GetAll)
+
+       TDirectory* saveDir = gDirectory;
+
+       TIter iter(gDirectory->GetListOfKeys());
+       TKey* key;
+
+       while ((key = (TKey*) iter.Next())) {
+               
+               TString keyNameStr(key->GetName());
+               if (queryId.GetAliCDBPath().Level1Comprises(keyNameStr)) {
+                       gDirectory->cd(keyNameStr);
+                       GetEntriesForLevel1(queryId, result);
+                       
+                       saveDir->cd();
+               }
+       }
+}
+
+//_____________________________________________________________________________
+void AliCDBDump::GetEntriesForLevel1(const AliCDBId& queryId, TList* result) {
+// multiple request (AliCDBStorage::GetAll)
+
+        TIter iter(gDirectory->GetListOfKeys());
+        TKey* key;
+
+       TDirectory* level0Dir = (TDirectory*) gDirectory->GetMother();
+
+        while ((key = (TKey*) iter.Next())) {
+
+                TString keyNameStr(key->GetName());
+                if (queryId.GetAliCDBPath().Level2Comprises(keyNameStr)) {
+                       
+                       AliCDBPath aPath(level0Dir->GetName(), 
+                                       gDirectory->GetName(), keyNameStr);
+                       AliCDBId anId(aPath, queryId.GetAliCDBRunRange(), 
+                                       queryId.GetVersion(), -1);
+
+                       AliCDBEntry* anEntry = GetEntry(anId);
+                       if (anEntry) {
+                               result->Add(anEntry);
+                       }
+       
+                }
+        }
+
+}
+
+                        
+//_____________________________________________________________________________
+TList* AliCDBDump::GetEntries(const AliCDBId& queryId) {
+// multiple request (AliCDBStorage::GetAll)
+
+       TDirectory::TContext context(gDirectory, fFile);
+
+       if (!(fFile && fFile->IsOpen())) {
+                AliError("AliCDBDump storage is not initialized properly");
+                return NULL;
+        }
+
+       TList* result = new TList();
+       result->SetOwner();
+
+       TIter iter(gDirectory->GetListOfKeys());
+       TKey* key;
+
+       while ((key = (TKey*) iter.Next())) {
+               
+               TString keyNameStr(key->GetName());
+               if (queryId.GetAliCDBPath().Level0Comprises(keyNameStr)) {
+                       gDirectory->cd(keyNameStr);
+                       GetEntriesForLevel0(queryId, result);
+
+                       fFile->cd();
+               }
+       }
+
+       return result;
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBDump::PutEntry(AliCDBEntry* entry) {
+// put an AliCDBEntry object into the database
+
+       TDirectory::TContext context(gDirectory, fFile);
+
+       if (!(fFile && fFile->IsOpen())) {
+               AliError("AliCDBDump storage is not initialized properly");
+               return kFALSE;
+       }
+
+       if (fReadOnly) {
+               AliError("AliCDBDump storage is read only!");
+               return kFALSE;
+       }
+
+       AliCDBId& id = entry->GetId();
+       
+        if (!gDirectory->cd(id.GetPath())) {
+                if (!MkDir(id.GetPath())) {
+                        AliError(Form("Can't open directory <%s>!", 
+                                       id.GetPath().Data()));
+                        return kFALSE;
+                }
+        }
+
+       // set version and subVersion for the entry to be stored
+       if (!PrepareId(id)) {
+               return kFALSE;          
+       }
+
+       // build keyname from entry's id
+       TString keyname;
+       if (!IdToKeyName(id.GetAliCDBRunRange(), id.GetVersion(), id.GetSubVersion(), keyname)) {
+               AliError("Invalid ID encountered! Subnormal error!");
+               return kFALSE;
+       }       
+
+       // write object (key name: Run#firstRun_#lastRun_v#version_s#subVersion)
+       Bool_t result = gDirectory->WriteTObject(entry, keyname);
+       if (!result) {
+               AliError(Form("Can't write entry to file: %s", 
+                               fFile->GetName()));
+       }
+
+        if(result) {
+               AliInfo(Form("AliCDBEntry stored into file %s",fFile->GetName()));
+               AliInfo(Form("TDirectory/key name: %s/%s",id.GetPath().Data(),keyname.Data()));
+        }
+
+       return result;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////
+//                                                                                             //
+// AliCDBDump factory                                                                                 //
+//                                                                                             //
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+ClassImp(AliCDBDumpFactory)
+
+//_____________________________________________________________________________
+Bool_t AliCDBDumpFactory::Validate(const char* dbString) {
+// check if the string is valid dump URI
+
+        TRegexp dbPattern("^dump://.+$");
+
+        return TString(dbString).Contains(dbPattern);
+}
+
+//_____________________________________________________________________________
+AliCDBParam* AliCDBDumpFactory::CreateParameter(const char* dbString) {
+// create AliCDBDumpParam class from the URI string
+
+        if (!Validate(dbString)) {
+                return NULL;
+        }
+
+        TString pathname(dbString + sizeof("dump://") - 1);
+
+       Bool_t readOnly;
+
+       if (pathname.Contains(TRegexp(";ReadOnly$"))) {
+               pathname.Resize(pathname.Length() - sizeof(";ReadOnly") + 1);
+               readOnly = kTRUE;
+       } else {
+               readOnly = kFALSE;
+       }
+
+       gSystem->ExpandPathName(pathname);
+       
+       if (pathname[0] != '/') {
+               pathname.Prepend(TString(gSystem->WorkingDirectory()) + '/');
+       }
+
+        AliInfo(pathname);
+
+        return new AliCDBDumpParam(pathname, readOnly);
+}
+
+//_____________________________________________________________________________
+AliCDBStorage* AliCDBDumpFactory::Create(const AliCDBParam* param) {
+// create AliCDBDump storage instance from parameters
+
+        if (AliCDBDumpParam::Class() == param->IsA()) {
+
+                const AliCDBDumpParam* dumpParam = 
+                       (const AliCDBDumpParam*) param;
+
+                return new AliCDBDump(dumpParam->GetPath(), 
+                               dumpParam->IsReadOnly());
+        }
+
+        return NULL;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////
+//                                                                                             //
+// AliCDBDump parameter class                                                                         //
+//                                                                                             //
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+ClassImp(AliCDBDumpParam)
+
+//_____________________________________________________________________________
+AliCDBDumpParam::AliCDBDumpParam() {
+// default constructor
+
+}
+
+//_____________________________________________________________________________
+AliCDBDumpParam::AliCDBDumpParam(const char* dbPath, Bool_t readOnly):
+        fDBPath(dbPath), fReadOnly(readOnly)
 {
-// puts an object into the database
-
-// AliCDBEntry entry is composed by the object and its MetaData
-// this method takes the metaData, reads the name, runRange and Version
-// creates the TDirectory structure into the file
-// looks for runs with same name, if exist increment version
-// (therefore version should not be put in the metadata)
-// Note: the key name of the entry is "DetSpecType"
-// return result 
-
-  if (!entry || !fFile) return kFALSE;
-  if (!fFile->IsWritable()) {
-    AliError(Form("The data base file was opened in read only mode. "
-                 "The object %s was not inserted", entry->GetName()));
-    return kFALSE;
-  }
-  
-  fFile->cd();
-  TDirectory* saveDir = gDirectory;
-
-  // go to or create the directory
-  TString name(entry->GetName());
-  while (name.BeginsWith("/")) name.Remove(0);
-  TDirectory* dir = fFile;
-  Int_t index = -1;
-  while ((index = name.Index("/")) >= 0) {
-    TString dirName(name(0, index));
-    if ((index > 0) && !dir->Get(dirName)) dir->mkdir(dirName);
-    dir->cd(dirName);
-    dir = gDirectory;
-    name.Remove(0, index+1);
-  } 
-
-  // determine the version number
-  Int_t version = 0;
-  TKey* key = dir->GetKey(name); 
-  if (key) {
-    Int_t nCycles = key->GetCycle();
-    for (Int_t iCycle = nCycles; iCycle > 0; iCycle--) {
-      key = dir->GetKey(name, iCycle); 
-      if (!key) continue;
-      AliCDBEntry* oldEntry = (AliCDBEntry*) key->ReadObj();
-      if (!oldEntry) continue;
-      if (oldEntry->InheritsFrom(AliCDBEntry::Class())) {
-       if (version <= oldEntry->GetCDBMetaData().GetVersion()) {
-         version = oldEntry->GetCDBMetaData().GetVersion()+1;
-       }
-      }
-      delete oldEntry;
-    }
-  }
-  entry->SetVersion(version);
-
-  Bool_t result = (entry->Write(name) != 0);
-  if (saveDir) saveDir->cd(); else gROOT->cd();
-  
-  if(result) {
-    AliInfo(Form("Run object %s",entry->GetName()));
-    AliInfo(Form("was successfully written into file %s",fFile->GetName()));
-  }  
-  
-  return result;
-}
-
-//_____________________________________________________________________________
-void AliCDBDump::TagForProduction
-               (const AliCDBMetaDataSelect& /* selMetaData */, UInt_t /* prodVers */){
-
-  AliError(Form("Not implemented in this case"));
+// constructor
+
+       TString uri;
+       uri += "dump://";
+       uri += dbPath;
+
+       if (fReadOnly) {
+               uri += ";ReadOnly";
+       }
+       
+        SetURI(uri);
+        SetType("dump");
+}
+
+//_____________________________________________________________________________
+AliCDBDumpParam::~AliCDBDumpParam() {
+// destructor
+
+}
+
+//_____________________________________________________________________________
+AliCDBParam* AliCDBDumpParam::CloneParam() const {
+// clone parameter
+
+       return new AliCDBDumpParam(fDBPath, fReadOnly);
+}
+
+//_____________________________________________________________________________
+ULong_t AliCDBDumpParam::Hash() const {
+// return Hash function
+
+       return fDBPath.Hash();
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBDumpParam::IsEqual(const TObject* obj) const {
+// check if this object is equal to AliCDBParam obj
+       
+       if (this == obj) {
+               return kTRUE;
+       }
+
+       if (AliCDBDumpParam::Class() != obj->IsA()) {
+               return kFALSE;
+       }
+
+       AliCDBDumpParam* other = (AliCDBDumpParam*) obj;
+
+       return fDBPath == other->fDBPath;
 }
index a6dd471..d04e1c7 100644 (file)
-#ifndef ALICDBDUMP_H
-#define ALICDBDUMP_H
+#ifndef ALI_CDB_DUMP_H
+#define ALI_CDB_DUMP_H
+
 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
  * See cxx source for full Copyright notice                               */
 
-/* $Id$ */
-
-///
-/// access classes for a data base in a LOCAL file
-///
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBDump                                              //
+//  access class to a DataBase in a dump storage (single file)     //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
 
 #include "AliCDBStorage.h"
-#include "AliCDBMetaDataSelect.h"
+#include "AliCDBManager.h"
 
+class TDirectory;
 class TFile;
 
-
 class AliCDBDump: public AliCDBStorage {
+       friend class AliCDBDumpFactory;
+
+public:
+
+       virtual Bool_t IsReadOnly() {return fReadOnly;};
+       virtual Bool_t HasSubVersion() {return kFALSE;};
+
+protected:
+
+       virtual AliCDBEntry* GetEntry(const AliCDBId& query);
+        virtual TList* GetEntries(const AliCDBId& query);
+        virtual Bool_t PutEntry(AliCDBEntry* entry);
+
+private:
+
+       AliCDBDump(const char* dbFile, Bool_t readOnly);
+       virtual ~AliCDBDump();  
+
+       Bool_t KeyNameToId(const char* keyname, AliCDBRunRange& runRange,
+                       Int_t& version, Int_t& subVersion);
+       Bool_t IdToKeyName(const AliCDBRunRange& runRange, Int_t version,
+                       Int_t subVersion, TString& keyname);    
+
+       Bool_t MkDir(const TString& dir);
+
+
+       Bool_t PrepareId(AliCDBId& id);
+       AliCDBId GetId(const AliCDBId& query);
+
+
+       void GetEntriesForLevel0(const AliCDBId& query, TList* result);
+       void GetEntriesForLevel1(const AliCDBId& query, TList* result);
+
+       TFile* fFile;           // Dump file
+       Bool_t fReadOnly;       // ReadOnly flag
+
+       ClassDef(AliCDBDump, 0);
+};
+
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBDumpFactory                                       //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
+
+class AliCDBDumpFactory: public AliCDBStorageFactory {
+
 public:
-  AliCDBDump(const char* fileName = "DB.root", Bool_t readOnly = kTRUE);
-  virtual ~AliCDBDump();
-  void        TagForProduction(const AliCDBMetaDataSelect& /* selMetaData */, UInt_t /* prodVers */);
+
+        virtual Bool_t Validate(const char* dbString);
+        virtual AliCDBParam* CreateParameter(const char* dbString);
 
 protected:
-  virtual AliCDBEntry*    GetEntry(AliCDBMetaDataSelect& selMetaData, Int_t runNumber);
+        virtual AliCDBStorage* Create(const AliCDBParam* param);
+
+        ClassDef(AliCDBDumpFactory, 0);
+};
+
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBDumpParam                                         //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
+
+class AliCDBDumpParam: public AliCDBParam {
+
+public:
+        AliCDBDumpParam();
+        AliCDBDumpParam(const char* dbPath, Bool_t readOnly = kFALSE);
+        
+        virtual ~AliCDBDumpParam();
+
+        const TString& GetPath() const {return fDBPath;};
+       Bool_t IsReadOnly() const {return fReadOnly;};
 
-  virtual Bool_t         PutEntry(AliCDBEntry* entry);
+       virtual AliCDBParam* CloneParam() const;
 
+       virtual ULong_t Hash() const;
+       virtual Bool_t IsEqual(const TObject* obj) const;
+       
 private:
-  AliCDBDump(const AliCDBDump& db);
-  AliCDBDump& operator = (const AliCDBDump& db);
 
-  TFile*                 fFile;    //! the DB local file
+        TString fDBPath;       // Dump file path name
+       Bool_t fReadOnly;       // ReadOnly flag
 
-  ClassDef(AliCDBDump, 0)   // access classes for a data base in a LOCAL file
+       ClassDef(AliCDBDumpParam, 0);
 };
 
 #endif
index b5fe1f8..29dce5c 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/* $Id$ */
-
-///////////////////////////////////////////////////////////////////////////////
-//                                                                           //
-// class that contains an object from the data base and knows about its      //
-// validity range (meta data)                                                //
-//                                                                           //
-///////////////////////////////////////////////////////////////////////////////
-
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBEntry                                             //
+//  container for an object, it identity (AliCDBId)               //
+//  and its metaData (AliCDBMetaData)                             //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
 
 #include "AliCDBEntry.h"
 
 ClassImp(AliCDBEntry)
 
-
 //_____________________________________________________________________________
-AliCDBEntry::AliCDBEntry() :
-  TObject(),
-  fObject(NULL),
-  fMetaData()
-{
+AliCDBEntry::AliCDBEntry():
+fObject(NULL),
+fMetaData(NULL), 
+fIsOwner(kFALSE){
 // default constructor
 
 }
 
 //_____________________________________________________________________________
-AliCDBEntry::AliCDBEntry(const TObject* object, const AliCDBMetaData& metaData) :
-  TObject(),
-  fObject(object->Clone()),
-  fMetaData(metaData)
-{
+AliCDBEntry::AliCDBEntry(TObject* object, const AliCDBId& id, 
+                       AliCDBMetaData* metaData, Bool_t owner):
+fObject(object), 
+fId(id), 
+fMetaData(metaData), 
+fIsOwner(owner){
 // constructor
 
 }
 
 //_____________________________________________________________________________
-AliCDBEntry::~AliCDBEntry()
-{
-// destructor
+AliCDBEntry::AliCDBEntry(TObject* object, const AliCDBPath& path, 
+                       const AliCDBRunRange& runRange,
+                        AliCDBMetaData* metaData,Bool_t owner):
+fObject(object), 
+fId(path, runRange, -1, -1), 
+fMetaData(metaData),
+fIsOwner(owner){
+// constructor
 
-  delete fObject;
 }
 
-
 //_____________________________________________________________________________
-AliCDBEntry::AliCDBEntry(const AliCDBEntry& entry) :
-  TObject(entry),
-  fMetaData(entry.fMetaData)
-{
-// copy constructor
+AliCDBEntry::AliCDBEntry(TObject* object, const AliCDBPath& path, 
+                       const AliCDBRunRange& runRange,
+                       Int_t version, AliCDBMetaData* metaData, Bool_t owner):
+fObject(object), 
+fId(path, runRange, version, -1), 
+fMetaData(metaData),
+fIsOwner(owner){
+// constructor
 
 }
 
 //_____________________________________________________________________________
-AliCDBEntry& AliCDBEntry::operator = (const AliCDBEntry& entry)
-{
-// assignment operator
-
-  delete fObject;
-  fObject = entry.fObject->Clone();
-  fMetaData = entry.fMetaData;
-  return *this;
+AliCDBEntry::AliCDBEntry(TObject* object, const AliCDBPath& path, 
+                       const AliCDBRunRange& runRange,
+                       Int_t version, Int_t subVersion, 
+                       AliCDBMetaData* metaData, Bool_t owner):
+fObject(object),
+fId(path, runRange, version, subVersion), 
+fMetaData(metaData), 
+fIsOwner(owner){
+// constructor
+
 }
 
 
+//_____________________________________________________________________________
+AliCDBEntry::AliCDBEntry(TObject* object, const AliCDBPath& path, 
+                       Int_t firstRun, Int_t lastRun, 
+                       AliCDBMetaData* metaData, Bool_t owner):
+fObject(object),
+fId(path, firstRun, lastRun, -1, -1), 
+fMetaData(metaData), 
+fIsOwner(owner){
+// constructor
+
+}
 
 //_____________________________________________________________________________
-const char* AliCDBEntry::GetName() const
-{
-// get the name
+AliCDBEntry::AliCDBEntry(TObject* object, const AliCDBPath& path, 
+                       Int_t firstRun, Int_t lastRun,
+                       Int_t version, AliCDBMetaData* metaData,
+                       Bool_t owner):
+fObject(object),
+fId(path, firstRun, lastRun, version, -1),
+fMetaData(metaData), 
+fIsOwner(owner){
+// constructor
 
-  return fMetaData.GetName();
 }
 
+//_____________________________________________________________________________
+AliCDBEntry::AliCDBEntry( TObject* object, const AliCDBPath& path, 
+                       Int_t firstRun, Int_t lastRun,
+                       Int_t version, Int_t subVersion,
+                       AliCDBMetaData* metaData, Bool_t owner):
+fObject(object),
+fId(path, firstRun, lastRun, version, subVersion),
+fMetaData(metaData), fIsOwner(owner){
+// constructor
+
+}
 
 //_____________________________________________________________________________
-Int_t AliCDBEntry::Compare(const TObject* object) const
-{
-// check whether this is preferred to object
+AliCDBEntry::~AliCDBEntry() {
+// destructor
+
+       if (fIsOwner) {
+               if (fObject) {
+                       delete fObject;
+               }
 
-  if (!object || !object->InheritsFrom(AliCDBEntry::Class())) return 1;
-  return fMetaData.Compare(&((AliCDBEntry*)object)->GetCDBMetaData());
+               if (fMetaData) {
+                       delete fMetaData;
+               }
+       }
 }
 
index ba50cd4..7f9e723 100644 (file)
@@ -1,45 +1,83 @@
-#ifndef ALICDBENTRY_H
-#define ALICDBENTRY_H
+#ifndef ALI_CDB_ENTRY_H
+#define ALI_CDB_ENTRY_H
+
 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
  * See cxx source for full Copyright notice                               */
 
-/* $Id$ */
-
-///
-/// class that contains an object from the data base and knows about its
-/// validity range (meta data)
-///
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBEntry                                             //
+//  container for an object, it identity (AliCDBId)               //
+//  and its metaData (AliCDBMetaData)                             //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
 
-#include <TObject.h>
+#include "AliCDBId.h"
 #include "AliCDBMetaData.h"
 
-
 class AliCDBEntry: public TObject {
+
 public:
-  AliCDBEntry();
-  AliCDBEntry(const TObject* object, const AliCDBMetaData& metaData);
-  virtual ~AliCDBEntry();
+       AliCDBEntry();
+
+       AliCDBEntry(TObject* object, const AliCDBId& id,  
+                       AliCDBMetaData* metaData, Bool_t owner = kFALSE);
+
+       AliCDBEntry(TObject* object, const AliCDBPath& path, const AliCDBRunRange& runRange,
+                       AliCDBMetaData* metaData, Bool_t owner = kFALSE);
+
+       AliCDBEntry(TObject* object, const AliCDBPath& path, const AliCDBRunRange& runRange,
+                       Int_t version, AliCDBMetaData* metaData, Bool_t owner = kFALSE);
+
+       AliCDBEntry(TObject* object, const AliCDBPath& path, const AliCDBRunRange& runRange,
+                       Int_t version, Int_t subVersion, 
+                       AliCDBMetaData* metaData, Bool_t owner = kFALSE);
+
+       AliCDBEntry(TObject* object, const AliCDBPath& path, Int_t firstRun, Int_t lastRun,
+                       AliCDBMetaData* metaData, Bool_t owner = kFALSE);
+
+       AliCDBEntry(TObject* object, const AliCDBPath& path, Int_t firstRun, Int_t lastRun,
+                       Int_t version, AliCDBMetaData* metaData, Bool_t owner = kFALSE);
+
+       AliCDBEntry(TObject* object, const AliCDBPath& path, Int_t firstRun, Int_t lastRun,
+                       Int_t version, Int_t subVersion, 
+                       AliCDBMetaData* metaData, Bool_t owner = kFALSE);
 
-  AliCDBEntry(const AliCDBEntry& entry);
-  AliCDBEntry& operator = (const AliCDBEntry& entry);
+       virtual ~AliCDBEntry();
 
-  void                 SetVersion(Int_t version = -1)
-    {fMetaData.SetVersion(version);}
 
-  void                 SetRunRange(Int_t firstRun = -1, Int_t lastRun=-1)
-    {fMetaData.SetRunRange(firstRun, lastRun);}
+       void            SetId(const AliCDBId& id) {fId = id;};
+       AliCDBId&       GetId() {return fId;};
+       const AliCDBId& GetId() const {return fId;};
+       
+       void            SetObject(TObject* object) {fObject = object;};
+       TObject*        GetObject() {return fObject;};
+       const TObject*  GetObject() const {return fObject;};    
 
-  virtual const char*  GetName() const;
-  const TObject*       GetObject() const {return fObject;}
-  const AliCDBMetaData&   GetCDBMetaData() const {return fMetaData;}
+       void                    SetMetaData(AliCDBMetaData* metaData) {fMetaData = metaData;};
+       AliCDBMetaData*         GetMetaData() {return fMetaData;};
+       const AliCDBMetaData*   GetMetaData() const {return fMetaData;};
 
-  virtual Int_t        Compare(const TObject* object) const;
+       void    SetOwner(Bool_t owner) {fIsOwner = owner;};
+       Bool_t  IsOwner() const {return fIsOwner;};
+       
+       void    SetVersion(Int_t version) {fId.SetVersion(version);}
+       void    SetSubVersion(Int_t subVersion) {fId.SetSubVersion(subVersion);}
+       
+       const TString   GetLastStorage() const {return fId.GetLastStorage();};
+       void            SetLastStorage(TString lastStorage) {fId.SetLastStorage(lastStorage);};
 
 private:
-  TObject*             fObject;         // pointer to the data base entry obj.
-  AliCDBMetaData    fMetaData;    // object's meta data
+       
+       AliCDBEntry(const AliCDBEntry& other); // no copy ctor
+       void operator= (const AliCDBEntry& other); // no assignment op
 
-  ClassDef(AliCDBEntry, 2)   // container for a data base entry object
+       TObject* fObject;               // object
+       AliCDBId fId;                   // entry ID
+       AliCDBMetaData* fMetaData;      // metaData
+       Bool_t fIsOwner;                // ownership flag
+       
+       ClassDef(AliCDBEntry, 1);
 };
 
 #endif
diff --git a/STEER/AliCDBGrid.cxx b/STEER/AliCDBGrid.cxx
new file mode 100644 (file)
index 0000000..ca49e31
--- /dev/null
@@ -0,0 +1,623 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/////////////////////////////////////////////////////////////////////////////////////////////////
+//                                                                                             //
+// AliCDBGrid                                                                                 //
+// access class to a DataBase in an AliEn storage                                             //
+//                                                                                             //
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+#include <TGrid.h>
+#include <TGridResult.h>
+#include <TFile.h>
+#include <TKey.h>
+#include <TROOT.h>
+#include <TSystem.h>
+#include <TObjArray.h>
+#include <TObjString.h>
+#include <TRegexp.h>
+
+#include "AliLog.h"
+#include "AliCDBGrid.h"
+
+
+ClassImp(AliCDBGrid)
+
+//_____________________________________________________________________________
+AliCDBGrid::AliCDBGrid(const char *host, const Int_t port, 
+                       const char *user, const char *dbPath, const char *se) :
+AliCDBStorage(),
+fHost(host),
+fPort(port),
+fUser(user),
+fDBPath(dbPath),
+fSE(se)
+{
+// constructor //
+
+       TString grid="alien://";
+       grid+=host; grid+=":"; grid+=port;
+
+       // if the same Grid is alreay active, skip connection
+       if (!gGrid || TString(host) != gGrid->GetHost() || 
+           port != gGrid->GetPort() || TString(user) != gGrid->GetUser()) {
+               // connection to the Grid
+               TGrid::Connect(grid.Data(),fUser.Data());
+       }
+
+       if(!gGrid) {
+               AliError("Connection failed!");
+               return;
+       }
+
+       TString initDir(gGrid->Pwd(0));
+       if (fDBPath[0] != '/') {
+               fDBPath.Prepend(initDir);
+       }
+
+       // check DBFolder: trying to cd to DBFolder; if it does not exist, create it
+       if(!gGrid->Cd(fDBPath.Data(),0)){
+               AliDebug(2,Form("Creating new folder <%s> ...",fDBPath.Data()));
+               if(!gGrid->Mkdir(fDBPath.Data(),"",0)){
+                       AliError(Form("Cannot create folder <%s> !",fDBPath.Data())); 
+               }
+       } else {
+               AliDebug(2,Form("Folder <%s> found",fDBPath.Data()));
+       }
+
+       // removes any '/' at the end of path, then append one '/'
+       while(fDBPath.EndsWith("/")) fDBPath.Remove(fDBPath.Last('/')); 
+       fDBPath+="/";
+
+       // return to the initial directory
+       gGrid->Cd(initDir.Data(),0);
+}
+
+//_____________________________________________________________________________
+AliCDBGrid::~AliCDBGrid()
+{
+// destructor
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBGrid::FilenameToId(const char* filename, AliCDBRunRange& runRange, 
+                               Int_t& gridVersion) {
+// build AliCDBId from filename numbers
+
+        Ssiz_t mSize;
+       
+       // valid filename: Run#firstRun_#lastRun_v#version.root
+        TRegexp keyPattern("^Run[0-9]+_[0-9]+_v[0-9]+.root$");
+        keyPattern.Index(filename, &mSize);
+        if (!mSize) {
+               AliDebug(2,Form("Bad filename <%s>.", filename));
+                return kFALSE;
+        }
+
+       TString idString(filename);
+       idString.Resize(idString.Length() - sizeof(".root") + 1);
+
+        TObjArray* strArray = (TObjArray*) idString.Tokenize("_");
+
+       TString firstRunString(((TObjString*) strArray->At(0))->GetString());
+       runRange.SetFirstRun(atoi(firstRunString.Data() + 3));
+       runRange.SetLastRun(atoi(((TObjString*) strArray->At(1))->GetString()));
+       
+       TString verString(((TObjString*) strArray->At(2))->GetString());
+       gridVersion = atoi(verString.Data() + 1);
+
+        delete strArray;
+
+        return kTRUE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBGrid::IdToFilename(const AliCDBRunRange& runRange, Int_t gridVersion, 
+                                TString& filename) {
+// build file name from AliCDBId data (run range, version)
+
+       if (!runRange.IsValid()) {
+               AliWarning(Form("Invalid run range <%d, %d>.", 
+                       runRange.GetFirstRun(), runRange.GetLastRun()));
+               return kFALSE;
+       }
+
+       if (gridVersion < 0) {
+               AliWarning(Form("Invalid version <%d>.", gridVersion));
+                return kFALSE;
+       }
+        filename += "Run";
+       filename += runRange.GetFirstRun();
+        filename += "_";
+        filename += runRange.GetLastRun();
+       filename += "_v";
+       filename += gridVersion;
+       filename += ".root";
+
+        return kTRUE;
+}
+
+//_____________________________________________________________________________
+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(fDBPath);
+
+       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+="/";
+               dirExist=gGrid->Cd(dirName,0);
+               if (!dirExist) {
+                       AliInfo(Form("Creating new folder <%s> ...",dirName.Data()));
+                       if(!gGrid->Mkdir(dirName,"",0)){
+                               AliError(Form("Cannot create directory <%s> !",dirName.Data()));
+                               gGrid->Cd(initDir.Data());
+                       return kFALSE;
+                       }
+               }
+       }
+       delete arrName;
+       gGrid->Cd(initDir,0);
+
+       const char* filename;
+       AliCDBRunRange aRunRange; // the runRange got from filename 
+       AliCDBRunRange lastRunRange(-1,-1); // highest runRange found
+       Int_t aVersion; // the version got from filename 
+       Int_t lastVersion=0; // highest version found
+
+       TGridResult *res = gGrid->Ls(dirName);
+
+       //loop on the files in the directory, look for highest version
+       for(int i=0; i < res->GetEntries(); i++){
+               filename=res->GetFileName(i);
+               if (!FilenameToId(filename, aRunRange, aVersion)) continue;
+               if (aRunRange.Overlaps(id.GetAliCDBRunRange()) && aVersion > lastVersion) {
+                       lastVersion = aVersion;
+                       lastRunRange = aRunRange;
+               }
+
+       }
+       delete res; 
+       id.SetVersion(lastVersion + 1);
+
+       TString lastStorage = id.GetLastStorage();
+       if(lastStorage.Contains(TString("new"), TString::kIgnoreCase) && id.GetVersion() > 1 ){
+               AliWarning(Form("*** WARNING! a NEW object is being stored with version v%d_s%d",
+                                       id.GetVersion()));
+               AliWarning(Form("and it will hide previously stored object with v%d_s%d!",
+                                       id.GetVersion()-1));
+       }
+
+       if(!lastRunRange.IsAnyRange() && !(lastRunRange.IsEqual(&id.GetAliCDBRunRange()))) 
+               AliWarning(Form("Run range modified w.r.t. previous version (Run%d_%d_v%d)",
+                       lastRunRange.GetFirstRun(), lastRunRange.GetLastRun(), id.GetVersion()));
+    
+       return kTRUE;
+}
+
+//_____________________________________________________________________________
+AliCDBId AliCDBGrid::GetId(const AliCDBId& query) {
+// look for filename matching query (called by GetEntry)
+
+       TString initDir(gGrid->Pwd(0));
+
+       AliCDBId result(query.GetAliCDBPath(), -1, -1, -1, -1);
+
+       TString dirName(fDBPath);
+       dirName += query.GetPath(); // dirName = fDBPath/idPath
+
+       if (!gGrid->Cd(dirName,0)) {
+               AliError(Form("Directory <%s> not found", (query.GetPath()).Data()));
+               AliError(Form("in DB folder %s", fDBPath.Data()));
+               return result;
+       }
+       TGridResult *res = gGrid->Ls(dirName);
+
+       const char* filename;
+       AliCDBRunRange aRunRange; // the runRange got from filename
+       Int_t aVersion; // the version got from filename
+       for(int i=0; i < res->GetEntries(); i++){
+               filename=res->GetFileName(i);
+               if (!FilenameToId(filename, aRunRange, aVersion)) continue;
+                // aRunRange and aVersion filled from filename
+               
+               if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue; 
+               // aRunRange contains requested run!
+
+               if (!query.HasVersion()){ // look for highest version
+                       if(result.GetVersion() > aVersion) continue;
+                       if(result.GetVersion() == aVersion) {
+                               AliError(Form("More than one object valid for run %d, version %d!", 
+                                       query.GetFirstRun(), aVersion));
+                               result.SetRunRange(-1,-1); result.SetVersion(-1);
+                       return result; 
+                       }
+                       result.SetVersion(aVersion);
+                       result.SetFirstRun(aRunRange.GetFirstRun());
+                       result.SetLastRun(aRunRange.GetLastRun());
+
+               } else { // look for specified version
+                       if(query.GetVersion() != aVersion) continue;
+                       if(result.GetVersion() == aVersion){
+                               AliError(Form("More than one object valid for run %d, version %d!", 
+                                       query.GetFirstRun(), aVersion));
+                                       result.SetRunRange(-1,-1); result.SetVersion(-1); 
+                                       return result; 
+                       }
+                       result.SetVersion(aVersion);
+                       result.SetFirstRun(aRunRange.GetFirstRun());
+                       result.SetLastRun(aRunRange.GetLastRun());
+               }
+       } // end loop on filenames
+       delete res;
+       
+       gGrid->Cd(initDir.Data(),0);
+       return result;
+}
+
+//_____________________________________________________________________________
+AliCDBEntry* AliCDBGrid::GetEntry(const AliCDBId& queryId) {
+// get AliCDBEntry from the database
+
+       AliCDBId dataId;
+       
+       // 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
+               dataId = GetId(GetSelection(queryId));
+       } else {
+               dataId = GetId(queryId);
+       }
+
+       if (!dataId.IsSpecified()) return NULL;
+
+       TString filename;
+       if (!IdToFilename(dataId.GetAliCDBRunRange(), dataId.GetVersion(),filename)) {
+               AliError("Bad data ID encountered! Subnormal error!");
+               return NULL;
+       }
+
+       filename.Prepend("/alien" + fDBPath + queryId.GetPath() + '/');
+       filename += "?se="; filename += fSE.Data(); 
+
+       AliInfo(Form("Opening file: %s",filename.Data()));
+       TFile *file = TFile::Open(filename);
+       if (!file) {
+               AliError(Form("Can't open file <%s>!", filename.Data()));
+               return NULL;
+       }
+
+       // get the only AliCDBEntry object from the file
+       // the object in the file is an AliCDBEntry entry named "AliCDBEntry"
+
+       TObject* anObject = file->Get("AliCDBEntry");
+
+       if (!anObject) {
+               AliError("Bad storage data: NULL entry object!");
+               return NULL;
+       }
+
+       if (AliCDBEntry::Class() != anObject->IsA()) {
+               AliError("Bad storage data: Invalid entry object!");
+               return NULL;
+       }
+
+       AliCDBId entryId = ((AliCDBEntry* ) anObject)->GetId();
+       // The object's Id is 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.
+       ((AliCDBEntry*) anObject)->SetLastStorage("grid");
+       if(!((entryId.GetAliCDBRunRange()).IsEqual(&dataId.GetAliCDBRunRange())) || 
+               entryId.GetVersion() != dataId.GetVersion()){
+               AliWarning(Form("Either RunRange or gridVersion in the object's metadata do noth match with fileName numbers:"));
+               AliWarning(Form("someone renamed file by hand!"));
+       }
+
+       // close file, return retieved entry
+       file->Close(); delete file; file=0;
+       return (AliCDBEntry*) anObject;
+}
+
+//_____________________________________________________________________________
+void AliCDBGrid::GetEntriesForLevel0(const char* level0,
+       const AliCDBId& queryId, TList* result) {
+// multiple request (AliCDBStorage::GetAll)
+
+       TString level0Dir=fDBPath;
+       level0Dir += level0;
+
+       if (!gGrid->Cd(level0Dir,0)) {
+               AliError(Form("Level0 directory <%s> not found", level0Dir.Data()));
+               return;
+       }
+
+       TGridResult *res = gGrid->Ls(level0Dir);
+       TString level1;
+       for(int i=0; i < res->GetEntries(); i++){
+               level1=res->GetFileName(i);
+       if (queryId.GetAliCDBPath().Level1Comprises(level1))
+               GetEntriesForLevel1(level0, level1, queryId, result);
+       }
+       delete res;
+}
+
+//_____________________________________________________________________________
+void AliCDBGrid::GetEntriesForLevel1(const char* level0, const char* level1,
+       const AliCDBId& queryId, TList* result) {
+// multiple request (AliCDBStorage::GetAll)
+
+       TString level1Dir=fDBPath;
+       level1Dir += level0;
+       level1Dir += '/';
+       level1Dir += level1;
+
+       if (!gGrid->Cd(level1Dir,0)) {
+               AliError(Form("Level1 directory <%s> not found", level1Dir.Data()));
+               return;
+       }
+
+       TGridResult *res = gGrid->Ls(level1Dir);
+       TString level2;
+       for(int i=0; i < res->GetEntries(); i++){
+               level2=res->GetFileName(i);
+               if (queryId.GetAliCDBPath().Level2Comprises(level2)){
+                       AliCDBPath entryPath(level0, level1, level2);
+                       AliCDBId entryId(entryPath, 
+                               queryId.GetAliCDBRunRange(),
+                               queryId.GetVersion(), 
+                               queryId.GetSubVersion());
+
+                       AliCDBEntry* anEntry = GetEntry(entryId);
+                       if (anEntry) result->Add(anEntry);
+
+               }
+       }
+       delete res;
+}
+
+//_____________________________________________________________________________
+TList* AliCDBGrid::GetEntries(const AliCDBId& queryId) {
+// multiple request (AliCDBStorage::GetAll)
+
+       TList* result = new TList();
+       result->SetOwner();
+
+       TString initDir(gGrid->Pwd(0));
+
+       TGridResult *res = gGrid->Ls(fDBPath);
+       TString level0;
+
+       for(int i=0; i < res->GetEntries(); i++){
+               level0=res->GetFileName(i);
+               if (queryId.GetAliCDBPath().Level0Comprises(level0)) 
+                       GetEntriesForLevel0(level0, queryId, result);                               
+       }        
+       delete res;
+       gGrid->Cd(initDir.Data(),0);
+       return result;  
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBGrid::PutEntry(AliCDBEntry* entry) {
+// put an AliCDBEntry object into the database
+       
+       AliCDBId& id = entry->GetId();
+
+       // set version for the entry to be stored
+       if (!PrepareId(id)) return kFALSE;       
+
+       // build filename from entry's id
+       TString filename;
+       if (!IdToFilename(id.GetAliCDBRunRange(), id.GetVersion(), filename)) {
+               AliError("Bad ID encountered! Subnormal error!");
+               return kFALSE;
+       } 
+
+       filename.Prepend("/alien" + fDBPath + id.GetPath() + '/');
+       TString filenameCopy(filename);
+       filename += "?se="; filename += fSE.Data(); 
+       TDirectory* saveDir = gDirectory;
+
+       // open file
+       TFile *file = TFile::Open(filename,"CREATE");
+       if(!file || !file->IsWritable()){
+               AliError(Form("Can't open file <%s>!", filename.Data()));    
+               if(file && !file->IsWritable()) file->Close(); delete file; file=0;
+               return kFALSE;
+       }
+  
+       file->cd(); 
+
+       entry->SetVersion(id.GetVersion());
+
+       // write object (key name: "AliCDBEntry")
+       Bool_t result = (entry->Write("AliCDBEntry") != 0); 
+       if (!result) AliError(Form("Can't write entry to file <%s>!",filename.Data()));
+
+
+       if (saveDir) saveDir->cd(); else gROOT->cd();
+       file->Close(); delete file; file=0;
+       if(result) {
+               AliInfo(Form("AliCDBEntry stored into file %s",filenameCopy.Data()));
+               AliInfo(Form("using S.E. %s", fSE.Data()));
+       }
+       return result;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////
+//                                                                                             //
+// AliCDBGrid factory                                                                                 //
+//                                                                                             //
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+ClassImp(AliCDBGridFactory)
+
+//_____________________________________________________________________________
+Bool_t AliCDBGridFactory::Validate(const char* gridString) {
+// check if the string is valid Grid URI
+
+       // pattern: alien://hostName:Port;user;dbPath;SE
+       // example of a valid pattern:
+       // "alien://aliendb4.cern.ch:9000;colla;DBTest;ALICE::CERN::Server"
+        TRegexp gridPattern("^alien://.+:[0-9]+;[a-zA-Z0-9_-.]+;.+;.+$");
+
+        return TString(gridString).Contains(gridPattern);
+}
+
+//_____________________________________________________________________________
+AliCDBParam* AliCDBGridFactory::CreateParameter(const char* gridString) {
+// create AliCDBGridParam class from the URI string
+
+       if (!Validate(gridString)) {
+               return NULL;
+       }
+       TString buffer(gridString + sizeof("alien://") - 1);
+       TString host = buffer(0,buffer.First(':')); // host (ex. aliendb4.cern.ch)
+       buffer = buffer(host.Sizeof(),buffer.Sizeof());
+       TString strPort = buffer(0, buffer.First(';'));
+       Int_t port = atoi(strPort.Data());      // port number (ex. 9000)
+       buffer = buffer(strPort.Sizeof(),buffer.Sizeof());
+       TString user = buffer(0,buffer.First(';')); // user (ex. colla)
+       buffer = buffer(user.Sizeof(),buffer.Sizeof());
+       TString dbPath = buffer(0,buffer.First(';')); // DB path (ex. /alice/cern.ch/user/c/colla/DB)
+       TString se = buffer(dbPath.Sizeof(),buffer.Sizeof()); // storage element (ex. ALICE::CERN::Server)
+       
+       AliInfo(Form("host: %s",host.Data()));
+       AliInfo(Form("port: %d",port));
+       AliInfo(Form("user: %s",user.Data()));
+       AliInfo(Form("dbPath: %s",dbPath.Data()));
+       AliInfo(Form("s.e.: %s",se.Data()));
+
+       return new AliCDBGridParam(host, port, user, dbPath, se);       
+}
+
+//_____________________________________________________________________________
+AliCDBStorage* AliCDBGridFactory::Create(const AliCDBParam* param) {
+// create AliCDBGrid storage instance from parameters
+       
+       if (AliCDBGridParam::Class() == param->IsA()) {
+               
+               const AliCDBGridParam* gridParam = (const AliCDBGridParam*) param;
+               AliCDBGrid *grid = new AliCDBGrid(gridParam->GetHost(), gridParam->GetPort(), 
+                                     gridParam->GetUser(), gridParam->GetPath(),
+                                     gridParam->GetSE()); 
+
+               if(gGrid) return grid;
+       }
+
+       return NULL;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////
+//                                                                                             //
+// AliCDBGrid Parameter class                                                                         //                                          //
+//                                                                                             //
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+ClassImp(AliCDBGridParam)
+
+//_____________________________________________________________________________
+AliCDBGridParam::AliCDBGridParam() {
+// default constructor
+
+}
+
+//_____________________________________________________________________________
+AliCDBGridParam::AliCDBGridParam(const char* host, 
+                               const Int_t port, 
+                               const char* user, 
+                               const char* dbPath, 
+                               const char* se):
+ fHost(host),
+ fPort(port),
+ fUser(user),
+ fDBPath(dbPath),
+ fSE(se)
+{
+// constructor
+       
+       SetType("alien");
+
+       TString uri=("alien://");
+       uri+=host; uri+=":"; uri+=port; uri+=";";
+       uri+=user; uri+=";"; uri+=dbPath; uri+=";";
+       uri+=se;
+       
+       SetURI(uri);
+}
+
+//_____________________________________________________________________________
+AliCDBGridParam::~AliCDBGridParam() {
+// destructor
+
+}
+
+//_____________________________________________________________________________
+AliCDBParam* AliCDBGridParam::CloneParam() const {
+// clone parameter
+
+        return new AliCDBGridParam(fHost, fPort, fUser, fDBPath, fSE);
+}
+
+//_____________________________________________________________________________
+ULong_t AliCDBGridParam::Hash() const {
+// return Hash function
+
+        return fHost.Hash()+fPort+fUser.Hash()+fDBPath.Hash()+fSE.Hash();
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBGridParam::IsEqual(const TObject* obj) const {
+// check if this object is equal to AliCDBParam obj
+
+        if (this == obj) {
+                return kTRUE;
+        }
+
+        if (AliCDBGridParam::Class() != obj->IsA()) {
+                return kFALSE;
+        }
+
+        AliCDBGridParam* other = (AliCDBGridParam*) obj;
+
+        if(fHost != other->fHost) return kFALSE;
+        if(fPort != other->fPort) return kFALSE;
+        if(fUser != other->fUser) return kFALSE;
+        if(fDBPath != other->fDBPath) return kFALSE;
+        if(fSE != other->fSE) return kFALSE;
+       return kTRUE;
+}
+
diff --git a/STEER/AliCDBGrid.h b/STEER/AliCDBGrid.h
new file mode 100644 (file)
index 0000000..fc68330
--- /dev/null
@@ -0,0 +1,120 @@
+#ifndef ALICDBGRID_H
+#define ALICDBGRID_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBGrid                                              //
+//  access class to a DataBase in an AliEn storage                //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
+
+#include "AliCDBStorage.h"
+#include "AliCDBManager.h"
+
+class AliCDBGrid: public AliCDBStorage {
+       friend class AliCDBGridFactory;
+
+public:
+                 
+       virtual Bool_t IsReadOnly() {return kFALSE;};
+       virtual Bool_t HasSubVersion() {return kFALSE;};
+  
+protected:
+
+       virtual AliCDBEntry*    GetEntry(const AliCDBId& queryId);
+       virtual TList*          GetEntries(const AliCDBId& queryId);
+       virtual Bool_t          PutEntry(AliCDBEntry* entry);
+
+private:
+       AliCDBGrid(const char *host="aliendb4.cern.ch", 
+               const Int_t port = 9000, 
+               const char *user="colla", 
+               const char* dbPath = "/alice/cern.ch/user/c/colla/DB", 
+               const char *SE="ALICE::CERN::Server");
+
+       virtual ~AliCDBGrid();
+
+       AliCDBGrid(const AliCDBGrid& db);
+       AliCDBGrid& operator = (const AliCDBGrid& db);
+
+       Bool_t FilenameToId(const char* filename, AliCDBRunRange& runRange, Int_t& version);
+       Bool_t IdToFilename(const AliCDBRunRange& runRange, Int_t version, TString& filename);
+
+       Bool_t PrepareId(AliCDBId& id);
+       AliCDBId GetId(const AliCDBId& query);
+
+
+       void GetEntriesForLevel0(const char* level0, const AliCDBId& query, TList* result);
+       void GetEntriesForLevel1(const char* level0, const char* level1, 
+                                const AliCDBId& query, TList* result);
+
+       TString    fHost;       // Grid host
+       Int_t      fPort;       // port
+       TString    fUser;       // User
+       TString    fDBPath;     // path of the DB folder
+       TString    fSE;         // Storage Element 
+
+ClassDef(AliCDBGrid, 0)      // access class to a DataBase in an AliEn storage 
+};
+
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBGridFactory                                       //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
+
+class AliCDBGridFactory: public AliCDBStorageFactory {
+
+public:
+
+       virtual Bool_t Validate(const char* gridString);
+        virtual AliCDBParam* CreateParameter(const char* gridString);
+
+protected:
+        virtual AliCDBStorage* Create(const AliCDBParam* param);
+
+        ClassDef(AliCDBGridFactory, 0);
+};
+
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBGridParam                                         //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
+
+class AliCDBGridParam: public AliCDBParam {
+       
+public:
+       AliCDBGridParam();
+       AliCDBGridParam(const char* host, const Int_t port, const char* user, 
+                       const char* dbPath, const char* se);
+       
+       virtual ~AliCDBGridParam();
+
+       const TString& GetHost() const {return fHost;};
+       const Int_t&   GetPort() const {return fPort;};
+       const TString& GetUser() const {return fUser;};
+       const TString& GetPath() const {return fDBPath;};
+       const TString& GetSE()   const {return fSE;};
+
+       virtual AliCDBParam* CloneParam() const;
+
+        virtual ULong_t Hash() const;
+        virtual Bool_t IsEqual(const TObject* obj) const;
+
+private:
+       TString fHost;       // Grid host
+       Int_t   fPort;       // port
+       TString fUser;       // User
+       TString fDBPath;     // path of the DB folder
+       TString fSE;         // Storage Element 
+
+       ClassDef(AliCDBGridParam, 0);
+};
+
+
+#endif
diff --git a/STEER/AliCDBId.cxx b/STEER/AliCDBId.cxx
new file mode 100644 (file)
index 0000000..218fe54
--- /dev/null
@@ -0,0 +1,116 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBId                                                //
+//  Identity of an object stored into a database:                 //
+//  path, run validity range, version, subVersion                 //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
+
+#include "AliCDBId.h"
+
+ClassImp(AliCDBId)
+
+//_____________________________________________________________________________
+AliCDBId::AliCDBId():
+fPath(), 
+fRunRange(-1,-1), 
+fVersion(-1), 
+fSubVersion(-1),
+fLastStorage("new")
+{
+// constructor
+
+}
+
+//_____________________________________________________________________________
+AliCDBId::AliCDBId(const AliCDBId& other):
+TObject(),
+fPath(other.fPath), 
+fRunRange(other.fRunRange),
+fVersion(other.fVersion), 
+fSubVersion(other.fSubVersion),
+fLastStorage(other.fLastStorage)
+{
+// constructor
+
+}
+
+//_____________________________________________________________________________
+AliCDBId::AliCDBId(const AliCDBPath& path, Int_t firstRun, Int_t lastRun, 
+       Int_t version, Int_t subVersion):
+fPath(path), 
+fRunRange(firstRun, lastRun), 
+fVersion(version), 
+fSubVersion(subVersion),
+fLastStorage("new")
+{
+// constructor
+
+} 
+
+//_____________________________________________________________________________
+AliCDBId::AliCDBId(const AliCDBPath& path, const AliCDBRunRange& runRange, 
+       Int_t version, Int_t subVersion):
+fPath(path), 
+fRunRange(runRange), 
+fVersion(version),
+fSubVersion(subVersion),
+fLastStorage("new")
+{
+// constructor
+
+}
+
+//_____________________________________________________________________________
+AliCDBId::~AliCDBId() {
+//destructor
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBId::IsValid() const {
+// validity check
+       
+       if (!(fPath.IsValid() && fRunRange.IsValid())) {
+               return kFALSE;
+       }
+       
+       // FALSE if doesn't have version but has subVersion
+       return !(!HasVersion() && HasSubVersion());
+}
+
+//_____________________________________________________________________________
+TString AliCDBId::ToString() const {
+// returns a string of Id data
+
+       TString result;
+       result += "Path \"";
+       result += GetPath();
+       result += "\"; RunRange [";
+       result += GetFirstRun();
+       result += ",";
+       result += GetLastRun();
+       result += "]; Version v";
+       result += GetVersion();
+       result += "_s";
+       result += GetSubVersion();
+       result += "; Previous storage ";
+       result += fLastStorage;
+       
+       return result;  
+}
diff --git a/STEER/AliCDBId.h b/STEER/AliCDBId.h
new file mode 100644 (file)
index 0000000..6d144f5
--- /dev/null
@@ -0,0 +1,90 @@
+#ifndef ALI_CDB_ID_H
+#define ALI_CDB_ID_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBId                                                //
+//  Identity of an object stored into a database:                 //
+//  path, run validity range, version, subVersion                 //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
+
+#include "AliCDBPath.h"
+#include "AliCDBRunRange.h"
+
+#include <TObject.h>
+
+class AliCDBId: public TObject {
+
+public:
+
+       AliCDBId();
+
+       AliCDBId(const AliCDBId& other);
+
+       AliCDBId(const AliCDBPath& path, const AliCDBRunRange& runRange,
+               Int_t version = -1, Int_t subVersion = -1);
+
+       AliCDBId(const AliCDBPath& path, 
+               Int_t firstRun , Int_t lastRun , Int_t verison = -1, 
+               Int_t subVersion = -1); 
+
+       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();};
+
+       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);};
+
+
+       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;};
+       
+       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 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);};
+       
+       TString ToString() const;
+
+private:
+
+       AliCDBPath fPath;               // path 
+       AliCDBRunRange fRunRange;       // run range
+       Int_t fVersion;                 // version
+       Int_t fSubVersion;              // subversion
+       TString fLastStorage;           // previous storage place (new, grid, local, dump)
+
+       ClassDef(AliCDBId, 1);
+};
+
+#endif
index 736f91e..dca9b9a 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/* $Id$ */
-
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //                                                                                             //
-// access class to a DB file inside an organized directory structure                           //
-// file name = "DBFolder/detector/dbType/detSpecType/Run#firstRun-#lastRun _v#version.root"    //                                   
+// AliCDBLocal                                                                                //
+// access class to a DataBase in a local storage                                              //
 //                                                                                             //
 /////////////////////////////////////////////////////////////////////////////////////////////////
 
-
-#include <TFile.h>
-#include <TKey.h>
-#include <TROOT.h>
 #include <TSystem.h>
-#include <TObjArray.h>
 #include <TObjString.h>
 #include <TRegexp.h>
+#include <TFile.h>
+#include <TKey.h>
 
-#include "AliLog.h"
 #include "AliCDBLocal.h"
-
+#include "AliCDBEntry.h"
+#include "AliLog.h"
 
 ClassImp(AliCDBLocal)
 
 //_____________________________________________________________________________
-AliCDBLocal::AliCDBLocal(const char* DBFolder) :
-  AliCDBStorage(),
-  fDBFolder(DBFolder)
+AliCDBLocal::AliCDBLocal(const char* baseDir):
+fBaseDirectory(baseDir) 
 {
 // constructor
-  gSystem->ExpandPathName(fDBFolder);
-  void *dir=0;
-  if(!(dir=gSystem->OpenDirectory(fDBFolder))){
-    AliFatal(Form("Path %s not a directory",fDBFolder.Data()));
-  }
-  gSystem->FreeDirectory(dir);
-  while(fDBFolder.EndsWith("/")) fDBFolder.Remove(fDBFolder.Last('/')); 
-  fDBFolder+="/";
+
+       // check baseDire: trying to cd to baseDir; if it does not exist, create it
+       void* dir = gSystem->OpenDirectory(baseDir);
+       if (dir == NULL) {
+               if (gSystem->mkdir(baseDir, kTRUE)) {
+                       AliError(Form("Can't open directory <%s>!", baseDir));
+               }
+
+       } else {
+               AliDebug(2,Form("Folder <%s> found",fBaseDirectory.Data()));
+               gSystem->FreeDirectory(dir);
+       }
 }
 
 //_____________________________________________________________________________
-AliCDBLocal::~AliCDBLocal()
-{
- // destructor
+AliCDBLocal::~AliCDBLocal() {
+// destructor
 
 }
 
+
 //_____________________________________________________________________________
-AliCDBLocal::AliCDBLocal(const AliCDBLocal& /*db*/) :
-  AliCDBStorage(),
-  fDBFolder("")
-{
- // copy constructor
+Bool_t AliCDBLocal::FilenameToId(const char* filename, AliCDBRunRange& runRange,
+// build AliCDBId from filename numbers
+
+       Int_t& version, Int_t& subVersion) {
+
+        Ssiz_t mSize;
 
- AliFatal("not implemented");
+       // valid filename: Run#firstRun_#lastRun_v#version_s#subVersion.root
+        TRegexp keyPattern("^Run[0-9]+_[0-9]+_v[0-9]+_s[0-9]+.root$");
+        keyPattern.Index(filename, &mSize);
+        if (!mSize) {
+               AliDebug(2, Form("Bad filename <%s>.", filename));
+                return kFALSE;
+        }
+
+       TString idString(filename);
+       idString.Resize(idString.Length() - sizeof(".root") + 1);
+
+        TObjArray* strArray = (TObjArray*) idString.Tokenize("_");
+
+       TString firstRunString(((TObjString*) strArray->At(0))->GetString());
+       runRange.SetFirstRun(atoi(firstRunString.Data() + 3));
+       runRange.SetLastRun(atoi(((TObjString*) strArray->At(1))->GetString()));
+       
+       TString verString(((TObjString*) strArray->At(2))->GetString());
+       version = atoi(verString.Data() + 1);
+
+       TString subVerString(((TObjString*) strArray->At(3))->GetString());
+        subVersion = atoi(subVerString.Data() + 1);
+
+        delete strArray;
+
+        return kTRUE;
 }
 
+
 //_____________________________________________________________________________
-AliCDBLocal& AliCDBLocal::operator = (const AliCDBLocal& /*db*/)
-{
-// assignment operator
+Bool_t AliCDBLocal::IdToFilename(const AliCDBRunRange& runRange, Int_t version,
+       Int_t subVersion, TString& filename) {
+// build file name from AliCDBId data (run range, version, subVersion)
+
+       if (!runRange.IsValid()) {
+               AliWarning(Form("Invalid run range <%d, %d>.", 
+                       runRange.GetFirstRun(), runRange.GetLastRun()));
+               return kFALSE;
+       }
+
+       if (version < 0) {
+               AliWarning(Form("Invalid version <%d>.", version));
+                return kFALSE;
+       }
 
- AliFatal("not implemented");
- return *this;
+       if (subVersion < 0) {
+               AliWarning(Form("Invalid subversion <%s>.", subVersion));
+               return kFALSE;
+       }
+        filename += "Run";
+       filename += runRange.GetFirstRun();
+        filename += "_";
+        filename += runRange.GetLastRun();
+       filename += "_v";
+       filename += version;
+       filename += "_s";
+       filename += subVersion;
+       filename += ".root";
+
+        return kTRUE;
 }
 
 //_____________________________________________________________________________
-AliCDBEntry* AliCDBLocal::GetEntry(AliCDBMetaDataSelect& selMetaData, Int_t runNumber)
-{
-// get an object from the data base   
-
- TDirectory* saveDir = gDirectory;
-
- // Find the right file in the directory
- TString prefix="_v"; // development mode: fileName=Run#Run1-#Run2_v#Version.root
- if(fStorageMode==kProduction) prefix="_Prod"; // production mode: fileName=Run#Run1-#Run2_Prod#Version.root            
-
- TString buffer(fDBFolder);
- TString name(selMetaData.GetName());
- buffer+=name; buffer+='/';
-
- int selVersion = selMetaData.GetVersion();
-
- void *dir = gSystem->OpenDirectory(buffer);
- if(!dir) {
-   AliError(Form("Directory %s not found", name.Data()));
-   AliError(Form("in DB folder %s", fDBFolder.Data()));
-   return NULL;
- }
-
- TString fileName="";
- TString levelContent="";
- int oldVers=-1;
- // in this array the "numbers" of the retrieved fileName (Run1, Run2, Version) are stored for later usage
- int fileNumbers[3]={-1,-1,-1}; 
- while(levelContent=gSystem->GetDirEntry(dir)){ 
-
-   if(levelContent=="." || levelContent=="..") continue; if(levelContent=="") break;
-   if(!levelContent.Contains("Run") || !levelContent.Contains(prefix)) continue;
-        
-   int numbers[3]={-1,-1,-1}; // numbers[0]=firstRun, numbers[1]=lastRun, numbers[2]=Version 
-   // gets the 3 "numbers" in the file name
-   if(!DecodeFileName(levelContent,numbers, prefix)) continue; // wrong run filename format
-   if(numbers[0]>runNumber ||  numbers[1]<runNumber) continue; // data not valid for run number
-
-   if(selVersion == -1) {
-     if(numbers[2] >= oldVers){
-        if(numbers[2] == oldVers){ 
-          // more than one file valid for the run -> error!   
-           AliError(Form("More than one object valid for run %d, version %d!", runNumber, oldVers));
-           AliError(Form("No object will be returned!"));
-          gSystem->FreeDirectory(dir);
-          return NULL;
-        }
-        fileName=levelContent;
-        oldVers=numbers[2];
-        fileNumbers[0]=numbers[0]; fileNumbers[1]=numbers[1]; fileNumbers[2]=numbers[2]; 
-     }
-   } else {
-     if(numbers[2] == selVersion){
-        if(fileName != ""){ 
-          // filename was already assigned, this means there is more than one file valid for the run -> error!   
-           AliError(Form("More than one object valid for run %d, version %d!", runNumber, selVersion));
-           AliError(Form("No object will be returned!"));
-          gSystem->FreeDirectory(dir);
-          return NULL;
-        }
-        fileName=levelContent;
-        fileNumbers[0]=numbers[0]; fileNumbers[1]=numbers[1]; fileNumbers[2]=numbers[2]; 
-     }
-   }   
+Bool_t AliCDBLocal::PrepareId(AliCDBId& id) {
+// prepare id (version, subVersion) of the object that will be stored (called by PutEntry)
+
+       TString dirName;
+       dirName += fBaseDirectory;
+       dirName += '/';
+       dirName += id.GetPath();
+
+       // go to the path; if directory does not exist, create it
+       void* dirPtr = gSystem->OpenDirectory(dirName);
+       if (!dirPtr) {
+               gSystem->mkdir(dirName, kTRUE);
+                dirPtr = gSystem->OpenDirectory(dirName);
+
+                if (!dirPtr) {
+                        AliError(Form("Can't create directory <%s>!", 
+                                       dirName.Data()));
+                        return kFALSE;
+                }
+       }
 
- } // end loop on runs    
- gSystem->FreeDirectory(dir);
- buffer+=fileName;
- if(!buffer.EndsWith(".root")){
-    AliError(Form("No DB file matching criteria found!"));
-    return NULL;    
- }
- TFile *DBFile = new TFile(buffer.Data(),"READ");
- if(!DBFile || !DBFile->IsOpen()) {
-    AliError(Form("could not open file %s", buffer.Data()));
-    return NULL;
- }
- AliInfo(Form("File %s succesfully opened", buffer.Data()));
-   
-// get the only AliCDBEntry object from the file
-// I assume that the object in the file is a AliCDBEntry entry with
-// name="detSpecType" (set in CDBMetaDataSelect)
+       const char* 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
+
+       if (!id.HasVersion()) { // version not specified: look for highest version & subVersion
+                               
+               while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on the files
+
+                       TString aString(filename);
+                       if (aString == "." || aString == "..") continue;
+       
+                       if (!FilenameToId(filename, aRunRange, aVersion, 
+                               aSubVersion)) {
+                               AliWarning(Form(
+                                       "Bad filename <%s>! I'll skip it.", 
+                                       filename));
+                               continue;
+                       }
+                       
+                       if (!aRunRange.Overlaps(id.GetAliCDBRunRange())) continue;
+                       if(aVersion < lastVersion) continue;
+                       if(aVersion > lastVersion) lastSubVersion = -1;
+                       if(aSubVersion < lastSubVersion) continue;
+                       lastVersion = aVersion;
+                       lastSubVersion = aSubVersion;
+                       lastRunRange = aRunRange;
+               }
+
+               id.SetVersion(lastVersion);
+               id.SetSubVersion(lastSubVersion + 1);
+
+       } else { // version specified, look for highest subVersion only
+               
+               while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on the files
+                       
+                       TString aString(filename);
+                       if (aString == "." || aString == "..") {
+                               continue;
+                       }
+
+                       if (!FilenameToId(filename, aRunRange, aVersion, 
+                               aSubVersion)) {
+                               AliWarning(Form(
+                                       "Bad filename <%s>!I'll skip it.",
+                                       filename));     
+                               continue;
+                       }
+
+                       if (aRunRange.Overlaps(id.GetAliCDBRunRange()) 
+                               && aVersion == id.GetVersion()
+                               && aSubVersion > lastSubVersion) {
+                               lastSubVersion = aSubVersion;
+                               lastRunRange = aRunRange;
+                       }
+       
+               }
+               
+               id.SetSubVersion(lastSubVersion + 1);
+       }
 
- DBFile->cd();
+       gSystem->FreeDirectory(dirPtr);
 
- AliCDBEntry *entry = (AliCDBEntry*) DBFile->Get(selMetaData.GetDetSpecType());
- if(!entry || !entry->InheritsFrom(AliCDBEntry::Class())) {
-   AliError(Form("No entry named %s found!",selMetaData.GetDetSpecType())); 
-   DBFile->Close(); delete DBFile; DBFile=0; 
-   if (saveDir) saveDir->cd(); else gROOT->cd();
-   return NULL;
- }
-  
-// Version 1:
-// set the run range and version got from the filename 
-// to the object's metadata!  
-  
-// entry->SetRunRange(fileNumbers[0],fileNumbers[1]);
-// entry->SetVersion(fileNumbers[2]);
-
-// Version 2: The object's metadata are not reset during storage
-// If object's metadata runRange or version do not match with filename,
-// it means that someone renamed file by hand. In this case a warning msg is issued.
- Int_t objFirstRun=(entry->GetCDBMetaData()).GetFirstRun();
- Int_t objLastRun=(entry->GetCDBMetaData()).GetLastRun();
- Int_t objVersion=(entry->GetCDBMetaData()).GetVersion();
- if(objFirstRun != fileNumbers[0] || objLastRun != fileNumbers[1] || objVersion != fileNumbers[2]){
-    AliWarning(Form("Either RunRange or Version in the object's metadata do noth match with fileName numbers:"));
-    AliWarning(Form("someone renamed file by hand!"));
- }
-
-// close file, return retieved entry
-
- DBFile->Close(); delete DBFile; DBFile=0;
- if (saveDir) saveDir->cd(); else gROOT->cd();
-   
-//  if(selMetaData.GetVersion() > -1 && fileNumbers[2] != selMetaData.GetVersion()) 
-//      AliWarning(Form("Warning: selected version (%d) not found, got version %d instead",
-//             selMetaData.GetVersion(),fileNumbers[2]));
-
- return entry;
-  
+       TString lastStorage = id.GetLastStorage();
+       if(lastStorage.Contains(TString("grid"), TString::kIgnoreCase) &&
+          id.GetSubVersion() > 0 ){
+               AliError(Form("Grid to Local Storage error! local object with version v%d_s%d found:",id.GetVersion(), id.GetSubVersion()-1));
+               AliError(Form("This object has been already transferred from Grid (check v%d_s0)!",id.GetVersion()));
+               return kFALSE;
+       }
+
+       if(lastStorage.Contains(TString("new"), TString::kIgnoreCase) &&
+          id.GetSubVersion() > 0 ){
+               AliWarning(Form("*** WARNING! a NEW object is being stored with version v%d_s%d",
+                                       id.GetVersion(),id.GetSubVersion()));
+               AliWarning(Form("and it will hide previously stored object with v%d_s%d!",
+                                       id.GetVersion(),id.GetSubVersion()-1));
+       }
+
+       if(!lastRunRange.IsAnyRange() && !(lastRunRange.IsEqual(& id.GetAliCDBRunRange()))) 
+               AliWarning(Form("Run range modified w.r.t. previous version (Run%d_%d_v%d_s%d)",
+                       lastRunRange.GetFirstRun(), lastRunRange.GetLastRun(), 
+                       id.GetVersion(), id.GetSubVersion()-1));
+
+       return kTRUE;
 }
 
+//_____________________________________________________________________________
+AliCDBId AliCDBLocal::GetId(const AliCDBId& query) {
+// look for filename matching query (called by GetEntry)
+
+       AliCDBId result(query.GetAliCDBPath(), -1, -1, -1, -1);
+
+       TString dirName;
+       dirName += fBaseDirectory;
+       dirName += '/';
+       dirName += query.GetPath(); // dirName = fDBPath/idPath
+
+       void* dirPtr = gSystem->OpenDirectory(dirName); 
+       if (!dirPtr) {
+               AliError(Form("Directory <%s> not found", (query.GetPath()).Data()));
+               AliError(Form("in DB folder %s", fBaseDirectory.Data()));
+               return result;
+       }
+
+       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){
+                               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 result; 
+                               }
+               }
+               
+       } 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){
+                               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 result; 
+                       }
+                       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){
+                               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 result; 
+                       }
+                       result.SetVersion(aVersion);
+                       result.SetSubVersion(aSubVersion);
+                       result.SetFirstRun(aRunRange.GetFirstRun());
+                       result.SetLastRun(aRunRange.GetLastRun());
+                       
+               }
+       }
+
+       gSystem->FreeDirectory(dirPtr);
+
+       return result;
+}
 
 //_____________________________________________________________________________
-Bool_t AliCDBLocal::PutEntry(AliCDBEntry* entry)
-{
-// puts an object into the database
-
-// AliCDBEntry entry is composed by the object and its MetaData
-// this method takes the metaData, reads the name, runRange and Version
-// creates the directory structure and the file name
-// looks for runs with same or overlapping runrange, if exist increment version
-// (therefore version should not be put in the metadata)
-// if the runrange is different (but overlapping) from a preceding version, a warning message
-// is issued. 
-// sets the runrange and version in the object metadata = -1 (to avoid inconsistencies)
-// open the filem, write the entry in the file.
-// Note: the key name of the entry is "detSpecType"
-// return result 
-   
- if(!entry) return kFALSE;
- TDirectory* saveDir = gDirectory;
-  
- Int_t firstRun=entry->GetCDBMetaData().GetFirstRun();
- Int_t lastRun=entry->GetCDBMetaData().GetLastRun();
- if(firstRun<0 || lastRun<0 || lastRun<firstRun) {
-    AliError(Form("Run range not set or not valid: %d - %d !", firstRun, lastRun));
-    return kFALSE;
- }
-
- TString name(entry->GetName()); 
- TString detSpecType(name(name.Last('/')+1, name.Length()-name.Last('/')));
- TString buffer(fDBFolder);
- void *dir=0;
- Int_t index = -1;
- name+='/'; // name=detector/dbType/detSpecType/
-
- while ((index = name.Index("/")) >= 0) {
-   TString dirName(name(0, index+1));
-   buffer+=dirName;
-   dir=gSystem->OpenDirectory(buffer);
-   if (!dir) {
-     AliWarning(Form("Directory %s does not exist! It will be created...",buffer.Data()));
-     gSystem->mkdir(buffer.Data());
-   }
-   name.Remove(0, index+1);
-   gSystem->FreeDirectory(dir);
- } 
- dir = gSystem->OpenDirectory(buffer);
- TString levelContent="";
- Int_t maxVersion=-1, run1=-1, run2=-1;
- int numbers[3]={-1,-1,-1}; // numbers[0]=firstRun, numbers[1]=lastRun, numbers[2]=Version
- while(levelContent=gSystem->GetDirEntry(dir)){
-   if(levelContent=="." || levelContent=="..") continue; if(levelContent=="") break;
-   if(levelContent.Contains("Run")){
-     if(levelContent.Contains("_Prod")) continue; //skip "Production" links
-     if(!DecodeFileName(levelContent, numbers, "_v")) continue;
-     if((firstRun>=numbers[0] && firstRun<=numbers[1]) ||
-       (lastRun>=numbers[0] && lastRun<=numbers[1]) ||
-       (firstRun<=numbers[0] && lastRun>=numbers[1])) {// overlap!     
-        if(numbers[2]>maxVersion) {
-          maxVersion=numbers[2];
-          run1=numbers[0]; run2=numbers[1];
+AliCDBEntry* AliCDBLocal::GetEntry(const AliCDBId& queryId) {
+// get AliCDBEntry from the database
+
+       AliCDBId dataId;
+       
+       // 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
+               dataId = GetId(GetSelection(queryId));
+       } else {
+               dataId = GetId(queryId);
        }
-     }
-   }
- }
- gSystem->FreeDirectory(dir);
- if((run1!=-1 && run2!=-1) && (firstRun!=run1 || lastRun!=run2)) 
-    AliWarning(Form("Run range modified w.r.t. preceding version (%d, %d)",run1, run2));
-    
- TString strfName=EncodeFileName(firstRun, lastRun, maxVersion+1);
- buffer+=strfName;
- // opening file
- TFile *DBFile = new TFile(buffer.Data(),"NEW");
- if(!DBFile || !DBFile->IsWritable()){
-    AliError(Form("The data base file is not writable. "
-               "The object %s was not inserted", entry->GetName()));
-    if(!DBFile->IsWritable()) DBFile->Close(); DBFile->Delete(); delete DBFile; DBFile=0;
-    return kFALSE;
- }
-  
- DBFile->cd();
+
+       if (!dataId.IsSpecified()) return NULL;
+
+       TString filename;
+       if (!IdToFilename(dataId.GetAliCDBRunRange(), dataId.GetVersion(),
+                dataId.GetSubVersion(), filename)) {
+
+               AliError("Bad data ID encountered! Subnormal error!");
+                return NULL;
+       }
+       
+       filename.Prepend((fBaseDirectory +'/' + queryId.GetPath() + '/'));
+
+       TFile file(filename, "READ"); // open file
+       if (!file.IsOpen()) {
+               AliError(Form("Can't open file <%s>!", filename.Data()));
+                return NULL;
+       }
+
+       // get the only AliCDBEntry object from the file
+       // the object in the file is an AliCDBEntry entry named "AliCDBEntry"
+       
+       TObject* anObject = file.Get("AliCDBEntry");
+       if (!anObject) {
+               AliError("Bad storage data: NULL entry object!");
+               return NULL;
+       }
+
+       if (AliCDBEntry::Class() != anObject->IsA()) {
+               AliError("Bad storage data: Invalid entry object!");
+               return NULL;
+       }
+       
+       AliCDBId entryId = ((AliCDBEntry* ) anObject)->GetId();
  
- entry->SetVersion(maxVersion+1);
+       // 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.
+       
+       ((AliCDBEntry*) anObject)-> SetLastStorage("local");
  
- // write object
- Bool_t result = (entry->Write(detSpecType) != 0); 
- if (saveDir) saveDir->cd(); else gROOT->cd();
- DBFile->Close(); DBFile->Delete(); delete DBFile; DBFile=0;
- if(result) {
-    AliInfo(Form("Run object %s",entry->GetName()));
-    AliInfo(Form("was successfully written into file %s",buffer.Data()));
- }
+       if(!((entryId.GetAliCDBRunRange()).IsEqual(& dataId.GetAliCDBRunRange())) || 
+               (entryId.GetVersion() != dataId.GetVersion()) || (entryId.GetSubVersion() != dataId.GetSubVersion())){
+               AliWarning(Form("Either object Id's RunRange or version do noth match with file name:"));
+               AliWarning("someone renamed file by hand!");
+        }
+       
+       // close file, return retieved entry
+       file.Close();
+       return (AliCDBEntry*) anObject;
+}
 
- return result;
+//_____________________________________________________________________________
+void AliCDBLocal::GetEntriesForLevel0(const char* level0,
+       const AliCDBId& queryId, TList* result) {
+// multiple request (AliCDBStorage::GetAll)
+
+       TString level0Dir;
+       level0Dir += fBaseDirectory;
+       level0Dir += '/';
+       level0Dir += level0;
+       
+       void* level0DirPtr = gSystem->OpenDirectory(level0Dir);
+       if (!level0DirPtr) {
+               AliError(Form("Can't open level0 directory <%s>!", 
+                       level0Dir.Data()));
+                return;
+       } 
+
+       const char* level1;
+       while ((level1 = gSystem->GetDirEntry(level0DirPtr))) {
+
+               TString level1Str(level1);
+               if (level1Str == "." || level1Str == "..") {
+                       continue;
+               }
+
+                if (queryId.GetAliCDBPath().Level1Comprises(level1)) {
+                       GetEntriesForLevel1(level0, level1, queryId, result);
+               }
+       }
 
+       gSystem->FreeDirectory(level0DirPtr);
 }
 
-/*****************************************************************************/ 
-TObjArray* AliCDBLocal::FindDBFiles(const char* name, Int_t runNumber){
-// Find DataBase file name in a local directory. The filename must be in the form: Run#run1-#run2_v#version.root
-// TRegexp allowed: name can be for example: "detector/*" !!
+//_____________________________________________________________________________
+void AliCDBLocal::GetEntriesForLevel1(const char* level0, const char* level1,
+       const AliCDBId& queryId, TList* result) {
+// multiple request (AliCDBStorage::GetAll)
+
+       TString level1Dir;
+       level1Dir += fBaseDirectory;
+       level1Dir += '/';
+       level1Dir += level0;
+       level1Dir += '/';
+       level1Dir += level1;
+
+       void* level1DirPtr = gSystem->OpenDirectory(level1Dir);
+       if (!level1DirPtr) {
+               AliError(Form("Can't open level1 directory <%s>!", 
+                       level1Dir.Data()));
+                return;
+       }
 
- TObjArray *FileNameColl=new TObjArray();
+       const char* level2;
+       while ((level2 = gSystem->GetDirEntry(level1DirPtr))) {
+
+               TString level2Str(level2);
+               if (level2Str == "." || level2Str == "..") {
+                       continue;
+               }
+
+               if (queryId.GetAliCDBPath().Level2Comprises(level2)) {
+                       
+                       AliCDBPath entryPath(level0, level1, level2);
+                       AliCDBId entryId(entryPath, queryId.GetAliCDBRunRange(),
+                               queryId.GetVersion(), queryId.GetSubVersion());
+
+                       AliCDBEntry* anEntry = GetEntry(entryId);
+                       if (anEntry) {
+                               result->Add(anEntry);
+                       }
+               }
+       }
 
- TString prefix="_v"; // development mode: fileName=Run#Run1-#Run2_v#Version.root
- if(fStorageMode==kProduction) prefix="_Prod"; // production mode: fileName=Run#Run1-#Run2_Prod#Version.root            
+       gSystem->FreeDirectory(level1DirPtr);
+}
 
- TString buffer(fDBFolder);
-// gSystem->ExpandPathName(buffer);
-  
- TString bufftInit=buffer; // buffInit="$ALICE_ROOT/DB/
- TString levelContent="";
- AliCDBMetaDataSelect selMetaData(name);
- TString detector(selMetaData.GetDetector());
- TString dbType(selMetaData.GetDBType());
- TString detSpecType(selMetaData.GetDetSpecType());
- int selVersion = selMetaData.GetVersion();
-
- void *dirLevInit = gSystem->OpenDirectory(buffer);
- while(levelContent=gSystem->GetDirEntry(dirLevInit)){ // lev0! In detector directory (ZDC, TPC...)!!
-
-   if(levelContent=="." || levelContent=="..") continue; if(levelContent=="") break;
-   if(!(detector=="*") && !levelContent.Contains(TRegexp(detector)) ) continue;
-
-   buffer=bufftInit+levelContent; buffer+='/'; // buffer="$ALICE_ROOT/DB/detector/
-   TString bufft0=buffer; // bufft0="$ALICE_ROOT/DB/detector/
-
-   void *dirLev0 = gSystem->OpenDirectory(buffer);
-   while(levelContent=gSystem->GetDirEntry(dirLev0)){ // lev1! dbType directory (Calib, Align)!!
-
-     if(levelContent=="." || levelContent=="..") continue; if(levelContent=="") break;
-     if(!(dbType=="*") && !levelContent.Contains(TRegexp(dbType))) continue; 
-
-     buffer=bufft0+levelContent;buffer+='/'; // buffer="$ALICE_ROOT/DB/detector/dbType/
-     TString bufft1=buffer; // bufft1="$ALICE_ROOT/DB/detector/dbType/
-
-     void *dirLev1 = gSystem->OpenDirectory(buffer);
-     while(levelContent=gSystem->GetDirEntry(dirLev1)){ // lev2! detSpecType directory (Pedestals, gain....)!!
-
-       if(levelContent=="." || levelContent=="..") continue; if(levelContent=="") break;
-       if(!(detSpecType=="*") && !levelContent.Contains(TRegexp(detSpecType))) continue; 
-
-       buffer=bufft1+levelContent;buffer+='/'; // buffer="$ALICE_ROOT/DB/detector/dbType/detSpecType/
-       TString bufft2=buffer; // bufft2="$ALICE_ROOT/DB/detector/dbType/detSpecType/
-
-       void *dirLev2 = gSystem->OpenDirectory(buffer);
-       TObjString *str=0;
-       while(levelContent=gSystem->GetDirEntry(dirLev2)){ // lev3! Run directory (Run#XXX-#YYY_v#ZZ.root)!!
-
-         if(levelContent=="." || levelContent=="..") continue; if(levelContent=="") break;
-         if(!levelContent.BeginsWith("Run")) continue;
-                if(!levelContent.Contains(prefix)) continue;
-                
-        int numbers[3]={-1,-1,-1}; // numbers[0]=firstRun, numbers[1]=lastRun, numbers[2]=Version 
-        if(!DecodeFileName(levelContent,numbers, prefix)) continue; // wrong run filename format!
-         if(numbers[0]>runNumber ||  numbers[1]<runNumber) continue; // data not valid for run number
-
-        if(numbers[2]==selVersion) {
-           buffer=bufft2+levelContent;
-           str=new TObjString(buffer.Data());
-            FileNameColl->Add(str);
-           break;
-        }
-        if(selVersion == -1) { // if version is not specified, collect all versions
-           buffer=bufft2+levelContent;
-           str=new TObjString(buffer.Data());
-            FileNameColl->Add(str);
-          }
-         } // end loop on runs       
-       } // end loop in lev1
-     } // end loop in lev0
-   } // end loop in levInit
-
- AliInfo(Form("Found %d entries matching requirements", FileNameColl->GetEntriesFast()));
- ToAliInfo(FileNameColl->ls());
- return FileNameColl;
+//_____________________________________________________________________________
+TList* AliCDBLocal::GetEntries(const AliCDBId& queryId) {
+// multiple request (AliCDBStorage::GetAll)
+
+       void* storageDirPtr = gSystem->OpenDirectory(fBaseDirectory);
+       if (!storageDirPtr) {
+               AliError(Form("Can't open storage directory <%s>",
+                       fBaseDirectory.Data()));
+               return NULL;
+       }       
+
+       TList* result = new TList();
+       result->SetOwner();
+
+       const char* level0;
+       while ((level0 = gSystem->GetDirEntry(storageDirPtr))) {
+               
+               TString level0Str(level0);
+               if (level0Str == "." || level0Str == "..") {
+                       continue;
+               }
+
+               if (queryId.GetAliCDBPath().Level0Comprises(level0)) {
+                       GetEntriesForLevel0(level0, queryId, result);   
+               }
+       }       
+       
+       gSystem->FreeDirectory(storageDirPtr);
+
+       return result;  
 }
 
 //_____________________________________________________________________________
-void AliCDBLocal::TagForProduction(const AliCDBMetaDataSelect& selMetaData, UInt_t prodVers){
-
-TString workingDir=gSystem->pwd();
-//Build the file path 
-TString buffer(fDBFolder); //gSystem->ExpandPathName() already done in ctor
-TString fName="";
-
-buffer+=selMetaData.GetName(); buffer+='/';
-//gSystem->ExpandPathName(dirName);
-
-if(!gSystem->cd(buffer))
-   {AliError(Form("Directory %s does not exist... check name!", buffer.Data())); gSystem->cd(workingDir.Data()); return;}
-
-// if version is not specified (=-1), then tag the highest version (BE CAREFUL!!)
-if(selMetaData.GetVersion() != -1){  
-  //Build the filename
-   fName = EncodeFileName(selMetaData.GetFirstRun(), selMetaData.GetLastRun(), selMetaData.GetVersion());
-} else {
-   //look in directory for valid DB files, seek highest version
-   void *dir = gSystem->OpenDirectory(buffer);
-   TString levelContent="";
-   int oldVers=-1;
-   while(levelContent=gSystem->GetDirEntry(dir)){ 
-
-      if(levelContent=="." || levelContent=="..") continue; if(levelContent=="") break;
-      if(!levelContent.Contains("Run") || !levelContent.Contains("_v")) continue;
-        
-      int numbers[3]={-1,-1,-1}; // numbers[0]=firstRun, numbers[1]=lastRun, numbers[2]=Version 
-      // gets the 3 "numbers" in the file name
-      if(!DecodeFileName(levelContent,numbers, "_v")) continue; // wrong run filename format!
-      if(numbers[0] != selMetaData.GetFirstRun() ||  numbers[1] != selMetaData.GetLastRun()) continue;
-      if(numbers[2] >= oldVers) {
-         fName=levelContent;
-         oldVers=numbers[2];
-      }   
-   } // end loop on runs    
+Bool_t AliCDBLocal::PutEntry(AliCDBEntry* entry) {
+// put an AliCDBEntry object into the database
+
+       AliCDBId& id = entry->GetId();
+
+       // set version and subVersion for the entry to be stored
+       if (!PrepareId(id)) return kFALSE;              
+
+       
+       // build filename from entry's id
+       TString filename;
+       if (!IdToFilename(id.GetAliCDBRunRange(), id.GetVersion(),
+               id.GetSubVersion(), filename)) {
+
+               AliError("Bad ID encountered! Subnormal error!");
+               return kFALSE;
+       }
+       
+       filename.Prepend(fBaseDirectory +'/' + id.GetPath() + '/');
+       
+       // open file
+       TFile file(filename, "CREATE");
+       if (!file.IsOpen()) {
+               AliError(Form("Can't open file <%s>!", filename.Data()));
+               return kFALSE;
+       }
+       
+       entry->SetVersion(id.GetVersion());
+       entry->SetSubVersion(id.GetSubVersion());
+       
+       // write object (key name: "AliCDBEntry")
+       Bool_t result = file.WriteTObject(entry, "AliCDBEntry");
+       if (!result) AliError(Form("Can't write entry to file: %s", filename.Data()));
+
+       file.Close();
+        if(result) AliInfo(Form("AliCDBEntry stored into file %s",filename.Data()));
+
+       return result;
 }
 
-   //check that the flename exists
-if(!gSystem->IsFileInIncludePath(fName.Data())){
-      AliError(Form("File name %s not found... check!", fName.Data())); 
-      gSystem->cd(workingDir.Data()); 
-      return;
+/////////////////////////////////////////////////////////////////////////////////////////////////
+//                                                                                             //
+// AliCDBLocal factory                                                                        //
+//                                                                                             //
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+ClassImp(AliCDBLocalFactory)
+
+//_____________________________________________________________________________
+Bool_t AliCDBLocalFactory::Validate(const char* dbString) {
+// check if the string is valid local URI
+
+        TRegexp dbPattern("^local://.+$");
+
+        return TString(dbString).Contains(dbPattern);
 }
 
-// file exists: make symbolic link! 
-TString prodfName=EncodeFileName(selMetaData.GetFirstRun(), selMetaData.GetLastRun(), prodVers, "_Prod");
-if(gSystem->Symlink(fName.Data(),prodfName.Data())<0){
-    AliError(Form("Link name already existing (%s): linkage failed!",prodfName.Data()));
-} else {
-    AliError(Form("File %s tagged for production with symlink %s",fName.Data(), prodfName.Data()));
+//_____________________________________________________________________________
+AliCDBParam* AliCDBLocalFactory::CreateParameter(const char* dbString) {
+// create AliCDBLocalParam class from the URI string
+
+       if (!Validate(dbString)) {
+               return NULL;
+       }
+
+       TString pathname(dbString + sizeof("local://") - 1);
+       
+       gSystem->ExpandPathName(pathname);
+
+       if (pathname[0] != '/') {
+               pathname.Prepend(TString(gSystem->WorkingDirectory()) + '/');
+       }
+
+       AliInfo(pathname);
+
+       return new AliCDBLocalParam(pathname);       
 }
 
-gSystem->cd(workingDir);
-return; 
+//_____________________________________________________________________________
+AliCDBStorage* AliCDBLocalFactory::Create(const AliCDBParam* param) {
+// create AliCDBLocal storage instance from parameters
+       
+       if (AliCDBLocalParam::Class() == param->IsA()) {
+               
+               const AliCDBLocalParam* localParam = 
+                       (const AliCDBLocalParam*) param;
+               
+               return new AliCDBLocal(localParam->GetPath());
+       }
 
+       return NULL;
 }
 
+/////////////////////////////////////////////////////////////////////////////////////////////////
+//                                                                                             //
+// AliCDBLocal Parameter class                                                                //                                          //
+//                                                                                             //
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+ClassImp(AliCDBLocalParam)
+
 //_____________________________________________________________________________
-Bool_t AliCDBLocal::DecodeFileName(const TString strName, int *numArray, TString prefix)
-{
-// Gets the numbers (#Run1, #Run2, #Version) 
-// from the filename: Run#Run1-#Run2_v#Version.root or  Run#Run1-#Run2_Prod#prodVers.root 
+AliCDBLocalParam::AliCDBLocalParam() {
+// default constructor
 
- int indexMinus=strName.Last('-');
- int indexUScore=strName.Last('_');
- int indexPoint=strName.Last('.');
- int nSkipChar=prefix.Length(); // prefix can be either "_v" or "_Prod" depending on fStorageMode 
- //if(prefix=="_v") {nSkipChar=2;} // development mode: _v# skip 2 characters
- //else if(prefix=="_Prod") {nSkipChar=5;} // production mode: _Prod# skip 5 characters
-
- if(indexUScore<0 || indexPoint<0 )
-    {AliDebug(2, Form("Check sintax %s",strName.Data())); return kFALSE;}
-
- if(indexMinus<0){ // only 1 Run number!
-   TString cRun=strName(3,indexUScore-3);
-   if(!(cRun.IsDigit()))
-      {AliDebug(2, Form("%s not a digit! Check sintax %s",cRun.Data(),strName.Data())); return kFALSE;}
-   numArray[0] = (int) strtol(cRun.Data(),0,10);
-   numArray[1] = numArray[0];
- }else{
-   TString cFirstRun = strName(3,indexMinus-3);         
-   TString cLastRun = strName(indexMinus+1,indexUScore-(indexMinus+1));         
-   if(!(cFirstRun.IsDigit()) || !(cLastRun.IsDigit()))
-      {AliDebug(2, Form("%s or %s are not digit! Check sintax %s",
-         cFirstRun.Data(), cLastRun.Data(), strName.Data())); return kFALSE;}
-   numArray[0] = (int) strtol(cFirstRun.Data(),0,10);
-   numArray[1] = (int) strtol(cLastRun.Data(),0,10);
- }
-// TString cVersion = strName(indexUScore+2,indexPoint-(indexUScore+2));
- TString cVersion = strName(indexUScore+nSkipChar,indexPoint-(indexUScore+nSkipChar));
- if(!(cVersion.IsDigit())){
-   AliDebug(2, Form("%s not a digit! Check sintax %s",cVersion.Data(),strName.Data())); return kFALSE;}
- numArray[2] = (int) strtol(cVersion.Data(),0,10);
-
- return kTRUE;
 }
 
+//_____________________________________________________________________________
+AliCDBLocalParam::AliCDBLocalParam(const char* dbPath):
+fDBPath(dbPath)
+{      
+// constructor
+
+       SetType("local");
+       SetURI(TString("local://") + dbPath);
+}
+
+//_____________________________________________________________________________
+AliCDBLocalParam::~AliCDBLocalParam() {
+// destructor
+
+}
 
 //_____________________________________________________________________________
-TString AliCDBLocal::EncodeFileName(int firstRun, int lastRun, int version, TString prefix){
-// Builds a file name of the form: Run#firstRun-#lastRun_v#Version.root
-
-TString fName="Run"; 
-if(firstRun==lastRun) {
-   fName+=firstRun;
-}else{
-   fName+=firstRun; fName+="-"; fName+=lastRun;
+AliCDBParam* AliCDBLocalParam::CloneParam() const {
+// clone parameter
+
+        return new AliCDBLocalParam(fDBPath);
 }
-fName+=prefix; fName+=version; fName+=".root";
 
-return fName;
+//_____________________________________________________________________________
+ULong_t AliCDBLocalParam::Hash() const {
+// return Hash function
+
+       return fDBPath.Hash();
 }
+
+//_____________________________________________________________________________
+Bool_t AliCDBLocalParam::IsEqual(const TObject* obj) const {
+// check if this object is equal to AliCDBParam obj
+
+        if (this == obj) {
+                return kTRUE;
+        }
+
+        if (AliCDBLocalParam::Class() != obj->IsA()) {
+                return kFALSE;
+        }
+
+        AliCDBLocalParam* other = (AliCDBLocalParam*) obj;
+
+        return fDBPath == other->fDBPath;
+}
+
index 26519f6..70745f0 100644 (file)
-#ifndef ALICDBLOCAL_H
-#define ALICDBLOCAL_H
+#ifndef ALI_CDB_LOCAL_H
+#define ALI_CDB_LOCAL_H
 
 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
  * See cxx source for full Copyright notice                               */
 
-/* $Id$ */
-
-///
-///  access class to a DB file inside an organized directory structure 
-///  file name = "DBFolder/detector/dbType/detSpecType/Run#firstRun-#lastRun _v#version.root"
-///
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBLocal                                             //
+//  access class to a DataBase in a local storage                  //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
 
 #include "AliCDBStorage.h"
-#include "AliCDBMetaDataSelect.h"
-#include "AliCDBMetaData.h"
-#include "AliCDBEntry.h"
+#include "AliCDBManager.h"
 
 class AliCDBLocal: public AliCDBStorage {
+       friend class AliCDBLocalFactory;
+
+public:
+
+       virtual Bool_t IsReadOnly() {return kFALSE;};
+       virtual Bool_t HasSubVersion() {return kTRUE;};
+
+protected:
+
+       virtual AliCDBEntry* GetEntry(const AliCDBId& queryId);
+        virtual TList* GetEntries(const AliCDBId& queryId);
+        virtual Bool_t PutEntry(AliCDBEntry* entry);
+
+private:
+
+       AliCDBLocal(const char* baseDir);
+       virtual ~AliCDBLocal();
+       
+       Bool_t FilenameToId(const char* filename, AliCDBRunRange& runRange, 
+                       Int_t& version, Int_t& subVersion);
+       Bool_t IdToFilename(const AliCDBRunRange& runRange, Int_t version, 
+                       Int_t subVersion, TString& filename);
+
+       Bool_t PrepareId(AliCDBId& id);
+       AliCDBId GetId(const AliCDBId& query);
+
+       void GetEntriesForLevel0(const char* level0, const AliCDBId& query, TList* result);
+       void GetEntriesForLevel1(const char* level0, const char* Level1,
+                       const AliCDBId& query, TList* result);
+
+       TString fBaseDirectory; // path of the DB folder
+
+       ClassDef(AliCDBLocal, 0); // access class to a DataBase in a local storage
+};
+
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBLocalFactory                                      //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
+
+class AliCDBLocalFactory: public AliCDBStorageFactory {
 
 public:
-//  AliCDBLocal();
-  AliCDBLocal(const char* DBFolder = "$(ALICE_ROOT)/DB");
-  virtual ~AliCDBLocal();
 
-  TObjArray*   FindDBFiles(const char *name, Int_t runNumber); // return list of files valid for run number
-  void        TagForProduction(const AliCDBMetaDataSelect& selMetaData, UInt_t prodVers); // tag a DB file for production mode
-  
+       virtual Bool_t Validate(const char* dbString);
+        virtual AliCDBParam* CreateParameter(const char* dbString);
+
 protected:
-  virtual AliCDBEntry* GetEntry(AliCDBMetaDataSelect& selMetaData, Int_t runNumber);
-  virtual Bool_t        PutEntry(AliCDBEntry* entry);
+        virtual AliCDBStorage* Create(const AliCDBParam* param);
+
+        ClassDef(AliCDBLocalFactory, 0);
+};
+
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBLocalParam                                        //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
+
+class AliCDBLocalParam: public AliCDBParam {
+       
+public:
+       AliCDBLocalParam();
+       AliCDBLocalParam(const char* dbPath);
+       
+       virtual ~AliCDBLocalParam();
+
+       const TString& GetPath() const {return fDBPath;};
+
+       virtual AliCDBParam* CloneParam() const;
+
+        virtual ULong_t Hash() const;
+        virtual Bool_t IsEqual(const TObject* obj) const;
 
 private:
-  AliCDBLocal(const AliCDBLocal& db);
-  AliCDBLocal& operator = (const AliCDBLocal& db);
-  
-  Bool_t     DecodeFileName(const TString strName, int *numArray, TString prefix="_v");        // Gets firstRun, lastRun, version from file name "strName"
-  TString    EncodeFileName(int firstRun, int lastRun, int version, TString prefix="_v"); // returns file name from firstRun, lastRun, version 
 
-  TString    fDBFolder;   // the DB folder
+       TString fDBPath; // path of the DB folder
 
-ClassDef(AliCDBLocal, 0)      // access class to a DB file in an organized directory structure (DBFolder/detector/dbType/detSpecType)
+       ClassDef(AliCDBLocalParam, 0);
 };
 
 #endif
diff --git a/STEER/AliCDBManager.cxx b/STEER/AliCDBManager.cxx
new file mode 100644 (file)
index 0000000..22802be
--- /dev/null
@@ -0,0 +1,301 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+#include "AliCDBManager.h"
+#include "AliCDBStorage.h"
+#include "AliLog.h"
+#include "AliCDBDump.h"
+#include "AliCDBLocal.h"
+#include "AliCDBGrid.h"
+
+#include <TObjString.h>
+#include <TSystem.h>
+
+ClassImp(AliCDBParam)
+
+ClassImp(AliCDBManager)
+
+AliCDBManager* AliCDBManager::fgInstance = 0x0;
+
+//_____________________________________________________________________________
+AliCDBManager* AliCDBManager::Instance() {
+// returns AliCDBManager instance (singleton)
+
+       if (!fgInstance) {
+               fgInstance = new AliCDBManager();
+               fgInstance->Init();
+       }
+
+       return fgInstance;
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::Init() {
+// factory registering
+
+       RegisterFactory(new AliCDBDumpFactory());
+       RegisterFactory(new AliCDBLocalFactory()); 
+       // AliCDBGridFactory is registered only if AliEn libraries are enabled in Root
+       if(!gSystem->Exec("root-config --has-alien |grep yes 2>&1 > /dev/null")){ // returns 0 if yes
+               AliInfo("AliEn classes enabled in Root. AliCDBGrid factory registered.");
+               RegisterFactory(new AliCDBGridFactory());
+       }
+}
+//_____________________________________________________________________________
+void AliCDBManager::Destroy() {
+// delete ALCDBManager instance and active storages
+
+       if (fgInstance) {
+               delete fgInstance;
+               fgInstance = 0x0;
+       }
+}
+
+//_____________________________________________________________________________
+AliCDBManager::AliCDBManager():
+       fDefaultStorage(NULL),
+       fDrainStorage(NULL)
+{
+// default constuctor
+       fFactories.SetOwner();
+}
+
+//_____________________________________________________________________________
+AliCDBManager::~AliCDBManager() {
+// destructor
+       DestroyActiveStorages();
+}
+
+//_____________________________________________________________________________
+AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) {
+// get a storage object from the list of active storages 
+
+        return (AliCDBStorage*) fActiveStorages.GetValue(param);
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){
+// put a storage object into the list of active storages
+
+       fActiveStorages.Add(param, storage);
+       AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries()));
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) {
+// add a storage factory to the list of registerd factories
+       if (!fFactories.Contains(factory)) {
+               fFactories.Add(factory);
+       }
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBManager::HasStorage(const char* dbString) {
+// check if dbString is a URI valid for one of the registered factories 
+
+       TIter iter(&fFactories);
+
+       AliCDBStorageFactory* factory;
+       while ((factory = (AliCDBStorageFactory*) iter.Next())) {
+
+               if (factory->Validate(dbString)) {
+                       return kTRUE;
+               }       
+       }
+
+       return kFALSE;
+}
+
+//_____________________________________________________________________________
+AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) {
+// create AliCDBParam object from URI string
+
+       TIter iter(&fFactories);
+
+        AliCDBStorageFactory* factory;
+        while ((factory = (AliCDBStorageFactory*) iter.Next())) {
+
+               AliCDBParam* param = factory->CreateParameter(dbString);
+               if (param) {
+                       return param;
+               }
+        }
+
+        return NULL;
+}
+
+//_____________________________________________________________________________
+AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) {
+// get storage object from URI string
+       
+       AliCDBParam* param = CreateParameter(dbString);
+       if (!param) {
+               return NULL;
+       }       
+
+       AliCDBStorage* aStorage = GetStorage(param);
+
+       delete param;
+       
+       return aStorage;
+}
+
+//_____________________________________________________________________________
+AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) {
+// get storage object from AliCDBParam object
+
+       // if the list of active storages already contains 
+       // the requested storage, return it
+       AliCDBStorage* aStorage = GetActiveStorage(param);
+       if (aStorage) {
+               return aStorage;
+       }
+
+       TIter iter(&fFactories);
+
+        AliCDBStorageFactory* factory;
+        
+       // loop on the list of registered factories
+       while ((factory = (AliCDBStorageFactory*) iter.Next())) {
+
+               // each factory tries to create its storage from the parameter
+               aStorage = factory->Create(param);
+               if (aStorage) {
+                       PutActiveStorage(param->CloneParam(), aStorage);
+                       // if default storage is not set, set to this storage
+                       if(!fDefaultStorage){
+                               fDefaultStorage=aStorage;
+                               AliInfo(Form("Default storage set to: %s",(param->GetURI()).Data()));
+                       }
+                       return aStorage;
+               }
+        }
+
+        return NULL;
+}
+
+//_____________________________________________________________________________
+TList* AliCDBManager::GetActiveStorages() {
+// return list of active storages
+
+       TList* result = new TList();
+
+       TIter iter(fActiveStorages.GetTable()); 
+       TPair* aPair;
+       while ((aPair = (TPair*) iter.Next())) {
+               result->Add(aPair->Value());
+       }
+
+       return result;
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::SetDrain(const char* dbString) {
+// set drain storage from URI string
+
+       fDrainStorage = GetStorage(dbString);   
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::SetDrain(const AliCDBParam* param) {
+// set drain storage from AliCDBParam
+       
+       fDrainStorage = GetStorage(param);
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::SetDrain(AliCDBStorage* storage) {
+// set drain storage from another active storage
+       
+       fDrainStorage = storage;
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
+// drain retrieved object to drain storage
+
+       AliInfo("Draining into drain storage...");
+       return fDrainStorage->Put(entry);
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::RemoveDrain() {
+// remove drain storage
+
+       fDrainStorage=0;
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::SetDefaultStorage(const char* dbString) {
+// sets default storage from URI string
+
+       if(fDefaultStorage) fDefaultStorage = 0;
+       fDefaultStorage = GetStorage(dbString); 
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
+// set default storage from AliCDBParam object
+       
+       if(fDefaultStorage) fDefaultStorage = 0;
+       fDrainStorage = GetStorage(param);
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
+// set default storage from another active storage
+       
+       if(fDefaultStorage) fDefaultStorage = 0;
+       fDefaultStorage = storage;
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::RemoveDefaultStorage() {
+// remove default storage
+
+       fDefaultStorage = 0;
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::DestroyActiveStorages() {
+// delete list of active storages
+
+       fActiveStorages.DeleteAll();
+}
+
+//_____________________________________________________________________________
+void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
+// destroys active storage (not implemented)
+
+}
+
+///////////////////////////////////////////////////////////
+// AliCDBManager Parameter class                         //
+// interface to specific AliCDBParameter class           //
+// (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam)  //
+///////////////////////////////////////////////////////////
+
+AliCDBParam::AliCDBParam() {
+// constructor
+
+}
+
+//_____________________________________________________________________________
+AliCDBParam::~AliCDBParam() {
+// destructor
+
+}
+
diff --git a/STEER/AliCDBManager.h b/STEER/AliCDBManager.h
new file mode 100644 (file)
index 0000000..da21b03
--- /dev/null
@@ -0,0 +1,136 @@
+#ifndef ALI_CDB_MANAGER_H
+#define ALI_CDB_MANAGER_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBManager                                            //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
+
+#include <TObject.h>
+#include <TList.h>
+#include <TMap.h>
+
+#include "AliCDBEntry.h"
+
+class AliCDBStorage;
+class AliCDBStorageFactory;
+class AliCDBParam;
+
+class AliCDBManager: public TObject {
+
+ public:
+
+       void RegisterFactory(AliCDBStorageFactory* factory);
+
+       Bool_t HasStorage(const char* dbString);
+
+       AliCDBParam* CreateParameter(const char* dbString);
+
+       AliCDBStorage* GetStorage(const char* dbString);
+       AliCDBStorage* GetStorage(const AliCDBParam* param);
+       
+       TList* GetActiveStorages();
+
+       void SetDefaultStorage(const char* dbString);
+       void SetDefaultStorage(const AliCDBParam* param);
+       void SetDefaultStorage(AliCDBStorage *storage);
+
+       Bool_t IsDefaultStorageSet() {return fDefaultStorage != 0;}
+       
+       AliCDBStorage* GetDefaultStorage() {return fDefaultStorage;}
+
+       void RemoveDefaultStorage();
+
+       void SetDrain(const char* dbString);
+       void SetDrain(const AliCDBParam* param);
+       void SetDrain(AliCDBStorage *storage);
+
+       Bool_t IsDrainSet() {return fDrainStorage != 0;}
+
+       Bool_t Drain(AliCDBEntry* entry);
+
+       void RemoveDrain();
+
+       void DestroyActiveStorages();
+       void DestroyActiveStorage(AliCDBStorage* storage);
+       
+       static void Destroy();
+       ~AliCDBManager();
+
+       static AliCDBManager* Instance();
+
+ private:
+               
+       AliCDBManager();
+       static AliCDBManager* fgInstance;
+       
+       AliCDBStorage* GetActiveStorage(const AliCDBParam* param);
+       void PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage);
+
+       void Init();
+       
+       TList fFactories;               // list of registered storage factories
+       TMap fActiveStorages;           // list of active storages
+       AliCDBStorage *fDefaultStorage; // pointer to default storage
+       AliCDBStorage *fDrainStorage;   // pointer to drain storage
+
+       ClassDef(AliCDBManager, 0);
+};
+
+
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBStorageFactory                                     //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
+
+class AliCDBParam;
+class AliCDBStorageFactory: public TObject {
+       friend class AliCDBManager;
+       
+public:
+       virtual Bool_t Validate(const char* dbString) = 0;
+       virtual AliCDBParam* CreateParameter(const char* dbString) = 0; 
+
+protected:
+       virtual AliCDBStorage* Create(const AliCDBParam* param) = 0;
+
+       ClassDef(AliCDBStorageFactory, 0);
+};
+
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBParam                                              //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
+
+class AliCDBParam: public TObject {
+
+public:
+
+       AliCDBParam();
+       virtual ~AliCDBParam();
+
+       const TString& GetType() const {return fType;};
+       const TString& GetURI() const {return fURI;};
+
+       virtual AliCDBParam* CloneParam() const = 0;
+
+protected:
+
+       void SetType(const char* type) {fType = type;};
+       void SetURI(const char* uri) {fURI = uri;};
+
+private:
+
+       TString fType;
+       TString fURI;
+
+       ClassDef(AliCDBParam, 0);
+};
+
+#endif
index 998db56..a700441 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/* $Id$ */
-
-///////////////////////////////////////////////////////////////////////////////
-//                                                                           //
-// Object meta data: full description of a run dependent database object     // 
-//                                                                           //
-///////////////////////////////////////////////////////////////////////////////
-
-
-#include <TRegexp.h>
-#include <TObjArray.h>
-#include <TObjString.h>
-#include <TSystem.h>
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBMetaData                                          //
+//  Set of data describing the object                                     //
+//  but not used to identify the object                           //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
 
 #include "AliCDBMetaData.h"
 #include "AliLog.h"
 
+#include <TObjString.h>
 
 ClassImp(AliCDBMetaData)
 
-
 //_____________________________________________________________________________
-AliCDBMetaData::AliCDBMetaData() :
-  TObject(),
-  fName(""),
-  fFirstRun(-1),
-  fLastRun(-1),
-  fVersion(-1),
-  fPeriod(-1),
-  fFormat(""),
-  fResponsible("Duck, Donald"),
-  fExtraInfo("")
-{
+AliCDBMetaData::AliCDBMetaData() {
 // default constructor
-// the default values mean no selection
-  DecodeName();
-}
 
-//_____________________________________________________________________________
-AliCDBMetaData::AliCDBMetaData
-         (const char* name, Int_t firstRun, Int_t lastRun, Int_t period, 
-         const char* objFormat, const char* responsible, 
-         const char* extraInfo):
-  TObject(),
-  fName(name),
-  fFirstRun(firstRun),
-  fLastRun(lastRun),
-  fVersion(-1),
-  fPeriod(period),
-  fFormat(objFormat),
-  fResponsible(responsible),
-  fExtraInfo(extraInfo)
-{
-// constructor
-  DecodeName();
+       fProperties.SetOwner(1);
 }
 
 //_____________________________________________________________________________
-AliCDBMetaData::AliCDBMetaData(const AliCDBMetaData& entry) :
-  TObject(entry),
-  fName(entry.fName),
-  fFirstRun(entry.fFirstRun),
-  fLastRun(entry.fLastRun),
-  fVersion(entry.fVersion),
-  fPeriod(entry.fPeriod),
-  fFormat(entry.fFormat),
-  fResponsible(entry.fResponsible),
-  fExtraInfo(entry.fExtraInfo)
-{
-// copy constructor
-  DecodeName();
-}
+AliCDBMetaData::~AliCDBMetaData() {
+// destructor
 
-//_____________________________________________________________________________
-AliCDBMetaData& AliCDBMetaData::operator = (const AliCDBMetaData& entry)
-{
-// assignment operator
-  fName = entry.fName;
-  fFirstRun = entry.fFirstRun;
-  fLastRun = entry.fLastRun;
-  fVersion = entry.fVersion;
-  fPeriod=entry.fPeriod;
-  fFormat=entry.fFormat;
-  fResponsible=entry.fResponsible;
-  fExtraInfo=entry.fExtraInfo;
-  DecodeName();
-  return *this;
 }
 
 //_____________________________________________________________________________
-void AliCDBMetaData::EncodeName(){
-// Encode name from single elements ("Detector", "DBType", "DetSpecType" -> "Detector/DBType/DetSpecType")   
-   fName = fDetector+'/'+fDBType+'/'+fDetSpecType;
-   if(fDBType == "*" && fDetSpecType == "*") fName = fDetector+'/'+'*';
-   if(fDetector == "*" && fDBType == "*" && fDetSpecType == "*") fName = "*";
+void AliCDBMetaData::SetProperty(const char* property, TObject* object) {
+// add something to the list of properties
 
+       fProperties.Add(new TObjString(property), object);
 }
 
 //_____________________________________________________________________________
-void AliCDBMetaData::DecodeName(){
-// Decode name into single elements ("Detector/DBType/DetSpecType" -> "Detector", "DBType", "DetSpecType")   
-
- if(fName==""){fDetector=""; fDBType=""; fDetSpecType=""; return;}
-
- while(fName.EndsWith("/")) fName.Remove(fName.Last('/'));
- while(fName.BeginsWith("/")) fName.Remove(fName.First('/'),1);
- // fName= "fDetector/fDBType/fDetSpecType
- int nslashes=fName.CountChar('/');
- if(nslashes>2){AliError("Wrong format!\n");fDetector=""; fDBType=""; fDetSpecType="";}
-
- if(nslashes == 0){
-   if(fName == "*"){fDetector="*"; fDBType="*"; fDetSpecType="*";}
-   else{AliError("Wrong format!\n"); fDetector=""; fDBType=""; fDetSpecType="";}
- }
- if(nslashes == 1){
-   if(fName.EndsWith("*"))
-     {fDetector=fName(0, fName.Index('/')); fDBType="*"; fDetSpecType="*";}
-   else {AliError("Wrong format!\n"); fDetector=""; fDBType=""; fDetSpecType="";}
- }
-
- if(nslashes == 2){
-   int firstsl=fName.First('/'), lastsl=fName.Last('/'), lgth=fName.Length();
-   fDetector=fName(0, firstsl); 
-   fDBType=fName(firstsl+1, lastsl-(firstsl+1));
-   fDetSpecType=fName(lastsl+1, lgth-(lastsl+1)); 
- }
- EncodeName();
-}
+TObject* AliCDBMetaData::GetProperty(const char* property) const {
+// get a property specified by its name (property)
 
-//_____________________________________________________________________________
-Bool_t AliCDBMetaData::IsStrictlyValid(Int_t runNumber, AliCDBMetaData* metaData) const
-{
-// check if the object is valid for runNumber. TRUE if metaData version is equal to this's version 
-
-  if ((fFirstRun >= 0) && (runNumber < fFirstRun)) return kFALSE;
-  if ((fLastRun >= 0) && (runNumber > fLastRun)) return kFALSE;
-  if (metaData) {
-    if ((metaData->fVersion >= 0) && (metaData->fVersion != fVersion)) 
-      return kFALSE;
-  }
-  return kTRUE;
-}
-
-//_____________________________________________________________________________
-Bool_t AliCDBMetaData::IsValid(Int_t runNumber, AliCDBMetaData* metaData) const
-{
-// check if the object is valid for runNumber. TRUE if metaData version less or equal wrt to this's
-
-  if ((fFirstRun >= 0) && (runNumber < fFirstRun)) return kFALSE;
-  if ((fLastRun >= 0) && (runNumber > fLastRun)) return kFALSE;
-  if (metaData) {
-    if ((metaData->fVersion >= 0) && (metaData->fVersion < fVersion)) 
-      return kFALSE;
-  }
-  return kTRUE;
-}
-
-//_____________________________________________________________________________
-Int_t AliCDBMetaData::Compare(const TObject* object) const
-{
-// check whether this is preferred to object
-
-  if (!object || !object->InheritsFrom(AliCDBMetaData::Class())) return 1;
-  if (fVersion < ((AliCDBMetaData*)object)->GetVersion()) return -1;
-  if (fVersion > ((AliCDBMetaData*)object)->GetVersion()) return 1;
-  return 0;
+       return fProperties.GetValue(property);
 }
 
 //_____________________________________________________________________________
-Bool_t AliCDBMetaData::Matches(const char* name, Int_t runNumber) const
-{
-// check whether name and run number match with this meta data
-
-  if ((fFirstRun >= 0) && (runNumber < fFirstRun)) return kFALSE;
-  if ((fLastRun >= 0) && (runNumber > fLastRun)) return kFALSE;
-  if (!TString(name).Contains(TRegexp(fName))) return kFALSE;
-  return kTRUE;
+Bool_t AliCDBMetaData::RemoveProperty(const char* property) {
+// removes a property
+
+       TObjString objStrProperty(property);
+       TObjString* aKey = (TObjString*) fProperties.Remove(&objStrProperty);   
+
+       if (aKey) {
+               delete aKey;
+               return kTRUE;
+       } else {
+               return kFALSE;
+       }
 }
 
-
 //_____________________________________________________________________________
-Bool_t operator == (const AliCDBMetaData& entry1, const AliCDBMetaData& entry2)
-{
-// compare two DB entries
-
-  if (strcmp(entry1.GetName(), entry2.GetName()) != 0) return kFALSE;
-  if (entry1.GetFirstRun() != entry2.GetFirstRun()) return kFALSE;
-  if (entry1.GetLastRun() != entry2.GetLastRun()) return kFALSE;
-  if (entry1.GetVersion() != entry2.GetVersion()) return kFALSE;
-  return kTRUE;
+void AliCDBMetaData::PrintMetaData() {
+// print the object's metaData
+
+       AliInfo("**** Object's MetaData set ****");
+       AliInfo(Form("  Object's class name:    %s", fObjectClassName.Data()));
+       AliInfo(Form("  Responsible:            %s", fResponsible.Data()));
+       AliInfo(Form("  Beam period:            %d", fBeamPeriod));
+       AliInfo(Form("  AliRoot version:        %s", fAliRootVersion.Data()));
+       AliInfo(Form("  Comment:                %s", fComment.Data()));
+       AliInfo("  Properties key names:");
+
+       TIter iter(fProperties.GetTable());     
+       TPair* aPair;
+       while ((aPair = (TPair*) iter.Next())) {
+               AliInfo(Form("                  %s",((TObjString* )aPair->Key())->String().Data()));
+       }
+       
 }
-
-
index caf2e24..264bb02 100644 (file)
@@ -1,86 +1,69 @@
-#ifndef ALICDBMETADATA_H
-#define ALICDBMETADATA_H
+#ifndef ALI_META_DATA_H
+#define ALI_META_DATA_H
+
 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
  * See cxx source for full Copyright notice                               */
 
-/* $Id$ */
-
-///
-///  CDB meta data: it fully describes a run dependent database object. 
-///  It is attached to the object to build an AliCDBEntry object
-/// 
-///
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBMetaData                                          //
+//  Set of data describing the object                                     //
+//  but not used to identify the object                           //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
 
 #include <TObject.h>
-#include <TString.h>
+#include <TMap.h>
 
 class AliCDBMetaData: public TObject {
+       
 public:
-  AliCDBMetaData();    // default constructor
-  AliCDBMetaData
-         (const char* name, Int_t firstRun = -1, Int_t lastRun = -1, Int_t period=-1, 
-         const char* objFormat="", const char* responsible="Duck, Donald", 
-         const char* extraInfo="");    // constructor
+       AliCDBMetaData();
+       virtual ~AliCDBMetaData();
 
-  virtual ~AliCDBMetaData() {};        // destructor
+       void            SetObjectClassName(const char* name) 
+                               {fObjectClassName = name;};
+       const char*     GetObjectClassName() const 
+                               {return fObjectClassName.Data();};
+       
+        void           SetResponsible(const char* yourName) 
+                               {fResponsible = yourName;};
+       const char*     GetResponsible() const 
+                               {return fResponsible.Data();};
 
-  AliCDBMetaData(const AliCDBMetaData& entry); // copy contructor      
-  AliCDBMetaData& operator = (const AliCDBMetaData& entry);    // assignment  operator
+       void            SetBeamPeriod(UInt_t period) 
+                               {fBeamPeriod = period;};
+       UInt_t          GetBeamPeriod() const 
+                               {return fBeamPeriod;};
 
+       void            SetAliRootVersion(const char* version)
+                               {fAliRootVersion = version;};
+       const char*     GetAliRootVersion() const 
+                               {return fAliRootVersion.Data();};
 
-  void         SetName(const char* name) {fName = name; DecodeName();} // object's name ("Detector/DBType/DetSpecType")
-  void                 SetDetector(const char* Detector) {fDetector = Detector; EncodeName();} // set the detector's name (ZDC,ITS ...)
-  void                 SetDBType(const char* DBType) {fDBType = DBType; EncodeName();} // set the database type (Calib, Align ...)
-  void                 SetDetSpecType(const char* DetSpecType) {fDetSpecType = DetSpecType; EncodeName();} // set the detector's specific type name (Pedestals, GainConst, DeadChannelMaps...)
-  void                 SetRunRange(Int_t firstRun = -1, Int_t lastRun = 1) 
-                       {fFirstRun = firstRun; fLastRun = lastRun;} // set the run validity range
-  void                 SetVersion(Int_t version = -1) {fVersion = version;} // object's version (automatically set during storage!)
-  void                 SetPeriod(Int_t period) {fPeriod = period;}     // set number of beam period
-  void                 SetFormat(const char* objFormat) {fFormat = objFormat;} // set infos about object's format (array o floats, histos...)
-  void                 SetResponsible(const char* responsible) {fResponsible = responsible;}   // who made the object?
-  void                 SetExtraInfo(const char* extraInfo) {fExtraInfo = extraInfo;}   // something else you would like to know
-  
+       void            SetComment(const char* comment) 
+                               {fComment = comment;};
+       const char*     GetComment() const 
+                               {return fComment.Data();};
 
-  const char*  GetName() const {return fName.Data();} // get the name 
-  const char*  GetDetector() const {return fDetector.Data();} // get the detector's name 
-  const char*  GetDBType() const {return fDBType.Data();} // get the database type 
-  const char*  GetDetSpecType() const {return fDetSpecType.Data();} // get the detector's specific type name 
-  
-  const Int_t  GetFirstRun() const {return fFirstRun;} // get the first valid run
-  const Int_t  GetLastRun() const {return fLastRun;} // get the last valid run
-  const Int_t  GetVersion() const {return fVersion;} // get the version
-  const Int_t  GetPeriod() const {return fPeriod;} // get the beam period
-  const char*  GetFormat() const {return fFormat.Data();} // get the object's format
-  const char*  GetResponsible() const  {return fResponsible.Data();} // get the responsible's name
-  const char*  GetExtraInfo() const {return fExtraInfo.Data();} // get the object's extra info
-  
-  Bool_t       IsValid(Int_t runNumber,     
-                       AliCDBMetaData* metaData = NULL) const; 
-  Bool_t       IsStrictlyValid(Int_t runNumber, 
-                       AliCDBMetaData* metaData = NULL) const;
-  Int_t                Compare(const TObject* object) const;
-  Bool_t       Matches(const char* name, Int_t runNumber) const;
+       void            SetProperty(const char* property, TObject* object);
+       TObject*        GetProperty(const char* property) const;
+       Bool_t          RemoveProperty(const char* property);
+       
+       void PrintMetaData();
+       
+private:
 
-protected:
-  TString      fName;           // name of the entry
-  TString      fDetector;       // name of the detector (ZDC, TPC, etc...)
-  TString      fDBType;         // name of the database type (Calib, Align)
-  TString      fDetSpecType;    // name of the detector's specific data type (pedestals, gain coeffs...)
-  Int_t        fFirstRun;       // index of first valid run
-  Int_t        fLastRun;        // index of last valid run
-  Int_t        fVersion;        // version of the entry
-  Int_t        fPeriod;         // beam period 
-  TString      fFormat;         // object's format
-  TString      fResponsible;    // name of the person responsible for the object
-  TString      fExtraInfo;      // extra info about the object
-  
-  void                 EncodeName();
-  void                 DecodeName();
+       TString fObjectClassName;       // object's class name
+       TString fResponsible;           // object's responsible person
+       UInt_t fBeamPeriod;             // beam period
+       TString fAliRootVersion;        // AliRoot version
+       TString fComment;               // extra comments
+       //TList fCalibRuns;             
+       
+       TMap fProperties;               // list of object specific properties
 
-ClassDef(AliCDBMetaData, 1)   // CDB meta data: full description of a run dependent database object
+       ClassDef(AliCDBMetaData, 1);
 };
 
-extern Bool_t operator == (const AliCDBMetaData& entry1, 
-                          const AliCDBMetaData& entry2);
-
 #endif
diff --git a/STEER/AliCDBPath.cxx b/STEER/AliCDBPath.cxx
new file mode 100644 (file)
index 0000000..82cce36
--- /dev/null
@@ -0,0 +1,226 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBPath                                              //
+//  Path string identifying the object:                           //
+//  "level0/level1/level2"                                        //
+//  (was: "Detector/DBType/DetSpecType")                          //
+//  (example: "ZDC/Calib/Pedestals")                              //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
+
+#include "AliCDBPath.h"
+
+#include <TObjArray.h>
+#include <TObjString.h>
+#include <TRegexp.h>
+
+#include "AliLog.h"
+
+ClassImp(AliCDBPath)
+
+//_____________________________________________________________________________
+AliCDBPath::AliCDBPath() {
+// default constructor
+
+}
+
+//_____________________________________________________________________________
+AliCDBPath::AliCDBPath(const AliCDBPath& other):
+TObject(),
+fPath(other.fPath)
+{
+// constructor
+       Init();
+       InitPath();
+
+}
+
+//_____________________________________________________________________________
+AliCDBPath::AliCDBPath(const char* level0, const char* level1,
+       const char* level2):
+fLevel0(level0), 
+fLevel1(level1), 
+fLevel2(level2)
+{
+// constructor
+
+       fPath += level0;
+       fPath += '/';
+       fPath += level1;
+       fPath += '/';
+       fPath += level2;
+
+       if ((IsWord(fLevel0) || fLevel0 == "*")
+               && (IsWord(fLevel1) || fLevel1 == "*")
+               && (IsWord(fLevel2) || fLevel2 == "*")) {
+
+               fIsValid = kTRUE;
+       } else {
+               fIsValid = kFALSE;
+               AliError(Form("Invalid AliCDBPath <%s/%s/%s>!", 
+                       level0, level1, level2));
+       }
+
+       Init();
+}
+
+//_____________________________________________________________________________
+AliCDBPath::AliCDBPath(const char* path):
+fPath(path)
+{
+// constructor
+
+       Init();
+       InitPath();     
+}
+
+//_____________________________________________________________________________
+AliCDBPath::AliCDBPath(const TString& path):
+fPath(path)
+{
+       Init();
+       InitPath();
+}
+
+//_____________________________________________________________________________
+void AliCDBPath::InitPath() {
+// sets fLevel0, fLevel1, fLevel2, validity flagss from fPath
+
+       TSubString strippedString = fPath.Strip(TString::kBoth);
+       TString aString(strippedString);
+       strippedString = aString.Strip(TString::kBoth, '/');
+
+       TObjArray* anArray = TString(strippedString).Tokenize("/");     
+       Int_t paramCount = anArray->GetEntriesFast();
+       
+       if (paramCount == 1) {
+               if (fPath == "*") {
+                       fLevel0 = "*";
+                       fLevel1 = "*";
+                       fLevel2 = "*";
+                       
+                       fIsValid = kTRUE;
+               } else {
+                       fIsValid = kFALSE;
+               }
+
+       } else if (paramCount == 2) {
+               fLevel0 = ((TObjString*) anArray->At(0))->GetString();
+               TString aString =  ((TObjString*) anArray->At(1))->GetString();
+
+               if (IsWord(fLevel0) && aString == "*") {
+                       fLevel1 = "*";
+                       fLevel2 = "*";
+               
+                       fIsValid = kTRUE;                       
+
+               } else {
+                       fIsValid = kFALSE;
+               }
+               
+       } else if (paramCount == 3) {
+               fLevel0 = ((TObjString*) anArray->At(0))->GetString();
+                fLevel1 = ((TObjString*) anArray->At(1))->GetString();
+                fLevel2 = ((TObjString*) anArray->At(2))->GetString();
+
+               if ((IsWord(fLevel0) || fLevel0 == "*")
+                       && (IsWord(fLevel1) || fLevel1 == "*")
+                       && (IsWord(fLevel2) || fLevel2 == "*")) {
+                       
+                       fIsValid = kTRUE;
+               } else {
+                       fIsValid = kFALSE;
+               }
+
+       } else {
+               fIsValid = kFALSE;
+
+       }
+       
+       if (!fIsValid) {
+               AliInfo(Form("Invalid AliCDBPath <%s>!", fPath.Data()));
+       }
+       
+       delete anArray;
+
+       Init();
+}
+
+//_____________________________________________________________________________
+AliCDBPath::~AliCDBPath() {
+// destructor
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBPath::IsWord(const TString& str) {
+// check if string is a word
+
+       TRegexp pattern("^[a-zA-Z0-9_]+$");
+
+       return str.Contains(pattern);   
+}
+
+//_____________________________________________________________________________
+void AliCDBPath::Init() {
+// set fIsWildcard flag
+
+       fIsWildcard = fPath.MaybeWildcard();    
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBPath::Level0Comprises(const TString& str) const {
+// check if Level0 is wildcard or is equal to str
+       
+       if (fLevel0 == "*") {
+               return kTRUE;
+       }
+
+       return fLevel0 == str;
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBPath::Level1Comprises(const TString& str) const {
+// check if Level1 is wildcard or is equal to str
+
+       if (fLevel1 == "*") {
+               return kTRUE;
+       }
+
+       return fLevel1 == str;
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBPath::Level2Comprises(const TString& str) const {
+// check if Level2 is wildcard or is equal to str
+       
+       if (fLevel2 == "*") {
+               return kTRUE;
+       }
+
+       return fLevel2 == str;
+}
+
+//_____________________________________________________________________________
+Bool_t AliCDBPath::Comprises(const AliCDBPath& other) const {
+// check if path is wildcard and comprises other
+
+       return Level0Comprises(other.fLevel0) 
+               && Level1Comprises(other.fLevel1)
+               && Level2Comprises(other.fLevel2);
+}
diff --git a/STEER/AliCDBPath.h b/STEER/AliCDBPath.h
new file mode 100644 (file)
index 0000000..5ca8d32
--- /dev/null
@@ -0,0 +1,74 @@
+#ifndef ALI_CDB_PATH_H
+#define ALI_CDB_PATH_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBPath                                              //
+//  Path string identifying the object:                           //
+//  "level0/level1/level2"                                        //
+//  (was: "Detector/DBType/DetSpecType")                          //
+//  (example: "ZDC/Calib/Pedestals")                              //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
+
+#include <TObject.h>
+#include <TString.h>
+
+class AliCDBPath: public TObject {
+
+public:
+       
+       AliCDBPath();
+
+       AliCDBPath(const AliCDBPath& other);
+
+       AliCDBPath(const char* level0, const char* level1, 
+                       const char* level2);
+
+       AliCDBPath(const char* path);
+
+       AliCDBPath(const TString& path);
+
+       virtual ~AliCDBPath();
+
+
+       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;};
+
+       Bool_t IsValid() const {return fIsValid;};
+
+       Bool_t IsWildcard() const {return fIsWildcard;};
+
+       Bool_t Level0Comprises(const TString& str) const;
+       Bool_t Level1Comprises(const TString& str) const;
+       Bool_t Level2Comprises(const TString& str) const;
+
+       Bool_t Comprises(const AliCDBPath& other) const;
+
+private:
+
+       Bool_t IsWord(const TString& str);
+
+       void InitPath();
+
+       void Init();
+
+       TString fPath;          // detector pathname (Detector/DBType/SpecType)
+       TString fLevel0;        // level0 name (ex. detector: ZDC, TPC...)
+       TString fLevel1;        // level1 name (ex. DB type, Calib, Align)
+       TString fLevel2;        // level2 name (ex. DetSpecType, pedestals, gain...)
+
+       Bool_t fIsValid;        // validity flag
+       Bool_t fIsWildcard;     // wildcard flag
+       
+       ClassDef(AliCDBPath, 1); 
+};
+
+#endif
diff --git a/STEER/AliCDBRunRange.cxx b/STEER/AliCDBRunRange.cxx
new file mode 100644 (file)
index 0000000..404f087
--- /dev/null
@@ -0,0 +1,123 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBRunRange                                          //
+//  defines the run validity range of the object:                 //
+//  [fFirstRun, fLastRun]                                         //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
+
+#include "AliCDBRunRange.h"
+
+#include "AliLog.h"
+
+ClassImp(AliCDBRunRange)
+
+//___________________________________________________________________________
+AliCDBRunRange::AliCDBRunRange():
+fFirstRun(-1), 
+fLastRun(-1)
+{
+// constructor
+
+}
+
+//___________________________________________________________________________
+AliCDBRunRange::AliCDBRunRange(Int_t firstRun, Int_t lastRun):
+fFirstRun(firstRun), 
+fLastRun(lastRun)
+{
+// constructor
+
+}
+
+//___________________________________________________________________________
+AliCDBRunRange::~AliCDBRunRange() {
+// destructor
+
+}
+
+//___________________________________________________________________________
+Bool_t AliCDBRunRange::Overlaps(const AliCDBRunRange& other) const {
+// check if this runRange overlaps other runRange
+       
+       if (!(IsValid() && other.IsValid())) {
+               AliError("Comparing invalid run ranges!");
+               return kFALSE;
+       }       
+       
+       if (IsAnyRange() || other.IsAnyRange()) {
+               AliError("Comparing unspecified ranges!");
+               return kFALSE;
+       }
+       
+       return (fFirstRun <= other.fFirstRun && other.fFirstRun <= fLastRun
+                       || fFirstRun <= other.fLastRun 
+                               && other.fLastRun <= fLastRun)
+               || (other.fFirstRun <= fFirstRun && fFirstRun <= other.fLastRun
+                       || other.fFirstRun <= fLastRun 
+                               && fLastRun <= other.fLastRun);
+}
+
+//___________________________________________________________________________
+Bool_t AliCDBRunRange::Comprises(const AliCDBRunRange& other) const {
+// check if this runRange contains other runRange
+
+       if (!(IsValid() && other.IsValid())) {
+               AliError("Comparing invalid run ranges!");
+               return kFALSE;
+       }       
+       
+       if (IsAnyRange()) {
+               return kTRUE;
+       }
+
+       return fFirstRun <= other.fFirstRun && other.fFirstRun <= fLastRun
+               && fFirstRun <= other.fLastRun && other.fLastRun <= fLastRun;
+}
+
+//___________________________________________________________________________
+Bool_t AliCDBRunRange::IsEqual(const TObject* obj) const {
+// check if this runRange is equal to other runRange
+       
+        if (this == obj) {
+                return kTRUE;
+        }
+
+        if (AliCDBRunRange::Class() != obj->IsA()) {
+                return kFALSE;
+        }
+        AliCDBRunRange* other = (AliCDBRunRange*) obj;
+       return fFirstRun == other->fFirstRun && fLastRun == other->fLastRun;
+}
+
+//___________________________________________________________________________
+Bool_t AliCDBRunRange::IsValid() const {
+// validity check
+
+       if (fFirstRun < 0 && fLastRun < 0) {
+               return kTRUE;
+       }
+
+       if (fFirstRun >= 0 && fLastRun >= fFirstRun) {
+               return kTRUE;
+       }
+
+       return kFALSE;
+}
+
+
diff --git a/STEER/AliCDBRunRange.h b/STEER/AliCDBRunRange.h
new file mode 100644 (file)
index 0000000..b765810
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef ALI_CDB_RUN_RANGE_H
+#define ALI_CDB_RUN_RANGE_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBRunRange                                          //
+//  defines the run validity range of the object:                 //
+//  [fFirstRun, fLastRun]                                         //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
+
+#include <TObject.h>
+
+class AliCDBRunRange: public TObject {
+
+public:
+       AliCDBRunRange();
+       AliCDBRunRange(Int_t firstRun, Int_t lastRun);
+       
+       virtual ~AliCDBRunRange();
+
+       
+       Int_t   GetFirstRun() const {return fFirstRun;};
+       Int_t   GetLastRun() const {return fLastRun;};
+
+       void    SetFirstRun(Int_t firstRun) {fFirstRun = firstRun;};
+       void    SetLastRun(Int_t lastRun) {fLastRun = lastRun;};
+
+       void    SetRunRange(Int_t firstRun, Int_t lastRun) 
+                       {fFirstRun=firstRun; fLastRun = lastRun;};
+
+
+       Bool_t IsValid() const;
+       
+       Bool_t IsAnyRange() const {return fFirstRun < 0 && fLastRun < 0;};
+
+       Bool_t Overlaps(const AliCDBRunRange& other) const;
+
+       Bool_t Comprises(const AliCDBRunRange& other) const;
+
+       virtual Bool_t IsEqual(const TObject *obj) const;
+       
+private:
+
+       Int_t fFirstRun;        // first valid run
+       Int_t fLastRun;         // last valid run       
+
+
+       ClassDef(AliCDBRunRange, 1);    
+};
+
+
+#endif
index b5aa8cc..b9bbcbe 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/* $Id$ */
-
-///////////////////////////////////////////////////////////////////////////////
-//                                                                           //
-// base class for data base access classes                                   //
-//                                                                           //
-///////////////////////////////////////////////////////////////////////////////
-
-
-#include <TFile.h>
-#include <TKey.h>
-#include <TROOT.h>
-
-#include "AliLog.h"
-#include "AliCDBEntry.h"
+#include "AliCDBManager.h"
 #include "AliCDBStorage.h"
 
+#include "AliCDBEntry.h"
+#include "AliLog.h"
 
 ClassImp(AliCDBStorage)
 
+//_____________________________________________________________________________
+AliCDBStorage::AliCDBStorage() {
+// constructor
+
+       fSelections.SetOwner(1);
+}
 
-AliCDBStorage* AliCDBStorage::fgInstance = NULL;
+//_____________________________________________________________________________
+AliCDBStorage::~AliCDBStorage() {
+// destructor
 
+}
 
 //_____________________________________________________________________________
-AliCDBStorage::AliCDBStorage() :
-  TObject(),
-  fSelection(),
-  fEntries(),
-  fDumpFile(NULL)
-{
-// default constructor
-  if (fgInstance) delete fgInstance;
-  fgInstance = this;
-  fStorageMode=kDevelopment;
+AliCDBId AliCDBStorage::GetSelection(const AliCDBId& id) {
+// return required version and subversion from the list of selection criteria 
+       
+       TIter iter(&fSelections);
+       AliCDBId* aSelection;
+        
+       // loop on the list of selection criteria
+       while ((aSelection = (AliCDBId*) iter.Next())) {
+               // check if selection element contains id's path and run (range) 
+               if (aSelection->Comprises(id)) {
+                       AliInfo(Form("Using selection criterion: %s ", aSelection->ToString().Data()));
+                       // return required version and subversion
+                       return AliCDBId(id.GetAliCDBPath(), 
+                               id.GetAliCDBRunRange(),
+                               aSelection->GetVersion(), 
+                               aSelection->GetSubVersion());  
+               }
+       }
+       
+       // no valid element is found in the list of selection criteria -> return
+       AliInfo("No matching selection criteria: highest version will be seeked!");
+       return AliCDBId(id.GetAliCDBPath(), id.GetAliCDBRunRange());
 }
 
 //_____________________________________________________________________________
-AliCDBStorage::~AliCDBStorage()
-{
-// destructor
-  fSelection.Delete();
-  fEntries.Delete();
-  if (fDumpFile) {
-    fDumpFile->Close();
-    delete fDumpFile;
-  }
-  fgInstance = NULL;
-}
-
-//_____________________________________________________________________________
-AliCDBStorage::AliCDBStorage(const AliCDBStorage& db) :
-  TObject(db),
-  fSelection(),
-  fEntries(),
-  fDumpFile(NULL)
-{
-// copy constructor
-
-  AliFatal("not implemented");
-}
+void AliCDBStorage::AddSelection(const AliCDBId& selection) {
+// add a selection criterion
+
+       AliCDBPath path = selection.GetPath();
+       if(!path.IsValid()) return;
+       
+       TIter iter(&fSelections);
+       const AliCDBId *anId;
+       while((anId = (AliCDBId*) iter.Next())){
+               if(selection.Comprises(*anId)){
+                       AliWarning("This selection is more general than a previous one and will hide it!");
+                       AliWarning(Form("%s", (anId->ToString()).Data()));
+                       fSelections.AddBefore(anId, new AliCDBId(selection));
+                       return;
+               }
+       
+       }
+       fSelections.AddFirst(new AliCDBId(selection));
+}
 
 //_____________________________________________________________________________
-AliCDBStorage& AliCDBStorage::operator = (const AliCDBStorage& /*db*/)
-{
-// assignment operator
+void AliCDBStorage::AddSelection(const AliCDBPath& path, 
+       const AliCDBRunRange& runRange, Int_t version, Int_t subVersion){
+// add a selection criterion
 
-  AliFatal("not implemented");
-  return *this;
+       AddSelection(AliCDBId(path, runRange, version, subVersion));
 }
 
+//_____________________________________________________________________________
+void AliCDBStorage::AddSelection(const AliCDBPath& path,
+       Int_t firstRun, Int_t lastRun, Int_t version, Int_t subVersion){
+// add a selection criterion
+       
+       AddSelection(AliCDBId(path, firstRun, lastRun, version, subVersion));
+}
 
-//_____________________________________________________________________________
-const TObject* AliCDBStorage::Get(const char* name, Int_t runNumber)
-{
-// get an object from the data base
-// (AliCDBStorage is NOT the owner of the returned object)
-// name must be in the form "Detector/DBType/DetSpecType"
-// es: "ZDC/Calib/Pedestals"
-
-  AliCDBMetaDataSelect defaultMetaData;
-  AliCDBMetaDataSelect* selectedMetaData = &defaultMetaData;
+//_____________________________________________________________________________
+void AliCDBStorage::RemoveSelection(const AliCDBId& selection) {
+// remove a selection criterion
 
-  // look for a meta data selection
-  for (Int_t i = 0; i < fSelection.GetEntriesFast(); i++) {
-    AliCDBMetaDataSelect* selection = (AliCDBMetaDataSelect*) fSelection[i];
-    if (!selection) continue;
-    if (selection->Matches(name, runNumber)) {
-      selectedMetaData = selection;
-    }
-  }
+       TIter iter(&fSelections);
+       AliCDBId* aSelection;
 
-  // get the entry
-  AliCDBMetaDataSelect selMetaData(*selectedMetaData);
-  selMetaData.SetName(name);
-  AliCDBEntry* entry = GetEntry(selMetaData, runNumber);
-  if (entry) {
-    AliDebug(2, "got the entry:");
-    ToAliDebug(2, entry->Dump());
-  } else {
-    AliDebug(2, Form("got no entry for %s", name));
-  }
+       while ((aSelection = (AliCDBId*) iter.Next())) {
+               if (selection.Comprises(*aSelection)) {
+                       fSelections.Remove(aSelection);
+               }
+       }
+}
 
-  // update array of current entries
-  if (!entry) return NULL;  
-  TObject* oldEntry = fEntries.FindObject(entry->GetName());
-  if (oldEntry) {
-    delete fEntries.Remove(oldEntry);
-  }
-  fEntries.Add(entry);
+//_____________________________________________________________________________
+void AliCDBStorage::RemoveSelection(const AliCDBPath& path, 
+       const AliCDBRunRange& runRange){
+// remove a selection criterion
 
-  // Dump entry to a file (in the same way as AliCDBDump::PutEntry, 
-  // so that the file can be opened as a AliCDBDump!)
+       RemoveSelection(AliCDBId(path, runRange, -1, -1));
+}
 
-  if (fDumpFile) {
-    fDumpFile->cd();
-    TDirectory* saveDir = gDirectory;
+//_____________________________________________________________________________
+void AliCDBStorage::RemoveSelection(const AliCDBPath& path,
+       Int_t firstRun, Int_t lastRun){
+// remove a selection criterion
 
-    // go to or create the directory
-    TString strname(name);
-    while (strname.BeginsWith("/")) strname.Remove(0);
-    TDirectory* dir = fDumpFile;
-    Int_t index = -1;
-    while ((index = strname.Index("/")) >= 0) {
-      TString dirName(strname(0, index));
-      if ((index > 0) && !dir->Get(dirName)) dir->mkdir(dirName);
-      dir->cd(dirName);
-      dir = gDirectory;
-      strname.Remove(0, index+1);
-    } 
+       RemoveSelection(AliCDBId(path, firstRun, lastRun, -1, -1));
+}
 
-    entry->Write(strname);
-    if (saveDir) saveDir->cd(); else gROOT->cd();
-  
-  }
-  
-  return (entry->GetObject())->Clone();
+//_____________________________________________________________________________
+void AliCDBStorage::RemoveSelection(const int position){
+// remove a selection criterion from its position in the list
 
+       fSelections.RemoveAt(position);
 }
 
 //_____________________________________________________________________________
-Bool_t AliCDBStorage::Put(const TObject* object, 
-                             const AliCDBMetaData& metaData)
-{
-// put an object into the data base
-// (AliCDBStorage does not adopt the object)
-// location of where the object is stored is defined by 
-// the AliCDBMetaData's name ("Detector/DBType/DetSpecType")
-// and run Range. Storage is handled by the PutEntry method
-// of the current AliCDBStorage instance. 
+void AliCDBStorage::RemoveAllSelections(){
+// remove all selection criteria
 
-  if (!object) return kFALSE;
+       fSelections.RemoveAll();
+}
 
-  AliCDBEntry *entry= new AliCDBEntry(object, metaData);
+//_____________________________________________________________________________
+void AliCDBStorage::PrintSelectionList(){
+// prints the list of selection criteria
+
+       TIter iter(&fSelections);
+       AliCDBId* aSelection;
+        
+       // loop on the list of selection criteria
+       int index=0;
+       while ((aSelection = (AliCDBId*) iter.Next())) {
+               AliInfo(Form("index %d -> selection: %s",index++, aSelection->ToString().Data()));
+       }
 
-  Bool_t result = PutEntry(entry);
-    
-  delete entry;
+}
 
-  return result;
+//_____________________________________________________________________________
+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()) {
+               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;
+       }
+
+       AliCDBEntry* entry = GetEntry(query);
+               
+       if (entry) {
+               AliInfo(Form("Valid AliCDBEntry object found! %s", entry->GetId().ToString().Data()));
+       } else {
+               AliInfo(Form("Sorry, found no object valid for: name = <%s>, run = %d", 
+                       (query.GetPath()).Data(), query.GetFirstRun()));
+       }
+       
+       // if drain storage is set, drain entry into drain storage
+       if(entry && (AliCDBManager::Instance())->IsDrainSet())
+               AliCDBManager::Instance()->Drain(entry);
+       
+       return entry;
 }
 
 //_____________________________________________________________________________
-Bool_t AliCDBStorage::PutEntry(AliCDBEntry* entry)
-{
-// put an object into the data base
-// Refer to the specific method of the current AliCDBStorage instance
-// (AliCDBDump, AliCDBLocalFile, AliCDBGrid)
+AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path, Int_t runNumber, 
+       Int_t version, Int_t subVersion) {
+// get an AliCDBEntry object from the database
 
-  if (!entry) return kFALSE;
-  AliError(Form("This is a read only data base. "
-               "The object %s was not inserted", entry->GetName()));
-  return kFALSE;
+       return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
 }
 
-
 //_____________________________________________________________________________
-void AliCDBStorage::Select(const AliCDBMetaDataSelect& selMetaData)
-{
-// add some meta data selection criteria
+AliCDBEntry* AliCDBStorage::Get(const AliCDBPath& path, 
+       const AliCDBRunRange& runRange, Int_t version,
+       Int_t subVersion) {
+// get an AliCDBEntry object from the database
 
-  fSelection.Add(new AliCDBMetaDataSelect(selMetaData));
+       return Get(AliCDBId(path, runRange, version, subVersion));
 }
 
-
 //_____________________________________________________________________________
-Bool_t AliCDBStorage::DumpToFile(const char* fileName)
-{
-// Dump entries retrieved from the data base to a file with the given name
+TList* AliCDBStorage::GetAll(const AliCDBId& query) {
+// get multiple AliCDBEntry objects from the database
+
+
+       if (!query.IsValid()) {
+                AliError(Form("Invalid query: %s", query.ToString().Data()));
+                return NULL;
+        }
+
+       if (query.IsAnyRange()) {
+               AliError(Form("Unspecified run or runrange: %s",
+                               query.ToString().Data()));      
+               return NULL;
+       }       
+        
+       TList *result = GetEntries(query);
+
+       Int_t nEntries = result->GetEntries();
+       if (nEntries) {
+                AliInfo(Form("%d AliCDBEntry objects found!",nEntries));
+                for(int i=0; i<nEntries;i++){
+                       AliCDBEntry *entry = (AliCDBEntry*) result->At(i);
+                       AliInfo(Form("%s",entry->GetId().ToString().Data()));
+                
+                }
+       } else {
+                AliInfo(Form("Sorry, found no object valid for: name = <%s>, run = %d", 
+                       (query.GetPath()).Data(), query.GetFirstRun()));
+       }
+
+       // if drain storage is set, drain entries into drain storage
+       if((AliCDBManager::Instance())->IsDrainSet()){
+               for(int i = 0; i<result->GetEntries(); i++){
+                       AliCDBEntry* entry = (AliCDBEntry*) result->At(i);
+                       AliCDBManager::Instance()->Drain(entry);
+               }
+       }
+       
+
+        return result;
+}
 
-  if (fDumpFile) {
-    fDumpFile->Close();
-    delete fDumpFile;
-  }
+//_____________________________________________________________________________
+TList* AliCDBStorage::GetAll(const AliCDBPath& path, Int_t runNumber, 
+       Int_t version, Int_t subVersion) {
+// get multiple AliCDBEntry objects from the database
 
-  TDirectory* dir = gDirectory;
-  fDumpFile = TFile::Open(fileName, "UPDATE");
-  if (dir) dir->cd(); else gROOT->cd();
-  if (!fDumpFile || !fDumpFile->IsOpen()) {
-    AliError(Form("could not open file %s", fileName));
-    delete fDumpFile;
-    fDumpFile = NULL;
-    return kFALSE;
-  }
-  return kTRUE;
+       return GetAll(AliCDBId(path, runNumber, runNumber, version,     
+                       subVersion));
 }
 
-
 //_____________________________________________________________________________
-AliCDBStorage* AliCDBStorage::Instance()
-{
-// return the current instance of the DB (AliCDBDump, AliCDBLocalFile...)
-// Example of usage: after creating an istance of AliCDBStorage:
-// AliCDBStorage::Instance()->Get(...)
+TList* AliCDBStorage::GetAll(const AliCDBPath& path, 
+       const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
+// get multiple AliCDBEntry objects from the database
 
-  return fgInstance;
+       return GetAll(AliCDBId(path, runRange, version, subVersion));
 }
 
 
 //_____________________________________________________________________________
-const AliCDBMetaData& AliCDBStorage::GetCDBMetaData(const char* name)
-{
-// Returns the object's metadata of the already retrieved object
-// (useful, for example, if you want to know the format of the object you have 
-// retrieved)
+Bool_t AliCDBStorage::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData) {
+// put an AliCDBEntry object from the database
+       
+       AliCDBEntry anEntry(object, id, metaData);
 
-AliCDBEntry *entry = (AliCDBEntry*) fEntries.FindObject(name);
- if(!entry){
-    AliError(Form("Entry %s not found! You make me crash!",name));
- }
- return entry->GetCDBMetaData(); 
+       return Put(&anEntry);
+} 
 
+//_____________________________________________________________________________
+Bool_t AliCDBStorage::Put(AliCDBEntry* entry) {
+// put an AliCDBEntry object from the database
+
+       if (!entry->GetId().IsValid()) {
+               AliWarning(Form("Invalid entry ID: %s", 
+                       entry->GetId().ToString().Data()));
+               return kFALSE;
+       }       
+
+       if (!entry->GetId().IsSpecified()) {
+               AliError(Form("Unspecified entry ID: %s", 
+                       entry->GetId().ToString().Data()));
+               return kFALSE;
+       }
+
+       return PutEntry(entry);
 }
 
index c9421dd..2b2a3a0 100644 (file)
@@ -1,75 +1,90 @@
-#ifndef ALICDBSTORAGE_H
-#define ALICDBSTORAGE_H
+#ifndef ALI_CDB_STORAGE_H
+#define ALI_CDB_STORAGE_H
+
 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
  * See cxx source for full Copyright notice                               */
 
-/* $Id$ */
-
-///
-/// base class for data base access classes
-///
+/////////////////////////////////////////////////////////////////////
+//                                                                 //
+//  class AliCDBStorage                                                   //
+//  interface to specific storage classes                          //
+//  (AliCDBGrid, AliCDBLocal, AliCDBDump)                         //
+//                                                                 //
+/////////////////////////////////////////////////////////////////////
 
-#include <TObject.h>
-#include <TObjArray.h>
-#include "AliCDBMetaDataSelect.h"
+#include "AliCDBId.h"
 #include "AliCDBMetaData.h"
 
+#include <TList.h>
 
-class TFile;
-class AliCDBMetaDataSelect;
-class AliCDBMetaData;
 class AliCDBEntry;
 
 class AliCDBStorage: public TObject {
-public:
-
-typedef enum {kDevelopment, kProduction} StorageMode_t;
-
-  virtual ~AliCDBStorage();
-
-  const TObject*         Get(const char* name, Int_t runNumber);       // Gets an object from the database
-
-  Bool_t                 Put(const TObject* object, 
-                            const AliCDBMetaData& metaData);   // Put an object into the database
-
-  void                   Select(const AliCDBMetaDataSelect& selMetaData);      // Add a selection criterion 
 
-  Bool_t                 DumpToFile(const char* fileName = "DB.root"); // prepares to dump the retrieved entries to a local file
-  
-  const AliCDBMetaData& GetCDBMetaData(const char* name);              // Gets the CDBMetaData of the retrieved entry (name=entry's name)
-  
-  virtual void          TagForProduction(const AliCDBMetaDataSelect& selMetaData, UInt_t prodVers) = 0;
-
-  static AliCDBStorage* Instance();            // Instance of the current AliCDBStorage object (AliCDBDump, AliCDBLocalFile etc...)
-
-  void                 SetStorageMode(StorageMode_t mode)         {fStorageMode = mode;}
-  StorageMode_t GetStorageMode()         {return fStorageMode;}
-  
+public:
+       AliCDBStorage();
+       virtual ~AliCDBStorage();       
+
+
+       void AddSelection(const AliCDBId& selection);
+
+       void AddSelection(const AliCDBPath& path, 
+                       const AliCDBRunRange& runRange,
+                       Int_t version,
+                       Int_t subVersion = -1);
+       
+       void AddSelection(const AliCDBPath& path,
+                       Int_t firstRun,
+                       Int_t lastRun,
+                       Int_t version,
+                       Int_t subVersion = -1);
+                       
+       void RemoveSelection(const AliCDBId& selection);
+
+       void RemoveSelection(const AliCDBPath& path,
+                       const AliCDBRunRange& runRange);
+       
+       void RemoveSelection(const AliCDBPath& path,
+                       Int_t firstRun = -1,
+                       Int_t lastRun = -1);
+
+       void RemoveSelection(const int position);
+       void RemoveAllSelections();
+               
+       AliCDBEntry* Get(const AliCDBId& query);
+       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);
+
+       TList* GetAll(const AliCDBId& query);
+       TList* GetAll(const AliCDBPath& path, Int_t runNumber, 
+                               Int_t version = -1, Int_t subVersion = -1);
+       TList* GetAll(const AliCDBPath& path, const AliCDBRunRange& runRange,
+                                Int_t version = -1, Int_t subVersion = -1); 
+       
+       void PrintSelectionList();
+
+
+       Bool_t Put(TObject* object, AliCDBId& id,  AliCDBMetaData* metaData);
+       Bool_t Put(AliCDBEntry* entry);
+
+
+       virtual Bool_t IsReadOnly() = 0;
+       virtual Bool_t HasSubVersion() = 0;
 
 protected:
-  AliCDBStorage();
-
-  virtual AliCDBEntry*    GetEntry(AliCDBMetaDataSelect& selMetaData, Int_t runNumber) = 0;    // virtual, see the correspondent method of the derived classes
-
-  virtual Bool_t          PutEntry(AliCDBEntry* entry);                        // virtual, see the correspondent method of the derived classes
-
-  AliCDBEntry*            GetCurrentEntry(const char* name) const
-    {return (AliCDBEntry*) fEntries.FindObject(name);}
-  
-  StorageMode_t fStorageMode;
+               
+       AliCDBId GetSelection(const AliCDBId& id);
+       virtual AliCDBEntry* GetEntry(const AliCDBId& query) = 0;
+       virtual TList* GetEntries(const AliCDBId& query) = 0;
+       virtual Bool_t PutEntry(AliCDBEntry* entry) = 0; 
 
 private:
-  AliCDBStorage(const AliCDBStorage& db);
-  AliCDBStorage& operator = (const AliCDBStorage& db);
-
-  TObjArray              fSelection;   //! meta data selection
-
-  TObjArray              fEntries;     //! array of current AliCDBEntry objects
-  TFile*                 fDumpFile;  //! file for dumped entries
 
-  static AliCDBStorage* fgInstance;   //! pointer to the DB instance
+       TList fSelections; // list of selection criteria
 
-  ClassDef(AliCDBStorage, 0)     // base class for data base access classes
+       ClassDef(AliCDBStorage, 0);
 };
 
 #endif
index 8be990d..ef3d93d 100644 (file)
@@ -62,7 +62,7 @@ class TTask;
 #include "AliHeader.h"
 #include "AliStack.h"
 #include "AliDetector.h"
-#include "AliCDBStorage.h"
+#include "AliCDBManager.h"
 #include "AliCDBLocal.h"
 
 ClassImp(AliRunLoader)
@@ -350,15 +350,16 @@ Int_t AliRunLoader::SetEventNumber(Int_t evno)
 }
 
 /**************************************************************************/
-const TObject* AliRunLoader::GetRunObject(const char* name) const
+AliCDBEntry* AliRunLoader::GetCDBEntry(const char* name) const
 {
-//Get an object from the run data storage
+//Get an AliCDBEntry from the run data storage
 
-  if (!AliCDBStorage::Instance()) {
-    AliWarning("No run data storage defined. Using AliCDBLocal.");
-    new AliCDBLocal;
+  if ( !(AliCDBManager::Instance()->IsDefaultStorageSet()) ) {
+    AliError("No run data storage defined!");
+    return 0x0;
   }
-  return AliCDBStorage::Instance()->Get(name, GetHeader()->GetRun());
+  return AliCDBManager::Instance()->GetDefaultStorage()->Get(name, GetHeader()->GetRun());
+
 }
 
 /**************************************************************************/
index 116cf8e..9f8c906 100644 (file)
@@ -43,6 +43,7 @@ class AliDetector;
 class AliHeader;
 class AliStack;
 class AliRunDigitizer;
+class AliCDBEntry;
 
 
 class AliRunLoader: public TNamed
@@ -71,7 +72,7 @@ class AliRunLoader: public TNamed
     
     Int_t       GetNumberOfEvents();
     
-    const TObject* GetRunObject(const char* name) const;
+    AliCDBEntry* GetCDBEntry(const char* name) const;
 
     void        MakeTree(Option_t *option);
     void        MakeHeader();
index e63dea2..a5206da 100644 (file)
 #pragma link C++ class  AliReconstruction+;
 #pragma link C++ class  AliVertexGenFile+;
 #pragma link C++ class  AliVertexer+;
-#pragma link C++ class  AliCDBMetaData+;
-#pragma link C++ class  AliCDBMetaDataSelect+;
-#pragma link C++ class  AliCDBEntry+;
-#pragma link C++ class  AliCDBStorage;
-#pragma link C++ class  AliCDBDump;
-#pragma link C++ class  AliCDBLocal;
+
+#pragma link C++ class AliCDBPath;
+#pragma link C++ class AliCDBRunRange;
+#pragma link C++ class AliCDBId;
+#pragma link C++ class AliCDBMetaData;
+#pragma link C++ class AliCDBEntry;
+#pragma link C++ class AliCDBStorage;
+#pragma link C++ class AliCDBStorageFactory;
+#pragma link C++ class AliCDBManager;
+#pragma link C++ class AliCDBParam;
+#pragma link C++ class AliCDBLocal;
+#pragma link C++ class AliCDBLocalFactory;
+#pragma link C++ class AliCDBLocalParam;
+#pragma link C++ class AliCDBDump;
+#pragma link C++ class AliCDBDumpFactory;
+#pragma link C++ class AliCDBDumpParam; 
+#pragma link C++ class AliCDBGrid;
+#pragma link C++ class AliCDBGridFactory;
+#pragma link C++ class AliCDBGridParam; 
+
 #pragma link C++ class  AliDetectorEventHeader+;
 
 #pragma link C++ class AliRunTag+;
index 1594cdb..c14573a 100644 (file)
@@ -20,10 +20,10 @@ AliMemoryWatcher.cxx \
 AliVertexer.cxx \
 AliMC.cxx AliSimulation.cxx AliReconstruction.cxx AliVertexGenFile.cxx \
 AliRunTag.cxx AliLHCTag.cxx AliDetectorTag.cxx AliEventTag.cxx \
-AliCDBMetaData.cxx AliCDBEntry.cxx AliCDBStorage.cxx AliCDBDump.cxx \
-AliCDBLocal.cxx\
-AliReconstructor.cxx AliCDBMetaDataSelect.cxx \
-AliDetectorEventHeader.cxx TTreeStream.cxx
+AliCDBEntry.cxx AliCDBId.cxx AliCDBMetaData.cxx \
+AliCDBPath.cxx AliCDBRunRange.cxx AliCDBManager.cxx\
+AliCDBStorage.cxx AliCDBLocal.cxx AliCDBDump.cxx AliCDBGrid.cxx\
+AliReconstructor.cxx AliDetectorEventHeader.cxx TTreeStream.cxx
 
 HDRS:= $(SRCS:.cxx=.h) 
 
index 6208fa9..542c205 100644 (file)
+AliCDBStorage *storLoc, *storGrid;
+
+AliCDBEntry *entry=0;
+TObjString *objstr=0;
+
 void DBAccessTutorial(){
 
+AliCDBManager *man = AliCDBManager::Instance();
+// pointer man points to the single instance of AliCDBManager. 
+// This will let us avoid typing AliCDBManager::Instance every time... 
 
-/***************************************************************************************************************
- Prelude(0):   if it doesn't exist, create DB directory: $ALICE_ROOT/DB
- ***************************************************************************************************************/
-TString DBFolder="$ALICE_ROOT/DBTutorial";
-gSystem->ExpandPathName(DBFolder);
 
-if(!gSystem->OpenDirectory(DBFolder)){
-       printf("Warning: folder DBTutorial does not exist, I will create it!");
-        TString command = "mkdir "+ DBFolder;
-       gSystem->Exec(command.Data());
-}
+printf("\n<< TUTORIAL >> Activating Grid storage...\n");
+storGrid = man->GetStorage("alien://aliendb4.cern.ch:9000;colla;DBGrid;ALICE::CERN::se01"); // replace "colla" with your username! 
+// The default storage is automatically set to this. 
+// One can access default storage with:
+// (AliCDBStorage*) AliCDBManager::Instance()->GetDefaultStorage()
+// To check the activation of the default storage:
+// (Bool_t) AliCDBManager::Instance()->IsDefaultStorageSet()
+
+printf("\n<< TUTORIAL >> Activating Local storage...\n");
+storLoc = man->GetStorage("local://DBLocal");
+// To set the default storage to this one:
+// AliCDBMAnager::Instance()->SetDefaultStorage("local://DBLocal") or
+// AliCDBMAnager::Instance()->SetDefaultStorage(storLoc) 
+
+/////////////////////////////////////////////
+// Step 0: Write/read in Local storage     //
+/////////////////////////////////////////////
+printf("\n<< TUTORIAL >> ********************************************\n");
+printf(  "<< TUTORIAL >> **** Step 0: write/read in local storage ***\n");
+printf(  "<< TUTORIAL >> ********************************************\n");
+
+
+//create the new object
+
+TObjString str1("This is step zero"); // object that will be stored
+
+AliCDBId id1("ZDC/Calib/Gain",0,10); // Id of the object: AliCDBId("name", firstRun, lastRun)
+
+AliCDBMetaData *md1= new AliCDBMetaData(); // metaData describing the object
+md1->SetObjectClassName("TObjString");
+md1->SetResponsible("Alberto Colla");
+md1->SetBeamPeriod(1);
+md1->SetAliRootVersion("05-04-00"); //root version
+md1->SetComment("This is a test");
+TObjString str("test");
+md1->SetProperty("key1",&str);
+
+
+// Store the object into local storage
+printf("\n<< TUTORIAL >> Storing object into local storage...\n");
+storLoc->Put(&str1,id1, md1); // filename: DBLocal/ZDC/Calib/Gain/Run0_10_v0_s0.root
+
+
+// read, update, store again
+printf("\n<< TUTORIAL >> Retrieve object from local storage...\n");
+entry = storLoc->Get("ZDC/Calib/Gain", 5);
+
+objstr = (TObjString*) entry->GetObject();
+printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
+
+objstr->SetString("This is step 0.1: slightly better!"); // update object
+
+printf("\n<< TUTORIAL >> Storing object into local storage...\n");
+storLoc->Put(entry); // store into local: filename = Run0_10_v0_s1.root
+
+// read, update, store again
+printf("\n<< TUTORIAL >> Retrieve object from local storage...\n");
+entry = storLoc->Get("ZDC/Calib/Gain", 5);
+
+objstr = (TObjString*) entry->GetObject();
+printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
+
+objstr -> SetString("This is step 0.2: much better!");
+
+printf("\n<< TUTORIAL >> Storing object into local storage...\n");
+storLoc->Put(entry); // store into local: filename = Run0_10_v0_s2.root
+
+///////////////////////////////////////////////////////////////////////
+// Step 1: read from Local, update, store locally and into Grid      //
+///////////////////////////////////////////////////////////////////////
+printf("\n<< TUTORIAL >> ********************************************\n");
+printf(  "<< TUTORIAL >> **** Step 1: write/read in Grid storage  ***\n");
+printf(  "<< TUTORIAL >> ********************************************\n");
+
+// read from local
+printf("\n<< TUTORIAL >> Retrieve object from local storage...\n");
+entry = storLoc->Get("ZDC/Calib/Gain", 5);
+objstr = (TObjString*) entry->GetObject();
+printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
+
+
+objstr -> SetString("This is step 1: stored into Local and into Grid!");
+
+printf("\n<< TUTORIAL >> Storing object into local storage...\n");
+storLoc->Put(entry); // store into local: filename =  Run0_10_v0_s3.root
+
+printf("\n<< TUTORIAL >> Storing object into Grid storage...\n");
+storGrid->Put(entry); // store into grid: filename =  DBGrid/ZDC/Calib/Gain/Run0_10_v1.root
+
+
+
+// step 2: read from Grid, update, store again (into Grid)
 
-/***************************************************************************************************************
- Prelude(1):   create a DB object. We'll take AliZDCCalibData 
-               (container class for ZDC Calibration data) as an example
- ***************************************************************************************************************/
-AliZDCCalibData *calibda=new AliZDCCalibData("ZDC");
+printf("\n<< TUTORIAL >> Retrieve object from Grid storage...\n");
+entry = storGrid->Get("ZDC/Calib/Gain", 5);
 
-// Fill array of ZDC energy calibration factors (4 float's) with some numbers
-Float_t EnFactorsArray[4]={20.,25.,200.,10.};
-calibda->SetEnCalib(EnFactorsArray);
+objstr = (TObjString*) entry->GetObject();
+printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
 
-printf("\nI am in Prelude(1). ZDC Energy calibration factors: \n");  
-printf("PM0=%f; PM1=%f; PM2=%f; PM3=%f \n",
-   calibda->GetEnCalib(0),  calibda->GetEnCalib(1),  calibda->GetEnCalib(2),  calibda->GetEnCalib(3) );  
+objstr -> SetString("This is step 2: update and store into Grid!");
 
-/***************************************************************************************************************
- Part 1:       Store the calibration object in the database, using 
-               the "Organized" storage system
-               (i.e. a well defined directory structure, defined by the 
-               object's metadata and set in the DBFodler above specified)
- ***************************************************************************************************************/
+printf("\n<< TUTORIAL >> Storing object into Grid storage...\n");
+storGrid->Put(entry); // store into grid: filename =   Run0_10_v2.root
 
-// a. Define the object's metadata (set of information which describes the object)
-// AliCDBMetaData(char* name, int firstRun, int lastRun,int Period,char* ObjectFormat, char* ResponsibleName, char* extraInfo)
-//
-// name: Object's name ("Detector/DBType/DetSpecType")
-// firstRun: first run for which the object is valid
-// lastRun:  last run for which the object is valid
-// period: beam period (to be better specified in future)
-// objectFormat: a string which describes the object's format
-// ResponsibleName: name of the person who created and stored the object
-// extraInfo: anything else you may want to know
+// step 3: read, update, store again (into Grid)
+printf("\n<< TUTORIAL >> Retrieve object from Grid storage...\n");
+entry = storGrid->Get("ZDC/Calib/Gain", 5);
+objstr = (TObjString*) entry->GetObject();
+printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
 
-AliCDBMetaData md("ZDC/Calib/GainFactors",1,10,1,"AliZDCCalibData: Pedestals (47 floats), En. calib factors (4 floats)","A. Colla", "Tutorial");
+objstr = (TObjString*) entry->GetObject();
+objstr -> SetString("This is step 3: update and store into Grid!");
 
-// b. Create the specific AliCDBStorage instance (AliCDBLocal in this case)
+printf("\n<< TUTORIAL >> Storing object into Grid storage...\n");
+storGrid->Put(entry); // store into grid: filename =   Run0_10_v3.root
 
-AliCDBLocal *loc = new AliCDBLocal(DBFolder.Data());
+  ////////////////////////////////////////////////
+ // Step 3.0: read from Grid, store locally!   //
+////////////////////////////////////////////////
+printf("\n<< TUTORIAL >> **********************************************\n");
+printf(  "<< TUTORIAL >> **** Step 3: read from Grid, store locally ***\n");
+printf(  "<< TUTORIAL >> **********************************************\n");
 
-// c. Put the object in the database. Use Put method: AliCDBStorage::Put(TObject object, AliCDBMetaData& metaData)
-// 
-// the object will be stored in the file DBFolder/ZDC/Calib/GainFactors/Run1-10_v0.root
-// Note that the version is automatically determined.
+printf("\n<< TUTORIAL >> Retrieve object from Grid storage...\n");
+entry = storGrid->Get("ZDC/Calib/Gain", 5);
+objstr = (TObjString*) entry->GetObject();
+printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
 
-AliCDBStorage::Instance()->Put(calibda, md); // we could also type: loc->Put(calibda, md)
+printf("\n<< TUTORIAL >> Storing object into local storage...\n");
+storLoc->Put(entry); // local: Run0_10_v3_s0.root
 
-// delete the AliCDBStorage instance and the object (optional)
-AliCDBStorage::Instance()->Delete();
+// Step 3.1: read from Local, update, store again into Local
+printf("\n<< TUTORIAL >> Retrieve object from local storage...\n");
+entry = storLoc->Get("ZDC/Calib/Gain", 5);
+objstr = (TObjString*) entry->GetObject();
+printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
 
+objstr->SetString("This is step 3.1: updated locally!");
 
-/***************************************************************************************************************
- Part 2:       Now we want to retrieve the object valid, say, for run 5 from the database folder. 
-               We will dump it in a dump file called "dummyDBTutorail.root", for later usage. 
- ***************************************************************************************************************/
+printf("\n<< TUTORIAL >> Storing object into local storage...\n");
+storLoc->Put(entry); // local: Run0_10_v3_s1.root
 
-// a. Create the specific AliCDBStorage instance (AliCDBLocal in this case)
-AliCDBLocal *loc = new AliCDBLocal(DBFolder.Data());
+/////////////////////////////////////////////////////////////
+// Step 3.2: read again from Grid version 3, store locally //
+//         -> ERROR, local update already present!!        //
+/////////////////////////////////////////////////////////////
+printf("\n<< TUTORIAL >> **********************************************\n");
+printf(  "<< TUTORIAL >> **** Step 3.2: error test                  ***\n");
+printf(  "<< TUTORIAL >> **********************************************\n");
 
-// b. Prepare AliCDBStorage to save the object in the dump file
-AliCDBStorage::Instance()->DumpToFile("dummyDBTutorial.root");
+printf("\n<< TUTORIAL >> Retrieve object from Grid storage...\n");
+entry = (AliCDBEntry*) storGrid->Get("ZDC/Calib/Gain",5);
+objstr = (TObjString*) entry->GetObject();
+printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
 
-// c. Get the object! 
-// TObject *AliCDBStorage::Get(char* name, int runNumber)
-// if no selection criteria are specified, the highest version found is retrieved.
+printf("\n<< TUTORIAL >> Trying to store object into local storage...\n");
+storLoc->Put(entry); // ERROR message!
 
-AliZDCCalibData *calibda2 = (AliZDCCalibData*) AliCDBStorage::Instance()->Get("ZDC/Calib/GainFactors",5);
+/////////////////////////////////////////////////////////////
+// Step 4: read from local, DRAIN to a dump storage: DBDrain.root! //
+/////////////////////////////////////////////////////////////
+printf("\n<< TUTORIAL >> ************************************************************\n");
+printf(  "<< TUTORIAL >> **** Step 4: Read from local and DRAIN to a dump storage ***\n");
+printf(  "<< TUTORIAL >> ************************************************************\n");
 
-printf("\nI am in Part2. ZDC Energy calibration factors: \n");  
-printf("PM0=%f; PM1=%f; PM2=%f; PM3=%f \n",
-   calibda2->GetEnCalib(0),  calibda2->GetEnCalib(1),  calibda2->GetEnCalib(2),  calibda2->GetEnCalib(3) );  
+printf("\n<< TUTORIAL >> Setting Drain storage ...\n");
+AliCDBManager::Instance()->SetDrain("dump://DBDrain.root"); //setting Drain storage
 
-AliCDBStorage::Instance()->Delete();
+// Testing default storage behavior: let's set default storage to Local storage
+AliCDBManager::Instance()->SetDefaultStorage(storLoc);
 
+// read from local (default) storage. The object is automatically drained into the drain storage!
+printf("\n<< TUTORIAL >> Retrieve object from local storage...\n");
+entry = man->GetDefaultStorage()->Get("ZDC/Calib/Gain",5); 
+objstr = (TObjString*) entry->GetObject();
+printf("\n<< TUTORIAL >> Object string: %s\n", objstr->GetName());
 
-/***************************************************************************************************************
- Part 3:       Now we will retrieve the object from the dump file. 
-               We will tune the energy calibration factors and we suppose that the new object is valid from run 1 to run 15.
-               Finally we will store the object in DBFolder again with the new run range specified in the object's metadata.  
- ***************************************************************************************************************/
+/////////////////////////////////////////////////////////////
+// Step 5: READ AND DRAIN multiple objects (with GetAll)   //
+/////////////////////////////////////////////////////////////
+printf("\n<< TUTORIAL >> *******************************************************\n");
+printf(  "<< TUTORIAL >> **** Step 5: Read and Drain multiple objects        ***\n");
+printf(  "<< TUTORIAL >> *******************************************************\n");
 
-// a. Create the specific AliCDBStorage instance (AliCDBDump in this case)
-AliCDBDump *df = new AliCDBDump("dummyDBTutorial.root");
 
-// b. Get the object.
-AliZDCCalibData *calibda3 = (AliZDCCalibData*) AliCDBStorage::Instance()->Get("ZDC/Calib/GainFactors",5);
+// Step 5.1: Store an object into four different Grid databases 
 
-//AliZDCCalibData calibda3copy=*calibda3;
+TObjString str2("This is the TPC/Calib/Gain object valid for runs 0 to 10.");
+AliCDBId id2("TPC/Calib/Gain",0,10);
 
-// c. Tune the energy calibration factors.
-calibda3->SetEnCalib(21.5, 0); calibda3->SetEnCalib(26.3, 1); 
-calibda3->SetEnCalib(201., 2); calibda3->SetEnCalib(9.45, 3);
+TObjString str3("This is the TPC/Calib/Drift object valid for runs 0 to 20.");
+AliCDBId id3("TPC/Calib/Drift",0,20);
 
-printf("\nI am in Part3. New ZDC Energy calibration factors: \n");  
-printf("PM0=%f; PM1=%f; PM2=%f; PM3=%f \n",
-   calibda3->GetEnCalib(0),  calibda3->GetEnCalib(1),  calibda3->GetEnCalib(2),  calibda3->GetEnCalib(3) );  
+TObjString str4("This is the TPC/Align/Angles object valid for runs 0 to 15.");
+AliCDBId id4("TPC/Align/Angles",0,15);
 
-// d. Get the object's metadata, set the new run range
-AliCDBMetaData md2 = AliCDBStorage::Instance()->GetCDBMetaData("ZDC/Calib/GainFactors");
-md2.SetRunRange(1,15);
+TObjString str5("This is the TPC/Align/Position object valid for runs 0 to 8.");
+AliCDBId id5("TPC/Align/Positions",0,8);
 
-// e. Store the object in the "organized" database.
-// the object will be stored in the file DBFolder/ZDC/Calib/GainFactors/Run1-15_v1.root
-// Note that, since there is an "overlap" of the new run range with the one specified
-// in the previous version, the version is automatically increased.
+printf("\n<< TUTORIAL >> Storing more objects into Grid storage...\n");
+storGrid->Put(&str2,id2,md1);
+storGrid->Put(&str3,id3,md1);
+storGrid->Put(&str4,id4,md1);
+storGrid->Put(&str5,id5,md1);
 
-AliCDBLocal *loc = new AliCDBLocal(DBFolder.Data());
-AliCDBStorage::Instance()->Put(calibda3, md2);
+// Step 5.2: Read all the TPC objects with GetAll and drain into DBDrain.root
 
-/***************************************************************************************************************
- Part 3:       Last act. 
-               We want to retrieve the object from the "organized" database folder again.
-               This time, anyway, we don't want the highest version but version 0 instead.
-               Therefore we have to specify the version wanted using the "Select" method of AliCDBStorage
-               and the aliCDBMetaDataSelect object.  
- ***************************************************************************************************************/
+printf("\n<< TUTORIAL >> Retrieve more objects from Grid storage and drain them into Dump ...\n");
+TList *list = (TList*)storGrid->GetAll("TPC/*",5);
 
-// a. Create the specific AliCDBStorage instance (AliCDBLocal in this case)
-loc = new AliCDBLocal(DBFolder.Data());
+// That's all folks! Delete AliCDBManager instance and metaData object
 
-// b. Specify the selection criterion. We want version 0 for the object valid for run range (1,100)
-// NOTE(1): TRegexp expression are valid! E.g. we could type "ZDC/Calib/*" if we want to specify version
-// for all the "ZDC/Calib" subsamples...
-// Note(2): we could also not specify the run range, if we want version 0 for any retrieved object
-AliCDBMetaDataSelect smd("ZDC/Calib/GainFactors",1,100,0);
-AliCDBStorage::Instance()->Select(smd);
+printf(  "<< TUTORIAL >> **** That's all folks!!        ***\n");
 
-// c. Get the object
-AliZDCCalibData *calibda4 = (AliZDCCalibData*) AliCDBStorage::Instance()->Get("ZDC/Calib/GainFactors",5);
-printf("\nI am in Part4. I've just got \"ZDC/Calib/GainFactors\" object valid for run 5, version 0.\n");
-printf("ZDC Energy calibration factors: \n");  
-printf("PM0=%f; PM1=%f; PM2=%f; PM3=%f \n",
-   calibda4->GetEnCalib(0),  calibda4->GetEnCalib(1),  calibda4->GetEnCalib(2),  calibda4->GetEnCalib(3) );  
-   
-printf("\nEnd of tutorial. Bye bye!! \n");
 
+AliCDBManager::Instance()->Destroy();
+delete entry;
+delete md1;
 
 }