]>
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 | |
b09247a2 | 23 | #include <cstdlib> |
9e1ceb13 | 24 | #include <TSystem.h> |
2c8628dd | 25 | #include <TKey.h> |
9e1ceb13 | 26 | #include <TFile.h> |
27 | #include <TRegexp.h> | |
28 | #include <TObjString.h> | |
29 | #include <TList.h> | |
2c8628dd | 30 | |
9e1ceb13 | 31 | #include "AliCDBDump.h" |
32 | #include "AliCDBEntry.h" | |
33 | #include "AliLog.h" | |
2c8628dd | 34 | |
fe913d8f | 35 | ClassImp(AliCDBDump) |
2c8628dd | 36 | |
2c8628dd | 37 | //_____________________________________________________________________________ |
9e1ceb13 | 38 | AliCDBDump::AliCDBDump(const char* dbFile, Bool_t readOnly): |
5078a13f | 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; | |
2c8628dd | 54 | } |
55 | ||
56 | //_____________________________________________________________________________ | |
9e1ceb13 | 57 | AliCDBDump::~AliCDBDump() { |
5078a13f | 58 | // destructor |
2c8628dd | 59 | |
5078a13f | 60 | if (fFile) { |
61 | fFile->Close(); | |
62 | delete fFile; | |
63 | } | |
2c8628dd | 64 | } |
65 | ||
9e1ceb13 | 66 | |
2c8628dd | 67 | //_____________________________________________________________________________ |
9e1ceb13 | 68 | Bool_t AliCDBDump::KeyNameToId(const char* keyname, AliCDBRunRange& runRange, |
5078a13f | 69 | Int_t& version, Int_t& subVersion) { |
70 | // build AliCDBId from keyname numbers | |
71 | ||
72 | Ssiz_t mSize; | |
9e1ceb13 | 73 | |
5078a13f | 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 | } | |
2c8628dd | 81 | |
5078a13f | 82 | TObjArray* strArray = (TObjArray*) TString(keyname).Tokenize("_"); |
9e1ceb13 | 83 | |
5078a13f | 84 | TString firstRunString(((TObjString*) strArray->At(0))->GetString()); |
85 | runRange.SetFirstRun(atoi(firstRunString.Data() + 3)); | |
86 | runRange.SetLastRun(atoi(((TObjString*) strArray->At(1))->GetString())); | |
9e1ceb13 | 87 | |
5078a13f | 88 | TString verString(((TObjString*) strArray->At(2))->GetString()); |
89 | version = atoi(verString.Data() + 1); | |
9e1ceb13 | 90 | |
5078a13f | 91 | TString subVerString(((TObjString*) strArray->At(3))->GetString()); |
92 | subVersion = atoi(subVerString.Data() + 1); | |
9e1ceb13 | 93 | |
5078a13f | 94 | delete strArray; |
9e1ceb13 | 95 | |
5078a13f | 96 | return kTRUE; |
2c8628dd | 97 | } |
98 | ||
99 | //_____________________________________________________________________________ | |
9e1ceb13 | 100 | Bool_t AliCDBDump::IdToKeyName(const AliCDBRunRange& runRange, Int_t version, |
5078a13f | 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; | |
2c8628dd | 130 | } |
131 | ||
9e1ceb13 | 132 | //_____________________________________________________________________________ |
133 | Bool_t AliCDBDump::MkDir(const TString& path) { | |
5078a13f | 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; | |
9e1ceb13 | 166 | } |
2c8628dd | 167 | |
168 | //_____________________________________________________________________________ | |
9e1ceb13 | 169 | Bool_t AliCDBDump::PrepareId(AliCDBId& id) { |
5078a13f | 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; | |
9e1ceb13 | 253 | |
254 | } | |
255 | ||
4667c116 | 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 | // } | |
9e1ceb13 | 366 | |
367 | //_____________________________________________________________________________ | |
4667c116 | 368 | AliCDBId* AliCDBDump::GetId(const AliCDBId& query) { |
5078a13f | 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! | |
9e1ceb13 | 390 | |
5078a13f | 391 | if (result->GetVersion() < aVersion) { |
392 | result->SetVersion(aVersion); | |
393 | result->SetSubVersion(aSubVersion); | |
9e1ceb13 | 394 | |
5078a13f | 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; | |
9e1ceb13 | 479 | } |
480 | ||
481 | //_____________________________________________________________________________ | |
4b5e0dce | 482 | AliCDBEntry* AliCDBDump::GetEntry(const AliCDBId& queryId) { |
5078a13f | 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; | |
9e1ceb13 | 532 | } |
533 | ||
4667c116 | 534 | //_____________________________________________________________________________ |
535 | AliCDBId* AliCDBDump::GetEntryId(const AliCDBId& queryId) { | |
5078a13f | 536 | // get AliCDBEntry from the database |
4667c116 | 537 | |
5078a13f | 538 | TDirectory::TContext context(gDirectory, fFile); |
4667c116 | 539 | |
5078a13f | 540 | if (!(fFile && fFile->IsOpen())) { |
541 | AliError("AliCDBDump storage is not initialized properly"); | |
542 | return NULL; | |
543 | } | |
4667c116 | 544 | |
5078a13f | 545 | if (!gDirectory->cd(queryId.GetPath())) { |
546 | return NULL; | |
547 | } | |
4667c116 | 548 | |
5078a13f | 549 | AliCDBId* dataId = 0; |
4667c116 | 550 | |
5078a13f | 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 | } | |
4667c116 | 560 | |
5078a13f | 561 | if (dataId && !dataId->IsSpecified()) { |
562 | delete dataId; | |
563 | return NULL; | |
564 | } | |
4667c116 | 565 | |
5078a13f | 566 | return dataId; |
4667c116 | 567 | } |
568 | ||
9e1ceb13 | 569 | //_____________________________________________________________________________ |
570 | void AliCDBDump::GetEntriesForLevel0(const AliCDBId& queryId, TList* result) { | |
5078a13f | 571 | // multiple request (AliCDBStorage::GetAll) |
572 | ||
573 | TDirectory* saveDir = gDirectory; | |
9e1ceb13 | 574 | |
5078a13f | 575 | TIter iter(gDirectory->GetListOfKeys()); |
576 | TKey* key; | |
9e1ceb13 | 577 | |
5078a13f | 578 | while ((key = (TKey*) iter.Next())) { |
9e1ceb13 | 579 | |
5078a13f | 580 | TString keyNameStr(key->GetName()); |
581 | if (queryId.GetAliCDBPath().Level1Comprises(keyNameStr)) { | |
582 | gDirectory->cd(keyNameStr); | |
583 | GetEntriesForLevel1(queryId, result); | |
4667c116 | 584 | |
5078a13f | 585 | saveDir->cd(); |
586 | } | |
587 | } | |
9e1ceb13 | 588 | } |
589 | ||
590 | //_____________________________________________________________________________ | |
591 | void AliCDBDump::GetEntriesForLevel1(const AliCDBId& queryId, TList* result) { | |
5078a13f | 592 | // multiple request (AliCDBStorage::GetAll) |
9e1ceb13 | 593 | |
5078a13f | 594 | TIter iter(gDirectory->GetListOfKeys()); |
595 | TKey* key; | |
9e1ceb13 | 596 | |
5078a13f | 597 | TDirectory* level0Dir = (TDirectory*) gDirectory->GetMother(); |
9e1ceb13 | 598 | |
5078a13f | 599 | while ((key = (TKey*) iter.Next())) { |
9e1ceb13 | 600 | |
5078a13f | 601 | TString keyNameStr(key->GetName()); |
602 | if (queryId.GetAliCDBPath().Level2Comprises(keyNameStr)) { | |
9e1ceb13 | 603 | |
5078a13f | 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 | } | |
9e1ceb13 | 616 | |
617 | } | |
618 | ||
5078a13f | 619 | |
9e1ceb13 | 620 | //_____________________________________________________________________________ |
621 | TList* AliCDBDump::GetEntries(const AliCDBId& queryId) { | |
5078a13f | 622 | // multiple request (AliCDBStorage::GetAll) |
9e1ceb13 | 623 | |
5078a13f | 624 | TDirectory::TContext context(gDirectory, fFile); |
9e1ceb13 | 625 | |
5078a13f | 626 | if (!(fFile && fFile->IsOpen())) { |
627 | AliError("AliCDBDump storage is not initialized properly"); | |
628 | return NULL; | |
629 | } | |
9e1ceb13 | 630 | |
5078a13f | 631 | TList* result = new TList(); |
632 | result->SetOwner(); | |
9e1ceb13 | 633 | |
5078a13f | 634 | TIter iter(gDirectory->GetListOfKeys()); |
635 | TKey* key; | |
9e1ceb13 | 636 | |
5078a13f | 637 | while ((key = (TKey*) iter.Next())) { |
9e1ceb13 | 638 | |
5078a13f | 639 | TString keyNameStr(key->GetName()); |
640 | if (queryId.GetAliCDBPath().Level0Comprises(keyNameStr)) { | |
641 | gDirectory->cd(keyNameStr); | |
642 | GetEntriesForLevel0(queryId, result); | |
9e1ceb13 | 643 | |
5078a13f | 644 | fFile->cd(); |
645 | } | |
646 | } | |
647 | ||
648 | return result; | |
9e1ceb13 | 649 | } |
650 | ||
651 | //_____________________________________________________________________________ | |
06eeadea | 652 | Bool_t AliCDBDump::PutEntry(AliCDBEntry* entry, const char* mirrors) { |
5078a13f | 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; | |
9e1ceb13 | 706 | } |
b05400be | 707 | //_____________________________________________________________________________ |
708 | TList* AliCDBDump::GetIdListFromFile(const char* fileName){ | |
709 | ||
5078a13f | 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; | |
b05400be | 738 | } |
739 | ||
740 | //_____________________________________________________________________________ | |
741 | Bool_t AliCDBDump::Contains(const char* path) const{ | |
5078a13f | 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 | } | |
b05400be | 749 | |
5078a13f | 750 | return gDirectory->cd(path); |
b05400be | 751 | |
752 | } | |
9e1ceb13 | 753 | |
62032124 | 754 | //_____________________________________________________________________________ |
755 | void AliCDBDump::QueryValidFiles() | |
756 | { | |
5078a13f | 757 | // Query the CDB for files valid for AliCDBStorage::fRun |
758 | // fills list fValidFileIds with AliCDBId objects created from file name | |
c3a7b59a | 759 | |
5078a13f | 760 | AliError("Not yet (and maybe never) implemented"); |
c3a7b59a | 761 | } |
762 | ||
763 | //_____________________________________________________________________________ | |
764 | Bool_t AliCDBDump::IdToFilename(const AliCDBId& /*id*/, TString& /*filename*/) const { | |
5078a13f | 765 | // build file name from AliCDBId (path, run range, version) and fDBFolder |
c3a7b59a | 766 | |
5078a13f | 767 | AliError("Not implemented"); |
768 | return kFALSE; | |
c3a7b59a | 769 | } |
770 | ||
62032124 | 771 | |
89004e35 | 772 | //_____________________________________________________________________________ |
0d3fff93 | 773 | void AliCDBDump::SetRetry(Int_t /* nretry */, Int_t /* initsec */) { |
89004e35 | 774 | |
5078a13f | 775 | // Function to set the exponential retry for putting entries in the OCDB |
89004e35 | 776 | |
5078a13f | 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; | |
89004e35 | 779 | } |
62032124 | 780 | |
9e1ceb13 | 781 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
782 | // // | |
783 | // AliCDBDump factory // | |
784 | // // | |
785 | ///////////////////////////////////////////////////////////////////////////////////////////////// | |
786 | ||
787 | ClassImp(AliCDBDumpFactory) | |
788 | ||
5078a13f | 789 | //_____________________________________________________________________________ |
790 | Bool_t AliCDBDumpFactory::Validate(const char* dbString) { | |
791 | // check if the string is valid dump URI | |
9e1ceb13 | 792 | |
5078a13f | 793 | TRegexp dbPattern("^dump://.+$"); |
9e1ceb13 | 794 | |
5078a13f | 795 | return TString(dbString).Contains(dbPattern); |
796 | } | |
9e1ceb13 | 797 | |
798 | //_____________________________________________________________________________ | |
799 | AliCDBParam* AliCDBDumpFactory::CreateParameter(const char* dbString) { | |
5078a13f | 800 | // create AliCDBDumpParam class from the URI string |
801 | ||
802 | if (!Validate(dbString)) { | |
803 | return NULL; | |
804 | } | |
9e1ceb13 | 805 | |
5078a13f | 806 | TString pathname(dbString + sizeof("dump://") - 1); |
9e1ceb13 | 807 | |
5078a13f | 808 | Bool_t readOnly; |
9e1ceb13 | 809 | |
5078a13f | 810 | if (pathname.Contains(TRegexp(";ReadOnly$"))) { |
811 | pathname.Resize(pathname.Length() - sizeof(";ReadOnly") + 1); | |
812 | readOnly = kTRUE; | |
813 | } else { | |
814 | readOnly = kFALSE; | |
815 | } | |
9e1ceb13 | 816 | |
5078a13f | 817 | gSystem->ExpandPathName(pathname); |
9e1ceb13 | 818 | |
5078a13f | 819 | if (pathname[0] != '/') { |
820 | pathname.Prepend(TString(gSystem->WorkingDirectory()) + '/'); | |
821 | } | |
9e1ceb13 | 822 | |
5078a13f | 823 | return new AliCDBDumpParam(pathname, readOnly); |
9e1ceb13 | 824 | } |
825 | ||
826 | //_____________________________________________________________________________ | |
827 | AliCDBStorage* AliCDBDumpFactory::Create(const AliCDBParam* param) { | |
5078a13f | 828 | // create AliCDBDump storage instance from parameters |
9e1ceb13 | 829 | |
5078a13f | 830 | if (AliCDBDumpParam::Class() == param->IsA()) { |
9e1ceb13 | 831 | |
5078a13f | 832 | const AliCDBDumpParam* dumpParam = |
833 | (const AliCDBDumpParam*) param; | |
9e1ceb13 | 834 | |
5078a13f | 835 | return new AliCDBDump(dumpParam->GetPath(), |
836 | dumpParam->IsReadOnly()); | |
837 | } | |
9e1ceb13 | 838 | |
5078a13f | 839 | return NULL; |
9e1ceb13 | 840 | } |
841 | ||
842 | ///////////////////////////////////////////////////////////////////////////////////////////////// | |
843 | // // | |
844 | // AliCDBDump parameter class // | |
845 | // // | |
846 | ///////////////////////////////////////////////////////////////////////////////////////////////// | |
847 | ||
848 | ClassImp(AliCDBDumpParam) | |
849 | ||
5078a13f | 850 | //_____________________________________________________________________________ |
851 | AliCDBDumpParam::AliCDBDumpParam(): | |
852 | fDBPath(), fReadOnly(kFALSE) | |
62032124 | 853 | { |
5078a13f | 854 | // default constructor |
9e1ceb13 | 855 | |
856 | } | |
857 | ||
858 | //_____________________________________________________________________________ | |
859 | AliCDBDumpParam::AliCDBDumpParam(const char* dbPath, Bool_t readOnly): | |
5078a13f | 860 | fDBPath(dbPath), fReadOnly(readOnly) |
2c8628dd | 861 | { |
5078a13f | 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"); | |
9e1ceb13 | 874 | } |
875 | ||
876 | //_____________________________________________________________________________ | |
877 | AliCDBDumpParam::~AliCDBDumpParam() { | |
5078a13f | 878 | // destructor |
9e1ceb13 | 879 | |
880 | } | |
881 | ||
882 | //_____________________________________________________________________________ | |
883 | AliCDBParam* AliCDBDumpParam::CloneParam() const { | |
5078a13f | 884 | // clone parameter |
9e1ceb13 | 885 | |
5078a13f | 886 | return new AliCDBDumpParam(fDBPath, fReadOnly); |
9e1ceb13 | 887 | } |
888 | ||
889 | //_____________________________________________________________________________ | |
890 | ULong_t AliCDBDumpParam::Hash() const { | |
5078a13f | 891 | // return Hash function |
9e1ceb13 | 892 | |
5078a13f | 893 | return fDBPath.Hash(); |
9e1ceb13 | 894 | } |
895 | ||
896 | //_____________________________________________________________________________ | |
897 | Bool_t AliCDBDumpParam::IsEqual(const TObject* obj) const { | |
5078a13f | 898 | // check if this object is equal to AliCDBParam obj |
899 | ||
900 | if (this == obj) { | |
901 | return kTRUE; | |
902 | } | |
9e1ceb13 | 903 | |
5078a13f | 904 | if (AliCDBDumpParam::Class() != obj->IsA()) { |
905 | return kFALSE; | |
906 | } | |
9e1ceb13 | 907 | |
5078a13f | 908 | AliCDBDumpParam* other = (AliCDBDumpParam*) obj; |
9e1ceb13 | 909 | |
5078a13f | 910 | return fDBPath == other->fDBPath; |
fe913d8f | 911 | } |