1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 /////////////////////////////////////////////////////////////////////////////////////////////////
19 // access class to a DataBase in a local storage //
21 /////////////////////////////////////////////////////////////////////////////////////////////////
24 #include <TObjString.h>
29 #include "AliCDBLocal.h"
30 #include "AliCDBEntry.h"
35 //_____________________________________________________________________________
36 AliCDBLocal::AliCDBLocal(const char* baseDir):
37 fBaseDirectory(baseDir)
41 // check baseDire: trying to cd to baseDir; if it does not exist, create it
42 void* dir = gSystem->OpenDirectory(baseDir);
44 if (gSystem->mkdir(baseDir, kTRUE)) {
45 AliError(Form("Can't open directory <%s>!", baseDir));
49 AliDebug(2,Form("Folder <%s> found",fBaseDirectory.Data()));
50 gSystem->FreeDirectory(dir);
53 fBaseFolder = fBaseDirectory;
56 //_____________________________________________________________________________
57 AliCDBLocal::~AliCDBLocal() {
63 //_____________________________________________________________________________
64 Bool_t AliCDBLocal::FilenameToId(const char* filename, AliCDBRunRange& runRange,
65 Int_t& version, Int_t& subVersion) {
66 // build AliCDBId from filename numbers
71 // valid filename: Run#firstRun_#lastRun_v#version_s#subVersion.root
72 TRegexp keyPattern("^Run[0-9]+_[0-9]+_v[0-9]+_s[0-9]+.root$");
73 keyPattern.Index(filename, &mSize);
75 AliDebug(2, Form("Bad filename <%s>.", filename));
79 TString idString(filename);
80 idString.Resize(idString.Length() - sizeof(".root") + 1);
82 TObjArray* strArray = (TObjArray*) idString.Tokenize("_");
84 TString firstRunString(((TObjString*) strArray->At(0))->GetString());
85 runRange.SetFirstRun(atoi(firstRunString.Data() + 3));
86 runRange.SetLastRun(atoi(((TObjString*) strArray->At(1))->GetString()));
88 TString verString(((TObjString*) strArray->At(2))->GetString());
89 version = atoi(verString.Data() + 1);
91 TString subVerString(((TObjString*) strArray->At(3))->GetString());
92 subVersion = atoi(subVerString.Data() + 1);
100 //_____________________________________________________________________________
101 Bool_t AliCDBLocal::IdToFilename(const AliCDBId& id, TString& filename) const {
102 // build file name from AliCDBId data (run range, version, subVersion)
104 if (!id.GetAliCDBRunRange().IsValid()) {
105 AliDebug(2,Form("Invalid run range <%d, %d>.",
106 id.GetFirstRun(), id.GetLastRun()));
110 if (id.GetVersion() < 0) {
111 AliDebug(2,Form("Invalid version <%d>.", id.GetVersion()));
115 if (id.GetSubVersion() < 0) {
116 AliDebug(2,Form("Invalid subversion <%s>.", id.GetSubVersion()));
120 filename = Form("Run%d_%d_v%d_s%d.root", id.GetFirstRun(), id.GetLastRun(),
121 id.GetVersion(), id.GetSubVersion());
123 filename.Prepend(fBaseDirectory +'/' + id.GetPath() + '/');
128 //_____________________________________________________________________________
129 Bool_t AliCDBLocal::PrepareId(AliCDBId& id) {
130 // prepare id (version, subVersion) of the object that will be stored (called by PutEntry)
132 TString dirName = Form("%s/%s", fBaseDirectory.Data(), id.GetPath().Data());
134 // go to the path; if directory does not exist, create it
135 void* dirPtr = gSystem->OpenDirectory(dirName);
137 gSystem->mkdir(dirName, kTRUE);
138 dirPtr = gSystem->OpenDirectory(dirName);
141 AliError(Form("Can't create directory <%s>!",
147 const char* filename;
148 AliCDBRunRange aRunRange; // the runRange got from filename
149 AliCDBRunRange lastRunRange(-1,-1); // highest runRange found
150 Int_t aVersion, aSubVersion; // the version subVersion got from filename
151 Int_t lastVersion = 0, lastSubVersion = -1; // highest version and subVersion found
153 if (!id.HasVersion()) { // version not specified: look for highest version & subVersion
155 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on the files
157 TString aString(filename);
158 if (aString == "." || aString == "..") continue;
160 if (!FilenameToId(filename, aRunRange, aVersion,
163 "Bad filename <%s>! I'll skip it.",
168 if (!aRunRange.Overlaps(id.GetAliCDBRunRange())) continue;
169 if(aVersion < lastVersion) continue;
170 if(aVersion > lastVersion) lastSubVersion = -1;
171 if(aSubVersion < lastSubVersion) continue;
172 lastVersion = aVersion;
173 lastSubVersion = aSubVersion;
174 lastRunRange = aRunRange;
177 id.SetVersion(lastVersion);
178 id.SetSubVersion(lastSubVersion + 1);
180 } else { // version specified, look for highest subVersion only
182 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on the files
184 TString aString(filename);
185 if (aString == "." || aString == "..") {
189 if (!FilenameToId(filename, aRunRange, aVersion,
192 "Bad filename <%s>!I'll skip it.",
197 if (aRunRange.Overlaps(id.GetAliCDBRunRange())
198 && aVersion == id.GetVersion()
199 && aSubVersion > lastSubVersion) {
200 lastSubVersion = aSubVersion;
201 lastRunRange = aRunRange;
206 id.SetSubVersion(lastSubVersion + 1);
209 gSystem->FreeDirectory(dirPtr);
211 TString lastStorage = id.GetLastStorage();
212 if(lastStorage.Contains(TString("grid"), TString::kIgnoreCase) &&
213 id.GetSubVersion() > 0 ){
214 AliError(Form("Grid to Local Storage error! local object with version v%d_s%d found:",id.GetVersion(), id.GetSubVersion()-1));
215 AliError(Form("This object has been already transferred from Grid (check v%d_s0)!",id.GetVersion()));
219 if(lastStorage.Contains(TString("new"), TString::kIgnoreCase) &&
220 id.GetSubVersion() > 0 ){
221 AliDebug(2, Form("A NEW object is being stored with version v%d_s%d",
222 id.GetVersion(),id.GetSubVersion()));
223 AliDebug(2, Form("and it will hide previously stored object with v%d_s%d!",
224 id.GetVersion(),id.GetSubVersion()-1));
227 if(!lastRunRange.IsAnyRange() && !(lastRunRange.IsEqual(& id.GetAliCDBRunRange())))
228 AliWarning(Form("Run range modified w.r.t. previous version (Run%d_%d_v%d_s%d)",
229 lastRunRange.GetFirstRun(), lastRunRange.GetLastRun(),
230 id.GetVersion(), id.GetSubVersion()-1));
235 // //_____________________________________________________________________________
236 // Bool_t AliCDBLocal::GetId(const AliCDBId& query, AliCDBId& result) {
237 // // look for filename matching query (called by GetEntry)
239 // TString dirName = Form("%s/%s", fBaseDirectory.Data(), query.GetPath().Data());
241 // void* dirPtr = gSystem->OpenDirectory(dirName);
243 // AliDebug(2,Form("Directory <%s> not found", (query.GetPath()).Data()));
244 // AliDebug(2,Form("in DB folder %s", fBaseDirectory.Data()));
248 // const char* filename;
250 // AliCDBRunRange aRunRange; // the runRange got from filename
251 // Int_t aVersion, aSubVersion; // the version and subVersion got from filename
253 // if (!query.HasVersion()) { // neither version and subversion specified -> look for highest version and subVersion
255 // while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
257 // TString aString(filename);
258 // if (aString == "." || aString == "..") continue;
260 // if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
261 // // aRunRange, aVersion, aSubVersion filled from filename
263 // if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
264 // // aRunRange contains requested run!
266 // if (result.GetVersion() < aVersion) {
267 // result.SetVersion(aVersion);
268 // result.SetSubVersion(aSubVersion);
270 // result.SetFirstRun(
271 // aRunRange.GetFirstRun());
272 // result.SetLastRun(
273 // aRunRange.GetLastRun());
275 // } else if (result.GetVersion() == aVersion
276 // && result.GetSubVersion()
279 // result.SetSubVersion(aSubVersion);
281 // result.SetFirstRun(
282 // aRunRange.GetFirstRun());
283 // result.SetLastRun(
284 // aRunRange.GetLastRun());
285 // } else if (result.GetVersion() == aVersion
286 // && result.GetSubVersion() == aSubVersion){
287 // AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
288 // query.GetFirstRun(), aVersion, aSubVersion));
289 // gSystem->FreeDirectory(dirPtr);
294 // } else if (!query.HasSubVersion()) { // version specified but not subversion -> look for highest subVersion
296 // result.SetVersion(query.GetVersion());
298 // while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
300 // TString aString(filename);
301 // if (aString == "." || aString == "..") continue;
303 // if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
304 // // aRunRange, aVersion, aSubVersion filled from filename
306 // if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
307 // // aRunRange contains requested run!
309 // if(query.GetVersion() != aVersion) continue;
310 // // aVersion is requested version!
312 // if(result.GetSubVersion() == aSubVersion){
313 // AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
314 // query.GetFirstRun(), aVersion, aSubVersion));
315 // gSystem->FreeDirectory(dirPtr);
318 // if( result.GetSubVersion() < aSubVersion) {
320 // result.SetSubVersion(aSubVersion);
322 // result.SetFirstRun(
323 // aRunRange.GetFirstRun());
324 // result.SetLastRun(
325 // aRunRange.GetLastRun());
329 // } else { // both version and subversion specified
331 // while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
333 // TString aString(filename);
334 // if (aString == "." || aString == "..") continue;
336 // if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
337 // // aRunRange, aVersion, aSubVersion filled from filename
339 // if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
340 // // aRunRange contains requested run!
342 // if(query.GetVersion() != aVersion || query.GetSubVersion() != aSubVersion) continue;
343 // // aVersion and aSubVersion are requested version and subVersion!
345 // if(result.GetVersion() == aVersion && result.GetSubVersion() == aSubVersion){
346 // AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
347 // query.GetFirstRun(), aVersion, aSubVersion));
348 // gSystem->FreeDirectory(dirPtr);
351 // result.SetVersion(aVersion);
352 // result.SetSubVersion(aSubVersion);
353 // result.SetFirstRun(aRunRange.GetFirstRun());
354 // result.SetLastRun(aRunRange.GetLastRun());
359 // gSystem->FreeDirectory(dirPtr);
364 //_____________________________________________________________________________
365 AliCDBId* AliCDBLocal::GetId(const AliCDBId& query) {
366 // look for filename matching query (called by GetEntryId)
368 TString dirName = Form("%s/%s", fBaseDirectory.Data(), query.GetPath().Data());
370 void* dirPtr = gSystem->OpenDirectory(dirName);
372 AliDebug(2,Form("Directory <%s> not found", (query.GetPath()).Data()));
373 AliDebug(2,Form("in DB folder %s", fBaseDirectory.Data()));
377 const char* filename;
378 AliCDBId *result = new AliCDBId();
379 result->SetPath(query.GetPath());
381 AliCDBRunRange aRunRange; // the runRange got from filename
382 Int_t aVersion, aSubVersion; // the version and subVersion got from filename
384 if (!query.HasVersion()) { // neither version and subversion specified -> look for highest version and subVersion
386 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
388 TString aString(filename);
389 if (aString == "." || aString == "..") continue;
391 if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
392 // aRunRange, aVersion, aSubVersion filled from filename
394 if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
395 // aRunRange contains requested run!
397 if (result->GetVersion() < aVersion) {
398 result->SetVersion(aVersion);
399 result->SetSubVersion(aSubVersion);
402 aRunRange.GetFirstRun());
404 aRunRange.GetLastRun());
406 } else if (result->GetVersion() == aVersion
407 && result->GetSubVersion()
410 result->SetSubVersion(aSubVersion);
413 aRunRange.GetFirstRun());
415 aRunRange.GetLastRun());
416 } else if (result->GetVersion() == aVersion
417 && result->GetSubVersion() == aSubVersion){
418 AliError(Form("More than one object valid for run %d, version %d_%d!",
419 query.GetFirstRun(), aVersion, aSubVersion));
420 gSystem->FreeDirectory(dirPtr);
426 } else if (!query.HasSubVersion()) { // version specified but not subversion -> look for highest subVersion
428 result->SetVersion(query.GetVersion());
430 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
432 TString aString(filename);
433 if (aString == "." || aString == "..") continue;
435 if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
436 // aRunRange, aVersion, aSubVersion filled from filename
438 if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
439 // aRunRange contains requested run!
441 if(query.GetVersion() != aVersion) continue;
442 // aVersion is requested version!
444 if(result->GetSubVersion() == aSubVersion){
445 AliError(Form("More than one object valid for run %d, version %d_%d!",
446 query.GetFirstRun(), aVersion, aSubVersion));
447 gSystem->FreeDirectory(dirPtr);
451 if( result->GetSubVersion() < aSubVersion) {
453 result->SetSubVersion(aSubVersion);
456 aRunRange.GetFirstRun());
458 aRunRange.GetLastRun());
462 } else { // both version and subversion specified
464 //AliCDBId dataId(queryId.GetAliCDBPath(), -1, -1, -1, -1);
466 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
468 TString aString(filename);
469 if (aString == "." || aString == "..") continue;
471 if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
472 // aRunRange, aVersion, aSubVersion filled from filename
474 if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
475 // aRunRange contains requested run!
477 if(query.GetVersion() != aVersion || query.GetSubVersion() != aSubVersion) continue;
478 // aVersion and aSubVersion are requested version and subVersion!
480 if(result->GetVersion() == aVersion && result->GetSubVersion() == aSubVersion){
481 AliError(Form("More than one object valid for run %d, version %d_%d!",
482 query.GetFirstRun(), aVersion, aSubVersion));
483 gSystem->FreeDirectory(dirPtr);
487 result->SetVersion(aVersion);
488 result->SetSubVersion(aSubVersion);
489 result->SetFirstRun(aRunRange.GetFirstRun());
490 result->SetLastRun(aRunRange.GetLastRun());
495 gSystem->FreeDirectory(dirPtr);
500 //_____________________________________________________________________________
501 AliCDBEntry* AliCDBLocal::GetEntry(const AliCDBId& queryId) {
502 // get AliCDBEntry from the database
504 AliCDBId* dataId = GetEntryId(queryId);
506 if (!dataId || !dataId->IsSpecified()) return NULL;
509 if (!IdToFilename(*dataId, filename)) {
511 AliDebug(2,Form("Bad data ID encountered! Subnormal error!"));
516 TFile file(filename, "READ"); // open file
517 if (!file.IsOpen()) {
518 AliDebug(2,Form("Can't open file <%s>!", filename.Data()));
523 // get the only AliCDBEntry object from the file
524 // the object in the file is an AliCDBEntry entry named "AliCDBEntry"
526 AliCDBEntry* anEntry = dynamic_cast<AliCDBEntry*> (file.Get("AliCDBEntry"));
528 AliDebug(2,Form("Bad storage data: No AliCDBEntry in file!"));
534 AliCDBId& entryId = anEntry->GetId();
536 // The object's Id are not reset during storage
537 // If object's Id runRange or version do not match with filename,
538 // it means that someone renamed file by hand. In this case a warning msg is issued.
540 anEntry-> SetLastStorage("local");
542 if(!entryId.IsEqual(dataId)){
543 AliWarning(Form("Mismatch between file name and object's Id!"));
544 AliWarning(Form("File name: %s", dataId->ToString().Data()));
545 AliWarning(Form("Object's Id: %s", entryId.ToString().Data()));
548 // Check whether entry contains a TTree. In case load the tree in memory!
549 LoadTreeFromFile(anEntry);
551 // close file, return retieved entry
557 //_____________________________________________________________________________
558 AliCDBId* AliCDBLocal::GetEntryId(const AliCDBId& queryId) {
559 // get AliCDBId from the database
561 AliCDBId* dataId = 0;
563 // look for a filename matching query requests (path, runRange, version, subVersion)
564 if (!queryId.HasVersion()) {
565 // if version is not specified, first check the selection criteria list
566 AliCDBId selectedId(queryId);
567 GetSelection(&selectedId);
568 dataId = GetId(selectedId);
570 dataId = GetId(queryId);
573 if (dataId && !dataId->IsSpecified()) {
581 //_____________________________________________________________________________
582 void AliCDBLocal::GetEntriesForLevel0(const char* level0,
583 const AliCDBId& queryId, TList* result) {
584 // multiple request (AliCDBStorage::GetAll)
586 TString level0Dir = Form("%s/%s", fBaseDirectory.Data(), level0);
588 void* level0DirPtr = gSystem->OpenDirectory(level0Dir);
590 AliDebug(2,Form("Can't open level0 directory <%s>!",
596 while ((level1 = gSystem->GetDirEntry(level0DirPtr))) {
598 TString level1Str(level1);
599 if (level1Str == "." || level1Str == "..") {
603 if (queryId.GetAliCDBPath().Level1Comprises(level1)) {
604 GetEntriesForLevel1(level0, level1, queryId, result);
608 gSystem->FreeDirectory(level0DirPtr);
611 //_____________________________________________________________________________
612 void AliCDBLocal::GetEntriesForLevel1(const char* level0, const char* level1,
613 const AliCDBId& queryId, TList* result) {
614 // multiple request (AliCDBStorage::GetAll)
616 TString level1Dir = Form("%s/%s/%s", fBaseDirectory.Data(), level0,level1);
618 void* level1DirPtr = gSystem->OpenDirectory(level1Dir);
620 AliDebug(2,Form("Can't open level1 directory <%s>!",
626 while ((level2 = gSystem->GetDirEntry(level1DirPtr))) {
628 TString level2Str(level2);
629 if (level2Str == "." || level2Str == "..") {
633 if (queryId.GetAliCDBPath().Level2Comprises(level2)) {
635 AliCDBPath entryPath(level0, level1, level2);
636 AliCDBId entryId(entryPath, queryId.GetAliCDBRunRange(),
637 queryId.GetVersion(), queryId.GetSubVersion());
639 AliCDBEntry* anEntry = GetEntry(entryId);
641 result->Add(anEntry);
646 gSystem->FreeDirectory(level1DirPtr);
649 //_____________________________________________________________________________
650 TList* AliCDBLocal::GetEntries(const AliCDBId& queryId) {
651 // multiple request (AliCDBStorage::GetAll)
653 void* storageDirPtr = gSystem->OpenDirectory(fBaseDirectory);
654 if (!storageDirPtr) {
655 AliDebug(2,Form("Can't open storage directory <%s>",
656 fBaseDirectory.Data()));
660 TList* result = new TList();
664 while ((level0 = gSystem->GetDirEntry(storageDirPtr))) {
666 TString level0Str(level0);
667 if (level0Str == "." || level0Str == "..") {
671 if (queryId.GetAliCDBPath().Level0Comprises(level0)) {
672 GetEntriesForLevel0(level0, queryId, result);
676 gSystem->FreeDirectory(storageDirPtr);
681 //_____________________________________________________________________________
682 Bool_t AliCDBLocal::PutEntry(AliCDBEntry* entry) {
683 // put an AliCDBEntry object into the database
685 AliCDBId& id = entry->GetId();
687 // set version and subVersion for the entry to be stored
688 if (!PrepareId(id)) return kFALSE;
691 // build filename from entry's id
693 if (!IdToFilename(id, filename)) {
695 AliDebug(2,Form("Bad ID encountered! Subnormal error!"));
700 TFile file(filename, "CREATE");
701 if (!file.IsOpen()) {
702 AliError(Form("Can't open file <%s>!", filename.Data()));
706 //SetTreeToFile(entry, &file);
708 entry->SetVersion(id.GetVersion());
709 entry->SetSubVersion(id.GetSubVersion());
711 // write object (key name: "AliCDBEntry")
712 Bool_t result = file.WriteTObject(entry, "AliCDBEntry");
713 if (!result) AliDebug(2,Form("Can't write entry to file: %s", filename.Data()));
717 if(!(id.GetPath().Contains("SHUTTLE/STATUS")))
718 AliInfo(Form("CDB object stored into file %s",filename.Data()));
724 //_____________________________________________________________________________
725 TList* AliCDBLocal::GetIdListFromFile(const char* fileName){
727 TString fullFileName(fileName);
728 fullFileName.Prepend(fBaseDirectory+'/');
729 TFile *file = TFile::Open(fullFileName);
731 AliError(Form("Can't open selection file <%s>!", fullFileName.Data()));
736 TList *list = new TList();
744 keycycle = "AliCDBId;";
747 id = (AliCDBId*) file->Get(keycycle);
751 file->Close(); delete file; file=0;
755 //_____________________________________________________________________________
756 Bool_t AliCDBLocal::Contains(const char* path) const{
757 // check for path in storage's fBaseDirectory
759 TString dirName = Form("%s/%s", fBaseDirectory.Data(), path);
760 Bool_t result=kFALSE;
762 void* dirPtr = gSystem->OpenDirectory(dirName);
763 if (dirPtr) result=kTRUE;
764 gSystem->FreeDirectory(dirPtr);
769 //_____________________________________________________________________________
770 void AliCDBLocal::QueryValidFiles()
772 // Query the CDB for files valid for AliCDBStorage::fRun
773 // fills list fValidFileIds with AliCDBId objects created from file name
775 if(fVersion != -1) AliWarning ("Version parameter is not used by local storage query!");
776 if(fMetaDataFilter) {
777 AliWarning ("CDB meta data parameters are not used by local storage query!");
778 delete fMetaDataFilter; fMetaDataFilter=0;
781 void* storageDirPtr = gSystem->OpenDirectory(fBaseDirectory);
784 while ((level0 = gSystem->GetDirEntry(storageDirPtr))) {
786 TString level0Str(level0);
787 if (level0Str == "." || level0Str == "..") {
791 if (fPathFilter.Level0Comprises(level0)) {
792 TString level0Dir = Form("%s/%s",fBaseDirectory.Data(),level0);
793 void* level0DirPtr = gSystem->OpenDirectory(level0Dir);
795 while ((level1 = gSystem->GetDirEntry(level0DirPtr))) {
797 TString level1Str(level1);
798 if (level1Str == "." || level1Str == "..") {
802 if (fPathFilter.Level1Comprises(level1)) {
803 TString level1Dir = Form("%s/%s/%s",
804 fBaseDirectory.Data(),level0,level1);
806 void* level1DirPtr = gSystem->OpenDirectory(level1Dir);
808 while ((level2 = gSystem->GetDirEntry(level1DirPtr))) {
810 TString level2Str(level2);
811 if (level2Str == "." || level2Str == "..") {
815 if (fPathFilter.Level2Comprises(level2)) {
816 TString dirName = Form("%s/%s/%s/%s",
817 fBaseDirectory.Data(),level0,level1,level2);
819 void* dirPtr = gSystem->OpenDirectory(dirName);
821 const char* filename;
823 AliCDBRunRange aRunRange; // the runRange got from filename
824 Int_t aVersion, aSubVersion; // the version and subVersion got from filename
826 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
828 TString aString(filename);
829 if (aString == "." || aString == "..") continue;
831 if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
832 AliCDBRunRange runrg(fRun,fRun);
833 if (!aRunRange.Comprises(runrg)) continue;
834 // aRunRange contains requested run!
835 AliCDBPath validPath(level0,level1,level2);
836 AliCDBId validId(validPath,aRunRange,aVersion,aSubVersion);
837 fValidFileIds.AddLast(validId.Clone());
839 gSystem->FreeDirectory(dirPtr);
842 gSystem->FreeDirectory(level1DirPtr);
845 gSystem->FreeDirectory(level0DirPtr);
848 gSystem->FreeDirectory(storageDirPtr);
852 //_____________________________________________________________________________
853 Int_t AliCDBLocal::GetLatestVersion(const char* path, Int_t run){
854 // get last version found in the database valid for run and path
856 AliCDBPath aCDBPath(path);
857 if(!aCDBPath.IsValid() || aCDBPath.IsWildcard()) {
858 AliError(Form("Invalid path in request: %s", path));
862 AliCDBId query(path, run, run, -1, -1);
863 AliCDBId* dataId = GetId(query);
865 if(!dataId) return -1;
867 Int_t version = dataId->GetVersion();
874 //_____________________________________________________________________________
875 Int_t AliCDBLocal::GetLatestSubVersion(const char* path, Int_t run, Int_t version){
876 // get last version found in the database valid for run and path
878 AliCDBPath aCDBPath(path);
879 if(!aCDBPath.IsValid() || aCDBPath.IsWildcard()) {
880 AliError(Form("Invalid path in request: %s", path));
884 AliCDBId query(path, run, run, version, -1);
885 AliCDBId *dataId = GetId(query);
887 if(!dataId) return -1;
889 Int_t subVersion = dataId->GetSubVersion();
896 /////////////////////////////////////////////////////////////////////////////////////////////////
898 // AliCDBLocal factory //
900 /////////////////////////////////////////////////////////////////////////////////////////////////
902 ClassImp(AliCDBLocalFactory)
904 //_____________________________________________________________________________
905 Bool_t AliCDBLocalFactory::Validate(const char* dbString) {
906 // check if the string is valid local URI
908 TRegexp dbPattern("^local://.+$");
910 return TString(dbString).Contains(dbPattern);
913 //_____________________________________________________________________________
914 AliCDBParam* AliCDBLocalFactory::CreateParameter(const char* dbString) {
915 // create AliCDBLocalParam class from the URI string
917 if (!Validate(dbString)) {
921 TString pathname(dbString + sizeof("local://") - 1);
923 gSystem->ExpandPathName(pathname);
925 if (pathname[0] != '/') {
926 pathname.Prepend(TString(gSystem->WorkingDirectory()) + '/');
929 return new AliCDBLocalParam(pathname);
932 //_____________________________________________________________________________
933 AliCDBStorage* AliCDBLocalFactory::Create(const AliCDBParam* param) {
934 // create AliCDBLocal storage instance from parameters
936 if (AliCDBLocalParam::Class() == param->IsA()) {
938 const AliCDBLocalParam* localParam =
939 (const AliCDBLocalParam*) param;
941 return new AliCDBLocal(localParam->GetPath());
947 /////////////////////////////////////////////////////////////////////////////////////////////////
949 // AliCDBLocal Parameter class // //
951 /////////////////////////////////////////////////////////////////////////////////////////////////
953 ClassImp(AliCDBLocalParam)
955 //_____________________________________________________________________________
956 AliCDBLocalParam::AliCDBLocalParam():
960 // default constructor
964 //_____________________________________________________________________________
965 AliCDBLocalParam::AliCDBLocalParam(const char* dbPath):
972 SetURI(TString("local://") + dbPath);
975 //_____________________________________________________________________________
976 AliCDBLocalParam::~AliCDBLocalParam() {
981 //_____________________________________________________________________________
982 AliCDBParam* AliCDBLocalParam::CloneParam() const {
985 return new AliCDBLocalParam(fDBPath);
988 //_____________________________________________________________________________
989 ULong_t AliCDBLocalParam::Hash() const {
990 // return Hash function
992 return fDBPath.Hash();
995 //_____________________________________________________________________________
996 Bool_t AliCDBLocalParam::IsEqual(const TObject* obj) const {
997 // check if this object is equal to AliCDBParam obj
1003 if (AliCDBLocalParam::Class() != obj->IsA()) {
1007 AliCDBLocalParam* other = (AliCDBLocalParam*) obj;
1009 return fDBPath == other->fDBPath;