]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliCDBDump.cxx
Protection against special particle types.
[u/mrichter/AliRoot.git] / STEER / AliCDBDump.cxx
CommitLineData
2c8628dd 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
9e1ceb13 16/////////////////////////////////////////////////////////////////////
17// //
18// class AliCDBDump //
19// access class to a DataBase in a dump storage (single file) //
20// //
21/////////////////////////////////////////////////////////////////////
2c8628dd 22
9e1ceb13 23#include <TSystem.h>
2c8628dd 24#include <TKey.h>
9e1ceb13 25#include <TFile.h>
26#include <TRegexp.h>
27#include <TObjString.h>
28#include <TList.h>
2c8628dd 29
9e1ceb13 30#include "AliCDBDump.h"
31#include "AliCDBEntry.h"
32#include "AliLog.h"
2c8628dd 33
fe913d8f 34ClassImp(AliCDBDump)
2c8628dd 35
2c8628dd 36//_____________________________________________________________________________
9e1ceb13 37AliCDBDump::AliCDBDump(const char* dbFile, Bool_t readOnly):
38fFile(NULL), fReadOnly(readOnly) {
2c8628dd 39// constructor
40
9e1ceb13 41 // opening file
42 fFile = TFile::Open(dbFile, fReadOnly ? "READ" : "UPDATE");
43 if (!fFile) {
44 AliError(Form("Can't open file <%s>!" , dbFile));
45 } else {
46 AliDebug(2,Form("File <%s> opened",dbFile));
47 if(fReadOnly) AliDebug(2,Form("in read-only mode"));
48 }
62032124 49
50 fType="dump";
51 fBaseFolder = dbFile;
2c8628dd 52}
53
54//_____________________________________________________________________________
9e1ceb13 55AliCDBDump::~AliCDBDump() {
2c8628dd 56// destructor
57
9e1ceb13 58 if (fFile) {
59 fFile->Close();
60 delete fFile;
61 }
2c8628dd 62}
63
9e1ceb13 64
2c8628dd 65//_____________________________________________________________________________
9e1ceb13 66Bool_t AliCDBDump::KeyNameToId(const char* keyname, AliCDBRunRange& runRange,
9e1ceb13 67 Int_t& version, Int_t& subVersion) {
fdf65bb5 68// build AliCDBId from keyname numbers
9e1ceb13 69
70 Ssiz_t mSize;
2c8628dd 71
9e1ceb13 72 // valid keyname: Run#firstRun_#lastRun_v#version_s#subVersion.root
73 TRegexp keyPattern("^Run[0-9]+_[0-9]+_v[0-9]+_s[0-9]+$");
74 keyPattern.Index(keyname, &mSize);
75 if (!mSize) {
76 AliDebug(2,Form("Bad keyname <%s>.", keyname));
77 return kFALSE;
78 }
79
80 TObjArray* strArray = (TObjArray*) TString(keyname).Tokenize("_");
81
82 TString firstRunString(((TObjString*) strArray->At(0))->GetString());
83 runRange.SetFirstRun(atoi(firstRunString.Data() + 3));
84 runRange.SetLastRun(atoi(((TObjString*) strArray->At(1))->GetString()));
85
86 TString verString(((TObjString*) strArray->At(2))->GetString());
87 version = atoi(verString.Data() + 1);
88
89 TString subVerString(((TObjString*) strArray->At(3))->GetString());
90 subVersion = atoi(subVerString.Data() + 1);
91
92 delete strArray;
93
94 return kTRUE;
2c8628dd 95}
96
97//_____________________________________________________________________________
9e1ceb13 98Bool_t AliCDBDump::IdToKeyName(const AliCDBRunRange& runRange, Int_t version,
99 Int_t subVersion, TString& keyname) {
100// build key name from AliCDBId data (run range, version, subVersion)
2c8628dd 101
9e1ceb13 102 if (!runRange.IsValid()) {
b05400be 103 AliDebug(2,Form("Invalid run range <%d, %d>.",
9e1ceb13 104 runRange.GetFirstRun(), runRange.GetLastRun()));
105 return kFALSE;
106 }
107
108 if (version < 0) {
b05400be 109 AliDebug(2,Form("Invalid version <%d>.", version));
9e1ceb13 110 return kFALSE;
111 }
112
113 if (subVersion < 0) {
b05400be 114 AliDebug(2,Form("Invalid subversion <%s>.", subVersion));
9e1ceb13 115 return kFALSE;
116 }
117
118 keyname += "Run";
119 keyname += runRange.GetFirstRun();
120 keyname += "_";
121 keyname += runRange.GetLastRun();
122 keyname += "_v";
123 keyname += version;
124 keyname += "_s";
125 keyname += subVersion;
126
127 return kTRUE;
2c8628dd 128}
129
9e1ceb13 130//_____________________________________________________________________________
131Bool_t AliCDBDump::MkDir(const TString& path) {
132// descend into TDirectory, making TDirectories if they don't exist
133 TObjArray* strArray = (TObjArray*) path.Tokenize("/");
134
135 TIter iter(strArray);
136 TObjString* str;
137
138 while ((str = (TObjString*) iter.Next())) {
139
140 TString dirName(str->GetString());
141 if (!dirName.Length()) {
142 continue;
143 }
144
145 if (gDirectory->cd(dirName)) {
146 continue;
147 }
148
149 TDirectory* aDir = gDirectory->mkdir(dirName, "");
150 if (!aDir) {
151 AliError(Form("Can't create directory <%s>!",
152 dirName.Data()));
153 delete strArray;
154
155 return kFALSE;
156 }
157
158 aDir->cd();
159 }
160
161 delete strArray;
162
163 return kTRUE;
164}
2c8628dd 165
166//_____________________________________________________________________________
9e1ceb13 167Bool_t AliCDBDump::PrepareId(AliCDBId& id) {
168// prepare id (version, subVersion) of the object that will be stored (called by PutEntry)
169
170 AliCDBRunRange aRunRange; // the runRange got from filename
171 AliCDBRunRange lastRunRange(-1,-1); // highest runRange found
172 Int_t aVersion, aSubVersion; // the version subVersion got from filename
173 Int_t lastVersion = 0, lastSubVersion = -1; // highest version and subVersion found
174
175
176 TIter iter(gDirectory->GetListOfKeys());
177 TKey* key;
178
179 if (!id.HasVersion()) { // version not specified: look for highest version & subVersion
180
181 while ((key = (TKey*) iter.Next())) { // loop on keys
182
183 const char* keyName = key->GetName();
184
185 if (!KeyNameToId(keyName, aRunRange, aVersion,
186 aSubVersion)) {
b05400be 187 AliDebug(2,Form(
9e1ceb13 188 "Bad keyname <%s>!I'll skip it.", keyName));
189 continue;
190 }
191
192 if (!aRunRange.Overlaps(id.GetAliCDBRunRange())) continue;
193 if(aVersion < lastVersion) continue;
194 if(aVersion > lastVersion) lastSubVersion = -1;
195 if(aSubVersion < lastSubVersion) continue;
196 lastVersion = aVersion;
197 lastSubVersion = aSubVersion;
198 lastRunRange = aRunRange;
199 }
200
201 id.SetVersion(lastVersion);
202 id.SetSubVersion(lastSubVersion + 1);
203
204 } else { // version specified, look for highest subVersion only
205
206 while ((key = (TKey*) iter.Next())) { // loop on the keys
207
208 const char* keyName = key->GetName();
209
210 if (!KeyNameToId(keyName, aRunRange, aVersion,
211 aSubVersion)) {
b05400be 212 AliDebug(2,Form(
9e1ceb13 213 "Bad keyname <%s>!I'll skip it.", keyName));
214 continue;
215 }
216
217 if (aRunRange.Overlaps(id.GetAliCDBRunRange())
218 && aVersion == id.GetVersion()
219 && aSubVersion > lastSubVersion) {
220 lastSubVersion = aSubVersion;
221 lastRunRange = aRunRange;
222 }
223
224 }
225
226 id.SetSubVersion(lastSubVersion + 1);
227 }
228
229 TString lastStorage = id.GetLastStorage();
230 if(lastStorage.Contains(TString("grid"), TString::kIgnoreCase) &&
231 id.GetSubVersion() > 0 ){
232 AliError(Form("Grid to Dump Storage error! local object with version v%d_s%d found:",id.GetVersion(), id.GetSubVersion()-1));
233 AliError(Form("This object has been already transferred from Grid (check v%d_s0)!",id.GetVersion()));
234 return kFALSE;
235 }
236
237 if(lastStorage.Contains(TString("new"), TString::kIgnoreCase) &&
238 id.GetSubVersion() > 0 ){
84090f85 239 AliDebug(2, Form("A NEW object is being stored with version v%d_s%d",
9e1ceb13 240 id.GetVersion(),id.GetSubVersion()));
84090f85 241 AliDebug(2, Form("and it will hide previously stored object with v%d_s%d!",
9e1ceb13 242 id.GetVersion(),id.GetSubVersion()-1));
243 }
244
245 if(!lastRunRange.IsAnyRange() && !(lastRunRange.IsEqual(& id.GetAliCDBRunRange())))
246 AliWarning(Form("Run range modified w.r.t. previous version (Run%d_%d_v%d_s%d)",
247 lastRunRange.GetFirstRun(), lastRunRange.GetLastRun(),
248 id.GetVersion(), id.GetSubVersion()-1));
249
250 return kTRUE;
251
252}
253
254
255//_____________________________________________________________________________
4b5e0dce 256Bool_t AliCDBDump::GetId(const AliCDBId& query, AliCDBId& result) {
9e1ceb13 257// look for filename matching query (called by GetEntry)
258
9e1ceb13 259
260 AliCDBRunRange aRunRange; // the runRange got from filename
261 Int_t aVersion, aSubVersion; // the version and subVersion got from filename
262
263 TIter iter(gDirectory->GetListOfKeys());
264 TKey* key;
265
266 if (!query.HasVersion()) { // neither version and subversion specified -> look for highest version and subVersion
267
268 while ((key = (TKey*) iter.Next())) { // loop on the keys
269
270 if (!KeyNameToId(key->GetName(), aRunRange, aVersion, aSubVersion)) continue;
271 // aRunRange, aVersion, aSubVersion filled from filename
272
273 if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
274 // aRunRange contains requested run!
275
276 if (result.GetVersion() < aVersion) {
277 result.SetVersion(aVersion);
278 result.SetSubVersion(aSubVersion);
279
280 result.SetFirstRun(
281 aRunRange.GetFirstRun());
282 result.SetLastRun(
283 aRunRange.GetLastRun());
284
285 } else if (result.GetVersion() == aVersion
286 && result.GetSubVersion()
287 < aSubVersion) {
288
289 result.SetSubVersion(aSubVersion);
290
291 result.SetFirstRun(
292 aRunRange.GetFirstRun());
293 result.SetLastRun(
294 aRunRange.GetLastRun());
295 } else if (result.GetVersion() == aVersion
296 && result.GetSubVersion() == aSubVersion){
024cf675 297 AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
9e1ceb13 298 query.GetFirstRun(), aVersion, aSubVersion));
299 result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
4b5e0dce 300 return kFALSE;
9e1ceb13 301 }
302 }
303
304 } else if (!query.HasSubVersion()) { // version specified but not subversion -> look for highest subVersion
305
306 result.SetVersion(query.GetVersion());
307
308 while ((key = (TKey*) iter.Next())) { // loop on the keys
309
310 if (!KeyNameToId(key->GetName(), aRunRange, aVersion, aSubVersion)) continue;
311 // aRunRange, aVersion, aSubVersion filled from filename
312
313 if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
314 // aRunRange contains requested run!
315
316 if(query.GetVersion() != aVersion) continue;
317 // aVersion is requested version!
318
319 if(result.GetSubVersion() == aSubVersion){
024cf675 320 AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
9e1ceb13 321 query.GetFirstRun(), aVersion, aSubVersion));
322 result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
4b5e0dce 323 return kFALSE;
9e1ceb13 324 }
325 if( result.GetSubVersion() < aSubVersion) {
326
327 result.SetSubVersion(aSubVersion);
328
329 result.SetFirstRun(
330 aRunRange.GetFirstRun());
331 result.SetLastRun(
332 aRunRange.GetLastRun());
333 }
334 }
335
336 } else { // both version and subversion specified
337
338 while ((key = (TKey*) iter.Next())) { // loop on the keys
339
340 if (!KeyNameToId(key->GetName(), aRunRange, aVersion, aSubVersion)) continue;
341 // aRunRange, aVersion, aSubVersion filled from filename
342
343 if (!aRunRange.Comprises(query.GetAliCDBRunRange())) continue;
344 // aRunRange contains requested run!
345
346 if(query.GetVersion() != aVersion || query.GetSubVersion() != aSubVersion) continue;
347 // aVersion and aSubVersion are requested version and subVersion!
348
349 if(result.GetVersion() == aVersion && result.GetSubVersion() == aSubVersion){
024cf675 350 AliDebug(2,Form("More than one object valid for run %d, version %d_%d!",
9e1ceb13 351 query.GetFirstRun(), aVersion, aSubVersion));
352 result.SetRunRange(-1,-1); result.SetVersion(-1); result.SetSubVersion(-1);
4b5e0dce 353 return kFALSE;
9e1ceb13 354 }
355 result.SetVersion(aVersion);
356 result.SetSubVersion(aSubVersion);
357 result.SetFirstRun(aRunRange.GetFirstRun());
358 result.SetLastRun(aRunRange.GetLastRun());
359
360 }
361 }
362
4b5e0dce 363 return kTRUE;
9e1ceb13 364}
365
366//_____________________________________________________________________________
4b5e0dce 367AliCDBEntry* AliCDBDump::GetEntry(const AliCDBId& queryId) {
9e1ceb13 368// get AliCDBEntry from the database
369
370 TDirectory::TContext context(gDirectory, fFile);
371
372 if (!(fFile && fFile->IsOpen())) {
373 AliError("AliCDBDump storage is not initialized properly");
374 return NULL;
375 }
376
4b5e0dce 377 if (!gDirectory->cd(queryId.GetPath())) {
9e1ceb13 378 return NULL;
379 }
380
4b5e0dce 381 AliCDBId dataId(queryId.GetAliCDBPath(), -1, -1, -1, -1);
382 Bool_t result;
9e1ceb13 383
384 // look for a filename matching query requests (path, runRange, version, subVersion)
4b5e0dce 385 if (!queryId.HasVersion()) {
9e1ceb13 386 // if version is not specified, first check the selection criteria list
4b5e0dce 387 AliCDBId selectedId(queryId);
388 GetSelection(&selectedId);
389 result = GetId(selectedId, dataId);
9e1ceb13 390 } else {
4b5e0dce 391 result = GetId(queryId, dataId);
9e1ceb13 392 }
393
4b5e0dce 394 if (!result || !dataId.IsSpecified()) {
9e1ceb13 395 return NULL;
396 }
397
398 TString keyname;
399 if (!IdToKeyName(dataId.GetAliCDBRunRange(), dataId.GetVersion(),
400 dataId.GetSubVersion(), keyname)) {
024cf675 401 AliDebug(2,Form("Bad ID encountered! Subnormal error!"));
9e1ceb13 402 return NULL;
403 }
404
405 // get the only AliCDBEntry object from the file
406 // the object in the file is an AliCDBEntry entry named keyname
407 // keyName = Run#firstRun_#lastRun_v#version_s#subVersion
408
409 TObject* anObject = gDirectory->Get(keyname);
410 if (!anObject) {
024cf675 411 AliDebug(2,Form("Bad storage data: NULL entry object!"));
9e1ceb13 412 return NULL;
413 }
414
415 if (AliCDBEntry::Class() != anObject->IsA()) {
024cf675 416 AliDebug(2,Form("Bad storage data: Invalid entry object!"));
9e1ceb13 417 return NULL;
418 }
419
420 ((AliCDBEntry*) anObject)->SetLastStorage("dump");
421
422 return (AliCDBEntry*) anObject;
423}
424
425//_____________________________________________________________________________
426void AliCDBDump::GetEntriesForLevel0(const AliCDBId& queryId, TList* result) {
427// multiple request (AliCDBStorage::GetAll)
428
429 TDirectory* saveDir = gDirectory;
430
431 TIter iter(gDirectory->GetListOfKeys());
432 TKey* key;
433
434 while ((key = (TKey*) iter.Next())) {
435
436 TString keyNameStr(key->GetName());
437 if (queryId.GetAliCDBPath().Level1Comprises(keyNameStr)) {
438 gDirectory->cd(keyNameStr);
439 GetEntriesForLevel1(queryId, result);
440
441 saveDir->cd();
442 }
443 }
444}
445
446//_____________________________________________________________________________
447void AliCDBDump::GetEntriesForLevel1(const AliCDBId& queryId, TList* result) {
448// multiple request (AliCDBStorage::GetAll)
449
450 TIter iter(gDirectory->GetListOfKeys());
451 TKey* key;
452
453 TDirectory* level0Dir = (TDirectory*) gDirectory->GetMother();
454
455 while ((key = (TKey*) iter.Next())) {
456
457 TString keyNameStr(key->GetName());
458 if (queryId.GetAliCDBPath().Level2Comprises(keyNameStr)) {
459
460 AliCDBPath aPath(level0Dir->GetName(),
461 gDirectory->GetName(), keyNameStr);
462 AliCDBId anId(aPath, queryId.GetAliCDBRunRange(),
463 queryId.GetVersion(), -1);
464
465 AliCDBEntry* anEntry = GetEntry(anId);
466 if (anEntry) {
467 result->Add(anEntry);
468 }
469
470 }
471 }
472
473}
474
475
476//_____________________________________________________________________________
477TList* AliCDBDump::GetEntries(const AliCDBId& queryId) {
478// multiple request (AliCDBStorage::GetAll)
479
480 TDirectory::TContext context(gDirectory, fFile);
481
482 if (!(fFile && fFile->IsOpen())) {
483 AliError("AliCDBDump storage is not initialized properly");
484 return NULL;
485 }
486
487 TList* result = new TList();
488 result->SetOwner();
489
490 TIter iter(gDirectory->GetListOfKeys());
491 TKey* key;
492
493 while ((key = (TKey*) iter.Next())) {
494
495 TString keyNameStr(key->GetName());
496 if (queryId.GetAliCDBPath().Level0Comprises(keyNameStr)) {
497 gDirectory->cd(keyNameStr);
498 GetEntriesForLevel0(queryId, result);
499
500 fFile->cd();
501 }
502 }
503
504 return result;
505}
506
507//_____________________________________________________________________________
508Bool_t AliCDBDump::PutEntry(AliCDBEntry* entry) {
509// put an AliCDBEntry object into the database
510
511 TDirectory::TContext context(gDirectory, fFile);
512
513 if (!(fFile && fFile->IsOpen())) {
514 AliError("AliCDBDump storage is not initialized properly");
515 return kFALSE;
516 }
517
518 if (fReadOnly) {
519 AliError("AliCDBDump storage is read only!");
520 return kFALSE;
521 }
522
523 AliCDBId& id = entry->GetId();
524
525 if (!gDirectory->cd(id.GetPath())) {
526 if (!MkDir(id.GetPath())) {
527 AliError(Form("Can't open directory <%s>!",
528 id.GetPath().Data()));
529 return kFALSE;
530 }
531 }
532
533 // set version and subVersion for the entry to be stored
534 if (!PrepareId(id)) {
535 return kFALSE;
536 }
537
538 // build keyname from entry's id
539 TString keyname;
540 if (!IdToKeyName(id.GetAliCDBRunRange(), id.GetVersion(), id.GetSubVersion(), keyname)) {
541 AliError("Invalid ID encountered! Subnormal error!");
542 return kFALSE;
543 }
544
545 // write object (key name: Run#firstRun_#lastRun_v#version_s#subVersion)
546 Bool_t result = gDirectory->WriteTObject(entry, keyname);
547 if (!result) {
c3a7b59a 548 AliError(Form("Can't write entry to file: %s",
9e1ceb13 549 fFile->GetName()));
550 }
551
552 if(result) {
b05400be 553 AliInfo(Form("CDB object stored into file %s",fFile->GetName()));
9e1ceb13 554 AliInfo(Form("TDirectory/key name: %s/%s",id.GetPath().Data(),keyname.Data()));
555 }
556
557 return result;
558}
b05400be 559//_____________________________________________________________________________
560TList* AliCDBDump::GetIdListFromFile(const char* fileName){
561
562 TString turl(fileName);
563 if (turl[0] != '/') {
564 turl.Prepend(TString(gSystem->WorkingDirectory()) + '/');
565 }
566 TFile *file = TFile::Open(turl);
567 if (!file) {
568 AliError(Form("Can't open selection file <%s>!", turl.Data()));
569 return NULL;
570 }
571 file->cd();
572
573 TList *list = new TList();
574 list->SetOwner();
575 int i=0;
576 TString keycycle;
577
578 AliCDBId *id;
579 while(1){
580 i++;
581 keycycle = "AliCDBId;";
582 keycycle+=i;
583
584 id = (AliCDBId*) file->Get(keycycle);
585 if(!id) break;
586 list->AddFirst(id);
587 }
588 file->Close(); delete file; file=0;
589 return list;
590}
591
592//_____________________________________________________________________________
593Bool_t AliCDBDump::Contains(const char* path) const{
594// check for path in storage
595
596 TDirectory::TContext context(gDirectory, fFile);
597 if (!(fFile && fFile->IsOpen())) {
598 AliError("AliCDBDump storage is not initialized properly");
599 return kFALSE;
600 }
601
602 return gDirectory->cd(path);
603
604}
9e1ceb13 605
62032124 606//_____________________________________________________________________________
607void AliCDBDump::QueryValidFiles()
608{
c3a7b59a 609// Query the CDB for files valid for AliCDBStorage::fRun
610// fills list fValidFileIds with AliCDBId objects created from file name
611
612 AliError("Not yet (and maybe never) implemented");
613}
614
615//_____________________________________________________________________________
616Bool_t AliCDBDump::IdToFilename(const AliCDBId& /*id*/, TString& /*filename*/) const {
617// build file name from AliCDBId (path, run range, version) and fDBFolder
618
619 AliError("Not implemented");
620 return kFALSE;
621}
622
623//_____________________________________________________________________________
624Int_t AliCDBDump::GetLatestVersion(const char* path, Int_t run){
625// get last version found in the database valid for run and path
626
627 AliCDBPath aCDBPath(path);
628 if(!aCDBPath.IsValid() || aCDBPath.IsWildcard()) {
629 AliError(Form("Invalid path in request: %s", path));
630 return -1;
631 }
632
633 AliCDBId query(path, run, run, -1, -1);
634 AliCDBId dataId;
635
636 GetId(query,dataId);
637
638 return dataId.GetVersion();
639}
640
641//_____________________________________________________________________________
642Int_t AliCDBDump::GetLatestSubVersion(const char* path, Int_t run, Int_t version){
643// get last version found in the database valid for run and path
644
645 AliCDBPath aCDBPath(path);
646 if(!aCDBPath.IsValid() || aCDBPath.IsWildcard()) {
647 AliError(Form("Invalid path in request: %s", path));
648 return -1;
649 }
650
651 AliCDBId query(path, run, run, version, -1);
652 AliCDBId dataId;
653
654 GetId(query,dataId);
655
656 return dataId.GetSubVersion();
62032124 657
658}
659
660
9e1ceb13 661/////////////////////////////////////////////////////////////////////////////////////////////////
662// //
663// AliCDBDump factory //
664// //
665/////////////////////////////////////////////////////////////////////////////////////////////////
666
667ClassImp(AliCDBDumpFactory)
668
669//_____________________________________________________________________________
670Bool_t AliCDBDumpFactory::Validate(const char* dbString) {
671// check if the string is valid dump URI
672
673 TRegexp dbPattern("^dump://.+$");
674
675 return TString(dbString).Contains(dbPattern);
676}
677
678//_____________________________________________________________________________
679AliCDBParam* AliCDBDumpFactory::CreateParameter(const char* dbString) {
680// create AliCDBDumpParam class from the URI string
681
682 if (!Validate(dbString)) {
683 return NULL;
684 }
685
686 TString pathname(dbString + sizeof("dump://") - 1);
687
688 Bool_t readOnly;
689
690 if (pathname.Contains(TRegexp(";ReadOnly$"))) {
691 pathname.Resize(pathname.Length() - sizeof(";ReadOnly") + 1);
692 readOnly = kTRUE;
693 } else {
694 readOnly = kFALSE;
695 }
696
697 gSystem->ExpandPathName(pathname);
698
699 if (pathname[0] != '/') {
700 pathname.Prepend(TString(gSystem->WorkingDirectory()) + '/');
701 }
702
9e1ceb13 703 return new AliCDBDumpParam(pathname, readOnly);
704}
705
706//_____________________________________________________________________________
707AliCDBStorage* AliCDBDumpFactory::Create(const AliCDBParam* param) {
708// create AliCDBDump storage instance from parameters
709
710 if (AliCDBDumpParam::Class() == param->IsA()) {
711
712 const AliCDBDumpParam* dumpParam =
713 (const AliCDBDumpParam*) param;
714
715 return new AliCDBDump(dumpParam->GetPath(),
716 dumpParam->IsReadOnly());
717 }
718
719 return NULL;
720}
721
722/////////////////////////////////////////////////////////////////////////////////////////////////
723// //
724// AliCDBDump parameter class //
725// //
726/////////////////////////////////////////////////////////////////////////////////////////////////
727
728ClassImp(AliCDBDumpParam)
729
730//_____________________________________________________________________________
62032124 731AliCDBDumpParam::AliCDBDumpParam():
732fDBPath(), fReadOnly(kFALSE)
733{
9e1ceb13 734// default constructor
735
736}
737
738//_____________________________________________________________________________
739AliCDBDumpParam::AliCDBDumpParam(const char* dbPath, Bool_t readOnly):
740 fDBPath(dbPath), fReadOnly(readOnly)
2c8628dd 741{
9e1ceb13 742// constructor
743
744 TString uri;
745 uri += "dump://";
746 uri += dbPath;
747
748 if (fReadOnly) {
749 uri += ";ReadOnly";
750 }
751
752 SetURI(uri);
753 SetType("dump");
754}
755
756//_____________________________________________________________________________
757AliCDBDumpParam::~AliCDBDumpParam() {
758// destructor
759
760}
761
762//_____________________________________________________________________________
763AliCDBParam* AliCDBDumpParam::CloneParam() const {
764// clone parameter
765
766 return new AliCDBDumpParam(fDBPath, fReadOnly);
767}
768
769//_____________________________________________________________________________
770ULong_t AliCDBDumpParam::Hash() const {
771// return Hash function
772
773 return fDBPath.Hash();
774}
775
776//_____________________________________________________________________________
777Bool_t AliCDBDumpParam::IsEqual(const TObject* obj) const {
778// check if this object is equal to AliCDBParam obj
779
780 if (this == obj) {
781 return kTRUE;
782 }
783
784 if (AliCDBDumpParam::Class() != obj->IsA()) {
785 return kFALSE;
786 }
787
788 AliCDBDumpParam* other = (AliCDBDumpParam*) obj;
789
790 return fDBPath == other->fDBPath;
fe913d8f 791}