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