]>
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; | |
141 | } | |
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) { |
c3a7b59a | 202 | aStorage->QueryCDB(fRun); |
203 | } | |
9e1ceb13 | 204 | return aStorage; |
205 | } | |
206 | } | |
207 | ||
c3a7b59a | 208 | AliError(Form("Failed to activate requested storage! Check URI: %s", param->GetURI().Data())); |
209 | ||
9e1ceb13 | 210 | return NULL; |
211 | } | |
212 | ||
62032124 | 213 | //_____________________________________________________________________________ |
214 | AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) { | |
215 | // get a storage object from the list of active storages | |
216 | ||
217 | return dynamic_cast<AliCDBStorage*> (fActiveStorages.GetValue(param)); | |
218 | } | |
219 | ||
9e1ceb13 | 220 | //_____________________________________________________________________________ |
221 | TList* AliCDBManager::GetActiveStorages() { | |
222 | // return list of active storages | |
62032124 | 223 | // user has responsibility to delete returned object |
9e1ceb13 | 224 | |
225 | TList* result = new TList(); | |
226 | ||
917a098b | 227 | TIter iter(fActiveStorages.GetTable()); |
62032124 | 228 | TPair* aPair=0; |
9e1ceb13 | 229 | while ((aPair = (TPair*) iter.Next())) { |
230 | result->Add(aPair->Value()); | |
231 | } | |
232 | ||
233 | return result; | |
234 | } | |
235 | ||
236 | //_____________________________________________________________________________ | |
237 | void AliCDBManager::SetDrain(const char* dbString) { | |
238 | // set drain storage from URI string | |
239 | ||
240 | fDrainStorage = GetStorage(dbString); | |
241 | } | |
242 | ||
243 | //_____________________________________________________________________________ | |
244 | void AliCDBManager::SetDrain(const AliCDBParam* param) { | |
245 | // set drain storage from AliCDBParam | |
b8ec52f6 | 246 | |
9e1ceb13 | 247 | fDrainStorage = GetStorage(param); |
248 | } | |
249 | ||
250 | //_____________________________________________________________________________ | |
251 | void AliCDBManager::SetDrain(AliCDBStorage* storage) { | |
252 | // set drain storage from another active storage | |
253 | ||
254 | fDrainStorage = storage; | |
255 | } | |
256 | ||
257 | //_____________________________________________________________________________ | |
258 | Bool_t AliCDBManager::Drain(AliCDBEntry *entry) { | |
259 | // drain retrieved object to drain storage | |
260 | ||
b8ec52f6 | 261 | AliDebug(2, "Draining into drain storage..."); |
9e1ceb13 | 262 | return fDrainStorage->Put(entry); |
263 | } | |
264 | ||
9e1ceb13 | 265 | //_____________________________________________________________________________ |
266 | void AliCDBManager::SetDefaultStorage(const char* dbString) { | |
267 | // sets default storage from URI string | |
268 | ||
82096dfc | 269 | AliInfo(Form("Setting Default storage to: %s",dbString)); |
270 | fDefaultStorage = GetStorage(dbString); | |
9e1ceb13 | 271 | } |
272 | ||
273 | //_____________________________________________________________________________ | |
274 | void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) { | |
275 | // set default storage from AliCDBParam object | |
276 | ||
b8ec52f6 | 277 | fDefaultStorage = GetStorage(param); |
9e1ceb13 | 278 | } |
279 | ||
280 | //_____________________________________________________________________________ | |
281 | void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) { | |
282 | // set default storage from another active storage | |
283 | ||
9e1ceb13 | 284 | fDefaultStorage = storage; |
285 | } | |
286 | ||
02c4845e | 287 | //_____________________________________________________________________________ |
024cf675 | 288 | void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) { |
289 | // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...)) | |
02c4845e | 290 | |
291 | AliCDBParam *aPar = CreateParameter(dbString); | |
292 | if(!aPar) return; | |
024cf675 | 293 | SetSpecificStorage(calibType, aPar); |
02c4845e | 294 | delete aPar; |
295 | } | |
296 | ||
297 | //_____________________________________________________________________________ | |
024cf675 | 298 | void AliCDBManager::SetSpecificStorage(const char* calibType, AliCDBParam* param) { |
299 | // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...)) | |
300 | // Default storage should be defined prior to any specific storages, e.g.: | |
301 | // AliCDBManager::instance()->SetDefaultStorage("alien://"); | |
c3a7b59a | 302 | // AliCDBManager::instance()->SetSpecificStorage("TPC/*","local://DB_TPC"); |
303 | // AliCDBManager::instance()->SetSpecificStorage("*/Align/*","local://DB_TPCAlign"); | |
304 | // calibType must be a valid CDB path! (3 level folder structure) | |
02c4845e | 305 | |
306 | if(!fDefaultStorage) { | |
c3a7b59a | 307 | AliError("Please activate a default storage first!"); |
02c4845e | 308 | return; |
309 | } | |
310 | ||
62032124 | 311 | AliCDBPath aPath(calibType); |
312 | if(!aPath.IsValid()){ | |
313 | AliError(Form("Not a valid path: %s", calibType)); | |
314 | return; | |
315 | } | |
316 | ||
317 | TObjString *objCalibType = new TObjString(aPath.GetPath()); | |
024cf675 | 318 | if(fSpecificStorages.Contains(objCalibType)){ |
62032124 | 319 | AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one", |
024cf675 | 320 | calibType)); |
8e245d15 | 321 | delete fSpecificStorages.Remove(objCalibType); |
02c4845e | 322 | } |
323 | GetStorage(param); | |
024cf675 | 324 | fSpecificStorages.Add(objCalibType, param->CloneParam()); |
02c4845e | 325 | } |
326 | ||
327 | //_____________________________________________________________________________ | |
024cf675 | 328 | AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) { |
329 | // get storage specific for detector or calibration type | |
4b5e0dce | 330 | |
9c7fb557 | 331 | AliCDBPath calibPath(calibType); |
332 | if(!calibPath.IsValid()) return NULL; | |
333 | ||
334 | AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibPath.GetPath()); | |
02c4845e | 335 | if(!checkPar){ |
b8ec52f6 | 336 | AliError(Form("%s storage not found!", calibType)); |
02c4845e | 337 | return NULL; |
338 | } else { | |
339 | return GetStorage(checkPar); | |
340 | } | |
341 | ||
342 | } | |
343 | ||
024cf675 | 344 | //_____________________________________________________________________________ |
345 | AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) { | |
82096dfc | 346 | // select storage valid for path from the list of specific storages |
024cf675 | 347 | |
62032124 | 348 | AliCDBPath aPath(path); |
349 | if(!aPath.IsValid()){ | |
350 | AliError(Form("Not a valid path: %s", path.Data())); | |
351 | return NULL; | |
352 | } | |
353 | ||
024cf675 | 354 | TIter iter(&fSpecificStorages); |
62032124 | 355 | TObjString *aCalibType=0; |
024cf675 | 356 | AliCDBParam* aPar=0; |
357 | while((aCalibType = (TObjString*) iter.Next())){ | |
62032124 | 358 | AliCDBPath calibTypePath(aCalibType->GetName()); |
359 | if(calibTypePath.Comprises(aPath)) { | |
024cf675 | 360 | aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType); |
361 | break; | |
362 | } | |
363 | } | |
364 | return aPar; | |
365 | } | |
366 | ||
02c4845e | 367 | //_____________________________________________________________________________ |
368 | AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber, | |
369 | Int_t version, Int_t subVersion) { | |
370 | // get an AliCDBEntry object from the database | |
371 | ||
024cf675 | 372 | if(runNumber < 0){ |
373 | // RunNumber is not specified. Try with fRun | |
374 | if (fRun < 0){ | |
375 | AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun."); | |
376 | return NULL; | |
377 | } | |
378 | runNumber = fRun; | |
379 | } | |
380 | ||
02c4845e | 381 | return Get(AliCDBId(path, runNumber, runNumber, version, subVersion)); |
382 | } | |
383 | ||
384 | //_____________________________________________________________________________ | |
385 | AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, | |
386 | const AliCDBRunRange& runRange, Int_t version, | |
387 | Int_t subVersion) { | |
388 | // get an AliCDBEntry object from the database! | |
389 | ||
390 | return Get(AliCDBId(path, runRange, version, subVersion)); | |
391 | } | |
392 | ||
393 | //_____________________________________________________________________________ | |
394 | AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) { | |
395 | // get an AliCDBEntry object from the database | |
396 | ||
397 | if(!fDefaultStorage) { | |
398 | AliError("No storage set!"); | |
399 | return NULL; | |
400 | } | |
401 | ||
402 | // check if query's path and runRange are valid | |
403 | // query is invalid also if version is not specified and subversion is! | |
404 | if (!query.IsValid()) { | |
405 | AliError(Form("Invalid query: %s", query.ToString().Data())); | |
406 | return NULL; | |
407 | } | |
024cf675 | 408 | |
409 | // query is not specified if path contains wildcard or run range= [-1,-1] | |
410 | if (!query.IsSpecified()) { | |
02c4845e | 411 | AliError(Form("Unspecified query: %s", |
412 | query.ToString().Data())); | |
413 | return NULL; | |
414 | } | |
415 | ||
6dc56e97 | 416 | if(fCache && query.GetFirstRun() != fRun) |
024cf675 | 417 | AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!"); |
418 | ||
8e245d15 | 419 | |
024cf675 | 420 | AliCDBEntry *entry=0; |
8e245d15 | 421 | |
024cf675 | 422 | // first look into map of cached objects |
62032124 | 423 | if(fCache && query.GetFirstRun() == fRun) |
024cf675 | 424 | entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath()); |
425 | ||
426 | if(entry) { | |
b8ec52f6 | 427 | AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data())); |
024cf675 | 428 | return entry; |
429 | } | |
430 | ||
431 | // Entry is not in cache -> retrieve it from CDB and cache it!! | |
432 | AliCDBStorage *aStorage=0; | |
433 | AliCDBParam *aPar=SelectSpecificStorage(query.GetPath()); | |
62032124 | 434 | |
02c4845e | 435 | if(aPar) { |
436 | aStorage=GetStorage(aPar); | |
437 | TString str = aPar->GetURI(); | |
438 | AliDebug(2,Form("Looking into storage: %s",str.Data())); | |
439 | ||
440 | } else { | |
441 | aStorage=GetDefaultStorage(); | |
442 | AliDebug(2,"Looking into default storage"); | |
443 | } | |
444 | ||
024cf675 | 445 | entry = aStorage->Get(query); |
446 | if (!entry) return NULL; | |
447 | ||
448 | if(fCache && (query.GetFirstRun() == fRun)){ | |
6a63c2e2 | 449 | AliDebug(2,Form("Caching entry %s !",query.GetPath().Data())); |
024cf675 | 450 | CacheEntry(query.GetPath(), entry); |
451 | } | |
8e245d15 | 452 | |
024cf675 | 453 | return entry; |
454 | ||
02c4845e | 455 | } |
456 | ||
457 | //_____________________________________________________________________________ | |
62032124 | 458 | TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber, |
02c4845e | 459 | Int_t version, Int_t subVersion) { |
460 | // get multiple AliCDBEntry objects from the database | |
461 | ||
afd8dbf4 | 462 | if(runNumber < 0){ |
463 | // RunNumber is not specified. Try with fRun | |
464 | if (fRun < 0){ | |
465 | AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun."); | |
466 | return NULL; | |
467 | } | |
468 | runNumber = fRun; | |
469 | } | |
470 | ||
02c4845e | 471 | return GetAll(AliCDBId(path, runNumber, runNumber, version, |
472 | subVersion)); | |
473 | } | |
474 | ||
475 | //_____________________________________________________________________________ | |
8e245d15 | 476 | TList* AliCDBManager::GetAll(const AliCDBPath& path, |
02c4845e | 477 | const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) { |
478 | // get multiple AliCDBEntry objects from the database | |
479 | ||
480 | return GetAll(AliCDBId(path, runRange, version, subVersion)); | |
481 | } | |
482 | ||
483 | //_____________________________________________________________________________ | |
484 | TList* AliCDBManager::GetAll(const AliCDBId& query) { | |
485 | // get multiple AliCDBEntry objects from the database | |
024cf675 | 486 | // Warning: this method works correctly only for queries of the type "Detector/*" |
487 | // and not for more specific queries e.g. "Detector/Calib/*" ! | |
8e245d15 | 488 | // Warning #2: Entries are cached, but GetAll will keep on retrieving objects from OCDB! |
489 | // To get an object from cache use Get() function | |
02c4845e | 490 | |
491 | if(!fDefaultStorage) { | |
492 | AliError("No storage set!"); | |
493 | return NULL; | |
494 | } | |
495 | ||
496 | if (!query.IsValid()) { | |
497 | AliError(Form("Invalid query: %s", query.ToString().Data())); | |
498 | return NULL; | |
499 | } | |
500 | ||
afd8dbf4 | 501 | if((fSpecificStorages.GetEntries()>0) && query.GetPath().BeginsWith('*')){ |
502 | // if specific storages are active a query with "*" is ambiguous | |
503 | AliError("Query too generic in this context!"); | |
8e245d15 | 504 | return NULL; |
02c4845e | 505 | } |
506 | ||
507 | if (query.IsAnyRange()) { | |
508 | AliError(Form("Unspecified run or runrange: %s", | |
8e245d15 | 509 | query.ToString().Data())); |
02c4845e | 510 | return NULL; |
8e245d15 | 511 | } |
512 | ||
02c4845e | 513 | TObjString objStrLev0(query.GetLevel0()); |
6dc56e97 | 514 | //AliCDBParam *aPar = (AliCDBParam*) fSpecificStorages.GetValue(&objStrLev0); |
515 | AliCDBParam *aPar=SelectSpecificStorage(query.GetPath()); | |
024cf675 | 516 | |
8e245d15 | 517 | AliCDBStorage *aStorage; |
02c4845e | 518 | if(aPar) { |
519 | aStorage=GetStorage(aPar); | |
520 | TString str = aPar->GetURI(); | |
521 | AliDebug(2,Form("Looking into storage: %s",str.Data())); | |
8e245d15 | 522 | |
02c4845e | 523 | } else { |
524 | aStorage=GetDefaultStorage(); | |
8e245d15 | 525 | AliDebug(2,"Looking into default storage"); |
02c4845e | 526 | } |
527 | ||
528 | TList *result = aStorage->GetAll(query); | |
8e245d15 | 529 | if(!result) return 0; |
530 | ||
531 | // caching entries | |
532 | if(fCache && (query.GetFirstRun() == fRun)){ | |
02c4845e | 533 | |
8e245d15 | 534 | TIter iter(result); |
535 | AliCDBEntry* entry=0; | |
536 | while((entry = dynamic_cast<AliCDBEntry*> (iter.Next()))){ | |
537 | const AliCDBId& anId = entry->GetId(); | |
538 | AliDebug(2,Form("Caching entry %s !", anId.GetPath().Data())); | |
539 | CacheEntry(anId.GetPath(), entry); | |
540 | } | |
541 | } | |
542 | ||
543 | return result; | |
02c4845e | 544 | } |
545 | ||
546 | //_____________________________________________________________________________ | |
b8ec52f6 | 547 | Bool_t AliCDBManager::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData, DataType type){ |
02c4845e | 548 | // store an AliCDBEntry object into the database |
549 | ||
550 | AliCDBEntry anEntry(object, id, metaData); | |
b8ec52f6 | 551 | return Put(&anEntry, type); |
02c4845e | 552 | |
553 | } | |
554 | ||
555 | ||
556 | //_____________________________________________________________________________ | |
b8ec52f6 | 557 | Bool_t AliCDBManager::Put(AliCDBEntry* entry, DataType type){ |
02c4845e | 558 | // store an AliCDBEntry object into the database |
559 | ||
b8ec52f6 | 560 | if(type == kPrivate && !fDefaultStorage) { |
02c4845e | 561 | AliError("No storage set!"); |
562 | return kFALSE; | |
563 | } | |
564 | ||
565 | if (!entry){ | |
566 | AliError("No entry!"); | |
567 | return kFALSE; | |
568 | } | |
569 | ||
570 | if (!entry->GetId().IsValid()) { | |
571 | AliError(Form("Invalid entry ID: %s", | |
572 | entry->GetId().ToString().Data())); | |
573 | return kFALSE; | |
574 | } | |
575 | ||
576 | if (!entry->GetId().IsSpecified()) { | |
577 | AliError(Form("Unspecified entry ID: %s", | |
578 | entry->GetId().ToString().Data())); | |
579 | return kFALSE; | |
580 | } | |
581 | ||
582 | AliCDBId id = entry->GetId(); | |
024cf675 | 583 | AliCDBParam *aPar = SelectSpecificStorage(id.GetPath()); |
584 | ||
02c4845e | 585 | AliCDBStorage *aStorage; |
586 | ||
587 | if(aPar) { | |
588 | aStorage=GetStorage(aPar); | |
02c4845e | 589 | } else { |
b8ec52f6 | 590 | switch(type){ |
591 | case kCondition: | |
592 | aStorage = GetStorage(fCondParam); | |
593 | break; | |
594 | case kReference: | |
595 | aStorage = GetStorage(fRefParam); | |
596 | break; | |
597 | case kPrivate: | |
598 | aStorage = GetDefaultStorage(); | |
599 | break; | |
600 | } | |
02c4845e | 601 | } |
602 | ||
b8ec52f6 | 603 | AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data())); |
604 | ||
605 | return aStorage->Put(entry, type); | |
02c4845e | 606 | |
607 | ||
608 | } | |
9e1ceb13 | 609 | |
4b5e0dce | 610 | //_____________________________________________________________________________ |
611 | void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry) | |
612 | { | |
613 | // cache AliCDBEntry. Cache is valid until run number is changed. | |
614 | ||
615 | AliDebug(2,Form("Filling cache with entry %s",path)); | |
616 | fEntryCache.Add(new TObjString(path), entry); | |
617 | AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries())); | |
618 | ||
619 | } | |
620 | ||
917a098b | 621 | //_____________________________________________________________________________ |
622 | void AliCDBManager::Print(Option_t* /*option*/) const | |
623 | { | |
624 | // Print list of active storages and their URIs | |
917a098b | 625 | |
b8ec52f6 | 626 | TString output=Form("Run number = %d; ",fRun); |
627 | output += "Cache is "; | |
917a098b | 628 | if(!fCache) output += "NOT "; |
b8ec52f6 | 629 | output += Form("ACTIVE; Number of active storages: %d\n",fActiveStorages.GetEntries()); |
917a098b | 630 | |
631 | if(fDefaultStorage) { | |
b8ec52f6 | 632 | output += Form("\t*** Default Storage URI: \"%s\"\n",fDefaultStorage->GetURI().Data()); |
633 | // AliInfo(output.Data()); | |
917a098b | 634 | } |
635 | if(fSpecificStorages.GetEntries()>0) { | |
917a098b | 636 | TIter iter(fSpecificStorages.GetTable()); |
62032124 | 637 | TPair *aPair=0; |
b8ec52f6 | 638 | Int_t i=1; |
917a098b | 639 | while((aPair = (TPair*) iter.Next())){ |
b8ec52f6 | 640 | output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n", |
641 | i++, ((TObjString*) aPair->Key())->GetName(), | |
917a098b | 642 | ((AliCDBParam*) aPair->Value())->GetURI().Data()); |
917a098b | 643 | } |
917a098b | 644 | } |
645 | if(fDrainStorage) { | |
b8ec52f6 | 646 | output += Form("*** Drain Storage URI: %s\n",fDrainStorage->GetURI().Data()); |
917a098b | 647 | } |
b8ec52f6 | 648 | AliInfo(output.Data()); |
917a098b | 649 | } |
650 | ||
4b5e0dce | 651 | //_____________________________________________________________________________ |
c3a7b59a | 652 | void AliCDBManager::SetRun(Int_t run) |
4b5e0dce | 653 | { |
917a098b | 654 | // Sets current run number. |
4b5e0dce | 655 | // When the run number changes the caching is cleared. |
4b5e0dce | 656 | |
657 | if (fRun == run) | |
658 | return; | |
659 | ||
660 | fRun = run; | |
661 | ClearCache(); | |
62032124 | 662 | QueryCDB(); |
4b5e0dce | 663 | } |
664 | ||
665 | //_____________________________________________________________________________ | |
666 | void AliCDBManager::ClearCache(){ | |
667 | // clear AliCDBEntry cache | |
668 | ||
669 | AliDebug(2,Form("Clearing cache!")); | |
670 | fEntryCache.DeleteAll(); | |
671 | AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries())); | |
672 | ||
673 | } | |
674 | ||
9e1ceb13 | 675 | //_____________________________________________________________________________ |
676 | void AliCDBManager::DestroyActiveStorages() { | |
677 | // delete list of active storages | |
678 | ||
679 | fActiveStorages.DeleteAll(); | |
02c4845e | 680 | fSpecificStorages.DeleteAll(); |
9e1ceb13 | 681 | } |
682 | ||
683 | //_____________________________________________________________________________ | |
684 | void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) { | |
b05400be | 685 | // destroys active storage |
686 | ||
687 | /* | |
917a098b | 688 | TIter iter(fActiveStorages.GetTable()); |
b05400be | 689 | TPair* aPair; |
690 | while ((aPair = (TPair*) iter.Next())) { | |
691 | if(storage == (AliCDBStorage*) aPair->Value()) | |
692 | delete fActiveStorages.Remove(aPair->Key()); | |
693 | storage->Delete(); storage=0x0; | |
694 | } | |
6dc56e97 | 695 | */ |
9e1ceb13 | 696 | |
697 | } | |
698 | ||
62032124 | 699 | //_____________________________________________________________________________ |
700 | void AliCDBManager::QueryCDB() { | |
701 | // query default and specific storages for files valid for fRun. Every storage loads the Ids into its list. | |
702 | ||
703 | if (fRun < 0){ | |
704 | AliError("Run number not yet set! Use AliCDBManager::SetRun."); | |
705 | return; | |
706 | } | |
6dc56e97 | 707 | if (!fDefaultStorage){ |
708 | AliError("Default storage is not set! Use AliCDBManager::SetDefaultStorage"); | |
709 | return; | |
710 | } | |
711 | if(fDefaultStorage->GetType() == "alien"){ | |
712 | fDefaultStorage->QueryCDB(fRun); | |
713 | } else { | |
714 | AliDebug(2,"Skipping query for valid files, it used only in grid..."); | |
715 | } | |
62032124 | 716 | |
717 | TIter iter(&fSpecificStorages); | |
718 | TObjString *aCalibType=0; | |
719 | AliCDBParam* aPar=0; | |
720 | while((aCalibType = dynamic_cast<TObjString*> (iter.Next()))){ | |
721 | aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType); | |
722 | if(aPar) { | |
c3a7b59a | 723 | AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName())); |
6dc56e97 | 724 | AliCDBStorage *aStorage = GetStorage(aPar); |
725 | if(aStorage->GetType() == "alien"){ | |
726 | aStorage->QueryCDB(fRun,aCalibType->GetName()); | |
727 | } else { | |
728 | AliDebug(2, | |
729 | "Skipping query for valid files, it is used only in grid..."); | |
730 | } | |
62032124 | 731 | } |
732 | } | |
62032124 | 733 | } |
734 | ||
b8ec52f6 | 735 | //______________________________________________________________________________________________ |
736 | const char* AliCDBManager::GetDataTypeName(DataType type) | |
737 | { | |
738 | // returns the name (string) of the data type | |
739 | ||
740 | switch (type){ | |
741 | case kCondition: return "Conditions"; | |
742 | case kReference: return "Reference"; | |
743 | case kPrivate: return "Private"; | |
744 | } | |
745 | return 0; | |
746 | ||
747 | } | |
62032124 | 748 | |
9e1ceb13 | 749 | /////////////////////////////////////////////////////////// |
750 | // AliCDBManager Parameter class // | |
751 | // interface to specific AliCDBParameter class // | |
752 | // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) // | |
753 | /////////////////////////////////////////////////////////// | |
754 | ||
62032124 | 755 | AliCDBParam::AliCDBParam(): |
fe12e09c | 756 | fType(), |
757 | fURI() | |
62032124 | 758 | { |
9e1ceb13 | 759 | // constructor |
760 | ||
761 | } | |
762 | ||
763 | //_____________________________________________________________________________ | |
764 | AliCDBParam::~AliCDBParam() { | |
765 | // destructor | |
766 | ||
767 | } | |
768 |