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