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