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 /////////////////////////////////////////////////////////////////////////////////////////////////
25 #include <TObjString.h>
30 #include "AliCDBLocal.h"
31 #include "AliCDBEntry.h"
36 //_____________________________________________________________________________
37 AliCDBLocal::AliCDBLocal(const char* baseDir):
38 fBaseDirectory(baseDir)
42 // check baseDire: trying to cd to baseDir; if it does not exist, create it
43 void* dir = gSystem->OpenDirectory(baseDir);
45 if (gSystem->mkdir(baseDir, kTRUE)) {
46 AliError(Form("Can't open directory <%s>!", baseDir));
50 AliDebug(2,Form("Folder <%s> found",fBaseDirectory.Data()));
51 gSystem->FreeDirectory(dir);
54 fBaseFolder = fBaseDirectory;
57 //_____________________________________________________________________________
58 AliCDBLocal::~AliCDBLocal() {
64 //_____________________________________________________________________________
65 Bool_t AliCDBLocal::FilenameToId(const char* filename, AliCDBRunRange& runRange,
66 Int_t& version, Int_t& subVersion) {
67 // build AliCDBId from filename numbers
72 // valid filename: Run#firstRun_#lastRun_v#version_s#subVersion.root
73 TRegexp keyPattern("^Run[0-9]+_[0-9]+_v[0-9]+_s[0-9]+.root$");
74 keyPattern.Index(filename, &mSize);
76 AliDebug(2, Form("Bad filename <%s>.", filename));
80 TString idString(filename);
81 idString.Resize(idString.Length() - sizeof(".root") + 1);
83 TObjArray* strArray = (TObjArray*) idString.Tokenize("_");
85 TString firstRunString(((TObjString*) strArray->At(0))->GetString());
86 runRange.SetFirstRun(atoi(firstRunString.Data() + 3));
87 runRange.SetLastRun(atoi(((TObjString*) strArray->At(1))->GetString()));
89 TString verString(((TObjString*) strArray->At(2))->GetString());
90 version = atoi(verString.Data() + 1);
92 TString subVerString(((TObjString*) strArray->At(3))->GetString());
93 subVersion = atoi(subVerString.Data() + 1);
101 //_____________________________________________________________________________
102 Bool_t AliCDBLocal::IdToFilename(const AliCDBId& id, TString& filename) const {
103 // build file name from AliCDBId data (run range, version, subVersion)
105 if (!id.GetAliCDBRunRange().IsValid()) {
106 AliDebug(2,Form("Invalid run range <%d, %d>.",
107 id.GetFirstRun(), id.GetLastRun()));
111 if (id.GetVersion() < 0) {
112 AliDebug(2,Form("Invalid version <%d>.", id.GetVersion()));
116 if (id.GetSubVersion() < 0) {
117 AliDebug(2,Form("Invalid subversion <%d>.", id.GetSubVersion()));
121 filename = Form("Run%d_%d_v%d_s%d.root", id.GetFirstRun(), id.GetLastRun(),
122 id.GetVersion(), id.GetSubVersion());
124 filename.Prepend(fBaseDirectory +'/' + id.GetPath() + '/');
129 //_____________________________________________________________________________
130 Bool_t AliCDBLocal::PrepareId(AliCDBId& id) {
131 // prepare id (version, subVersion) of the object that will be stored (called by PutEntry)
133 TString dirName = Form("%s/%s", fBaseDirectory.Data(), id.GetPath().Data());
135 // go to the path; if directory does not exist, create it
136 void* dirPtr = gSystem->OpenDirectory(dirName);
138 gSystem->mkdir(dirName, kTRUE);
139 dirPtr = gSystem->OpenDirectory(dirName);
142 AliError(Form("Can't create directory <%s>!",
148 const char* filename;
149 AliCDBRunRange aRunRange; // the runRange got from filename
150 AliCDBRunRange lastRunRange(-1,-1); // highest runRange found
151 Int_t aVersion, aSubVersion; // the version subVersion got from filename
152 Int_t lastVersion = 0, lastSubVersion = -1; // highest version and subVersion found
154 if (!id.HasVersion()) { // version not specified: look for highest version & subVersion
156 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on the files
158 TString aString(filename);
159 if (aString == "." || aString == "..") continue;
161 if (!FilenameToId(filename, aRunRange, aVersion,
164 "Bad filename <%s>! I'll skip it.",
169 if (!aRunRange.Overlaps(id.GetAliCDBRunRange())) continue;
170 if(aVersion < lastVersion) continue;
171 if(aVersion > lastVersion) lastSubVersion = -1;
172 if(aSubVersion < lastSubVersion) continue;
173 lastVersion = aVersion;
174 lastSubVersion = aSubVersion;
175 lastRunRange = aRunRange;
178 id.SetVersion(lastVersion);
179 id.SetSubVersion(lastSubVersion + 1);
181 } else { // version specified, look for highest subVersion only
183 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on the files
185 TString aString(filename);
186 if (aString == "." || aString == "..") {
190 if (!FilenameToId(filename, aRunRange, aVersion,
193 "Bad filename <%s>!I'll skip it.",
198 if (aRunRange.Overlaps(id.GetAliCDBRunRange())
199 && aVersion == id.GetVersion()
200 && aSubVersion > lastSubVersion) {
201 lastSubVersion = aSubVersion;
202 lastRunRange = aRunRange;
207 id.SetSubVersion(lastSubVersion + 1);
210 gSystem->FreeDirectory(dirPtr);
212 TString lastStorage = id.GetLastStorage();
213 if(lastStorage.Contains(TString("grid"), TString::kIgnoreCase) &&
214 id.GetSubVersion() > 0 ){
215 AliError(Form("Grid to Local Storage error! local object with version v%d_s%d found:",id.GetVersion(), id.GetSubVersion()-1));
216 AliError(Form("This object has been already transferred from Grid (check v%d_s0)!",id.GetVersion()));
220 if(lastStorage.Contains(TString("new"), TString::kIgnoreCase) &&
221 id.GetSubVersion() > 0 ){
222 AliDebug(2, Form("A NEW object is being stored with version v%d_s%d",
223 id.GetVersion(),id.GetSubVersion()));
224 AliDebug(2, Form("and it will hide previously stored object with v%d_s%d!",
225 id.GetVersion(),id.GetSubVersion()-1));
228 if(!lastRunRange.IsAnyRange() && !(lastRunRange.IsEqual(& id.GetAliCDBRunRange())))
229 AliWarning(Form("Run range modified w.r.t. previous version (Run%d_%d_v%d_s%d)",
230 lastRunRange.GetFirstRun(), lastRunRange.GetLastRun(),
231 id.GetVersion(), id.GetSubVersion()-1));
236 // //_____________________________________________________________________________
237 // Bool_t AliCDBLocal::GetId(const AliCDBId& query, AliCDBId& result) {
238 // // look for filename matching query (called by GetEntry)
240 // TString dirName = Form("%s/%s", fBaseDirectory.Data(), query.GetPath().Data());
242 // void* dirPtr = gSystem->OpenDirectory(dirName);
244 // AliDebug(2,Form("Directory <%s> not found", (query.GetPath()).Data()));
245 // AliDebug(2,Form("in DB folder %s", fBaseDirectory.Data()));
249 // const char* filename;
251 // AliCDBRunRange aRunRange; // the runRange got from filename
252 // Int_t aVersion, aSubVersion; // the version and subVersion got from filename
254 // if (!query.HasVersion()) { // neither version and subversion specified -> look for highest version and subVersion
256 // while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
258 // TString aString(filename);
259 // if (aString == "." || aString == "..") continue;
261 // if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
262 // // aRunRange, aVersion, aSubVersion filled from filename
264 // if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
265 // // aRunRange contains requested run!
267 // if (result.GetVersion() < aVersion) {
268 // result.SetVersion(aVersion);
269 // result.SetSubVersion(aSubVersion);
271 // result.SetFirstRun(
272 // aRunRange.GetFirstRun());
273 // result.SetLastRun(
274 // aRunRange.GetLastRun());
276 // } else if (result.GetVersion() == aVersion
277 // && result.GetSubVersion()
280 // result.SetSubVersion(aSubVersion);
282 // result.SetFirstRun(
283 // aRunRange.GetFirstRun());
284 // result.SetLastRun(
285 // aRunRange.GetLastRun());
286 // } else if (result.GetVersion() == aVersion
287 // && result.GetSubVersion() == aSubVersion){
288 // AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
289 // query.GetFirstRun(), aVersion, aSubVersion));
290 // gSystem->FreeDirectory(dirPtr);
295 // } else if (!query.HasSubVersion()) { // version specified but not subversion -> look for highest subVersion
297 // result.SetVersion(query.GetVersion());
299 // while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
301 // TString aString(filename);
302 // if (aString == "." || aString == "..") continue;
304 // if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
305 // // aRunRange, aVersion, aSubVersion filled from filename
307 // if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
308 // // aRunRange contains requested run!
310 // if(query.GetVersion() != aVersion) continue;
311 // // aVersion is requested version!
313 // if(result.GetSubVersion() == aSubVersion){
314 // AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
315 // query.GetFirstRun(), aVersion, aSubVersion));
316 // gSystem->FreeDirectory(dirPtr);
319 // if( result.GetSubVersion() < aSubVersion) {
321 // result.SetSubVersion(aSubVersion);
323 // result.SetFirstRun(
324 // aRunRange.GetFirstRun());
325 // result.SetLastRun(
326 // aRunRange.GetLastRun());
330 // } else { // both version and subversion specified
332 // while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
334 // TString aString(filename);
335 // if (aString == "." || aString == "..") continue;
337 // if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
338 // // aRunRange, aVersion, aSubVersion filled from filename
340 // if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
341 // // aRunRange contains requested run!
343 // if(query.GetVersion() != aVersion || query.GetSubVersion() != aSubVersion) continue;
344 // // aVersion and aSubVersion are requested version and subVersion!
346 // if(result.GetVersion() == aVersion && result.GetSubVersion() == aSubVersion){
347 // AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
348 // query.GetFirstRun(), aVersion, aSubVersion));
349 // gSystem->FreeDirectory(dirPtr);
352 // result.SetVersion(aVersion);
353 // result.SetSubVersion(aSubVersion);
354 // result.SetFirstRun(aRunRange.GetFirstRun());
355 // result.SetLastRun(aRunRange.GetLastRun());
360 // gSystem->FreeDirectory(dirPtr);
365 //_____________________________________________________________________________
366 AliCDBId* AliCDBLocal::GetId(const AliCDBId& query) {
367 // look for filename matching query (called by GetEntryId)
369 TString dirName = Form("%s/%s", fBaseDirectory.Data(), query.GetPath().Data());
371 void* dirPtr = gSystem->OpenDirectory(dirName);
373 AliDebug(2,Form("Directory <%s> not found", (query.GetPath()).Data()));
374 AliDebug(2,Form("in DB folder %s", fBaseDirectory.Data()));
378 const char* filename;
379 AliCDBId *result = new AliCDBId();
380 result->SetPath(query.GetPath());
382 AliCDBRunRange aRunRange; // the runRange got from filename
383 Int_t aVersion, aSubVersion; // the version and subVersion got from filename
385 if (!query.HasVersion()) { // neither version and subversion specified -> look for highest version and subVersion
387 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
389 TString aString(filename);
390 if (aString == "." || aString == "..") continue;
392 if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
393 // aRunRange, aVersion, aSubVersion filled from filename
395 if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
396 // aRunRange contains requested run!
398 AliDebug(1,Form("Filename %s matches\n",filename));
400 if (result->GetVersion() < aVersion) {
401 result->SetVersion(aVersion);
402 result->SetSubVersion(aSubVersion);
405 aRunRange.GetFirstRun());
407 aRunRange.GetLastRun());
409 } else if (result->GetVersion() == aVersion
410 && result->GetSubVersion()
413 result->SetSubVersion(aSubVersion);
416 aRunRange.GetFirstRun());
418 aRunRange.GetLastRun());
419 } else if (result->GetVersion() == aVersion
420 && result->GetSubVersion() == aSubVersion){
421 AliError(Form("More than one object valid for run %d, version %d_%d!",
422 query.GetFirstRun(), aVersion, aSubVersion));
423 gSystem->FreeDirectory(dirPtr);
429 } else if (!query.HasSubVersion()) { // version specified but not subversion -> look for highest subVersion
431 result->SetVersion(query.GetVersion());
433 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
435 TString aString(filename);
436 if (aString == "." || aString == "..") continue;
438 if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
439 // aRunRange, aVersion, aSubVersion filled from filename
441 if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
442 // aRunRange contains requested run!
444 if(query.GetVersion() != aVersion) continue;
445 // aVersion is requested version!
447 if(result->GetSubVersion() == aSubVersion){
448 AliError(Form("More than one object valid for run %d, version %d_%d!",
449 query.GetFirstRun(), aVersion, aSubVersion));
450 gSystem->FreeDirectory(dirPtr);
454 if( result->GetSubVersion() < aSubVersion) {
456 result->SetSubVersion(aSubVersion);
459 aRunRange.GetFirstRun());
461 aRunRange.GetLastRun());
465 } else { // both version and subversion specified
467 //AliCDBId dataId(queryId.GetAliCDBPath(), -1, -1, -1, -1);
469 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
471 TString aString(filename);
472 if (aString == "." || aString == "..") continue;
474 if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
475 // aRunRange, aVersion, aSubVersion filled from filename
477 if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
478 // aRunRange contains requested run!
480 if(query.GetVersion() != aVersion || query.GetSubVersion() != aSubVersion) continue;
481 // aVersion and aSubVersion are requested version and subVersion!
483 if(result->GetVersion() == aVersion && result->GetSubVersion() == aSubVersion){
484 AliError(Form("More than one object valid for run %d, version %d_%d!",
485 query.GetFirstRun(), aVersion, aSubVersion));
486 gSystem->FreeDirectory(dirPtr);
490 result->SetVersion(aVersion);
491 result->SetSubVersion(aSubVersion);
492 result->SetFirstRun(aRunRange.GetFirstRun());
493 result->SetLastRun(aRunRange.GetLastRun());
498 gSystem->FreeDirectory(dirPtr);
503 //_____________________________________________________________________________
504 AliCDBEntry* AliCDBLocal::GetEntry(const AliCDBId& queryId) {
505 // get AliCDBEntry from the database
507 AliCDBId* dataId = GetEntryId(queryId);
509 if (!dataId || !dataId->IsSpecified()) return NULL;
512 if (!IdToFilename(*dataId, filename)) {
514 AliDebug(2,Form("Bad data ID encountered! Subnormal error!"));
519 TFile file(filename, "READ"); // open file
520 if (!file.IsOpen()) {
521 AliDebug(2,Form("Can't open file <%s>!", filename.Data()));
526 // get the only AliCDBEntry object from the file
527 // the object in the file is an AliCDBEntry entry named "AliCDBEntry"
529 AliCDBEntry* anEntry = dynamic_cast<AliCDBEntry*> (file.Get("AliCDBEntry"));
531 AliDebug(2,Form("Bad storage data: No AliCDBEntry in file!"));
537 AliCDBId& entryId = anEntry->GetId();
539 // The object's Id are not reset during storage
540 // If object's Id runRange or version do not match with filename,
541 // it means that someone renamed file by hand. In this case a warning msg is issued.
543 anEntry-> SetLastStorage("local");
545 if(!entryId.IsEqual(dataId)){
546 AliWarning(Form("Mismatch between file name and object's Id!"));
547 AliWarning(Form("File name: %s", dataId->ToString().Data()));
548 AliWarning(Form("Object's Id: %s", entryId.ToString().Data()));
551 // Check whether entry contains a TTree. In case load the tree in memory!
552 LoadTreeFromFile(anEntry);
554 // close file, return retieved entry
560 //_____________________________________________________________________________
561 AliCDBId* AliCDBLocal::GetEntryId(const AliCDBId& queryId) {
562 // get AliCDBId from the database
564 AliCDBId* dataId = 0;
566 // look for a filename matching query requests (path, runRange, version, subVersion)
567 if (!queryId.HasVersion()) {
568 // if version is not specified, first check the selection criteria list
569 AliCDBId selectedId(queryId);
570 GetSelection(&selectedId);
571 dataId = GetId(selectedId);
573 dataId = GetId(queryId);
576 if (dataId && !dataId->IsSpecified()) {
584 //_____________________________________________________________________________
585 void AliCDBLocal::GetEntriesForLevel0(const char* level0,
586 const AliCDBId& queryId, TList* result) {
587 // multiple request (AliCDBStorage::GetAll)
589 TString level0Dir = Form("%s/%s", fBaseDirectory.Data(), level0);
591 void* level0DirPtr = gSystem->OpenDirectory(level0Dir);
593 AliDebug(2,Form("Can't open level0 directory <%s>!",
600 while ((level1 = gSystem->GetDirEntry(level0DirPtr))) {
602 TString level1Str(level1);
603 if (level1Str == "." || level1Str == "..") {
607 TString fullPath = Form("%s/%s",level0Dir.Data(), level1);
609 Int_t res=gSystem->GetPathInfo(fullPath.Data(), 0, (Long64_t*) 0, &flag, 0);
612 AliDebug(2, Form("Error reading entry %s !",level1Str.Data()));
615 if(!(flag&2)) continue; // bit 1 of flag = directory!
617 if (queryId.GetAliCDBPath().Level1Comprises(level1)) {
618 GetEntriesForLevel1(level0, level1, queryId, result);
622 gSystem->FreeDirectory(level0DirPtr);
625 //_____________________________________________________________________________
626 void AliCDBLocal::GetEntriesForLevel1(const char* level0, const char* level1,
627 const AliCDBId& queryId, TList* result) {
628 // multiple request (AliCDBStorage::GetAll)
630 TString level1Dir = Form("%s/%s/%s", fBaseDirectory.Data(), level0,level1);
632 void* level1DirPtr = gSystem->OpenDirectory(level1Dir);
634 AliDebug(2,Form("Can't open level1 directory <%s>!",
641 while ((level2 = gSystem->GetDirEntry(level1DirPtr))) {
643 TString level2Str(level2);
644 if (level2Str == "." || level2Str == "..") {
648 TString fullPath = Form("%s/%s",level1Dir.Data(), level2);
650 Int_t res=gSystem->GetPathInfo(fullPath.Data(), 0, (Long64_t*) 0, &flag, 0);
653 AliDebug(2, Form("Error reading entry %s !",level2Str.Data()));
656 if(!(flag&2)) continue; // bit 1 of flag = directory!
658 if (queryId.GetAliCDBPath().Level2Comprises(level2)) {
660 AliCDBPath entryPath(level0, level1, level2);
661 AliCDBId entryId(entryPath, queryId.GetAliCDBRunRange(),
662 queryId.GetVersion(), queryId.GetSubVersion());
664 AliCDBEntry* anEntry = GetEntry(entryId);
666 result->Add(anEntry);
671 gSystem->FreeDirectory(level1DirPtr);
674 //_____________________________________________________________________________
675 TList* AliCDBLocal::GetEntries(const AliCDBId& queryId) {
676 // multiple request (AliCDBStorage::GetAll)
678 void* storageDirPtr = gSystem->OpenDirectory(fBaseDirectory);
679 if (!storageDirPtr) {
680 AliDebug(2,Form("Can't open storage directory <%s>",
681 fBaseDirectory.Data()));
685 TList* result = new TList();
690 while ((level0 = gSystem->GetDirEntry(storageDirPtr))) {
692 TString level0Str(level0);
693 if (level0Str == "." || level0Str == "..") {
697 TString fullPath = Form("%s/%s",fBaseDirectory.Data(), level0);
699 Int_t res=gSystem->GetPathInfo(fullPath.Data(), 0, (Long64_t*) 0, &flag, 0);
702 AliDebug(2, Form("Error reading entry %s !",level0Str.Data()));
706 if(!(flag&2)) continue; // bit 1 of flag = directory!
708 if (queryId.GetAliCDBPath().Level0Comprises(level0)) {
709 GetEntriesForLevel0(level0, queryId, result);
713 gSystem->FreeDirectory(storageDirPtr);
718 //_____________________________________________________________________________
719 Bool_t AliCDBLocal::PutEntry(AliCDBEntry* entry) {
720 // put an AliCDBEntry object into the database
722 AliCDBId& id = entry->GetId();
724 // set version and subVersion for the entry to be stored
725 if (!PrepareId(id)) return kFALSE;
728 // build filename from entry's id
730 if (!IdToFilename(id, filename)) {
732 AliDebug(2,Form("Bad ID encountered! Subnormal error!"));
737 TFile file(filename, "CREATE");
738 if (!file.IsOpen()) {
739 AliError(Form("Can't open file <%s>!", filename.Data()));
743 //SetTreeToFile(entry, &file);
745 entry->SetVersion(id.GetVersion());
746 entry->SetSubVersion(id.GetSubVersion());
748 // write object (key name: "AliCDBEntry")
749 Bool_t result = file.WriteTObject(entry, "AliCDBEntry");
750 if (!result) AliDebug(2,Form("Can't write entry to file: %s", filename.Data()));
754 if(!(id.GetPath().Contains("SHUTTLE/STATUS")))
755 AliInfo(Form("CDB object stored into file %s",filename.Data()));
761 //_____________________________________________________________________________
762 TList* AliCDBLocal::GetIdListFromFile(const char* fileName){
764 TString fullFileName(fileName);
765 fullFileName.Prepend(fBaseDirectory+'/');
766 TFile *file = TFile::Open(fullFileName);
768 AliError(Form("Can't open selection file <%s>!", fullFileName.Data()));
773 TList *list = new TList();
781 keycycle = "AliCDBId;";
784 id = (AliCDBId*) file->Get(keycycle);
788 file->Close(); delete file; file=0;
792 //_____________________________________________________________________________
793 Bool_t AliCDBLocal::Contains(const char* path) const{
794 // check for path in storage's fBaseDirectory
796 TString dirName = Form("%s/%s", fBaseDirectory.Data(), path);
797 Bool_t result=kFALSE;
799 void* dirPtr = gSystem->OpenDirectory(dirName);
800 if (dirPtr) result=kTRUE;
801 gSystem->FreeDirectory(dirPtr);
806 //_____________________________________________________________________________
807 void AliCDBLocal::QueryValidFiles()
809 // Query the CDB for files valid for AliCDBStorage::fRun
810 // fills list fValidFileIds with AliCDBId objects created from file name
812 if(fVersion != -1) AliWarning ("Version parameter is not used by local storage query!");
813 if(fMetaDataFilter) {
814 AliWarning ("CDB meta data parameters are not used by local storage query!");
815 delete fMetaDataFilter; fMetaDataFilter=0;
818 void* storageDirPtr = gSystem->OpenDirectory(fBaseDirectory);
821 while ((level0 = gSystem->GetDirEntry(storageDirPtr))) {
823 TString level0Str(level0);
824 if (level0Str == "." || level0Str == "..") {
828 if (fPathFilter.Level0Comprises(level0)) {
829 TString level0Dir = Form("%s/%s",fBaseDirectory.Data(),level0);
830 void* level0DirPtr = gSystem->OpenDirectory(level0Dir);
832 while ((level1 = gSystem->GetDirEntry(level0DirPtr))) {
834 TString level1Str(level1);
835 if (level1Str == "." || level1Str == "..") {
839 if (fPathFilter.Level1Comprises(level1)) {
840 TString level1Dir = Form("%s/%s/%s",
841 fBaseDirectory.Data(),level0,level1);
843 void* level1DirPtr = gSystem->OpenDirectory(level1Dir);
845 while ((level2 = gSystem->GetDirEntry(level1DirPtr))) {
847 TString level2Str(level2);
848 if (level2Str == "." || level2Str == "..") {
852 if (fPathFilter.Level2Comprises(level2)) {
853 TString dirName = Form("%s/%s/%s/%s",
854 fBaseDirectory.Data(),level0,level1,level2);
856 void* dirPtr = gSystem->OpenDirectory(dirName);
858 const char* filename;
860 AliCDBRunRange aRunRange; // the runRange got from filename
861 Int_t aVersion, aSubVersion; // the version and subVersion got from filename
863 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
865 TString aString(filename);
866 if (aString == "." || aString == "..") continue;
868 if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
869 AliCDBRunRange runrg(fRun,fRun);
870 if (!aRunRange.Comprises(runrg)) continue;
871 // aRunRange contains requested run!
872 AliCDBPath validPath(level0,level1,level2);
873 AliCDBId validId(validPath,aRunRange,aVersion,aSubVersion);
874 fValidFileIds.AddLast(validId.Clone());
876 gSystem->FreeDirectory(dirPtr);
879 gSystem->FreeDirectory(level1DirPtr);
882 gSystem->FreeDirectory(level0DirPtr);
885 gSystem->FreeDirectory(storageDirPtr);
889 //_____________________________________________________________________________
890 Int_t AliCDBLocal::GetLatestVersion(const char* path, Int_t run){
891 // get last version found in the database valid for run and path
893 AliCDBPath aCDBPath(path);
894 if(!aCDBPath.IsValid() || aCDBPath.IsWildcard()) {
895 AliError(Form("Invalid path in request: %s", path));
899 AliCDBId query(path, run, run, -1, -1);
900 AliCDBId* dataId = GetId(query);
902 if(!dataId) return -1;
904 Int_t version = dataId->GetVersion();
911 //_____________________________________________________________________________
912 Int_t AliCDBLocal::GetLatestSubVersion(const char* path, Int_t run, Int_t version){
913 // get last version found in the database valid for run and path
915 AliCDBPath aCDBPath(path);
916 if(!aCDBPath.IsValid() || aCDBPath.IsWildcard()) {
917 AliError(Form("Invalid path in request: %s", path));
921 AliCDBId query(path, run, run, version, -1);
922 AliCDBId *dataId = GetId(query);
924 if(!dataId) return -1;
926 Int_t subVersion = dataId->GetSubVersion();
933 /////////////////////////////////////////////////////////////////////////////////////////////////
935 // AliCDBLocal factory //
937 /////////////////////////////////////////////////////////////////////////////////////////////////
939 ClassImp(AliCDBLocalFactory)
941 //_____________________________________________________________________________
942 Bool_t AliCDBLocalFactory::Validate(const char* dbString) {
943 // check if the string is valid local URI
945 TRegexp dbPattern("^local://.+$");
947 return TString(dbString).Contains(dbPattern);
950 //_____________________________________________________________________________
951 AliCDBParam* AliCDBLocalFactory::CreateParameter(const char* dbString) {
952 // create AliCDBLocalParam class from the URI string
954 if (!Validate(dbString)) {
958 TString pathname(dbString + sizeof("local://") - 1);
960 gSystem->ExpandPathName(pathname);
962 if (pathname[0] != '/') {
963 pathname.Prepend(TString(gSystem->WorkingDirectory()) + '/');
966 return new AliCDBLocalParam(pathname);
969 //_____________________________________________________________________________
970 AliCDBStorage* AliCDBLocalFactory::Create(const AliCDBParam* param) {
971 // create AliCDBLocal storage instance from parameters
973 if (AliCDBLocalParam::Class() == param->IsA()) {
975 const AliCDBLocalParam* localParam =
976 (const AliCDBLocalParam*) param;
978 return new AliCDBLocal(localParam->GetPath());
984 /////////////////////////////////////////////////////////////////////////////////////////////////
986 // AliCDBLocal Parameter class // //
988 /////////////////////////////////////////////////////////////////////////////////////////////////
990 ClassImp(AliCDBLocalParam)
992 //_____________________________________________________________________________
993 AliCDBLocalParam::AliCDBLocalParam():
997 // default constructor
1001 //_____________________________________________________________________________
1002 AliCDBLocalParam::AliCDBLocalParam(const char* dbPath):
1009 SetURI(TString("local://") + dbPath);
1012 //_____________________________________________________________________________
1013 AliCDBLocalParam::~AliCDBLocalParam() {
1018 //_____________________________________________________________________________
1019 AliCDBParam* AliCDBLocalParam::CloneParam() const {
1022 return new AliCDBLocalParam(fDBPath);
1025 //_____________________________________________________________________________
1026 ULong_t AliCDBLocalParam::Hash() const {
1027 // return Hash function
1029 return fDBPath.Hash();
1032 //_____________________________________________________________________________
1033 Bool_t AliCDBLocalParam::IsEqual(const TObject* obj) const {
1034 // check if this object is equal to AliCDBParam obj
1040 if (AliCDBLocalParam::Class() != obj->IsA()) {
1044 AliCDBLocalParam* other = (AliCDBLocalParam*) obj;
1046 return fDBPath == other->fDBPath;