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