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 AliDebug(1, Form("fBaseDirectory = %s",fBaseDirectory.Data()));
44 // check baseDire: trying to cd to baseDir; if it does not exist, create it
45 void* dir = gSystem->OpenDirectory(baseDir);
47 if (gSystem->mkdir(baseDir, kTRUE)) {
48 AliError(Form("Can't open directory <%s>!", baseDir));
52 AliDebug(2,Form("Folder <%s> found",fBaseDirectory.Data()));
53 gSystem->FreeDirectory(dir);
56 fBaseFolder = fBaseDirectory;
59 //_____________________________________________________________________________
60 AliCDBLocal::~AliCDBLocal() {
66 //_____________________________________________________________________________
67 Bool_t AliCDBLocal::FilenameToId(const char* filename, AliCDBRunRange& runRange,
68 Int_t& version, Int_t& subVersion) {
69 // build AliCDBId from filename numbers
74 // valid filename: Run#firstRun_#lastRun_v#version_s#subVersion.root
75 TRegexp keyPattern("^Run[0-9]+_[0-9]+_v[0-9]+_s[0-9]+.root$");
76 keyPattern.Index(filename, &mSize);
78 AliDebug(2, Form("Bad filename <%s>.", filename));
82 TString idString(filename);
83 idString.Resize(idString.Length() - sizeof(".root") + 1);
85 TObjArray* strArray = (TObjArray*) idString.Tokenize("_");
87 TString firstRunString(((TObjString*) strArray->At(0))->GetString());
88 runRange.SetFirstRun(atoi(firstRunString.Data() + 3));
89 runRange.SetLastRun(atoi(((TObjString*) strArray->At(1))->GetString()));
91 TString verString(((TObjString*) strArray->At(2))->GetString());
92 version = atoi(verString.Data() + 1);
94 TString subVerString(((TObjString*) strArray->At(3))->GetString());
95 subVersion = atoi(subVerString.Data() + 1);
103 //_____________________________________________________________________________
104 Bool_t AliCDBLocal::IdToFilename(const AliCDBId& id, TString& filename) const {
105 // build file name from AliCDBId data (run range, version, subVersion)
107 AliDebug(1, Form("fBaseDirectory = %s",fBaseDirectory.Data()));
109 if (!id.GetAliCDBRunRange().IsValid()) {
110 AliDebug(2,Form("Invalid run range <%d, %d>.",
111 id.GetFirstRun(), id.GetLastRun()));
115 if (id.GetVersion() < 0) {
116 AliDebug(2,Form("Invalid version <%d>.", id.GetVersion()));
120 if (id.GetSubVersion() < 0) {
121 AliDebug(2,Form("Invalid subversion <%d>.", id.GetSubVersion()));
125 filename = Form("Run%d_%d_v%d_s%d.root", id.GetFirstRun(), id.GetLastRun(),
126 id.GetVersion(), id.GetSubVersion());
128 filename.Prepend(fBaseDirectory +'/' + id.GetPath() + '/');
133 //_____________________________________________________________________________
134 Bool_t AliCDBLocal::PrepareId(AliCDBId& id) {
135 // prepare id (version, subVersion) of the object that will be stored (called by PutEntry)
137 TString dirName = Form("%s/%s", fBaseDirectory.Data(), id.GetPath().Data());
139 // go to the path; if directory does not exist, create it
140 void* dirPtr = gSystem->OpenDirectory(dirName);
142 gSystem->mkdir(dirName, kTRUE);
143 dirPtr = gSystem->OpenDirectory(dirName);
146 AliError(Form("Can't create directory <%s>!",
152 const char* filename;
153 AliCDBRunRange aRunRange; // the runRange got from filename
154 AliCDBRunRange lastRunRange(-1,-1); // highest runRange found
155 Int_t aVersion, aSubVersion; // the version subVersion got from filename
156 Int_t lastVersion = 0, lastSubVersion = -1; // highest version and subVersion found
158 if (!id.HasVersion()) { // version not specified: look for highest version & subVersion
160 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on the files
162 TString aString(filename);
163 if (aString == "." || aString == "..") continue;
165 if (!FilenameToId(filename, aRunRange, aVersion,
168 "Bad filename <%s>! I'll skip it.",
173 if (!aRunRange.Overlaps(id.GetAliCDBRunRange())) continue;
174 if(aVersion < lastVersion) continue;
175 if(aVersion > lastVersion) lastSubVersion = -1;
176 if(aSubVersion < lastSubVersion) continue;
177 lastVersion = aVersion;
178 lastSubVersion = aSubVersion;
179 lastRunRange = aRunRange;
182 id.SetVersion(lastVersion);
183 id.SetSubVersion(lastSubVersion + 1);
185 } else { // version specified, look for highest subVersion only
187 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on the files
189 TString aString(filename);
190 if (aString == "." || aString == "..") {
194 if (!FilenameToId(filename, aRunRange, aVersion,
197 "Bad filename <%s>!I'll skip it.",
202 if (aRunRange.Overlaps(id.GetAliCDBRunRange())
203 && aVersion == id.GetVersion()
204 && aSubVersion > lastSubVersion) {
205 lastSubVersion = aSubVersion;
206 lastRunRange = aRunRange;
211 id.SetSubVersion(lastSubVersion + 1);
214 gSystem->FreeDirectory(dirPtr);
216 TString lastStorage = id.GetLastStorage();
217 if(lastStorage.Contains(TString("grid"), TString::kIgnoreCase) &&
218 id.GetSubVersion() > 0 ){
219 AliError(Form("Grid to Local Storage error! local object with version v%d_s%d found:",id.GetVersion(), id.GetSubVersion()-1));
220 AliError(Form("This object has been already transferred from Grid (check v%d_s0)!",id.GetVersion()));
224 if(lastStorage.Contains(TString("new"), TString::kIgnoreCase) &&
225 id.GetSubVersion() > 0 ){
226 AliDebug(2, Form("A NEW object is being stored with version v%d_s%d",
227 id.GetVersion(),id.GetSubVersion()));
228 AliDebug(2, Form("and it will hide previously stored object with v%d_s%d!",
229 id.GetVersion(),id.GetSubVersion()-1));
232 if(!lastRunRange.IsAnyRange() && !(lastRunRange.IsEqual(& id.GetAliCDBRunRange())))
233 AliWarning(Form("Run range modified w.r.t. previous version (Run%d_%d_v%d_s%d)",
234 lastRunRange.GetFirstRun(), lastRunRange.GetLastRun(),
235 id.GetVersion(), id.GetSubVersion()-1));
240 // //_____________________________________________________________________________
241 // Bool_t AliCDBLocal::GetId(const AliCDBId& query, AliCDBId& result) {
242 // // look for filename matching query (called by GetEntry)
244 // TString dirName = Form("%s/%s", fBaseDirectory.Data(), query.GetPath().Data());
246 // void* dirPtr = gSystem->OpenDirectory(dirName);
248 // AliDebug(2,Form("Directory <%s> not found", (query.GetPath()).Data()));
249 // AliDebug(2,Form("in DB folder %s", fBaseDirectory.Data()));
253 // const char* filename;
255 // AliCDBRunRange aRunRange; // the runRange got from filename
256 // Int_t aVersion, aSubVersion; // the version and subVersion got from filename
258 // if (!query.HasVersion()) { // neither version and subversion specified -> look for highest version and subVersion
260 // while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
262 // TString aString(filename);
263 // if (aString == "." || aString == "..") continue;
265 // if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
266 // // aRunRange, aVersion, aSubVersion filled from filename
268 // if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
269 // // aRunRange contains requested run!
271 // if (result.GetVersion() < aVersion) {
272 // result.SetVersion(aVersion);
273 // result.SetSubVersion(aSubVersion);
275 // result.SetFirstRun(
276 // aRunRange.GetFirstRun());
277 // result.SetLastRun(
278 // aRunRange.GetLastRun());
280 // } else if (result.GetVersion() == aVersion
281 // && result.GetSubVersion()
284 // result.SetSubVersion(aSubVersion);
286 // result.SetFirstRun(
287 // aRunRange.GetFirstRun());
288 // result.SetLastRun(
289 // aRunRange.GetLastRun());
290 // } else if (result.GetVersion() == aVersion
291 // && result.GetSubVersion() == aSubVersion){
292 // AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
293 // query.GetFirstRun(), aVersion, aSubVersion));
294 // gSystem->FreeDirectory(dirPtr);
299 // } else if (!query.HasSubVersion()) { // version specified but not subversion -> look for highest subVersion
301 // result.SetVersion(query.GetVersion());
303 // while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
305 // TString aString(filename);
306 // if (aString == "." || aString == "..") continue;
308 // if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
309 // // aRunRange, aVersion, aSubVersion filled from filename
311 // if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
312 // // aRunRange contains requested run!
314 // if(query.GetVersion() != aVersion) continue;
315 // // aVersion is requested version!
317 // if(result.GetSubVersion() == aSubVersion){
318 // AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
319 // query.GetFirstRun(), aVersion, aSubVersion));
320 // gSystem->FreeDirectory(dirPtr);
323 // if( result.GetSubVersion() < aSubVersion) {
325 // result.SetSubVersion(aSubVersion);
327 // result.SetFirstRun(
328 // aRunRange.GetFirstRun());
329 // result.SetLastRun(
330 // aRunRange.GetLastRun());
334 // } else { // both version and subversion specified
336 // while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
338 // TString aString(filename);
339 // if (aString == "." || aString == "..") continue;
341 // if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
342 // // aRunRange, aVersion, aSubVersion filled from filename
344 // if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
345 // // aRunRange contains requested run!
347 // if(query.GetVersion() != aVersion || query.GetSubVersion() != aSubVersion) continue;
348 // // aVersion and aSubVersion are requested version and subVersion!
350 // if(result.GetVersion() == aVersion && result.GetSubVersion() == aSubVersion){
351 // AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
352 // query.GetFirstRun(), aVersion, aSubVersion));
353 // gSystem->FreeDirectory(dirPtr);
356 // result.SetVersion(aVersion);
357 // result.SetSubVersion(aSubVersion);
358 // result.SetFirstRun(aRunRange.GetFirstRun());
359 // result.SetLastRun(aRunRange.GetLastRun());
364 // gSystem->FreeDirectory(dirPtr);
369 //_____________________________________________________________________________
370 AliCDBId* AliCDBLocal::GetId(const AliCDBId& query) {
371 // look for filename matching query (called by GetEntryId)
373 TString dirName = Form("%s/%s", fBaseDirectory.Data(), query.GetPath().Data());
375 void* dirPtr = gSystem->OpenDirectory(dirName);
377 AliDebug(2,Form("Directory <%s> not found", (query.GetPath()).Data()));
378 AliDebug(2,Form("in DB folder %s", fBaseDirectory.Data()));
382 const char* filename;
383 AliCDBId *result = new AliCDBId();
384 result->SetPath(query.GetPath());
386 AliCDBRunRange aRunRange; // the runRange got from filename
387 Int_t aVersion, aSubVersion; // the version and subVersion got from filename
389 if (!query.HasVersion()) { // neither version and subversion specified -> look for highest version and subVersion
391 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
393 TString aString(filename);
394 if (aString == "." || aString == "..") continue;
396 if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
397 // aRunRange, aVersion, aSubVersion filled from filename
399 if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
400 // aRunRange contains requested run!
402 AliDebug(1,Form("Filename %s matches\n",filename));
404 if (result->GetVersion() < aVersion) {
405 result->SetVersion(aVersion);
406 result->SetSubVersion(aSubVersion);
409 aRunRange.GetFirstRun());
411 aRunRange.GetLastRun());
413 } else if (result->GetVersion() == aVersion
414 && result->GetSubVersion()
417 result->SetSubVersion(aSubVersion);
420 aRunRange.GetFirstRun());
422 aRunRange.GetLastRun());
423 } else if (result->GetVersion() == aVersion
424 && result->GetSubVersion() == aSubVersion){
425 AliError(Form("More than one object valid for run %d, version %d_%d!",
426 query.GetFirstRun(), aVersion, aSubVersion));
427 gSystem->FreeDirectory(dirPtr);
433 } else if (!query.HasSubVersion()) { // version specified but not subversion -> look for highest subVersion
435 result->SetVersion(query.GetVersion());
437 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
439 TString aString(filename);
440 if (aString == "." || aString == "..") continue;
442 if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
443 // aRunRange, aVersion, aSubVersion filled from filename
445 if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
446 // aRunRange contains requested run!
448 if(query.GetVersion() != aVersion) continue;
449 // aVersion is requested version!
451 if(result->GetSubVersion() == aSubVersion){
452 AliError(Form("More than one object valid for run %d, version %d_%d!",
453 query.GetFirstRun(), aVersion, aSubVersion));
454 gSystem->FreeDirectory(dirPtr);
458 if( result->GetSubVersion() < aSubVersion) {
460 result->SetSubVersion(aSubVersion);
463 aRunRange.GetFirstRun());
465 aRunRange.GetLastRun());
469 } else { // both version and subversion specified
471 //AliCDBId dataId(queryId.GetAliCDBPath(), -1, -1, -1, -1);
473 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
475 TString aString(filename);
476 if (aString == "." || aString == "..") continue;
478 if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
479 // aRunRange, aVersion, aSubVersion filled from filename
481 if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
482 // aRunRange contains requested run!
484 if(query.GetVersion() != aVersion || query.GetSubVersion() != aSubVersion) continue;
485 // aVersion and aSubVersion are requested version and subVersion!
487 if(result->GetVersion() == aVersion && result->GetSubVersion() == aSubVersion){
488 AliError(Form("More than one object valid for run %d, version %d_%d!",
489 query.GetFirstRun(), aVersion, aSubVersion));
490 gSystem->FreeDirectory(dirPtr);
494 result->SetVersion(aVersion);
495 result->SetSubVersion(aSubVersion);
496 result->SetFirstRun(aRunRange.GetFirstRun());
497 result->SetLastRun(aRunRange.GetLastRun());
502 gSystem->FreeDirectory(dirPtr);
507 //_____________________________________________________________________________
508 AliCDBEntry* AliCDBLocal::GetEntry(const AliCDBId& queryId) {
509 // get AliCDBEntry from the database
511 AliCDBId* dataId = GetEntryId(queryId);
513 if (!dataId || !dataId->IsSpecified()) return NULL;
516 if (!IdToFilename(*dataId, filename)) {
518 AliDebug(2,Form("Bad data ID encountered! Subnormal error!"));
523 TFile file(filename, "READ"); // open file
524 if (!file.IsOpen()) {
525 AliDebug(2,Form("Can't open file <%s>!", filename.Data()));
530 // get the only AliCDBEntry object from the file
531 // the object in the file is an AliCDBEntry entry named "AliCDBEntry"
533 AliCDBEntry* anEntry = dynamic_cast<AliCDBEntry*> (file.Get("AliCDBEntry"));
535 AliDebug(2,Form("Bad storage data: No AliCDBEntry in file!"));
541 AliCDBId& entryId = anEntry->GetId();
543 // The object's Id are not reset during storage
544 // If object's Id runRange or version do not match with filename,
545 // it means that someone renamed file by hand. In this case a warning msg is issued.
547 anEntry-> SetLastStorage("local");
549 if(!entryId.IsEqual(dataId)){
550 AliWarning(Form("Mismatch between file name and object's Id!"));
551 AliWarning(Form("File name: %s", dataId->ToString().Data()));
552 AliWarning(Form("Object's Id: %s", entryId.ToString().Data()));
555 // Check whether entry contains a TTree. In case load the tree in memory!
556 LoadTreeFromFile(anEntry);
558 // close file, return retieved entry
564 //_____________________________________________________________________________
565 AliCDBId* AliCDBLocal::GetEntryId(const AliCDBId& queryId) {
566 // get AliCDBId from the database
568 AliCDBId* dataId = 0;
570 // look for a filename matching query requests (path, runRange, version, subVersion)
571 if (!queryId.HasVersion()) {
572 // if version is not specified, first check the selection criteria list
573 AliCDBId selectedId(queryId);
574 GetSelection(&selectedId);
575 dataId = GetId(selectedId);
577 dataId = GetId(queryId);
580 if (dataId && !dataId->IsSpecified()) {
588 //_____________________________________________________________________________
589 void AliCDBLocal::GetEntriesForLevel0(const char* level0,
590 const AliCDBId& queryId, TList* result) {
591 // multiple request (AliCDBStorage::GetAll)
593 TString level0Dir = Form("%s/%s", fBaseDirectory.Data(), level0);
595 void* level0DirPtr = gSystem->OpenDirectory(level0Dir);
597 AliDebug(2,Form("Can't open level0 directory <%s>!",
604 while ((level1 = gSystem->GetDirEntry(level0DirPtr))) {
606 TString level1Str(level1);
607 if (level1Str == "." || level1Str == "..") {
611 TString fullPath = Form("%s/%s",level0Dir.Data(), level1);
613 Int_t res=gSystem->GetPathInfo(fullPath.Data(), 0, (Long64_t*) 0, &flag, 0);
616 AliDebug(2, Form("Error reading entry %s !",level1Str.Data()));
619 if(!(flag&2)) continue; // bit 1 of flag = directory!
621 if (queryId.GetAliCDBPath().Level1Comprises(level1)) {
622 GetEntriesForLevel1(level0, level1, queryId, result);
626 gSystem->FreeDirectory(level0DirPtr);
629 //_____________________________________________________________________________
630 void AliCDBLocal::GetEntriesForLevel1(const char* level0, const char* level1,
631 const AliCDBId& queryId, TList* result) {
632 // multiple request (AliCDBStorage::GetAll)
634 TString level1Dir = Form("%s/%s/%s", fBaseDirectory.Data(), level0,level1);
636 void* level1DirPtr = gSystem->OpenDirectory(level1Dir);
638 AliDebug(2,Form("Can't open level1 directory <%s>!",
645 while ((level2 = gSystem->GetDirEntry(level1DirPtr))) {
647 TString level2Str(level2);
648 if (level2Str == "." || level2Str == "..") {
652 TString fullPath = Form("%s/%s",level1Dir.Data(), level2);
654 Int_t res=gSystem->GetPathInfo(fullPath.Data(), 0, (Long64_t*) 0, &flag, 0);
657 AliDebug(2, Form("Error reading entry %s !",level2Str.Data()));
660 if(!(flag&2)) continue; // bit 1 of flag = directory!
662 if (queryId.GetAliCDBPath().Level2Comprises(level2)) {
664 AliCDBPath entryPath(level0, level1, level2);
665 AliCDBId entryId(entryPath, queryId.GetAliCDBRunRange(),
666 queryId.GetVersion(), queryId.GetSubVersion());
668 AliCDBEntry* anEntry = GetEntry(entryId);
670 result->Add(anEntry);
675 gSystem->FreeDirectory(level1DirPtr);
678 //_____________________________________________________________________________
679 TList* AliCDBLocal::GetEntries(const AliCDBId& queryId) {
680 // multiple request (AliCDBStorage::GetAll)
682 void* storageDirPtr = gSystem->OpenDirectory(fBaseDirectory);
683 if (!storageDirPtr) {
684 AliDebug(2,Form("Can't open storage directory <%s>",
685 fBaseDirectory.Data()));
689 TList* result = new TList();
694 while ((level0 = gSystem->GetDirEntry(storageDirPtr))) {
696 TString level0Str(level0);
697 if (level0Str == "." || level0Str == "..") {
701 TString fullPath = Form("%s/%s",fBaseDirectory.Data(), level0);
703 Int_t res=gSystem->GetPathInfo(fullPath.Data(), 0, (Long64_t*) 0, &flag, 0);
706 AliDebug(2, Form("Error reading entry %s !",level0Str.Data()));
710 if(!(flag&2)) continue; // bit 1 of flag = directory!
712 if (queryId.GetAliCDBPath().Level0Comprises(level0)) {
713 GetEntriesForLevel0(level0, queryId, result);
717 gSystem->FreeDirectory(storageDirPtr);
722 //_____________________________________________________________________________
723 Bool_t AliCDBLocal::PutEntry(AliCDBEntry* entry) {
724 // put an AliCDBEntry object into the database
726 AliCDBId& id = entry->GetId();
728 // set version and subVersion for the entry to be stored
729 if (!PrepareId(id)) return kFALSE;
732 // build filename from entry's id
734 if (!IdToFilename(id, filename)) {
736 AliDebug(2,Form("Bad ID encountered! Subnormal error!"));
741 TFile file(filename, "CREATE");
742 if (!file.IsOpen()) {
743 AliError(Form("Can't open file <%s>!", filename.Data()));
747 //SetTreeToFile(entry, &file);
749 entry->SetVersion(id.GetVersion());
750 entry->SetSubVersion(id.GetSubVersion());
752 // write object (key name: "AliCDBEntry")
753 Bool_t result = file.WriteTObject(entry, "AliCDBEntry");
754 if (!result) AliDebug(2,Form("Can't write entry to file: %s", filename.Data()));
758 if(!(id.GetPath().Contains("SHUTTLE/STATUS")))
759 AliInfo(Form("CDB object stored into file %s",filename.Data()));
765 //_____________________________________________________________________________
766 TList* AliCDBLocal::GetIdListFromFile(const char* fileName){
768 TString fullFileName(fileName);
769 fullFileName.Prepend(fBaseDirectory+'/');
770 TFile *file = TFile::Open(fullFileName);
772 AliError(Form("Can't open selection file <%s>!", fullFileName.Data()));
777 TList *list = new TList();
785 keycycle = "AliCDBId;";
788 id = (AliCDBId*) file->Get(keycycle);
792 file->Close(); delete file; file=0;
796 //_____________________________________________________________________________
797 Bool_t AliCDBLocal::Contains(const char* path) const{
798 // check for path in storage's fBaseDirectory
800 TString dirName = Form("%s/%s", fBaseDirectory.Data(), path);
801 Bool_t result=kFALSE;
803 void* dirPtr = gSystem->OpenDirectory(dirName);
804 if (dirPtr) result=kTRUE;
805 gSystem->FreeDirectory(dirPtr);
810 //_____________________________________________________________________________
811 void AliCDBLocal::QueryValidFiles()
813 // Query the CDB for files valid for AliCDBStorage::fRun
814 // fills list fValidFileIds with AliCDBId objects created from file name
816 if(fVersion != -1) AliWarning ("Version parameter is not used by local storage query!");
817 if(fMetaDataFilter) {
818 AliWarning ("CDB meta data parameters are not used by local storage query!");
819 delete fMetaDataFilter; fMetaDataFilter=0;
822 void* storageDirPtr = gSystem->OpenDirectory(fBaseDirectory);
825 while ((level0 = gSystem->GetDirEntry(storageDirPtr))) {
827 TString level0Str(level0);
828 if (level0Str == "." || level0Str == "..") {
832 if (fPathFilter.Level0Comprises(level0)) {
833 TString level0Dir = Form("%s/%s",fBaseDirectory.Data(),level0);
834 void* level0DirPtr = gSystem->OpenDirectory(level0Dir);
836 while ((level1 = gSystem->GetDirEntry(level0DirPtr))) {
838 TString level1Str(level1);
839 if (level1Str == "." || level1Str == "..") {
843 if (fPathFilter.Level1Comprises(level1)) {
844 TString level1Dir = Form("%s/%s/%s",
845 fBaseDirectory.Data(),level0,level1);
847 void* level1DirPtr = gSystem->OpenDirectory(level1Dir);
849 while ((level2 = gSystem->GetDirEntry(level1DirPtr))) {
851 TString level2Str(level2);
852 if (level2Str == "." || level2Str == "..") {
856 if (fPathFilter.Level2Comprises(level2)) {
857 TString dirName = Form("%s/%s/%s/%s",
858 fBaseDirectory.Data(),level0,level1,level2);
860 void* dirPtr = gSystem->OpenDirectory(dirName);
862 const char* filename;
864 AliCDBRunRange aRunRange; // the runRange got from filename
865 Int_t aVersion, aSubVersion; // the version and subVersion got from filename
867 while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files
869 TString aString(filename);
870 if (aString == "." || aString == "..") continue;
872 if (!FilenameToId(filename, aRunRange, aVersion, aSubVersion)) continue;
873 AliCDBRunRange runrg(fRun,fRun);
874 if (!aRunRange.Comprises(runrg)) continue;
875 // aRunRange contains requested run!
876 AliCDBPath validPath(level0,level1,level2);
877 AliCDBId validId(validPath,aRunRange,aVersion,aSubVersion);
878 fValidFileIds.AddLast(validId.Clone());
880 gSystem->FreeDirectory(dirPtr);
883 gSystem->FreeDirectory(level1DirPtr);
886 gSystem->FreeDirectory(level0DirPtr);
889 gSystem->FreeDirectory(storageDirPtr);
893 //_____________________________________________________________________________
894 Int_t AliCDBLocal::GetLatestVersion(const char* path, Int_t run){
895 // get last version found in the database valid for run and path
897 AliCDBPath aCDBPath(path);
898 if(!aCDBPath.IsValid() || aCDBPath.IsWildcard()) {
899 AliError(Form("Invalid path in request: %s", path));
903 AliCDBId query(path, run, run, -1, -1);
904 AliCDBId* dataId = GetId(query);
906 if(!dataId) return -1;
908 Int_t version = dataId->GetVersion();
915 //_____________________________________________________________________________
916 Int_t AliCDBLocal::GetLatestSubVersion(const char* path, Int_t run, Int_t version){
917 // get last version found in the database valid for run and path
919 AliCDBPath aCDBPath(path);
920 if(!aCDBPath.IsValid() || aCDBPath.IsWildcard()) {
921 AliError(Form("Invalid path in request: %s", path));
925 AliCDBId query(path, run, run, version, -1);
926 AliCDBId *dataId = GetId(query);
928 if(!dataId) return -1;
930 Int_t subVersion = dataId->GetSubVersion();
937 /////////////////////////////////////////////////////////////////////////////////////////////////
939 // AliCDBLocal factory //
941 /////////////////////////////////////////////////////////////////////////////////////////////////
943 ClassImp(AliCDBLocalFactory)
945 //_____________________________________________________________________________
946 Bool_t AliCDBLocalFactory::Validate(const char* dbString) {
947 // check if the string is valid local URI
949 TRegexp dbPatternLocal("^local://.+$");
951 return (TString(dbString).Contains(dbPatternLocal) || TString(dbString).BeginsWith("snapshot://folder="));
954 //_____________________________________________________________________________
955 AliCDBParam* AliCDBLocalFactory::CreateParameter(const char* dbString) {
956 // create AliCDBLocalParam class from the URI string
958 if (!Validate(dbString)) {
962 TString checkSS(dbString);
963 if(checkSS.BeginsWith("snapshot://"))
965 TString snapshotPath("OCDB");
966 snapshotPath.Prepend(TString(gSystem->WorkingDirectory()) + '/');
967 checkSS.Remove(0,checkSS.First(':')+3);
968 return new AliCDBLocalParam(snapshotPath,checkSS);
971 // if the string argument is not a snapshot URI, than it is a plain local URI
972 TString pathname(dbString + sizeof("local://") - 1);
974 if(gSystem->ExpandPathName(pathname))
977 if (pathname[0] != '/') {
978 pathname.Prepend(TString(gSystem->WorkingDirectory()) + '/');
980 //pathname.Prepend("local://");
982 return new AliCDBLocalParam(pathname);
985 //_____________________________________________________________________________
986 AliCDBStorage* AliCDBLocalFactory::Create(const AliCDBParam* param) {
987 // create AliCDBLocal storage instance from parameters
989 if (AliCDBLocalParam::Class() == param->IsA()) {
991 const AliCDBLocalParam* localParam =
992 (const AliCDBLocalParam*) param;
994 return new AliCDBLocal(localParam->GetPath());
999 //_____________________________________________________________________________
1000 void AliCDBLocal::SetRetry(Int_t /* nretry */, Int_t /* initsec */) {
1002 // Function to set the exponential retry for putting entries in the OCDB
1004 AliInfo("This function sets the exponential retry for putting entries in the OCDB - to be used ONLY for AliCDBGrid --> returning without doing anything");
1010 /////////////////////////////////////////////////////////////////////////////////////////////////
1012 // AliCDBLocal Parameter class // //
1014 /////////////////////////////////////////////////////////////////////////////////////////////////
1016 ClassImp(AliCDBLocalParam)
1018 //_____________________________________________________________________________
1019 AliCDBLocalParam::AliCDBLocalParam():
1023 // default constructor
1027 //_____________________________________________________________________________
1028 AliCDBLocalParam::AliCDBLocalParam(const char* dbPath):
1035 SetURI(TString("local://") + dbPath);
1038 //_____________________________________________________________________________
1039 AliCDBLocalParam::AliCDBLocalParam(const char* dbPath, const char* uri):
1046 SetURI(TString("alien://") + uri);
1049 //_____________________________________________________________________________
1050 AliCDBLocalParam::~AliCDBLocalParam() {
1055 //_____________________________________________________________________________
1056 AliCDBParam* AliCDBLocalParam::CloneParam() const {
1059 return new AliCDBLocalParam(fDBPath);
1062 //_____________________________________________________________________________
1063 ULong_t AliCDBLocalParam::Hash() const {
1064 // return Hash function
1066 return fDBPath.Hash();
1069 //_____________________________________________________________________________
1070 Bool_t AliCDBLocalParam::IsEqual(const TObject* obj) const {
1071 // check if this object is equal to AliCDBParam obj
1077 if (AliCDBLocalParam::Class() != obj->IsA()) {
1081 AliCDBLocalParam* other = (AliCDBLocalParam*) obj;
1083 return fDBPath == other->fDBPath;