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