]>
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" |
28 | #include "AliCDBMetaData.h" | |
9e1ceb13 | 29 | |
02c4845e | 30 | #include <TObjString.h> |
9e1ceb13 | 31 | #include <TSystem.h> |
32 | ||
33 | ClassImp(AliCDBParam) | |
34 | ||
35 | ClassImp(AliCDBManager) | |
36 | ||
b8ec52f6 | 37 | //TODO OCDB and Reference folder should not be fully hardcoded but built from run number (or year/LHC period) |
38 | TString AliCDBManager::fgkCondUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/CDB?user=aliprod"); | |
39 | TString AliCDBManager::fgkRefUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/Reference?user=aliprod"); | |
9e1ceb13 | 40 | AliCDBManager* AliCDBManager::fgInstance = 0x0; |
41 | ||
42 | //_____________________________________________________________________________ | |
b8ec52f6 | 43 | AliCDBManager* AliCDBManager::Instance() |
44 | { | |
9e1ceb13 | 45 | // returns AliCDBManager instance (singleton) |
46 | ||
47 | if (!fgInstance) { | |
48 | fgInstance = new AliCDBManager(); | |
49 | fgInstance->Init(); | |
50 | } | |
51 | ||
52 | return fgInstance; | |
53 | } | |
54 | ||
55 | //_____________________________________________________________________________ | |
56 | void AliCDBManager::Init() { | |
57 | // factory registering | |
58 | ||
59 | RegisterFactory(new AliCDBDumpFactory()); | |
60 | RegisterFactory(new AliCDBLocalFactory()); | |
61 | // AliCDBGridFactory is registered only if AliEn libraries are enabled in Root | |
62 | if(!gSystem->Exec("root-config --has-alien |grep yes 2>&1 > /dev/null")){ // returns 0 if yes | |
63 | AliInfo("AliEn classes enabled in Root. AliCDBGrid factory registered."); | |
64 | RegisterFactory(new AliCDBGridFactory()); | |
b8ec52f6 | 65 | fCondParam = CreateParameter(fgkCondUri); |
66 | fRefParam = CreateParameter(fgkRefUri); | |
9e1ceb13 | 67 | } |
68 | } | |
69 | //_____________________________________________________________________________ | |
70 | void AliCDBManager::Destroy() { | |
71 | // delete ALCDBManager instance and active storages | |
72 | ||
73 | if (fgInstance) { | |
4b5e0dce | 74 | //fgInstance->Delete(); |
9e1ceb13 | 75 | delete fgInstance; |
76 | fgInstance = 0x0; | |
77 | } | |
78 | } | |
79 | ||
80 | //_____________________________________________________________________________ | |
81 | AliCDBManager::AliCDBManager(): | |
fe12e09c | 82 | TObject(), |
b8ec52f6 | 83 | fCondParam(0), |
84 | fRefParam(0), | |
fe12e09c | 85 | fFactories(), |
86 | fActiveStorages(), | |
87 | fSpecificStorages(), | |
88 | fDefaultStorage(NULL), | |
89 | fDrainStorage(NULL), | |
90 | fEntryCache(), | |
91 | fCache(kTRUE), | |
92 | fRun(-1) | |
9e1ceb13 | 93 | { |
94 | // default constuctor | |
4b5e0dce | 95 | fFactories.SetOwner(1); |
62032124 | 96 | fActiveStorages.SetOwner(1); |
97 | fSpecificStorages.SetOwner(1); | |
98 | fEntryCache.SetOwner(1); | |
9e1ceb13 | 99 | } |
100 | ||
101 | //_____________________________________________________________________________ | |
102 | AliCDBManager::~AliCDBManager() { | |
103 | // destructor | |
4b5e0dce | 104 | ClearCache(); |
9e1ceb13 | 105 | DestroyActiveStorages(); |
62032124 | 106 | fFactories.Delete(); |
b05400be | 107 | fDrainStorage = 0x0; |
108 | fDefaultStorage = 0x0; | |
b8ec52f6 | 109 | delete fCondParam; |
110 | delete fRefParam; | |
9e1ceb13 | 111 | } |
112 | ||
9e1ceb13 | 113 | //_____________________________________________________________________________ |
114 | void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){ | |
115 | // put a storage object into the list of active storages | |
116 | ||
117 | fActiveStorages.Add(param, storage); | |
118 | AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries())); | |
119 | } | |
120 | ||
121 | //_____________________________________________________________________________ | |
122 | void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) { | |
123 | // add a storage factory to the list of registerd factories | |
124 | ||
125 | if (!fFactories.Contains(factory)) { | |
126 | fFactories.Add(factory); | |
127 | } | |
128 | } | |
129 | ||
130 | //_____________________________________________________________________________ | |
fdf65bb5 | 131 | Bool_t AliCDBManager::HasStorage(const char* dbString) const { |
9e1ceb13 | 132 | // check if dbString is a URI valid for one of the registered factories |
133 | ||
134 | TIter iter(&fFactories); | |
135 | ||
62032124 | 136 | AliCDBStorageFactory* factory=0; |
9e1ceb13 | 137 | while ((factory = (AliCDBStorageFactory*) iter.Next())) { |
138 | ||
139 | if (factory->Validate(dbString)) { | |
140 | return kTRUE; | |
4005d0b5 | 141 | } |
9e1ceb13 | 142 | } |
143 | ||
144 | return kFALSE; | |
145 | } | |
146 | ||
147 | //_____________________________________________________________________________ | |
fdf65bb5 | 148 | AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const { |
9e1ceb13 | 149 | // create AliCDBParam object from URI string |
150 | ||
151 | TIter iter(&fFactories); | |
152 | ||
62032124 | 153 | AliCDBStorageFactory* factory=0; |
9e1ceb13 | 154 | while ((factory = (AliCDBStorageFactory*) iter.Next())) { |
9e1ceb13 | 155 | AliCDBParam* param = factory->CreateParameter(dbString); |
62032124 | 156 | if(param) return param; |
9e1ceb13 | 157 | } |
158 | ||
159 | return NULL; | |
160 | } | |
161 | ||
162 | //_____________________________________________________________________________ | |
163 | AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) { | |
164 | // get storage object from URI string | |
165 | ||
166 | AliCDBParam* param = CreateParameter(dbString); | |
167 | if (!param) { | |
c3a7b59a | 168 | AliError(Form("Failed to activate requested storage! Check URI: %s", dbString)); |
9e1ceb13 | 169 | return NULL; |
82096dfc | 170 | } |
9e1ceb13 | 171 | |
172 | AliCDBStorage* aStorage = GetStorage(param); | |
173 | ||
174 | delete param; | |
9e1ceb13 | 175 | return aStorage; |
176 | } | |
177 | ||
178 | //_____________________________________________________________________________ | |
179 | AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) { | |
180 | // get storage object from AliCDBParam object | |
181 | ||
82096dfc | 182 | // if the list of active storages already contains |
9e1ceb13 | 183 | // the requested storage, return it |
184 | AliCDBStorage* aStorage = GetActiveStorage(param); | |
185 | if (aStorage) { | |
186 | return aStorage; | |
187 | } | |
188 | ||
189 | TIter iter(&fFactories); | |
190 | ||
62032124 | 191 | AliCDBStorageFactory* factory=0; |
917a098b | 192 | |
9e1ceb13 | 193 | // loop on the list of registered factories |
194 | while ((factory = (AliCDBStorageFactory*) iter.Next())) { | |
195 | ||
196 | // each factory tries to create its storage from the parameter | |
197 | aStorage = factory->Create(param); | |
198 | if (aStorage) { | |
199 | PutActiveStorage(param->CloneParam(), aStorage); | |
917a098b | 200 | aStorage->SetURI(param->GetURI()); |
6dc56e97 | 201 | if(fRun >= 0) { |
96b7636d | 202 | if(aStorage->GetType() == "alien"){ |
203 | aStorage->QueryCDB(fRun); | |
204 | } else { | |
205 | AliDebug(2, | |
206 | "Skipping query for valid files, it is used only in grid..."); | |
207 | } | |
c3a7b59a | 208 | } |
9e1ceb13 | 209 | return aStorage; |
210 | } | |
211 | } | |
212 | ||
c3a7b59a | 213 | AliError(Form("Failed to activate requested storage! Check URI: %s", param->GetURI().Data())); |
214 | ||
9e1ceb13 | 215 | return NULL; |
216 | } | |
217 | ||
62032124 | 218 | //_____________________________________________________________________________ |
219 | AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) { | |
220 | // get a storage object from the list of active storages | |
221 | ||
222 | return dynamic_cast<AliCDBStorage*> (fActiveStorages.GetValue(param)); | |
223 | } | |
224 | ||
9e1ceb13 | 225 | //_____________________________________________________________________________ |
226 | TList* AliCDBManager::GetActiveStorages() { | |
227 | // return list of active storages | |
62032124 | 228 | // user has responsibility to delete returned object |
9e1ceb13 | 229 | |
230 | TList* result = new TList(); | |
231 | ||
917a098b | 232 | TIter iter(fActiveStorages.GetTable()); |
62032124 | 233 | TPair* aPair=0; |
9e1ceb13 | 234 | while ((aPair = (TPair*) iter.Next())) { |
235 | result->Add(aPair->Value()); | |
236 | } | |
237 | ||
238 | return result; | |
239 | } | |
240 | ||
241 | //_____________________________________________________________________________ | |
242 | void AliCDBManager::SetDrain(const char* dbString) { | |
243 | // set drain storage from URI string | |
244 | ||
245 | fDrainStorage = GetStorage(dbString); | |
246 | } | |
247 | ||
248 | //_____________________________________________________________________________ | |
249 | void AliCDBManager::SetDrain(const AliCDBParam* param) { | |
250 | // set drain storage from AliCDBParam | |
b8ec52f6 | 251 | |
9e1ceb13 | 252 | fDrainStorage = GetStorage(param); |
253 | } | |
254 | ||
255 | //_____________________________________________________________________________ | |
256 | void AliCDBManager::SetDrain(AliCDBStorage* storage) { | |
257 | // set drain storage from another active storage | |
258 | ||
259 | fDrainStorage = storage; | |
260 | } | |
261 | ||
262 | //_____________________________________________________________________________ | |
263 | Bool_t AliCDBManager::Drain(AliCDBEntry *entry) { | |
264 | // drain retrieved object to drain storage | |
265 | ||
b8ec52f6 | 266 | AliDebug(2, "Draining into drain storage..."); |
9e1ceb13 | 267 | return fDrainStorage->Put(entry); |
268 | } | |
269 | ||
9e1ceb13 | 270 | //_____________________________________________________________________________ |
271 | void AliCDBManager::SetDefaultStorage(const char* dbString) { | |
272 | // sets default storage from URI string | |
273 | ||
82096dfc | 274 | AliInfo(Form("Setting Default storage to: %s",dbString)); |
275 | fDefaultStorage = GetStorage(dbString); | |
9e1ceb13 | 276 | } |
277 | ||
278 | //_____________________________________________________________________________ | |
279 | void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) { | |
280 | // set default storage from AliCDBParam object | |
281 | ||
b8ec52f6 | 282 | fDefaultStorage = GetStorage(param); |
9e1ceb13 | 283 | } |
284 | ||
285 | //_____________________________________________________________________________ | |
286 | void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) { | |
287 | // set default storage from another active storage | |
288 | ||
9e1ceb13 | 289 | fDefaultStorage = storage; |
290 | } | |
291 | ||
02c4845e | 292 | //_____________________________________________________________________________ |
024cf675 | 293 | void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) { |
294 | // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...)) | |
02c4845e | 295 | |
296 | AliCDBParam *aPar = CreateParameter(dbString); | |
297 | if(!aPar) return; | |
024cf675 | 298 | SetSpecificStorage(calibType, aPar); |
02c4845e | 299 | delete aPar; |
300 | } | |
301 | ||
302 | //_____________________________________________________________________________ | |
024cf675 | 303 | void AliCDBManager::SetSpecificStorage(const char* calibType, AliCDBParam* param) { |
304 | // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...)) | |
305 | // Default storage should be defined prior to any specific storages, e.g.: | |
306 | // AliCDBManager::instance()->SetDefaultStorage("alien://"); | |
c3a7b59a | 307 | // AliCDBManager::instance()->SetSpecificStorage("TPC/*","local://DB_TPC"); |
308 | // AliCDBManager::instance()->SetSpecificStorage("*/Align/*","local://DB_TPCAlign"); | |
309 | // calibType must be a valid CDB path! (3 level folder structure) | |
02c4845e | 310 | |
311 | if(!fDefaultStorage) { | |
c3a7b59a | 312 | AliError("Please activate a default storage first!"); |
02c4845e | 313 | return; |
314 | } | |
4005d0b5 | 315 | |
62032124 | 316 | AliCDBPath aPath(calibType); |
317 | if(!aPath.IsValid()){ | |
318 | AliError(Form("Not a valid path: %s", calibType)); | |
319 | return; | |
320 | } | |
321 | ||
322 | TObjString *objCalibType = new TObjString(aPath.GetPath()); | |
024cf675 | 323 | if(fSpecificStorages.Contains(objCalibType)){ |
62032124 | 324 | AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one", |
024cf675 | 325 | calibType)); |
4005d0b5 | 326 | AliCDBParam *checkPar = dynamic_cast<AliCDBParam*> (fSpecificStorages.GetValue(calibType)); |
327 | if(checkPar) delete checkPar; | |
8e245d15 | 328 | delete fSpecificStorages.Remove(objCalibType); |
02c4845e | 329 | } |
330 | GetStorage(param); | |
96b7636d | 331 | |
332 | fSpecificStorages.Add(objCalibType, param->CloneParam()); | |
02c4845e | 333 | } |
334 | ||
335 | //_____________________________________________________________________________ | |
024cf675 | 336 | AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) { |
337 | // get storage specific for detector or calibration type | |
4b5e0dce | 338 | |
9c7fb557 | 339 | AliCDBPath calibPath(calibType); |
340 | if(!calibPath.IsValid()) return NULL; | |
96b7636d | 341 | |
9c7fb557 | 342 | AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibPath.GetPath()); |
02c4845e | 343 | if(!checkPar){ |
b8ec52f6 | 344 | AliError(Form("%s storage not found!", calibType)); |
02c4845e | 345 | return NULL; |
346 | } else { | |
347 | return GetStorage(checkPar); | |
348 | } | |
96b7636d | 349 | |
02c4845e | 350 | } |
351 | ||
024cf675 | 352 | //_____________________________________________________________________________ |
353 | AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) { | |
82096dfc | 354 | // select storage valid for path from the list of specific storages |
024cf675 | 355 | |
62032124 | 356 | AliCDBPath aPath(path); |
4005d0b5 | 357 | if(!aPath.IsValid()) return NULL; |
62032124 | 358 | |
024cf675 | 359 | TIter iter(&fSpecificStorages); |
62032124 | 360 | TObjString *aCalibType=0; |
96b7636d | 361 | AliCDBPath tmpPath("null/null/null"); |
024cf675 | 362 | AliCDBParam* aPar=0; |
363 | while((aCalibType = (TObjString*) iter.Next())){ | |
62032124 | 364 | AliCDBPath calibTypePath(aCalibType->GetName()); |
365 | if(calibTypePath.Comprises(aPath)) { | |
96b7636d | 366 | if(calibTypePath.Comprises(tmpPath)) continue; |
024cf675 | 367 | aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType); |
96b7636d | 368 | tmpPath.SetPath(calibTypePath.GetPath()); |
024cf675 | 369 | } |
370 | } | |
371 | return aPar; | |
372 | } | |
373 | ||
02c4845e | 374 | //_____________________________________________________________________________ |
375 | AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber, | |
376 | Int_t version, Int_t subVersion) { | |
377 | // get an AliCDBEntry object from the database | |
378 | ||
024cf675 | 379 | if(runNumber < 0){ |
380 | // RunNumber is not specified. Try with fRun | |
381 | if (fRun < 0){ | |
382 | AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun."); | |
383 | return NULL; | |
384 | } | |
385 | runNumber = fRun; | |
386 | } | |
387 | ||
02c4845e | 388 | return Get(AliCDBId(path, runNumber, runNumber, version, subVersion)); |
389 | } | |
390 | ||
391 | //_____________________________________________________________________________ | |
392 | AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, | |
393 | const AliCDBRunRange& runRange, Int_t version, | |
394 | Int_t subVersion) { | |
395 | // get an AliCDBEntry object from the database! | |
396 | ||
397 | return Get(AliCDBId(path, runRange, version, subVersion)); | |
398 | } | |
399 | ||
400 | //_____________________________________________________________________________ | |
401 | AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) { | |
402 | // get an AliCDBEntry object from the database | |
403 | ||
404 | if(!fDefaultStorage) { | |
405 | AliError("No storage set!"); | |
406 | return NULL; | |
407 | } | |
408 | ||
409 | // check if query's path and runRange are valid | |
410 | // query is invalid also if version is not specified and subversion is! | |
411 | if (!query.IsValid()) { | |
412 | AliError(Form("Invalid query: %s", query.ToString().Data())); | |
413 | return NULL; | |
414 | } | |
024cf675 | 415 | |
416 | // query is not specified if path contains wildcard or run range= [-1,-1] | |
417 | if (!query.IsSpecified()) { | |
02c4845e | 418 | AliError(Form("Unspecified query: %s", |
419 | query.ToString().Data())); | |
420 | return NULL; | |
421 | } | |
422 | ||
6dc56e97 | 423 | if(fCache && query.GetFirstRun() != fRun) |
024cf675 | 424 | AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!"); |
425 | ||
8e245d15 | 426 | |
024cf675 | 427 | AliCDBEntry *entry=0; |
8e245d15 | 428 | |
024cf675 | 429 | // first look into map of cached objects |
62032124 | 430 | if(fCache && query.GetFirstRun() == fRun) |
024cf675 | 431 | entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath()); |
432 | ||
433 | if(entry) { | |
b8ec52f6 | 434 | AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data())); |
024cf675 | 435 | return entry; |
436 | } | |
96b7636d | 437 | |
438 | // Entry is not in cache -> retrieve it from CDB and cache it!! | |
024cf675 | 439 | AliCDBStorage *aStorage=0; |
440 | AliCDBParam *aPar=SelectSpecificStorage(query.GetPath()); | |
62032124 | 441 | |
02c4845e | 442 | if(aPar) { |
443 | aStorage=GetStorage(aPar); | |
444 | TString str = aPar->GetURI(); | |
445 | AliDebug(2,Form("Looking into storage: %s",str.Data())); | |
446 | ||
447 | } else { | |
448 | aStorage=GetDefaultStorage(); | |
96b7636d | 449 | AliDebug(2,"Looking into default storage"); |
02c4845e | 450 | } |
451 | ||
024cf675 | 452 | entry = aStorage->Get(query); |
453 | if (!entry) return NULL; | |
454 | ||
455 | if(fCache && (query.GetFirstRun() == fRun)){ | |
024cf675 | 456 | CacheEntry(query.GetPath(), entry); |
457 | } | |
8e245d15 | 458 | |
024cf675 | 459 | return entry; |
460 | ||
02c4845e | 461 | } |
462 | ||
463 | //_____________________________________________________________________________ | |
62032124 | 464 | TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber, |
02c4845e | 465 | Int_t version, Int_t subVersion) { |
466 | // get multiple AliCDBEntry objects from the database | |
467 | ||
afd8dbf4 | 468 | if(runNumber < 0){ |
469 | // RunNumber is not specified. Try with fRun | |
470 | if (fRun < 0){ | |
471 | AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun."); | |
472 | return NULL; | |
473 | } | |
474 | runNumber = fRun; | |
475 | } | |
476 | ||
02c4845e | 477 | return GetAll(AliCDBId(path, runNumber, runNumber, version, |
478 | subVersion)); | |
479 | } | |
480 | ||
481 | //_____________________________________________________________________________ | |
8e245d15 | 482 | TList* AliCDBManager::GetAll(const AliCDBPath& path, |
02c4845e | 483 | const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) { |
484 | // get multiple AliCDBEntry objects from the database | |
485 | ||
486 | return GetAll(AliCDBId(path, runRange, version, subVersion)); | |
487 | } | |
488 | ||
489 | //_____________________________________________________________________________ | |
490 | TList* AliCDBManager::GetAll(const AliCDBId& query) { | |
491 | // get multiple AliCDBEntry objects from the database | |
024cf675 | 492 | // Warning: this method works correctly only for queries of the type "Detector/*" |
493 | // and not for more specific queries e.g. "Detector/Calib/*" ! | |
8e245d15 | 494 | // Warning #2: Entries are cached, but GetAll will keep on retrieving objects from OCDB! |
495 | // To get an object from cache use Get() function | |
02c4845e | 496 | |
497 | if(!fDefaultStorage) { | |
498 | AliError("No storage set!"); | |
499 | return NULL; | |
500 | } | |
501 | ||
502 | if (!query.IsValid()) { | |
503 | AliError(Form("Invalid query: %s", query.ToString().Data())); | |
504 | return NULL; | |
505 | } | |
506 | ||
afd8dbf4 | 507 | if((fSpecificStorages.GetEntries()>0) && query.GetPath().BeginsWith('*')){ |
508 | // if specific storages are active a query with "*" is ambiguous | |
509 | AliError("Query too generic in this context!"); | |
8e245d15 | 510 | return NULL; |
02c4845e | 511 | } |
512 | ||
513 | if (query.IsAnyRange()) { | |
514 | AliError(Form("Unspecified run or runrange: %s", | |
8e245d15 | 515 | query.ToString().Data())); |
02c4845e | 516 | return NULL; |
8e245d15 | 517 | } |
518 | ||
6dc56e97 | 519 | AliCDBParam *aPar=SelectSpecificStorage(query.GetPath()); |
024cf675 | 520 | |
8e245d15 | 521 | AliCDBStorage *aStorage; |
02c4845e | 522 | if(aPar) { |
523 | aStorage=GetStorage(aPar); | |
96b7636d | 524 | AliDebug(2,Form("Looking into storage: %s", aPar->GetURI().Data())); |
8e245d15 | 525 | |
02c4845e | 526 | } else { |
527 | aStorage=GetDefaultStorage(); | |
8e245d15 | 528 | AliDebug(2,"Looking into default storage"); |
02c4845e | 529 | } |
530 | ||
96b7636d | 531 | TList *result = 0; |
532 | if(aStorage) result = aStorage->GetAll(query); | |
8e245d15 | 533 | if(!result) return 0; |
534 | ||
96b7636d | 535 | // loop on result to check whether entries should be re-queried with specific storages |
536 | if(fSpecificStorages.GetEntries()>0 && ! (fSpecificStorages.GetEntries() == 1 && aPar)) { | |
537 | AliInfo("Now look into all other specific storages..."); | |
538 | ||
539 | TIter iter(result); | |
540 | AliCDBEntry* chkEntry=0; | |
541 | ||
542 | while((chkEntry = dynamic_cast<AliCDBEntry*> (iter.Next()))){ | |
543 | AliCDBId& chkId = chkEntry->GetId(); | |
544 | AliDebug(2, Form("Checking id %s ", chkId.GetPath().Data())); | |
545 | AliCDBParam *chkPar=SelectSpecificStorage(chkId.GetPath()); | |
546 | if (!chkPar || aPar == chkPar) continue; | |
547 | AliCDBStorage *chkStorage = GetStorage(chkPar); | |
548 | AliDebug(2, Form("Found specific storage! %s", chkPar->GetURI().Data())); | |
549 | ||
550 | AliCDBEntry *newEntry=0; | |
551 | chkId.SetRunRange(query.GetFirstRun(), query.GetLastRun()); | |
552 | chkId.SetVersion(query.GetVersion()); | |
553 | chkId.SetSubVersion(query.GetSubVersion()); | |
554 | ||
555 | if(chkStorage) newEntry = chkStorage->Get(chkId); | |
556 | if(!newEntry) continue; | |
557 | ||
558 | // object is found in specific storage: replace entry in the result list! | |
559 | chkEntry->SetOwner(1); | |
560 | delete result->Remove(chkEntry); | |
561 | result->AddFirst(newEntry); | |
562 | } | |
563 | ||
564 | Int_t nEntries = result->GetEntries(); | |
565 | AliInfo("After look into other specific storages, result list is:"); | |
566 | for(int i=0; i<nEntries;i++){ | |
567 | AliCDBEntry *entry = (AliCDBEntry*) result->At(i); | |
568 | AliInfo(Form("%s",entry->GetId().ToString().Data())); | |
569 | } | |
570 | } | |
571 | ||
8e245d15 | 572 | // caching entries |
573 | if(fCache && (query.GetFirstRun() == fRun)){ | |
02c4845e | 574 | |
8e245d15 | 575 | TIter iter(result); |
576 | AliCDBEntry* entry=0; | |
577 | while((entry = dynamic_cast<AliCDBEntry*> (iter.Next()))){ | |
96b7636d | 578 | CacheEntry(entry->GetId().GetPath(), entry); |
8e245d15 | 579 | } |
580 | } | |
581 | ||
582 | return result; | |
02c4845e | 583 | } |
584 | ||
585 | //_____________________________________________________________________________ | |
b8ec52f6 | 586 | Bool_t AliCDBManager::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData, DataType type){ |
02c4845e | 587 | // store an AliCDBEntry object into the database |
588 | ||
589 | AliCDBEntry anEntry(object, id, metaData); | |
b8ec52f6 | 590 | return Put(&anEntry, type); |
02c4845e | 591 | |
592 | } | |
593 | ||
594 | ||
595 | //_____________________________________________________________________________ | |
b8ec52f6 | 596 | Bool_t AliCDBManager::Put(AliCDBEntry* entry, DataType type){ |
02c4845e | 597 | // store an AliCDBEntry object into the database |
598 | ||
b8ec52f6 | 599 | if(type == kPrivate && !fDefaultStorage) { |
02c4845e | 600 | AliError("No storage set!"); |
601 | return kFALSE; | |
602 | } | |
603 | ||
604 | if (!entry){ | |
605 | AliError("No entry!"); | |
606 | return kFALSE; | |
607 | } | |
608 | ||
609 | if (!entry->GetId().IsValid()) { | |
610 | AliError(Form("Invalid entry ID: %s", | |
611 | entry->GetId().ToString().Data())); | |
612 | return kFALSE; | |
613 | } | |
614 | ||
615 | if (!entry->GetId().IsSpecified()) { | |
616 | AliError(Form("Unspecified entry ID: %s", | |
617 | entry->GetId().ToString().Data())); | |
618 | return kFALSE; | |
619 | } | |
620 | ||
621 | AliCDBId id = entry->GetId(); | |
024cf675 | 622 | AliCDBParam *aPar = SelectSpecificStorage(id.GetPath()); |
623 | ||
4005d0b5 | 624 | AliCDBStorage *aStorage=0; |
02c4845e | 625 | |
626 | if(aPar) { | |
627 | aStorage=GetStorage(aPar); | |
02c4845e | 628 | } else { |
b8ec52f6 | 629 | switch(type){ |
630 | case kCondition: | |
631 | aStorage = GetStorage(fCondParam); | |
632 | break; | |
633 | case kReference: | |
634 | aStorage = GetStorage(fRefParam); | |
635 | break; | |
636 | case kPrivate: | |
637 | aStorage = GetDefaultStorage(); | |
638 | break; | |
639 | } | |
02c4845e | 640 | } |
641 | ||
b8ec52f6 | 642 | AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data())); |
643 | ||
4005d0b5 | 644 | Bool_t result = aStorage->Put(entry, type); |
645 | ||
646 | if(fRun >= 0) QueryCDB(); | |
647 | ||
648 | return result; | |
02c4845e | 649 | |
650 | ||
651 | } | |
9e1ceb13 | 652 | |
4b5e0dce | 653 | //_____________________________________________________________________________ |
654 | void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry) | |
655 | { | |
656 | // cache AliCDBEntry. Cache is valid until run number is changed. | |
657 | ||
96b7636d | 658 | AliCDBEntry *chkEntry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(path)); |
659 | ||
660 | if(chkEntry) { | |
661 | AliDebug(2, Form("Object %s already in cache !!", path)); | |
662 | return; | |
663 | } else { | |
664 | AliDebug(2,Form("Caching entry %s", path)); | |
665 | } | |
666 | ||
4b5e0dce | 667 | fEntryCache.Add(new TObjString(path), entry); |
96b7636d | 668 | AliDebug(2,Form("Cache entries: %d", fEntryCache.GetEntries())); |
4b5e0dce | 669 | |
670 | } | |
671 | ||
917a098b | 672 | //_____________________________________________________________________________ |
673 | void AliCDBManager::Print(Option_t* /*option*/) const | |
674 | { | |
675 | // Print list of active storages and their URIs | |
917a098b | 676 | |
b8ec52f6 | 677 | TString output=Form("Run number = %d; ",fRun); |
678 | output += "Cache is "; | |
917a098b | 679 | if(!fCache) output += "NOT "; |
b8ec52f6 | 680 | output += Form("ACTIVE; Number of active storages: %d\n",fActiveStorages.GetEntries()); |
917a098b | 681 | |
682 | if(fDefaultStorage) { | |
b8ec52f6 | 683 | output += Form("\t*** Default Storage URI: \"%s\"\n",fDefaultStorage->GetURI().Data()); |
684 | // AliInfo(output.Data()); | |
917a098b | 685 | } |
686 | if(fSpecificStorages.GetEntries()>0) { | |
917a098b | 687 | TIter iter(fSpecificStorages.GetTable()); |
62032124 | 688 | TPair *aPair=0; |
b8ec52f6 | 689 | Int_t i=1; |
917a098b | 690 | while((aPair = (TPair*) iter.Next())){ |
b8ec52f6 | 691 | output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n", |
692 | i++, ((TObjString*) aPair->Key())->GetName(), | |
917a098b | 693 | ((AliCDBParam*) aPair->Value())->GetURI().Data()); |
917a098b | 694 | } |
917a098b | 695 | } |
696 | if(fDrainStorage) { | |
b8ec52f6 | 697 | output += Form("*** Drain Storage URI: %s\n",fDrainStorage->GetURI().Data()); |
917a098b | 698 | } |
b8ec52f6 | 699 | AliInfo(output.Data()); |
917a098b | 700 | } |
701 | ||
4b5e0dce | 702 | //_____________________________________________________________________________ |
c3a7b59a | 703 | void AliCDBManager::SetRun(Int_t run) |
4b5e0dce | 704 | { |
917a098b | 705 | // Sets current run number. |
4b5e0dce | 706 | // When the run number changes the caching is cleared. |
4b5e0dce | 707 | |
708 | if (fRun == run) | |
709 | return; | |
710 | ||
711 | fRun = run; | |
712 | ClearCache(); | |
62032124 | 713 | QueryCDB(); |
4b5e0dce | 714 | } |
715 | ||
716 | //_____________________________________________________________________________ | |
717 | void AliCDBManager::ClearCache(){ | |
718 | // clear AliCDBEntry cache | |
719 | ||
720 | AliDebug(2,Form("Clearing cache!")); | |
721 | fEntryCache.DeleteAll(); | |
722 | AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries())); | |
723 | ||
724 | } | |
725 | ||
4005d0b5 | 726 | //_____________________________________________________________________________ |
727 | void AliCDBManager::UnloadFromCache(const char* path){ | |
728 | // unload cached object | |
729 | ||
730 | AliCDBPath queryPath(path); | |
731 | if(!queryPath.IsValid()) return; | |
732 | ||
733 | if(!queryPath.IsWildcard()) { // path is not wildcard, get it directly from the cache and unload it! | |
734 | if(fEntryCache.Contains(path)){ | |
735 | AliInfo(Form("Unloading object \"%s\" from cache", path)); | |
736 | TObjString pathStr(path); | |
737 | AliCDBEntry *entry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(&pathStr)); | |
738 | if(entry) delete entry; | |
739 | delete fEntryCache.Remove(&pathStr); | |
740 | } else { | |
741 | AliError(Form("Cache does not contain object \"%s\"!", path)) | |
742 | } | |
743 | AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries())); | |
744 | return; | |
745 | } | |
746 | ||
747 | // path is wildcard: loop on the cache and unload all comprised objects! | |
748 | TIter iter(fEntryCache.GetTable()); | |
749 | TPair* pair = 0; | |
750 | ||
751 | while((pair = dynamic_cast<TPair*> (iter.Next()))){ | |
752 | AliCDBPath entryPath = pair->Key()->GetName(); | |
753 | if(queryPath.Comprises(entryPath)) { | |
754 | AliInfo(Form("Unloading object \"%s\" from cache", entryPath.GetPath().Data())); | |
755 | TObjString pathStr(entryPath.GetPath().Data()); | |
756 | AliCDBEntry *entry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(&pathStr)); | |
757 | if(entry) delete entry; | |
758 | delete fEntryCache.Remove(&pathStr); | |
759 | } | |
760 | } | |
761 | AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries())); | |
762 | } | |
763 | ||
9e1ceb13 | 764 | //_____________________________________________________________________________ |
765 | void AliCDBManager::DestroyActiveStorages() { | |
766 | // delete list of active storages | |
767 | ||
768 | fActiveStorages.DeleteAll(); | |
02c4845e | 769 | fSpecificStorages.DeleteAll(); |
9e1ceb13 | 770 | } |
771 | ||
772 | //_____________________________________________________________________________ | |
773 | void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) { | |
b05400be | 774 | // destroys active storage |
775 | ||
776 | /* | |
917a098b | 777 | TIter iter(fActiveStorages.GetTable()); |
b05400be | 778 | TPair* aPair; |
779 | while ((aPair = (TPair*) iter.Next())) { | |
780 | if(storage == (AliCDBStorage*) aPair->Value()) | |
781 | delete fActiveStorages.Remove(aPair->Key()); | |
782 | storage->Delete(); storage=0x0; | |
783 | } | |
6dc56e97 | 784 | */ |
9e1ceb13 | 785 | |
786 | } | |
787 | ||
62032124 | 788 | //_____________________________________________________________________________ |
789 | void AliCDBManager::QueryCDB() { | |
790 | // query default and specific storages for files valid for fRun. Every storage loads the Ids into its list. | |
791 | ||
792 | if (fRun < 0){ | |
793 | AliError("Run number not yet set! Use AliCDBManager::SetRun."); | |
794 | return; | |
795 | } | |
6dc56e97 | 796 | if (!fDefaultStorage){ |
797 | AliError("Default storage is not set! Use AliCDBManager::SetDefaultStorage"); | |
798 | return; | |
799 | } | |
800 | if(fDefaultStorage->GetType() == "alien"){ | |
801 | fDefaultStorage->QueryCDB(fRun); | |
802 | } else { | |
803 | AliDebug(2,"Skipping query for valid files, it used only in grid..."); | |
804 | } | |
62032124 | 805 | |
806 | TIter iter(&fSpecificStorages); | |
807 | TObjString *aCalibType=0; | |
808 | AliCDBParam* aPar=0; | |
809 | while((aCalibType = dynamic_cast<TObjString*> (iter.Next()))){ | |
810 | aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType); | |
811 | if(aPar) { | |
c3a7b59a | 812 | AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName())); |
6dc56e97 | 813 | AliCDBStorage *aStorage = GetStorage(aPar); |
814 | if(aStorage->GetType() == "alien"){ | |
815 | aStorage->QueryCDB(fRun,aCalibType->GetName()); | |
816 | } else { | |
817 | AliDebug(2, | |
818 | "Skipping query for valid files, it is used only in grid..."); | |
819 | } | |
62032124 | 820 | } |
821 | } | |
62032124 | 822 | } |
823 | ||
b8ec52f6 | 824 | //______________________________________________________________________________________________ |
825 | const char* AliCDBManager::GetDataTypeName(DataType type) | |
826 | { | |
827 | // returns the name (string) of the data type | |
828 | ||
829 | switch (type){ | |
830 | case kCondition: return "Conditions"; | |
831 | case kReference: return "Reference"; | |
832 | case kPrivate: return "Private"; | |
833 | } | |
834 | return 0; | |
835 | ||
836 | } | |
62032124 | 837 | |
9e1ceb13 | 838 | /////////////////////////////////////////////////////////// |
839 | // AliCDBManager Parameter class // | |
840 | // interface to specific AliCDBParameter class // | |
841 | // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) // | |
842 | /////////////////////////////////////////////////////////// | |
843 | ||
62032124 | 844 | AliCDBParam::AliCDBParam(): |
fe12e09c | 845 | fType(), |
846 | fURI() | |
62032124 | 847 | { |
9e1ceb13 | 848 | // constructor |
849 | ||
850 | } | |
851 | ||
852 | //_____________________________________________________________________________ | |
853 | AliCDBParam::~AliCDBParam() { | |
854 | // destructor | |
855 | ||
856 | } | |
857 |