]>
Commit | Line | Data |
---|---|---|
9e1ceb13 | 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 | **************************************************************************/ | |
fdf65bb5 | 15 | //------------------------------------------------------------------------- |
16 | // Implementation of AliCDBManager and AliCDBParam classe | |
17 | // Author: Alberto Colla | |
18 | // e-mail: Alberto.Colla@cern.ch | |
19 | //------------------------------------------------------------------------- | |
9e1ceb13 | 20 | |
c11cdcf2 | 21 | #include <stdlib.h> |
22 | ||
9e1ceb13 | 23 | #include "AliCDBManager.h" |
24 | #include "AliCDBStorage.h" | |
25 | #include "AliLog.h" | |
26 | #include "AliCDBDump.h" | |
27 | #include "AliCDBLocal.h" | |
28 | #include "AliCDBGrid.h" | |
02c4845e | 29 | #include "AliCDBEntry.h" |
7de84b33 | 30 | #include "AliCDBHandler.h" |
9e1ceb13 | 31 | |
02c4845e | 32 | #include <TObjString.h> |
7de84b33 | 33 | #include <TSAXParser.h> |
34 | #include <TFile.h> | |
647d2bb8 | 35 | #include <TKey.h> |
7de84b33 | 36 | #include <TUUID.h> |
27cac7e3 | 37 | #include <TGrid.h> |
9e1ceb13 | 38 | |
39 | ClassImp(AliCDBParam) | |
40 | ||
41 | ClassImp(AliCDBManager) | |
42 | ||
b8ec52f6 | 43 | //TODO OCDB and Reference folder should not be fully hardcoded but built from run number (or year/LHC period) |
44 | TString AliCDBManager::fgkCondUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/CDB?user=aliprod"); | |
45 | TString AliCDBManager::fgkRefUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/Reference?user=aliprod"); | |
7de84b33 | 46 | TString AliCDBManager::fgkMCIdealStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Ideal"); |
47 | TString AliCDBManager::fgkMCFullStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Full"); | |
48 | TString AliCDBManager::fgkMCResidualStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Residual"); | |
49 | TString AliCDBManager::fgkOCDBFolderXMLfile("alien:///alice/data/OCDBFoldervsRunRange.xml"); | |
9e1ceb13 | 50 | AliCDBManager* AliCDBManager::fgInstance = 0x0; |
51 | ||
52 | //_____________________________________________________________________________ | |
d1982b43 | 53 | AliCDBManager* AliCDBManager::Instance(TMap *entryCache, Int_t run) |
b8ec52f6 | 54 | { |
9e1ceb13 | 55 | // returns AliCDBManager instance (singleton) |
56 | ||
57 | if (!fgInstance) { | |
58 | fgInstance = new AliCDBManager(); | |
d1982b43 | 59 | if (!entryCache) |
60 | fgInstance->Init(); | |
61 | else | |
62 | fgInstance->InitFromCache(entryCache,run); | |
9e1ceb13 | 63 | } |
64 | ||
65 | return fgInstance; | |
66 | } | |
67 | ||
68 | //_____________________________________________________________________________ | |
69 | void AliCDBManager::Init() { | |
70 | // factory registering | |
71 | ||
72 | RegisterFactory(new AliCDBDumpFactory()); | |
73 | RegisterFactory(new AliCDBLocalFactory()); | |
74 | // AliCDBGridFactory is registered only if AliEn libraries are enabled in Root | |
95cf1c7a | 75 | if(!gSystem->Exec("root-config --has-alien 2>/dev/null |grep yes 2>&1 > /dev/null")){ // returns 0 if yes |
9e1ceb13 | 76 | AliInfo("AliEn classes enabled in Root. AliCDBGrid factory registered."); |
77 | RegisterFactory(new AliCDBGridFactory()); | |
b8ec52f6 | 78 | fCondParam = CreateParameter(fgkCondUri); |
79 | fRefParam = CreateParameter(fgkRefUri); | |
9e1ceb13 | 80 | } |
4667c116 | 81 | |
82 | InitShortLived(); | |
9e1ceb13 | 83 | } |
d1982b43 | 84 | |
85 | //_____________________________________________________________________________ | |
86 | void AliCDBManager::InitFromCache(TMap *entryCache, Int_t run) { | |
87 | // initialize manager from existing cache | |
88 | // used on the slaves in case of parallel reconstruction | |
89 | SetRun(run); | |
90 | ||
91 | TIter iter(entryCache->GetTable()); | |
92 | TPair* pair = 0; | |
93 | ||
94 | while((pair = dynamic_cast<TPair*> (iter.Next()))){ | |
95 | fEntryCache.Add(pair->Key(),pair->Value()); | |
96 | } | |
97 | // fEntry is the new owner of the cache | |
98 | fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE); | |
77d2efce | 99 | entryCache->SetOwnerKeyValue(kFALSE,kFALSE); |
d1982b43 | 100 | AliInfo(Form("%d cache entries have been loaded",fEntryCache.GetEntries())); |
101 | } | |
102 | ||
7ec0d3df | 103 | //_____________________________________________________________________________ |
c022b397 | 104 | void AliCDBManager::DumpToSnapshotFile(const char* snapshotFileName, Bool_t singleKeys){ |
7ec0d3df | 105 | // |
106 | // dump the entries map and the ids list to | |
107 | // the output file | |
108 | ||
109 | // open the file | |
110 | TFile *f = TFile::Open(snapshotFileName,"RECREATE"); | |
111 | if (!f || f->IsZombie()){ | |
112 | AliError(Form("Cannot open file %s",snapshotFileName)); | |
113 | return; | |
114 | } | |
115 | ||
116 | Printf("\ndumping entriesMap (entries'cache) with %d entries!\n", fEntryCache.GetEntries()); | |
117 | Printf("\ndumping entriesList with %d entries!\n", fIds->GetEntries()); | |
118 | ||
119 | f->cd(); | |
120 | ||
c022b397 | 121 | if(singleKeys){ |
122 | f->WriteObject(&fEntryCache,"CDBentriesMap"); | |
123 | f->WriteObject(fIds,"CDBidsList"); | |
124 | }else{ | |
125 | // We write the entries one by one named by their calibration path | |
126 | /* | |
127 | fEntryCache.Write("CDBentriesMap"); | |
128 | fIds->Write("CDBidsList"); | |
129 | */ | |
130 | TIter iter(fEntryCache.GetTable()); | |
131 | TPair* pair = 0; | |
132 | while((pair = dynamic_cast<TPair*> (iter.Next()))){ | |
133 | TObjString *os = dynamic_cast<TObjString*>(pair->Key()); | |
dc6bcf30 | 134 | if (!os) continue; |
c022b397 | 135 | TString path = os->GetString(); |
136 | AliCDBEntry *entry = dynamic_cast<AliCDBEntry*>(pair->Value()); | |
dc6bcf30 | 137 | if (!entry) continue; |
c022b397 | 138 | path.ReplaceAll("/","*"); |
139 | entry->Write(path.Data()); | |
140 | } | |
141 | } | |
7ec0d3df | 142 | f->Close(); |
143 | delete f; | |
144 | ||
c11cdcf2 | 145 | exit(0); |
7ec0d3df | 146 | } |
147 | ||
647d2bb8 | 148 | //_____________________________________________________________________________ |
b0e8cda6 | 149 | Bool_t AliCDBManager::InitFromSnapshot(const char* snapshotFileName, Bool_t overwrite){ |
647d2bb8 | 150 | // initialize manager from a CDB snapshot, that is add the entries |
151 | // to the entries map and the ids to the ids list taking them from | |
152 | // the map and the list found in the input file | |
153 | ||
69aa0e14 | 154 | // if the manager is locked it cannot initialize from a snapshot |
155 | if(fLock) { | |
156 | AliError("Being locked I cannot initialize from the snapshot!"); | |
157 | return kFALSE; | |
158 | } | |
159 | ||
647d2bb8 | 160 | // open the file |
161 | TString snapshotFile(snapshotFileName); | |
162 | if(snapshotFile.BeginsWith("alien://")){ | |
163 | if(!gGrid) { | |
164 | TGrid::Connect("alien://",""); | |
165 | if(!gGrid) { | |
166 | AliError("Connection to alien failed!"); | |
167 | return kFALSE; | |
168 | } | |
169 | } | |
170 | } | |
171 | ||
172 | TFile *f = TFile::Open(snapshotFileName); | |
173 | if (!f || f->IsZombie()){ | |
174 | AliError(Form("Cannot open file %s",snapshotFileName)); | |
175 | return kFALSE; | |
176 | } | |
177 | ||
b0e8cda6 | 178 | // retrieve entries' map from snapshot file |
647d2bb8 | 179 | TMap *entriesMap = 0; |
180 | TIter next(f->GetListOfKeys()); | |
181 | TKey *key; | |
182 | while ((key = (TKey*)next())) { | |
183 | if (strcmp(key->GetClassName(),"TMap") != 0) continue; | |
184 | entriesMap = (TMap*)key->ReadObj(); | |
185 | break; | |
186 | } | |
187 | if (!entriesMap || entriesMap->GetEntries()==0){ | |
188 | AliError("Cannot get valid map of CDB entries from snapshot file"); | |
189 | return kFALSE; | |
190 | } | |
191 | ||
b0e8cda6 | 192 | // retrieve ids' list from snapshot file |
647d2bb8 | 193 | TList *idsList = 0; |
194 | TIter nextKey(f->GetListOfKeys()); | |
195 | TKey *keyN; | |
196 | while ((keyN = (TKey*)nextKey())) { | |
197 | if (strcmp(keyN->GetClassName(),"TList") != 0) continue; | |
198 | idsList = (TList*)keyN->ReadObj(); | |
199 | break; | |
200 | } | |
201 | if (!idsList || idsList->GetEntries()==0){ | |
202 | AliError("Cannot get valid list of CDB entries from snapshot file"); | |
203 | return kFALSE; | |
204 | } | |
205 | ||
b0e8cda6 | 206 | // Add each (entry,id) from the snapshot to the memory: entry to the cache, id to the list of ids. |
207 | // If "overwrite" is false: add the entry to the cache and its id to the list of ids | |
208 | // only if neither of them is already there. | |
209 | // If "overwrite" is true: write the snapshot entry,id in any case. If something | |
210 | // was already there for that calibration type, remove it and issue a warning | |
647d2bb8 | 211 | TIter iterObj(entriesMap->GetTable()); |
212 | TPair* pair = 0; | |
b0e8cda6 | 213 | Int_t nAdded=0; |
647d2bb8 | 214 | while((pair = dynamic_cast<TPair*> (iterObj.Next()))){ |
b0e8cda6 | 215 | TObjString* os = (TObjString*) pair->Key(); |
216 | TString path = os->GetString(); | |
217 | TIter iterId(idsList); | |
218 | AliCDBId* id=0; | |
219 | AliCDBId* correspondingId=0; | |
220 | while((id = dynamic_cast<AliCDBId*> (iterId.Next()))){ | |
221 | TString idpath(id->GetPath()); | |
222 | if(idpath==path){ | |
223 | correspondingId=id; | |
224 | break; | |
225 | } | |
226 | } | |
227 | if(!correspondingId){ | |
228 | AliError(Form("id for \"%s\" not found in the snapshot (while entry was). This entry is skipped!",path.Data())); | |
229 | break; | |
230 | } | |
231 | Bool_t cached = fEntryCache.Contains(path.Data()); | |
232 | Bool_t registeredId = kFALSE; | |
233 | TIter iter(fIds); | |
234 | AliCDBId *idT = 0; | |
235 | while((idT = dynamic_cast<AliCDBId*> (iter.Next()))){ | |
236 | if(idT->GetPath()==path){ | |
237 | registeredId = kTRUE; | |
238 | break; | |
239 | } | |
240 | } | |
241 | ||
242 | if(overwrite){ | |
243 | if(cached || registeredId){ | |
244 | AliWarning(Form("An entry was already cached for \"%s\". Removing it before caching from snapshot",path.Data())); | |
245 | UnloadFromCache(path.Data()); | |
246 | } | |
247 | fEntryCache.Add(pair->Key(),pair->Value()); | |
248 | fIds->Add(id); | |
249 | nAdded++; | |
250 | }else{ | |
251 | if(cached || registeredId){ | |
252 | AliWarning(Form("An entry was already cached for \"%s\". Not adding this object from snapshot",path.Data())); | |
253 | }else{ | |
254 | fEntryCache.Add(pair->Key(),pair->Value()); | |
255 | fIds->Add(id); | |
256 | nAdded++; | |
257 | } | |
258 | } | |
647d2bb8 | 259 | } |
b0e8cda6 | 260 | |
647d2bb8 | 261 | // fEntry is the new owner of the cache |
262 | fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE); | |
263 | entriesMap->SetOwnerKeyValue(kFALSE,kFALSE); | |
647d2bb8 | 264 | fIds->SetOwner(kTRUE); |
265 | idsList->SetOwner(kFALSE); | |
b0e8cda6 | 266 | AliInfo(Form("%d new (entry,id) cached. Total number %d",nAdded,fEntryCache.GetEntries())); |
267 | ||
647d2bb8 | 268 | f->Close(); |
269 | delete f; | |
647d2bb8 | 270 | |
271 | return kTRUE; | |
272 | } | |
273 | ||
9e1ceb13 | 274 | //_____________________________________________________________________________ |
275 | void AliCDBManager::Destroy() { | |
276 | // delete ALCDBManager instance and active storages | |
277 | ||
278 | if (fgInstance) { | |
4b5e0dce | 279 | //fgInstance->Delete(); |
9e1ceb13 | 280 | delete fgInstance; |
281 | fgInstance = 0x0; | |
282 | } | |
283 | } | |
284 | ||
285 | //_____________________________________________________________________________ | |
286 | AliCDBManager::AliCDBManager(): | |
fe12e09c | 287 | TObject(), |
288 | fFactories(), | |
289 | fActiveStorages(), | |
290 | fSpecificStorages(), | |
b21e3194 | 291 | fEntryCache(), |
292 | fIds(0), | |
293 | fStorageMap(0), | |
294 | fShortLived(0), | |
fe12e09c | 295 | fDefaultStorage(NULL), |
296 | fDrainStorage(NULL), | |
b21e3194 | 297 | fCondParam(0), |
298 | fRefParam(0), | |
4667c116 | 299 | fRun(-1), |
1f341624 | 300 | fCache(kTRUE), |
7de84b33 | 301 | fLock(kFALSE), |
c022b397 | 302 | fSnapshotMode(kFALSE), |
303 | fSnapshotFile(0), | |
7de84b33 | 304 | fRaw(kFALSE), |
305 | fStartRunLHCPeriod(-1), | |
306 | fEndRunLHCPeriod(-1), | |
a6f59240 | 307 | fLHCPeriod(""), |
308 | fKey(0) | |
9e1ceb13 | 309 | { |
310 | // default constuctor | |
4b5e0dce | 311 | fFactories.SetOwner(1); |
62032124 | 312 | fActiveStorages.SetOwner(1); |
313 | fSpecificStorages.SetOwner(1); | |
d1982b43 | 314 | fEntryCache.SetName("CDBEntryCache"); |
77d2efce | 315 | fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE); |
b21e3194 | 316 | |
317 | fStorageMap = new TMap(); | |
318 | fStorageMap->SetOwner(1); | |
319 | fIds = new TList(); | |
320 | fIds->SetOwner(1); | |
9e1ceb13 | 321 | } |
322 | ||
323 | //_____________________________________________________________________________ | |
324 | AliCDBManager::~AliCDBManager() { | |
325 | // destructor | |
4b5e0dce | 326 | ClearCache(); |
9e1ceb13 | 327 | DestroyActiveStorages(); |
62032124 | 328 | fFactories.Delete(); |
b05400be | 329 | fDrainStorage = 0x0; |
330 | fDefaultStorage = 0x0; | |
b21e3194 | 331 | delete fStorageMap; fStorageMap = 0; |
332 | delete fIds; fIds = 0; | |
b8ec52f6 | 333 | delete fCondParam; |
334 | delete fRefParam; | |
4667c116 | 335 | delete fShortLived; fShortLived = 0x0; |
c022b397 | 336 | //fSnapshotCache = 0; |
337 | //fSnapshotIdsList = 0; | |
338 | if(fSnapshotMode){ | |
339 | fSnapshotFile->Close(); | |
340 | fSnapshotFile = 0; | |
341 | } | |
9e1ceb13 | 342 | } |
343 | ||
9e1ceb13 | 344 | //_____________________________________________________________________________ |
345 | void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){ | |
346 | // put a storage object into the list of active storages | |
347 | ||
348 | fActiveStorages.Add(param, storage); | |
349 | AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries())); | |
350 | } | |
351 | ||
352 | //_____________________________________________________________________________ | |
353 | void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) { | |
354 | // add a storage factory to the list of registerd factories | |
355 | ||
356 | if (!fFactories.Contains(factory)) { | |
357 | fFactories.Add(factory); | |
358 | } | |
359 | } | |
360 | ||
361 | //_____________________________________________________________________________ | |
fdf65bb5 | 362 | Bool_t AliCDBManager::HasStorage(const char* dbString) const { |
b21e3194 | 363 | // check if dbString is a URI valid for one of the registered factories |
9e1ceb13 | 364 | |
365 | TIter iter(&fFactories); | |
366 | ||
62032124 | 367 | AliCDBStorageFactory* factory=0; |
9e1ceb13 | 368 | while ((factory = (AliCDBStorageFactory*) iter.Next())) { |
369 | ||
370 | if (factory->Validate(dbString)) { | |
371 | return kTRUE; | |
4005d0b5 | 372 | } |
9e1ceb13 | 373 | } |
374 | ||
375 | return kFALSE; | |
376 | } | |
377 | ||
378 | //_____________________________________________________________________________ | |
fdf65bb5 | 379 | AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const { |
9e1ceb13 | 380 | // create AliCDBParam object from URI string |
381 | ||
382 | TIter iter(&fFactories); | |
7de84b33 | 383 | |
62032124 | 384 | AliCDBStorageFactory* factory=0; |
9e1ceb13 | 385 | while ((factory = (AliCDBStorageFactory*) iter.Next())) { |
9e1ceb13 | 386 | AliCDBParam* param = factory->CreateParameter(dbString); |
62032124 | 387 | if(param) return param; |
9e1ceb13 | 388 | } |
389 | ||
390 | return NULL; | |
391 | } | |
392 | ||
393 | //_____________________________________________________________________________ | |
394 | AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) { | |
395 | // get storage object from URI string | |
1f341624 | 396 | |
9e1ceb13 | 397 | AliCDBParam* param = CreateParameter(dbString); |
398 | if (!param) { | |
c3a7b59a | 399 | AliError(Form("Failed to activate requested storage! Check URI: %s", dbString)); |
9e1ceb13 | 400 | return NULL; |
82096dfc | 401 | } |
9e1ceb13 | 402 | |
403 | AliCDBStorage* aStorage = GetStorage(param); | |
404 | ||
405 | delete param; | |
9e1ceb13 | 406 | return aStorage; |
407 | } | |
408 | ||
409 | //_____________________________________________________________________________ | |
410 | AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) { | |
411 | // get storage object from AliCDBParam object | |
1f341624 | 412 | |
82096dfc | 413 | // if the list of active storages already contains |
9e1ceb13 | 414 | // the requested storage, return it |
415 | AliCDBStorage* aStorage = GetActiveStorage(param); | |
416 | if (aStorage) { | |
417 | return aStorage; | |
418 | } | |
419 | ||
1f341624 | 420 | // if lock is ON, cannot activate more storages! |
421 | if(fLock) { | |
422 | if (fDefaultStorage) { | |
423 | AliFatal("Lock is ON, and default storage is already set: " | |
424 | "cannot reset it or activate more storages!"); | |
425 | } | |
426 | } | |
427 | ||
9e1ceb13 | 428 | TIter iter(&fFactories); |
429 | ||
62032124 | 430 | AliCDBStorageFactory* factory=0; |
917a098b | 431 | |
9e1ceb13 | 432 | // loop on the list of registered factories |
433 | while ((factory = (AliCDBStorageFactory*) iter.Next())) { | |
434 | ||
435 | // each factory tries to create its storage from the parameter | |
436 | aStorage = factory->Create(param); | |
437 | if (aStorage) { | |
438 | PutActiveStorage(param->CloneParam(), aStorage); | |
917a098b | 439 | aStorage->SetURI(param->GetURI()); |
6dc56e97 | 440 | if(fRun >= 0) { |
96b7636d | 441 | if(aStorage->GetType() == "alien"){ |
442 | aStorage->QueryCDB(fRun); | |
443 | } else { | |
444 | AliDebug(2, | |
445 | "Skipping query for valid files, it is used only in grid..."); | |
446 | } | |
c3a7b59a | 447 | } |
9e1ceb13 | 448 | return aStorage; |
449 | } | |
450 | } | |
451 | ||
c3a7b59a | 452 | AliError(Form("Failed to activate requested storage! Check URI: %s", param->GetURI().Data())); |
453 | ||
9e1ceb13 | 454 | return NULL; |
455 | } | |
456 | ||
62032124 | 457 | //_____________________________________________________________________________ |
458 | AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) { | |
459 | // get a storage object from the list of active storages | |
460 | ||
461 | return dynamic_cast<AliCDBStorage*> (fActiveStorages.GetValue(param)); | |
462 | } | |
463 | ||
9e1ceb13 | 464 | //_____________________________________________________________________________ |
465 | TList* AliCDBManager::GetActiveStorages() { | |
466 | // return list of active storages | |
62032124 | 467 | // user has responsibility to delete returned object |
9e1ceb13 | 468 | |
469 | TList* result = new TList(); | |
470 | ||
917a098b | 471 | TIter iter(fActiveStorages.GetTable()); |
62032124 | 472 | TPair* aPair=0; |
9e1ceb13 | 473 | while ((aPair = (TPair*) iter.Next())) { |
474 | result->Add(aPair->Value()); | |
475 | } | |
476 | ||
477 | return result; | |
478 | } | |
479 | ||
480 | //_____________________________________________________________________________ | |
481 | void AliCDBManager::SetDrain(const char* dbString) { | |
482 | // set drain storage from URI string | |
483 | ||
484 | fDrainStorage = GetStorage(dbString); | |
485 | } | |
486 | ||
487 | //_____________________________________________________________________________ | |
488 | void AliCDBManager::SetDrain(const AliCDBParam* param) { | |
489 | // set drain storage from AliCDBParam | |
b8ec52f6 | 490 | |
9e1ceb13 | 491 | fDrainStorage = GetStorage(param); |
492 | } | |
493 | ||
494 | //_____________________________________________________________________________ | |
495 | void AliCDBManager::SetDrain(AliCDBStorage* storage) { | |
496 | // set drain storage from another active storage | |
497 | ||
498 | fDrainStorage = storage; | |
499 | } | |
500 | ||
501 | //_____________________________________________________________________________ | |
502 | Bool_t AliCDBManager::Drain(AliCDBEntry *entry) { | |
503 | // drain retrieved object to drain storage | |
504 | ||
b8ec52f6 | 505 | AliDebug(2, "Draining into drain storage..."); |
9e1ceb13 | 506 | return fDrainStorage->Put(entry); |
507 | } | |
508 | ||
7de84b33 | 509 | //____________________________________________________________________________ |
9e1ceb13 | 510 | void AliCDBManager::SetDefaultStorage(const char* dbString) { |
511 | // sets default storage from URI string | |
1f341624 | 512 | |
7de84b33 | 513 | // checking whether we are in the raw case |
514 | TString dbStringTemp(dbString); | |
27cac7e3 | 515 | if (dbStringTemp == "raw://") |
516 | { | |
517 | fRaw = kTRUE; | |
518 | AliInfo("Setting the run-number will set the corresponding OCDB for raw data reconstruction."); | |
cdc36cbf | 519 | AliInfo("Connecting to the grid..."); |
520 | if(!gGrid) { | |
521 | TGrid::Connect("alien://",""); | |
522 | if(!gGrid) { | |
523 | AliError("Connection to alien failed!"); | |
524 | return; | |
525 | } | |
526 | } | |
27cac7e3 | 527 | return; |
528 | } | |
7de84b33 | 529 | |
530 | AliCDBStorage* bckStorage = fDefaultStorage; | |
531 | ||
82096dfc | 532 | fDefaultStorage = GetStorage(dbString); |
95c0e132 | 533 | |
534 | if(!fDefaultStorage) return; | |
7de84b33 | 535 | |
4954c5cd | 536 | if(bckStorage && (fDefaultStorage != bckStorage)){ |
537 | AliWarning("Existing default storage replaced: clearing cache!"); | |
538 | ClearCache(); | |
539 | } | |
7de84b33 | 540 | |
b21e3194 | 541 | if (fStorageMap->Contains("default")) { |
e1dd4d81 | 542 | delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key()); |
b21e3194 | 543 | } |
544 | fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI())); | |
9e1ceb13 | 545 | } |
9e1ceb13 | 546 | //_____________________________________________________________________________ |
547 | void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) { | |
548 | // set default storage from AliCDBParam object | |
1f341624 | 549 | |
4954c5cd | 550 | AliCDBStorage* bckStorage = fDefaultStorage; |
551 | ||
b8ec52f6 | 552 | fDefaultStorage = GetStorage(param); |
4954c5cd | 553 | |
95c0e132 | 554 | if(!fDefaultStorage) return; |
555 | ||
4954c5cd | 556 | if(bckStorage && (fDefaultStorage != bckStorage)){ |
557 | AliWarning("Existing default storage replaced: clearing cache!"); | |
558 | ClearCache(); | |
559 | } | |
b21e3194 | 560 | |
561 | if (fStorageMap->Contains("default")) { | |
e1dd4d81 | 562 | delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key()); |
b21e3194 | 563 | } |
564 | fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI())); | |
9e1ceb13 | 565 | } |
566 | ||
567 | //_____________________________________________________________________________ | |
568 | void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) { | |
569 | // set default storage from another active storage | |
1f341624 | 570 | |
571 | // if lock is ON, cannot activate more storages! | |
572 | if(fLock) { | |
573 | if (fDefaultStorage) { | |
574 | AliFatal("Lock is ON, and default storage is already set: " | |
575 | "cannot reset it or activate more storages!"); | |
576 | } | |
577 | } | |
578 | ||
579 | if (!storage) { | |
580 | UnsetDefaultStorage(); | |
581 | return; | |
582 | } | |
583 | ||
4954c5cd | 584 | AliCDBStorage* bckStorage = fDefaultStorage; |
585 | ||
9e1ceb13 | 586 | fDefaultStorage = storage; |
4954c5cd | 587 | |
588 | if(bckStorage && (fDefaultStorage != bckStorage)){ | |
589 | AliWarning("Existing default storage replaced: clearing cache!"); | |
590 | ClearCache(); | |
591 | } | |
b21e3194 | 592 | |
593 | if (fStorageMap->Contains("default")) { | |
e1dd4d81 | 594 | delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key()); |
b21e3194 | 595 | } |
596 | fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI())); | |
9e1ceb13 | 597 | } |
4667c116 | 598 | |
7de84b33 | 599 | //_____________________________________________________________________________ |
600 | void AliCDBManager::SetDefaultStorage(const char* mcString, const char* simType) { | |
601 | // sets default storage for MC data | |
602 | // mcString MUST be "MC", | |
603 | // simType can be "Ideal","Residual","Full" | |
604 | ||
605 | TString strmcString(mcString); | |
606 | TString strsimType(simType); | |
607 | TString dbString; | |
608 | if (strmcString != "MC"){ | |
609 | AliFatal("Method requires first string to be MC!"); | |
610 | } | |
611 | else { | |
612 | if (strsimType == "Ideal"){ | |
613 | dbString = fgkMCIdealStorage; | |
614 | } | |
615 | else if (strsimType == "Full"){ | |
616 | dbString = fgkMCFullStorage; | |
617 | } | |
618 | else if (strsimType == "Residual"){ | |
619 | dbString = fgkMCResidualStorage; | |
620 | } | |
621 | else { | |
622 | AliFatal("Error in setting the storage for MC data, second argument MUST be either \"Ideal\" or \"Full\" or \"Residual\"."); | |
623 | } | |
624 | ||
625 | SetDefaultStorage(dbString.Data()); | |
b7df0cc5 | 626 | fStartRunLHCPeriod=0; |
627 | fEndRunLHCPeriod=AliCDBRunRange::Infinity(); | |
628 | if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",dbString.Data())); | |
7de84b33 | 629 | } |
630 | } | |
631 | //_____________________________________________________________________________ | |
632 | void AliCDBManager::SetDefaultStorageFromRun(Int_t run) { | |
633 | // set default storage from the run number - to be used only with raw data | |
634 | ||
635 | // if lock is ON, cannot activate more storages! | |
636 | if(fLock) { | |
637 | if (fDefaultStorage) { | |
638 | AliFatal("Lock is ON, and default storage is already set: " | |
639 | "cannot activate default storage from run number"); | |
640 | } | |
641 | } | |
642 | ||
643 | // retrieve XML file from alien | |
27cac7e3 | 644 | if(!gGrid) { |
645 | TGrid::Connect("alien://",""); | |
646 | if(!gGrid) { | |
647 | AliError("Connection to alien failed!"); | |
648 | return; | |
649 | } | |
650 | } | |
7de84b33 | 651 | TUUID uuid; |
652 | TString rndname = "/tmp/"; | |
653 | rndname += "OCDBFolderXML."; | |
654 | rndname += uuid.AsString(); | |
655 | rndname += ".xml"; | |
656 | AliDebug(2, Form("file to be copied = %s", fgkOCDBFolderXMLfile.Data())); | |
657 | if (!TFile::Cp(fgkOCDBFolderXMLfile.Data(), rndname.Data())) { | |
658 | AliFatal(Form("Cannot make a local copy of OCDBFolder xml file in %s",rndname.Data())); | |
659 | } | |
660 | AliCDBHandler* saxcdb = new AliCDBHandler(); | |
661 | saxcdb->SetRun(run); | |
662 | TSAXParser *saxParser = new TSAXParser(); | |
663 | saxParser->ConnectToHandler("AliCDBHandler", saxcdb); | |
664 | saxParser->ParseFile(rndname.Data()); | |
665 | AliInfo(Form(" LHC folder = %s", saxcdb->GetOCDBFolder().Data())); | |
666 | AliInfo(Form(" LHC period start run = %d", saxcdb->GetStartRunRange())); | |
667 | AliInfo(Form(" LHC period end run = %d", saxcdb->GetEndRunRange())); | |
668 | fLHCPeriod = saxcdb->GetOCDBFolder(); | |
669 | fStartRunLHCPeriod = saxcdb->GetStartRunRange(); | |
670 | fEndRunLHCPeriod = saxcdb->GetEndRunRange(); | |
671 | ||
672 | SetDefaultStorage(fLHCPeriod.Data()); | |
673 | if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",fLHCPeriod.Data())); | |
674 | ||
675 | } | |
676 | ||
4667c116 | 677 | //_____________________________________________________________________________ |
1f341624 | 678 | void AliCDBManager::UnsetDefaultStorage() { |
679 | // Unset default storage | |
680 | ||
681 | // if lock is ON, action is forbidden! | |
682 | if(fLock) { | |
683 | if (fDefaultStorage) { | |
684 | AliFatal("Lock is ON: cannot unset default storage!"); | |
685 | } | |
686 | } | |
687 | ||
688 | if (fDefaultStorage) { | |
689 | AliWarning("Clearing cache!"); | |
690 | ClearCache(); | |
691 | } | |
4130f78c | 692 | |
693 | fRun = fStartRunLHCPeriod = fEndRunLHCPeriod = -1; | |
694 | fRaw = kFALSE; | |
1f341624 | 695 | |
696 | fDefaultStorage = 0x0; | |
4667c116 | 697 | } |
9e1ceb13 | 698 | |
02c4845e | 699 | //_____________________________________________________________________________ |
024cf675 | 700 | void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) { |
701 | // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...)) | |
02c4845e | 702 | |
703 | AliCDBParam *aPar = CreateParameter(dbString); | |
704 | if(!aPar) return; | |
024cf675 | 705 | SetSpecificStorage(calibType, aPar); |
02c4845e | 706 | delete aPar; |
707 | } | |
708 | ||
709 | //_____________________________________________________________________________ | |
647d2bb8 | 710 | void AliCDBManager::SetSpecificStorage(const char* calibType, const AliCDBParam* param) { |
024cf675 | 711 | // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...)) |
712 | // Default storage should be defined prior to any specific storages, e.g.: | |
713 | // AliCDBManager::instance()->SetDefaultStorage("alien://"); | |
c3a7b59a | 714 | // AliCDBManager::instance()->SetSpecificStorage("TPC/*","local://DB_TPC"); |
715 | // AliCDBManager::instance()->SetSpecificStorage("*/Align/*","local://DB_TPCAlign"); | |
716 | // calibType must be a valid CDB path! (3 level folder structure) | |
02c4845e | 717 | |
7de84b33 | 718 | |
b5e4b0d2 | 719 | if(!fDefaultStorage && !fRaw) { |
c3a7b59a | 720 | AliError("Please activate a default storage first!"); |
02c4845e | 721 | return; |
722 | } | |
4005d0b5 | 723 | |
7de84b33 | 724 | |
62032124 | 725 | AliCDBPath aPath(calibType); |
726 | if(!aPath.IsValid()){ | |
727 | AliError(Form("Not a valid path: %s", calibType)); | |
728 | return; | |
729 | } | |
730 | ||
731 | TObjString *objCalibType = new TObjString(aPath.GetPath()); | |
024cf675 | 732 | if(fSpecificStorages.Contains(objCalibType)){ |
62032124 | 733 | AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one", |
024cf675 | 734 | calibType)); |
4005d0b5 | 735 | AliCDBParam *checkPar = dynamic_cast<AliCDBParam*> (fSpecificStorages.GetValue(calibType)); |
736 | if(checkPar) delete checkPar; | |
8e245d15 | 737 | delete fSpecificStorages.Remove(objCalibType); |
02c4845e | 738 | } |
95c0e132 | 739 | AliCDBStorage *aStorage = GetStorage(param); |
740 | if(!aStorage) return; | |
96b7636d | 741 | |
742 | fSpecificStorages.Add(objCalibType, param->CloneParam()); | |
b21e3194 | 743 | |
744 | if(fStorageMap->Contains(objCalibType)){ | |
745 | delete fStorageMap->Remove(objCalibType); | |
746 | } | |
747 | fStorageMap->Add(objCalibType->Clone(), new TObjString(param->GetURI())); | |
748 | ||
02c4845e | 749 | } |
750 | ||
751 | //_____________________________________________________________________________ | |
024cf675 | 752 | AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) { |
753 | // get storage specific for detector or calibration type | |
4b5e0dce | 754 | |
9c7fb557 | 755 | AliCDBPath calibPath(calibType); |
756 | if(!calibPath.IsValid()) return NULL; | |
96b7636d | 757 | |
9c7fb557 | 758 | AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibPath.GetPath()); |
02c4845e | 759 | if(!checkPar){ |
b8ec52f6 | 760 | AliError(Form("%s storage not found!", calibType)); |
02c4845e | 761 | return NULL; |
762 | } else { | |
763 | return GetStorage(checkPar); | |
764 | } | |
96b7636d | 765 | |
02c4845e | 766 | } |
767 | ||
024cf675 | 768 | //_____________________________________________________________________________ |
769 | AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) { | |
82096dfc | 770 | // select storage valid for path from the list of specific storages |
024cf675 | 771 | |
62032124 | 772 | AliCDBPath aPath(path); |
4005d0b5 | 773 | if(!aPath.IsValid()) return NULL; |
62032124 | 774 | |
024cf675 | 775 | TIter iter(&fSpecificStorages); |
62032124 | 776 | TObjString *aCalibType=0; |
96b7636d | 777 | AliCDBPath tmpPath("null/null/null"); |
024cf675 | 778 | AliCDBParam* aPar=0; |
779 | while((aCalibType = (TObjString*) iter.Next())){ | |
62032124 | 780 | AliCDBPath calibTypePath(aCalibType->GetName()); |
781 | if(calibTypePath.Comprises(aPath)) { | |
96b7636d | 782 | if(calibTypePath.Comprises(tmpPath)) continue; |
024cf675 | 783 | aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType); |
96b7636d | 784 | tmpPath.SetPath(calibTypePath.GetPath()); |
024cf675 | 785 | } |
786 | } | |
787 | return aPar; | |
788 | } | |
789 | ||
02c4845e | 790 | //_____________________________________________________________________________ |
4667c116 | 791 | AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber, |
02c4845e | 792 | Int_t version, Int_t subVersion) { |
793 | // get an AliCDBEntry object from the database | |
794 | ||
024cf675 | 795 | if(runNumber < 0){ |
796 | // RunNumber is not specified. Try with fRun | |
797 | if (fRun < 0){ | |
798 | AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun."); | |
799 | return NULL; | |
800 | } | |
801 | runNumber = fRun; | |
802 | } | |
803 | ||
02c4845e | 804 | return Get(AliCDBId(path, runNumber, runNumber, version, subVersion)); |
805 | } | |
806 | ||
807 | //_____________________________________________________________________________ | |
4667c116 | 808 | AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, |
02c4845e | 809 | const AliCDBRunRange& runRange, Int_t version, |
810 | Int_t subVersion) { | |
811 | // get an AliCDBEntry object from the database! | |
812 | ||
813 | return Get(AliCDBId(path, runRange, version, subVersion)); | |
814 | } | |
815 | ||
816 | //_____________________________________________________________________________ | |
16fcd618 | 817 | AliCDBEntry* AliCDBManager::Get(const AliCDBId& query, Bool_t forceCaching) { |
02c4845e | 818 | // get an AliCDBEntry object from the database |
819 | ||
02c4845e | 820 | // check if query's path and runRange are valid |
821 | // query is invalid also if version is not specified and subversion is! | |
822 | if (!query.IsValid()) { | |
823 | AliError(Form("Invalid query: %s", query.ToString().Data())); | |
824 | return NULL; | |
825 | } | |
024cf675 | 826 | |
827 | // query is not specified if path contains wildcard or run range= [-1,-1] | |
828 | if (!query.IsSpecified()) { | |
4667c116 | 829 | AliError(Form("Unspecified query: %s", |
02c4845e | 830 | query.ToString().Data())); |
831 | return NULL; | |
832 | } | |
833 | ||
7273fe5b | 834 | if(fLock && !(fRun >= query.GetFirstRun() && fRun <= query.GetLastRun())) |
1f341624 | 835 | AliFatal("Lock is ON: cannot use different run number than the internal one!"); |
836 | ||
7273fe5b | 837 | if(fCache && !(fRun >= query.GetFirstRun() && fRun <= query.GetLastRun())) |
024cf675 | 838 | AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!"); |
839 | ||
024cf675 | 840 | AliCDBEntry *entry=0; |
8e245d15 | 841 | |
024cf675 | 842 | // first look into map of cached objects |
62032124 | 843 | if(fCache && query.GetFirstRun() == fRun) |
024cf675 | 844 | entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath()); |
024cf675 | 845 | if(entry) { |
b8ec52f6 | 846 | AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data())); |
024cf675 | 847 | return entry; |
848 | } | |
96b7636d | 849 | |
4f3d68f3 | 850 | // if snapshot flag is set, try getting from the snapshot |
81e6f43c | 851 | // but in the case a specific storage is specified for this path |
852 | AliCDBParam *aPar=SelectSpecificStorage(query.GetPath()); | |
853 | if(!aPar){ | |
854 | if(fSnapshotMode && query.GetFirstRun() == fRun) | |
4f3d68f3 | 855 | { |
81e6f43c | 856 | entry = GetEntryFromSnapshot(query.GetPath()); |
4f3d68f3 | 857 | if(entry) { |
858 | AliInfo(Form("Object \"%s\" retrieved from the snapshot.",query.GetPath().Data())); | |
859 | if(query.GetFirstRun() == fRun) // no need to check fCache, fSnapshotMode not possible otherwise | |
860 | CacheEntry(query.GetPath(), entry); | |
c022b397 | 861 | |
4f3d68f3 | 862 | if(!fIds->Contains(&entry->GetId())) |
863 | fIds->Add(entry->GetId().Clone()); | |
c022b397 | 864 | |
4f3d68f3 | 865 | return entry; |
866 | } | |
81e6f43c | 867 | } |
c022b397 | 868 | } |
869 | ||
870 | // Entry is not in cache (and, in case we are in snapshot mode, not in the snapshot either) | |
871 | // => retrieve it from the storage and cache it!! | |
d1982b43 | 872 | if(!fDefaultStorage) { |
873 | AliError("No storage set!"); | |
874 | return NULL; | |
875 | } | |
62032124 | 876 | |
81e6f43c | 877 | AliCDBStorage *aStorage=0; |
02c4845e | 878 | if(aPar) { |
879 | aStorage=GetStorage(aPar); | |
880 | TString str = aPar->GetURI(); | |
881 | AliDebug(2,Form("Looking into storage: %s",str.Data())); | |
02c4845e | 882 | } else { |
883 | aStorage=GetDefaultStorage(); | |
96b7636d | 884 | AliDebug(2,"Looking into default storage"); |
02c4845e | 885 | } |
4667c116 | 886 | |
024cf675 | 887 | entry = aStorage->Get(query); |
024cf675 | 888 | |
16fcd618 | 889 | if(entry && fCache && (query.GetFirstRun()==fRun || forceCaching)){ |
024cf675 | 890 | CacheEntry(query.GetPath(), entry); |
891 | } | |
8e245d15 | 892 | |
b21e3194 | 893 | if(entry && !fIds->Contains(&entry->GetId())){ |
894 | fIds->Add(entry->GetId().Clone()); | |
895 | } | |
896 | ||
897 | ||
024cf675 | 898 | return entry; |
4667c116 | 899 | |
900 | } | |
901 | ||
c022b397 | 902 | //_____________________________________________________________________________ |
903 | AliCDBEntry* AliCDBManager::GetEntryFromSnapshot(const char* path) { | |
904 | // get the entry from the open snapshot file | |
905 | ||
906 | TString sPath(path); | |
907 | sPath.ReplaceAll("/","*"); | |
908 | AliCDBEntry *entry = dynamic_cast<AliCDBEntry*>(fSnapshotFile->Get(sPath.Data())); | |
909 | if(!entry){ | |
910 | AliDebug(2,Form("Cannot get a CDB entry for \"%s\" from snapshot file",path)); | |
911 | return 0; | |
912 | } | |
913 | ||
914 | return entry; | |
915 | } | |
916 | ||
917 | //_____________________________________________________________________________ | |
918 | Bool_t AliCDBManager::SetSnapshotMode(const char* snapshotFileName) { | |
919 | // set the manager in snapshot mode | |
920 | ||
921 | if(!fCache){ | |
922 | AliError("Cannot set the CDB manage in snapshot mode if the cache is not active!"); | |
923 | return kFALSE; | |
924 | } | |
925 | ||
c022b397 | 926 | //open snapshot file |
927 | TString snapshotFile(snapshotFileName); | |
928 | if(snapshotFile.BeginsWith("alien://")){ | |
929 | if(!gGrid) { | |
930 | TGrid::Connect("alien://",""); | |
931 | if(!gGrid) { | |
932 | AliError("Connection to alien failed!"); | |
933 | return kFALSE; | |
934 | } | |
935 | } | |
936 | } | |
937 | ||
938 | fSnapshotFile = TFile::Open(snapshotFileName); | |
939 | if (!fSnapshotFile || fSnapshotFile->IsZombie()){ | |
940 | AliError(Form("Cannot open file %s",snapshotFileName)); | |
941 | return kFALSE; | |
942 | } | |
943 | ||
b7df0cc5 | 944 | AliInfo("The CDB manager is set in snapshot mode!"); |
14ddb007 | 945 | fSnapshotMode = kTRUE; |
c022b397 | 946 | return kTRUE; |
947 | ||
948 | } | |
949 | ||
0f40a831 | 950 | //_____________________________________________________________________________ |
951 | const char* AliCDBManager::GetURI(const char* path) { | |
952 | // return the URI of the storage where to look for path | |
953 | ||
954 | if(!IsDefaultStorageSet()) return 0; | |
955 | ||
956 | AliCDBParam *aPar=SelectSpecificStorage(path); | |
957 | ||
958 | if(aPar) { | |
959 | return aPar->GetURI().Data(); | |
960 | ||
961 | } else { | |
962 | return GetDefaultStorage()->GetURI().Data(); | |
963 | } | |
964 | ||
965 | return 0; | |
966 | } | |
967 | ||
b7df0cc5 | 968 | //_____________________________________________________________________________ |
969 | Int_t AliCDBManager::GetStartRunLHCPeriod(){ | |
970 | // get the first run of validity | |
971 | // for the current period | |
972 | // if set | |
973 | if(fStartRunLHCPeriod==-1) | |
974 | AliWarning("Run-range not yet set for the current LHC period."); | |
975 | return fStartRunLHCPeriod; | |
976 | } | |
977 | ||
978 | //_____________________________________________________________________________ | |
979 | Int_t AliCDBManager::GetEndRunLHCPeriod(){ | |
980 | // get the last run of validity | |
981 | // for the current period | |
982 | // if set | |
983 | if(fEndRunLHCPeriod==-1) | |
984 | AliWarning("Run-range not yet set for the current LHC period."); | |
985 | return fEndRunLHCPeriod; | |
986 | } | |
987 | ||
988 | //_____________________________________________________________________________ | |
989 | TString AliCDBManager::GetLHCPeriod(){ | |
990 | // get the current LHC period string | |
991 | // | |
992 | if(fLHCPeriod.IsWhitespace() || fLHCPeriod.IsNull()) | |
993 | AliWarning("LHC period (OCDB folder) not yet set"); | |
994 | return fLHCPeriod; | |
995 | } | |
996 | ||
4667c116 | 997 | //_____________________________________________________________________________ |
998 | AliCDBId* AliCDBManager::GetId(const AliCDBPath& path, Int_t runNumber, | |
999 | Int_t version, Int_t subVersion) { | |
1000 | // get the AliCDBId of the valid object from the database (does not retrieve the object) | |
1001 | // User must delete returned object! | |
1002 | ||
1003 | if(runNumber < 0){ | |
1004 | // RunNumber is not specified. Try with fRun | |
1005 | if (fRun < 0){ | |
1006 | AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun."); | |
1007 | return NULL; | |
1008 | } | |
1009 | runNumber = fRun; | |
1010 | } | |
1011 | ||
1012 | return GetId(AliCDBId(path, runNumber, runNumber, version, subVersion)); | |
1013 | } | |
1014 | ||
1015 | //_____________________________________________________________________________ | |
1016 | AliCDBId* AliCDBManager::GetId(const AliCDBPath& path, | |
1017 | const AliCDBRunRange& runRange, Int_t version, | |
1018 | Int_t subVersion) { | |
1019 | // get the AliCDBId of the valid object from the database (does not retrieve the object) | |
1020 | // User must delete returned object! | |
1021 | ||
1022 | return GetId(AliCDBId(path, runRange, version, subVersion)); | |
1023 | } | |
1024 | ||
1025 | //_____________________________________________________________________________ | |
1026 | AliCDBId* AliCDBManager::GetId(const AliCDBId& query) { | |
1027 | // get the AliCDBId of the valid object from the database (does not retrieve the object) | |
1028 | // User must delete returned object! | |
1029 | ||
1030 | if(!fDefaultStorage) { | |
1031 | AliError("No storage set!"); | |
1032 | return NULL; | |
1033 | } | |
1034 | ||
1035 | // check if query's path and runRange are valid | |
1036 | // query is invalid also if version is not specified and subversion is! | |
1037 | if (!query.IsValid()) { | |
1038 | AliError(Form("Invalid query: %s", query.ToString().Data())); | |
1039 | return NULL; | |
1040 | } | |
1041 | ||
1042 | // query is not specified if path contains wildcard or run range= [-1,-1] | |
1043 | if (!query.IsSpecified()) { | |
1044 | AliError(Form("Unspecified query: %s", | |
1045 | query.ToString().Data())); | |
1046 | return NULL; | |
1047 | } | |
1048 | ||
1049 | if(fCache && query.GetFirstRun() != fRun) | |
1050 | AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!"); | |
1051 | ||
1052 | AliCDBEntry* entry = 0; | |
1053 | ||
1054 | // first look into map of cached objects | |
1055 | if(fCache && query.GetFirstRun() == fRun) | |
1056 | entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath()); | |
1057 | ||
1058 | if(entry) { | |
1059 | AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data())); | |
1060 | return dynamic_cast<AliCDBId*> (entry->GetId().Clone()); | |
1061 | } | |
1062 | ||
1063 | // Entry is not in cache -> retrieve it from CDB and cache it!! | |
1064 | AliCDBStorage *aStorage=0; | |
1065 | AliCDBParam *aPar=SelectSpecificStorage(query.GetPath()); | |
1066 | ||
1067 | if(aPar) { | |
1068 | aStorage=GetStorage(aPar); | |
1069 | TString str = aPar->GetURI(); | |
1070 | AliDebug(2,Form("Looking into storage: %s",str.Data())); | |
024cf675 | 1071 | |
4667c116 | 1072 | } else { |
1073 | aStorage=GetDefaultStorage(); | |
1074 | AliDebug(2,"Looking into default storage"); | |
1075 | } | |
1076 | ||
1077 | return aStorage->GetId(query); | |
1078 | ||
02c4845e | 1079 | } |
1080 | ||
1081 | //_____________________________________________________________________________ | |
62032124 | 1082 | TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber, |
02c4845e | 1083 | Int_t version, Int_t subVersion) { |
1084 | // get multiple AliCDBEntry objects from the database | |
1085 | ||
afd8dbf4 | 1086 | if(runNumber < 0){ |
1087 | // RunNumber is not specified. Try with fRun | |
1088 | if (fRun < 0){ | |
1089 | AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun."); | |
1090 | return NULL; | |
1091 | } | |
1092 | runNumber = fRun; | |
1093 | } | |
1094 | ||
02c4845e | 1095 | return GetAll(AliCDBId(path, runNumber, runNumber, version, |
1096 | subVersion)); | |
1097 | } | |
1098 | ||
1099 | //_____________________________________________________________________________ | |
8e245d15 | 1100 | TList* AliCDBManager::GetAll(const AliCDBPath& path, |
02c4845e | 1101 | const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) { |
1102 | // get multiple AliCDBEntry objects from the database | |
1103 | ||
1104 | return GetAll(AliCDBId(path, runRange, version, subVersion)); | |
1105 | } | |
1106 | ||
1107 | //_____________________________________________________________________________ | |
1108 | TList* AliCDBManager::GetAll(const AliCDBId& query) { | |
1109 | // get multiple AliCDBEntry objects from the database | |
024cf675 | 1110 | // Warning: this method works correctly only for queries of the type "Detector/*" |
1111 | // and not for more specific queries e.g. "Detector/Calib/*" ! | |
8e245d15 | 1112 | // Warning #2: Entries are cached, but GetAll will keep on retrieving objects from OCDB! |
1113 | // To get an object from cache use Get() function | |
02c4845e | 1114 | |
1115 | if(!fDefaultStorage) { | |
1116 | AliError("No storage set!"); | |
1117 | return NULL; | |
1118 | } | |
1119 | ||
1120 | if (!query.IsValid()) { | |
1121 | AliError(Form("Invalid query: %s", query.ToString().Data())); | |
1122 | return NULL; | |
1123 | } | |
1124 | ||
afd8dbf4 | 1125 | if((fSpecificStorages.GetEntries()>0) && query.GetPath().BeginsWith('*')){ |
1126 | // if specific storages are active a query with "*" is ambiguous | |
1127 | AliError("Query too generic in this context!"); | |
8e245d15 | 1128 | return NULL; |
02c4845e | 1129 | } |
1130 | ||
1131 | if (query.IsAnyRange()) { | |
1132 | AliError(Form("Unspecified run or runrange: %s", | |
8e245d15 | 1133 | query.ToString().Data())); |
02c4845e | 1134 | return NULL; |
8e245d15 | 1135 | } |
1136 | ||
1f341624 | 1137 | if(fLock && query.GetFirstRun() != fRun) |
1138 | AliFatal("Lock is ON: cannot use different run number than the internal one!"); | |
1139 | ||
6dc56e97 | 1140 | AliCDBParam *aPar=SelectSpecificStorage(query.GetPath()); |
024cf675 | 1141 | |
8e245d15 | 1142 | AliCDBStorage *aStorage; |
02c4845e | 1143 | if(aPar) { |
1144 | aStorage=GetStorage(aPar); | |
96b7636d | 1145 | AliDebug(2,Form("Looking into storage: %s", aPar->GetURI().Data())); |
8e245d15 | 1146 | |
02c4845e | 1147 | } else { |
1148 | aStorage=GetDefaultStorage(); | |
8e245d15 | 1149 | AliDebug(2,"Looking into default storage"); |
02c4845e | 1150 | } |
1151 | ||
96b7636d | 1152 | TList *result = 0; |
1153 | if(aStorage) result = aStorage->GetAll(query); | |
8e245d15 | 1154 | if(!result) return 0; |
1155 | ||
96b7636d | 1156 | // loop on result to check whether entries should be re-queried with specific storages |
1157 | if(fSpecificStorages.GetEntries()>0 && ! (fSpecificStorages.GetEntries() == 1 && aPar)) { | |
1158 | AliInfo("Now look into all other specific storages..."); | |
1159 | ||
1160 | TIter iter(result); | |
1161 | AliCDBEntry* chkEntry=0; | |
1162 | ||
1163 | while((chkEntry = dynamic_cast<AliCDBEntry*> (iter.Next()))){ | |
1164 | AliCDBId& chkId = chkEntry->GetId(); | |
1165 | AliDebug(2, Form("Checking id %s ", chkId.GetPath().Data())); | |
1166 | AliCDBParam *chkPar=SelectSpecificStorage(chkId.GetPath()); | |
1167 | if (!chkPar || aPar == chkPar) continue; | |
1168 | AliCDBStorage *chkStorage = GetStorage(chkPar); | |
1169 | AliDebug(2, Form("Found specific storage! %s", chkPar->GetURI().Data())); | |
1170 | ||
1171 | AliCDBEntry *newEntry=0; | |
1172 | chkId.SetRunRange(query.GetFirstRun(), query.GetLastRun()); | |
1173 | chkId.SetVersion(query.GetVersion()); | |
1174 | chkId.SetSubVersion(query.GetSubVersion()); | |
1175 | ||
1176 | if(chkStorage) newEntry = chkStorage->Get(chkId); | |
1177 | if(!newEntry) continue; | |
1178 | ||
1179 | // object is found in specific storage: replace entry in the result list! | |
1180 | chkEntry->SetOwner(1); | |
1181 | delete result->Remove(chkEntry); | |
1182 | result->AddFirst(newEntry); | |
1183 | } | |
1184 | ||
1185 | Int_t nEntries = result->GetEntries(); | |
1186 | AliInfo("After look into other specific storages, result list is:"); | |
1187 | for(int i=0; i<nEntries;i++){ | |
1188 | AliCDBEntry *entry = (AliCDBEntry*) result->At(i); | |
1189 | AliInfo(Form("%s",entry->GetId().ToString().Data())); | |
1190 | } | |
1191 | } | |
1192 | ||
8e245d15 | 1193 | // caching entries |
b21e3194 | 1194 | TIter iter(result); |
1195 | AliCDBEntry* entry=0; | |
1196 | while((entry = dynamic_cast<AliCDBEntry*> (iter.Next()))){ | |
02c4845e | 1197 | |
b21e3194 | 1198 | if(!fIds->Contains(&entry->GetId())){ |
1199 | fIds->Add(entry->GetId().Clone()); | |
1200 | } | |
1201 | if(fCache && (query.GetFirstRun() == fRun)){ | |
96b7636d | 1202 | CacheEntry(entry->GetId().GetPath(), entry); |
8e245d15 | 1203 | } |
1204 | } | |
1205 | ||
b21e3194 | 1206 | |
8e245d15 | 1207 | return result; |
02c4845e | 1208 | } |
1209 | ||
1210 | //_____________________________________________________________________________ | |
c5941d67 | 1211 | Bool_t AliCDBManager::Put(TObject* object, const AliCDBId& id, AliCDBMetaData* metaData, const char* mirrors, const DataType type){ |
02c4845e | 1212 | // store an AliCDBEntry object into the database |
1213 | ||
968cfa08 | 1214 | if (object==0x0) { |
1215 | AliError("Null Entry! No storage will be done!"); | |
1216 | return kFALSE; | |
1217 | } | |
1218 | ||
02c4845e | 1219 | AliCDBEntry anEntry(object, id, metaData); |
c5941d67 | 1220 | return Put(&anEntry, mirrors, type); |
02c4845e | 1221 | |
1222 | } | |
1223 | ||
1224 | ||
1225 | //_____________________________________________________________________________ | |
06eeadea | 1226 | Bool_t AliCDBManager::Put(AliCDBEntry* entry, const char* mirrors, DataType type){ |
02c4845e | 1227 | // store an AliCDBEntry object into the database |
1228 | ||
b8ec52f6 | 1229 | if(type == kPrivate && !fDefaultStorage) { |
02c4845e | 1230 | AliError("No storage set!"); |
1231 | return kFALSE; | |
1232 | } | |
1233 | ||
8da73612 | 1234 | if (!entry){ |
1235 | AliError("No entry!"); | |
968cfa08 | 1236 | return kFALSE; |
1237 | } | |
1238 | ||
8da73612 | 1239 | if (entry->GetObject()==0x0){ |
1240 | AliError("No valid object in CDB entry!"); | |
02c4845e | 1241 | return kFALSE; |
1242 | } | |
1243 | ||
1244 | if (!entry->GetId().IsValid()) { | |
1245 | AliError(Form("Invalid entry ID: %s", | |
1246 | entry->GetId().ToString().Data())); | |
1247 | return kFALSE; | |
1248 | } | |
1249 | ||
1250 | if (!entry->GetId().IsSpecified()) { | |
1251 | AliError(Form("Unspecified entry ID: %s", | |
1252 | entry->GetId().ToString().Data())); | |
1253 | return kFALSE; | |
1254 | } | |
1255 | ||
1256 | AliCDBId id = entry->GetId(); | |
024cf675 | 1257 | AliCDBParam *aPar = SelectSpecificStorage(id.GetPath()); |
1258 | ||
4005d0b5 | 1259 | AliCDBStorage *aStorage=0; |
02c4845e | 1260 | |
1261 | if(aPar) { | |
1262 | aStorage=GetStorage(aPar); | |
02c4845e | 1263 | } else { |
b8ec52f6 | 1264 | switch(type){ |
1265 | case kCondition: | |
1266 | aStorage = GetStorage(fCondParam); | |
1267 | break; | |
1268 | case kReference: | |
1269 | aStorage = GetStorage(fRefParam); | |
1270 | break; | |
1271 | case kPrivate: | |
1272 | aStorage = GetDefaultStorage(); | |
1273 | break; | |
1274 | } | |
02c4845e | 1275 | } |
1276 | ||
b8ec52f6 | 1277 | AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data())); |
1278 | ||
3d152e8d | 1279 | TString strMirrors(mirrors); |
1280 | Bool_t result = "kFALSE"; | |
1281 | if(!strMirrors.IsNull() && !strMirrors.IsWhitespace()) | |
1282 | result = aStorage->Put(entry, mirrors, type); | |
1283 | else | |
c5941d67 | 1284 | result = aStorage->Put(entry, "", type); |
4005d0b5 | 1285 | |
1286 | if(fRun >= 0) QueryCDB(); | |
1287 | ||
1288 | return result; | |
02c4845e | 1289 | |
1290 | ||
1291 | } | |
9e1ceb13 | 1292 | |
c5941d67 | 1293 | //_____________________________________________________________________________ |
1294 | void AliCDBManager::SetMirrorSEs(const char* mirrors) | |
1295 | { | |
1296 | // set mirror Storage Elements for the default storage, if it is of type "alien" | |
1297 | if(fDefaultStorage->GetType() != "alien"){ | |
1298 | AliInfo("The default storage is not of type \"alien\". Settings for Storage Elements are not taken into account!"); | |
1299 | return; | |
1300 | } | |
1301 | fDefaultStorage->SetMirrorSEs(mirrors); | |
1302 | } | |
1303 | ||
1304 | //_____________________________________________________________________________ | |
1305 | const char* AliCDBManager::GetMirrorSEs() const { | |
1306 | // get mirror Storage Elements for the default storage, if it is of type "alien" | |
1307 | if(fDefaultStorage->GetType() != "alien"){ | |
1308 | AliInfo("The default storage is not of type \"alien\". Settings for Storage Elements are not taken into account!"); | |
1309 | return ""; | |
1310 | } | |
1311 | return fDefaultStorage->GetMirrorSEs(); | |
1312 | } | |
1313 | ||
4b5e0dce | 1314 | //_____________________________________________________________________________ |
1315 | void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry) | |
1316 | { | |
1317 | // cache AliCDBEntry. Cache is valid until run number is changed. | |
1318 | ||
96b7636d | 1319 | AliCDBEntry *chkEntry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(path)); |
1320 | ||
1321 | if(chkEntry) { | |
1322 | AliDebug(2, Form("Object %s already in cache !!", path)); | |
1323 | return; | |
1324 | } else { | |
1325 | AliDebug(2,Form("Caching entry %s", path)); | |
1326 | } | |
1327 | ||
4b5e0dce | 1328 | fEntryCache.Add(new TObjString(path), entry); |
96b7636d | 1329 | AliDebug(2,Form("Cache entries: %d", fEntryCache.GetEntries())); |
4b5e0dce | 1330 | |
1331 | } | |
1332 | ||
917a098b | 1333 | //_____________________________________________________________________________ |
1334 | void AliCDBManager::Print(Option_t* /*option*/) const | |
1335 | { | |
1336 | // Print list of active storages and their URIs | |
917a098b | 1337 | |
b8ec52f6 | 1338 | TString output=Form("Run number = %d; ",fRun); |
1339 | output += "Cache is "; | |
917a098b | 1340 | if(!fCache) output += "NOT "; |
b8ec52f6 | 1341 | output += Form("ACTIVE; Number of active storages: %d\n",fActiveStorages.GetEntries()); |
917a098b | 1342 | |
1343 | if(fDefaultStorage) { | |
b8ec52f6 | 1344 | output += Form("\t*** Default Storage URI: \"%s\"\n",fDefaultStorage->GetURI().Data()); |
1345 | // AliInfo(output.Data()); | |
917a098b | 1346 | } |
1347 | if(fSpecificStorages.GetEntries()>0) { | |
917a098b | 1348 | TIter iter(fSpecificStorages.GetTable()); |
62032124 | 1349 | TPair *aPair=0; |
b8ec52f6 | 1350 | Int_t i=1; |
917a098b | 1351 | while((aPair = (TPair*) iter.Next())){ |
b8ec52f6 | 1352 | output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n", |
1353 | i++, ((TObjString*) aPair->Key())->GetName(), | |
917a098b | 1354 | ((AliCDBParam*) aPair->Value())->GetURI().Data()); |
917a098b | 1355 | } |
917a098b | 1356 | } |
1357 | if(fDrainStorage) { | |
b8ec52f6 | 1358 | output += Form("*** Drain Storage URI: %s\n",fDrainStorage->GetURI().Data()); |
917a098b | 1359 | } |
b8ec52f6 | 1360 | AliInfo(output.Data()); |
917a098b | 1361 | } |
1362 | ||
4b5e0dce | 1363 | //_____________________________________________________________________________ |
c3a7b59a | 1364 | void AliCDBManager::SetRun(Int_t run) |
4b5e0dce | 1365 | { |
917a098b | 1366 | // Sets current run number. |
4b5e0dce | 1367 | // When the run number changes the caching is cleared. |
1f341624 | 1368 | |
27cac7e3 | 1369 | if(fRun == run) |
4b5e0dce | 1370 | return; |
1371 | ||
1f341624 | 1372 | if(fLock && fRun >= 0) { |
1373 | AliFatal("Lock is ON, cannot reset run number!"); | |
1374 | } | |
1375 | ||
4b5e0dce | 1376 | fRun = run; |
27cac7e3 | 1377 | if(fRaw){ |
7de84b33 | 1378 | // here the LHCPeriod xml file is parsed; the string containing the correct period is returned; the default storage is set |
1379 | if (fStartRunLHCPeriod <= run && fEndRunLHCPeriod >= run){ | |
1380 | AliInfo("LHCPeriod alien folder for current run already in memory"); | |
27cac7e3 | 1381 | }else{ |
7de84b33 | 1382 | SetDefaultStorageFromRun(run); |
27cac7e3 | 1383 | if(fEntryCache.GetEntries()!=0) ClearCache(); |
1384 | return; | |
7de84b33 | 1385 | } |
1386 | } | |
4b5e0dce | 1387 | ClearCache(); |
62032124 | 1388 | QueryCDB(); |
4b5e0dce | 1389 | } |
1390 | ||
1391 | //_____________________________________________________________________________ | |
1392 | void AliCDBManager::ClearCache(){ | |
1393 | // clear AliCDBEntry cache | |
1394 | ||
1f341624 | 1395 | AliDebug(2, Form("Cache entries to be deleted: %d",fEntryCache.GetEntries())); |
1396 | ||
1397 | /* | |
1398 | // To clean entries one by one | |
1399 | TIter iter(fEntryCache.GetTable()); | |
1400 | TPair* pair=0; | |
1401 | while((pair= dynamic_cast<TPair*> (iter.Next()))){ | |
1402 | ||
1403 | TObjString* key = dynamic_cast<TObjString*> (pair->Key()); | |
1404 | AliCDBEntry* entry = dynamic_cast<AliCDBEntry*> (pair->Value()); | |
1405 | AliDebug(2, Form("Deleting entry: %s", key->GetName())); | |
1406 | if (entry) delete entry; | |
1407 | delete fEntryCache.Remove(key); | |
1408 | } | |
1409 | */ | |
4b5e0dce | 1410 | fEntryCache.DeleteAll(); |
1f341624 | 1411 | AliDebug(2, Form("After deleting - Cache entries: %d",fEntryCache.GetEntries())); |
4b5e0dce | 1412 | } |
1413 | ||
4005d0b5 | 1414 | //_____________________________________________________________________________ |
1415 | void AliCDBManager::UnloadFromCache(const char* path){ | |
1416 | // unload cached object | |
b0e8cda6 | 1417 | // that is remove the entry from the cache and the id from the list of ids |
1418 | // | |
b086955d | 1419 | if(!fActiveStorages.GetEntries()) { |
1420 | AliDebug(2, Form("No active storages. Object \"%s\" is not unloaded from cache", path)); | |
1421 | return; | |
1422 | } | |
1423 | ||
4005d0b5 | 1424 | AliCDBPath queryPath(path); |
1425 | if(!queryPath.IsValid()) return; | |
1426 | ||
1427 | if(!queryPath.IsWildcard()) { // path is not wildcard, get it directly from the cache and unload it! | |
1428 | if(fEntryCache.Contains(path)){ | |
b0e8cda6 | 1429 | AliDebug(2, Form("Unloading object \"%s\" from cache and from list of ids", path)); |
4005d0b5 | 1430 | TObjString pathStr(path); |
4005d0b5 | 1431 | delete fEntryCache.Remove(&pathStr); |
a5362473 | 1432 | // we do not remove from the list of Id's (it's not very coherent but we leave the |
1433 | // id for the benefit of the userinfo) | |
1434 | /* | |
b0e8cda6 | 1435 | TIter iter(fIds); |
1436 | AliCDBId *id = 0; | |
1437 | while((id = dynamic_cast<AliCDBId*> (iter.Next()))){ | |
1438 | if(queryPath.Comprises(id->GetPath())) | |
1439 | delete fIds->Remove(id); | |
a5362473 | 1440 | }*/ |
4005d0b5 | 1441 | } else { |
b0e8cda6 | 1442 | AliError(Form("Cache does not contain object \"%s\"!", path)); |
4005d0b5 | 1443 | } |
b0e8cda6 | 1444 | AliDebug(2, Form("Cache entries: %d",fEntryCache.GetEntries())); |
4005d0b5 | 1445 | return; |
1446 | } | |
1447 | ||
1448 | // path is wildcard: loop on the cache and unload all comprised objects! | |
1449 | TIter iter(fEntryCache.GetTable()); | |
1450 | TPair* pair = 0; | |
b0e8cda6 | 1451 | Int_t removed=0; |
4005d0b5 | 1452 | |
1453 | while((pair = dynamic_cast<TPair*> (iter.Next()))){ | |
1454 | AliCDBPath entryPath = pair->Key()->GetName(); | |
1455 | if(queryPath.Comprises(entryPath)) { | |
b0e8cda6 | 1456 | AliDebug(2, Form("Unloading object \"%s\" from cache and from list of ids", entryPath.GetPath().Data())); |
1457 | TObjString pathStr(entryPath.GetPath()); | |
4005d0b5 | 1458 | delete fEntryCache.Remove(&pathStr); |
a5362473 | 1459 | removed++; |
b0e8cda6 | 1460 | |
a5362473 | 1461 | // we do not remove from the list of Id's (it's not very coherent but we leave the |
1462 | // id for the benefit of the userinfo) | |
1463 | /* | |
b0e8cda6 | 1464 | TIter iterids(fIds); |
1465 | AliCDBId *anId = 0; | |
1466 | while((anId = dynamic_cast<AliCDBId*> (iterids.Next()))){ | |
1467 | AliCDBPath aPath = anId->GetPath(); | |
1468 | TString aPathStr = aPath.GetPath(); | |
1469 | if(queryPath.Comprises(aPath)) { | |
1470 | delete fIds->Remove(anId); | |
b0e8cda6 | 1471 | } |
a5362473 | 1472 | }*/ |
4005d0b5 | 1473 | } |
1474 | } | |
b0e8cda6 | 1475 | AliDebug(2,Form("Cache entries and ids removed: %d Remaining: %d",removed,fEntryCache.GetEntries())); |
4005d0b5 | 1476 | } |
1477 | ||
9e1ceb13 | 1478 | //_____________________________________________________________________________ |
1479 | void AliCDBManager::DestroyActiveStorages() { | |
1480 | // delete list of active storages | |
1481 | ||
1482 | fActiveStorages.DeleteAll(); | |
02c4845e | 1483 | fSpecificStorages.DeleteAll(); |
9e1ceb13 | 1484 | } |
1485 | ||
1486 | //_____________________________________________________________________________ | |
1487 | void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) { | |
b05400be | 1488 | // destroys active storage |
1489 | ||
1490 | /* | |
917a098b | 1491 | TIter iter(fActiveStorages.GetTable()); |
b05400be | 1492 | TPair* aPair; |
1493 | while ((aPair = (TPair*) iter.Next())) { | |
1494 | if(storage == (AliCDBStorage*) aPair->Value()) | |
1495 | delete fActiveStorages.Remove(aPair->Key()); | |
1496 | storage->Delete(); storage=0x0; | |
1497 | } | |
6dc56e97 | 1498 | */ |
9e1ceb13 | 1499 | |
1500 | } | |
1501 | ||
62032124 | 1502 | //_____________________________________________________________________________ |
1503 | void AliCDBManager::QueryCDB() { | |
1504 | // query default and specific storages for files valid for fRun. Every storage loads the Ids into its list. | |
1505 | ||
1506 | if (fRun < 0){ | |
1507 | AliError("Run number not yet set! Use AliCDBManager::SetRun."); | |
1508 | return; | |
1509 | } | |
6dc56e97 | 1510 | if (!fDefaultStorage){ |
1511 | AliError("Default storage is not set! Use AliCDBManager::SetDefaultStorage"); | |
1512 | return; | |
1513 | } | |
1514 | if(fDefaultStorage->GetType() == "alien"){ | |
1515 | fDefaultStorage->QueryCDB(fRun); | |
1516 | } else { | |
1517 | AliDebug(2,"Skipping query for valid files, it used only in grid..."); | |
1518 | } | |
62032124 | 1519 | |
1520 | TIter iter(&fSpecificStorages); | |
1521 | TObjString *aCalibType=0; | |
1522 | AliCDBParam* aPar=0; | |
1523 | while((aCalibType = dynamic_cast<TObjString*> (iter.Next()))){ | |
1524 | aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType); | |
1525 | if(aPar) { | |
c3a7b59a | 1526 | AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName())); |
6dc56e97 | 1527 | AliCDBStorage *aStorage = GetStorage(aPar); |
1528 | if(aStorage->GetType() == "alien"){ | |
1529 | aStorage->QueryCDB(fRun,aCalibType->GetName()); | |
1530 | } else { | |
1531 | AliDebug(2, | |
1532 | "Skipping query for valid files, it is used only in grid..."); | |
1533 | } | |
62032124 | 1534 | } |
1535 | } | |
62032124 | 1536 | } |
1537 | ||
b8ec52f6 | 1538 | //______________________________________________________________________________________________ |
1539 | const char* AliCDBManager::GetDataTypeName(DataType type) | |
1540 | { | |
1541 | // returns the name (string) of the data type | |
1542 | ||
1543 | switch (type){ | |
1544 | case kCondition: return "Conditions"; | |
1545 | case kReference: return "Reference"; | |
1546 | case kPrivate: return "Private"; | |
1547 | } | |
1548 | return 0; | |
1549 | ||
1550 | } | |
62032124 | 1551 | |
4667c116 | 1552 | //______________________________________________________________________________________________ |
1553 | void AliCDBManager::InitShortLived() | |
1554 | { | |
1555 | // Init the list of short-lived objects | |
1556 | // currently disabled | |
1557 | ||
1558 | fShortLived=0x0; | |
1559 | ||
1560 | // fShortLived = new TList(); | |
1561 | // fShortLived->SetOwner(1); | |
1562 | // | |
1563 | // fShortLived->Add(new TObjString("EMCAL/Calib/Data")); | |
1564 | // | |
1565 | // fShortLived->Add(new TObjString("HMPID/Calib/Nmean")); | |
1566 | // fShortLived->Add(new TObjString("HMPID/Calib/Qthre")); | |
1567 | // | |
1568 | // fShortLived->Add(new TObjString("ITS/Calib/CalibSPD")); | |
1569 | // | |
1570 | // fShortLived->Add(new TObjString("MUON/Calib/Gains")); | |
1571 | // fShortLived->Add(new TObjString("MUON/Calib/HV")); | |
1572 | // fShortLived->Add(new TObjString("MUON/Calib/Pedestals")); | |
1573 | // | |
1574 | // fShortLived->Add(new TObjString("PHOS/Calib/CpvGainPedestals")); | |
1575 | // fShortLived->Add(new TObjString("PHOS/Calib/EmcGainPedestals")); | |
1576 | // | |
1577 | // fShortLived->Add(new TObjString("PMD/Calib/Data")); | |
1578 | // | |
1579 | // fShortLived->Add(new TObjString("TRD/Calib/ChamberGainFactor")); | |
1580 | // fShortLived->Add(new TObjString("TRD/Calib/LocalGainFactor")); | |
1581 | // fShortLived->Add(new TObjString("TRD/Calib/ChamberT0")); | |
1582 | // fShortLived->Add(new TObjString("TRD/Calib/LocalT0")); | |
1583 | // fShortLived->Add(new TObjString("TRD/Calib/ChamberVdrift")); | |
1584 | // fShortLived->Add(new TObjString("TRD/Calib/LocalVdrift")); | |
1585 | // | |
1586 | // fShortLived->Add(new TObjString("ZDC/Calib/Data")); | |
1587 | ||
1588 | } | |
1589 | ||
1590 | //______________________________________________________________________________________________ | |
1591 | Bool_t AliCDBManager::IsShortLived(const char* path) | |
1592 | { | |
1593 | // returns the name (string) of the data type | |
1594 | ||
1595 | if(!fShortLived) return kFALSE; | |
1596 | ||
1597 | AliCDBPath aPath(path); | |
1598 | if(!aPath.IsValid()){ | |
1599 | AliError(Form("Not a valid path: %s", path)); | |
1600 | return kFALSE; | |
1601 | } | |
1602 | ||
1603 | return fShortLived->Contains(path); | |
1604 | ||
1605 | } | |
1606 | ||
1f341624 | 1607 | //______________________________________________________________________________________________ |
a6f59240 | 1608 | ULong_t AliCDBManager::SetLock(Bool_t lock, ULong_t key){ |
1609 | // To lock/unlock user must provide the key. A new key is provided after | |
1610 | // each successful lock. User should always backup the returned key and | |
1611 | // use it on next access. | |
1612 | if (fLock == lock) return 0; // nothing to be done | |
1613 | if (lock) { | |
1614 | // User wants to lock - check his identity | |
1615 | if (fKey) { | |
1616 | // Lock has a user - check his key | |
1617 | if (fKey != key) { | |
1618 | AliFatal("Wrong key provided to lock CDB. Please remove CDB lock access from your code !"); | |
1619 | return 0; | |
1620 | } | |
1621 | } | |
1622 | // Provide new key | |
1623 | fKey = gSystem->Now(); | |
1624 | fLock = kTRUE; | |
1625 | return fKey; | |
1626 | } | |
1627 | // User wants to unlock - check the provided key | |
1628 | if (key != fKey) { | |
1629 | AliFatal("Lock is ON: wrong key provided"); | |
1630 | return 0; | |
1631 | } | |
1632 | fLock = kFALSE; | |
1633 | return key; | |
1f341624 | 1634 | } |
1635 | ||
9e1ceb13 | 1636 | /////////////////////////////////////////////////////////// |
1637 | // AliCDBManager Parameter class // | |
1638 | // interface to specific AliCDBParameter class // | |
1639 | // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) // | |
1640 | /////////////////////////////////////////////////////////// | |
1641 | ||
62032124 | 1642 | AliCDBParam::AliCDBParam(): |
fe12e09c | 1643 | fType(), |
1644 | fURI() | |
62032124 | 1645 | { |
9e1ceb13 | 1646 | // constructor |
1647 | ||
1648 | } | |
1649 | ||
1650 | //_____________________________________________________________________________ | |
1651 | AliCDBParam::~AliCDBParam() { | |
1652 | // destructor | |
1653 | ||
1654 | } | |
1655 |