]>
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) { |
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 | } | |
4005d0b5 | 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)); |
4005d0b5 | 321 | AliCDBParam *checkPar = dynamic_cast<AliCDBParam*> (fSpecificStorages.GetValue(calibType)); |
322 | if(checkPar) delete checkPar; | |
8e245d15 | 323 | delete fSpecificStorages.Remove(objCalibType); |
02c4845e | 324 | } |
325 | GetStorage(param); | |
024cf675 | 326 | fSpecificStorages.Add(objCalibType, param->CloneParam()); |
02c4845e | 327 | } |
328 | ||
329 | //_____________________________________________________________________________ | |
024cf675 | 330 | AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) { |
331 | // get storage specific for detector or calibration type | |
4b5e0dce | 332 | |
9c7fb557 | 333 | AliCDBPath calibPath(calibType); |
334 | if(!calibPath.IsValid()) return NULL; | |
335 | ||
336 | AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibPath.GetPath()); | |
02c4845e | 337 | if(!checkPar){ |
b8ec52f6 | 338 | AliError(Form("%s storage not found!", calibType)); |
02c4845e | 339 | return NULL; |
340 | } else { | |
341 | return GetStorage(checkPar); | |
342 | } | |
343 | ||
344 | } | |
345 | ||
024cf675 | 346 | //_____________________________________________________________________________ |
347 | AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) { | |
82096dfc | 348 | // select storage valid for path from the list of specific storages |
024cf675 | 349 | |
62032124 | 350 | AliCDBPath aPath(path); |
4005d0b5 | 351 | if(!aPath.IsValid()) return NULL; |
62032124 | 352 | |
024cf675 | 353 | TIter iter(&fSpecificStorages); |
62032124 | 354 | TObjString *aCalibType=0; |
024cf675 | 355 | AliCDBParam* aPar=0; |
356 | while((aCalibType = (TObjString*) iter.Next())){ | |
62032124 | 357 | AliCDBPath calibTypePath(aCalibType->GetName()); |
358 | if(calibTypePath.Comprises(aPath)) { | |
024cf675 | 359 | aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType); |
360 | break; | |
361 | } | |
362 | } | |
363 | return aPar; | |
364 | } | |
365 | ||
02c4845e | 366 | //_____________________________________________________________________________ |
367 | AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber, | |
368 | Int_t version, Int_t subVersion) { | |
369 | // get an AliCDBEntry object from the database | |
370 | ||
024cf675 | 371 | if(runNumber < 0){ |
372 | // RunNumber is not specified. Try with fRun | |
373 | if (fRun < 0){ | |
374 | AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun."); | |
375 | return NULL; | |
376 | } | |
377 | runNumber = fRun; | |
378 | } | |
379 | ||
02c4845e | 380 | return Get(AliCDBId(path, runNumber, runNumber, version, subVersion)); |
381 | } | |
382 | ||
383 | //_____________________________________________________________________________ | |
384 | AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, | |
385 | const AliCDBRunRange& runRange, Int_t version, | |
386 | Int_t subVersion) { | |
387 | // get an AliCDBEntry object from the database! | |
388 | ||
389 | return Get(AliCDBId(path, runRange, version, subVersion)); | |
390 | } | |
391 | ||
392 | //_____________________________________________________________________________ | |
393 | AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) { | |
394 | // get an AliCDBEntry object from the database | |
395 | ||
396 | if(!fDefaultStorage) { | |
397 | AliError("No storage set!"); | |
398 | return NULL; | |
399 | } | |
400 | ||
401 | // check if query's path and runRange are valid | |
402 | // query is invalid also if version is not specified and subversion is! | |
403 | if (!query.IsValid()) { | |
404 | AliError(Form("Invalid query: %s", query.ToString().Data())); | |
405 | return NULL; | |
406 | } | |
024cf675 | 407 | |
408 | // query is not specified if path contains wildcard or run range= [-1,-1] | |
409 | if (!query.IsSpecified()) { | |
02c4845e | 410 | AliError(Form("Unspecified query: %s", |
411 | query.ToString().Data())); | |
412 | return NULL; | |
413 | } | |
414 | ||
6dc56e97 | 415 | if(fCache && query.GetFirstRun() != fRun) |
024cf675 | 416 | AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!"); |
417 | ||
8e245d15 | 418 | |
024cf675 | 419 | AliCDBEntry *entry=0; |
8e245d15 | 420 | |
024cf675 | 421 | // first look into map of cached objects |
62032124 | 422 | if(fCache && query.GetFirstRun() == fRun) |
024cf675 | 423 | entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath()); |
424 | ||
425 | if(entry) { | |
b8ec52f6 | 426 | AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data())); |
024cf675 | 427 | return entry; |
428 | } | |
429 | ||
430 | // Entry is not in cache -> retrieve it from CDB and cache it!! | |
431 | AliCDBStorage *aStorage=0; | |
432 | AliCDBParam *aPar=SelectSpecificStorage(query.GetPath()); | |
62032124 | 433 | |
02c4845e | 434 | if(aPar) { |
435 | aStorage=GetStorage(aPar); | |
436 | TString str = aPar->GetURI(); | |
437 | AliDebug(2,Form("Looking into storage: %s",str.Data())); | |
438 | ||
439 | } else { | |
440 | aStorage=GetDefaultStorage(); | |
441 | AliDebug(2,"Looking into default storage"); | |
442 | } | |
443 | ||
024cf675 | 444 | entry = aStorage->Get(query); |
445 | if (!entry) return NULL; | |
446 | ||
447 | if(fCache && (query.GetFirstRun() == fRun)){ | |
6a63c2e2 | 448 | AliDebug(2,Form("Caching entry %s !",query.GetPath().Data())); |
024cf675 | 449 | CacheEntry(query.GetPath(), entry); |
450 | } | |
8e245d15 | 451 | |
024cf675 | 452 | return entry; |
453 | ||
02c4845e | 454 | } |
455 | ||
456 | //_____________________________________________________________________________ | |
62032124 | 457 | TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber, |
02c4845e | 458 | Int_t version, Int_t subVersion) { |
459 | // get multiple AliCDBEntry objects from the database | |
460 | ||
afd8dbf4 | 461 | if(runNumber < 0){ |
462 | // RunNumber is not specified. Try with fRun | |
463 | if (fRun < 0){ | |
464 | AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun."); | |
465 | return NULL; | |
466 | } | |
467 | runNumber = fRun; | |
468 | } | |
469 | ||
02c4845e | 470 | return GetAll(AliCDBId(path, runNumber, runNumber, version, |
471 | subVersion)); | |
472 | } | |
473 | ||
474 | //_____________________________________________________________________________ | |
8e245d15 | 475 | TList* AliCDBManager::GetAll(const AliCDBPath& path, |
02c4845e | 476 | const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) { |
477 | // get multiple AliCDBEntry objects from the database | |
478 | ||
479 | return GetAll(AliCDBId(path, runRange, version, subVersion)); | |
480 | } | |
481 | ||
482 | //_____________________________________________________________________________ | |
483 | TList* AliCDBManager::GetAll(const AliCDBId& query) { | |
484 | // get multiple AliCDBEntry objects from the database | |
024cf675 | 485 | // Warning: this method works correctly only for queries of the type "Detector/*" |
486 | // and not for more specific queries e.g. "Detector/Calib/*" ! | |
8e245d15 | 487 | // Warning #2: Entries are cached, but GetAll will keep on retrieving objects from OCDB! |
488 | // To get an object from cache use Get() function | |
02c4845e | 489 | |
490 | if(!fDefaultStorage) { | |
491 | AliError("No storage set!"); | |
492 | return NULL; | |
493 | } | |
494 | ||
495 | if (!query.IsValid()) { | |
496 | AliError(Form("Invalid query: %s", query.ToString().Data())); | |
497 | return NULL; | |
498 | } | |
499 | ||
afd8dbf4 | 500 | if((fSpecificStorages.GetEntries()>0) && query.GetPath().BeginsWith('*')){ |
501 | // if specific storages are active a query with "*" is ambiguous | |
502 | AliError("Query too generic in this context!"); | |
8e245d15 | 503 | return NULL; |
02c4845e | 504 | } |
505 | ||
506 | if (query.IsAnyRange()) { | |
507 | AliError(Form("Unspecified run or runrange: %s", | |
8e245d15 | 508 | query.ToString().Data())); |
02c4845e | 509 | return NULL; |
8e245d15 | 510 | } |
511 | ||
02c4845e | 512 | TObjString objStrLev0(query.GetLevel0()); |
6dc56e97 | 513 | //AliCDBParam *aPar = (AliCDBParam*) fSpecificStorages.GetValue(&objStrLev0); |
514 | AliCDBParam *aPar=SelectSpecificStorage(query.GetPath()); | |
024cf675 | 515 | |
8e245d15 | 516 | AliCDBStorage *aStorage; |
02c4845e | 517 | if(aPar) { |
518 | aStorage=GetStorage(aPar); | |
519 | TString str = aPar->GetURI(); | |
520 | AliDebug(2,Form("Looking into storage: %s",str.Data())); | |
8e245d15 | 521 | |
02c4845e | 522 | } else { |
523 | aStorage=GetDefaultStorage(); | |
8e245d15 | 524 | AliDebug(2,"Looking into default storage"); |
02c4845e | 525 | } |
526 | ||
527 | TList *result = aStorage->GetAll(query); | |
8e245d15 | 528 | if(!result) return 0; |
529 | ||
530 | // caching entries | |
531 | if(fCache && (query.GetFirstRun() == fRun)){ | |
02c4845e | 532 | |
8e245d15 | 533 | TIter iter(result); |
534 | AliCDBEntry* entry=0; | |
535 | while((entry = dynamic_cast<AliCDBEntry*> (iter.Next()))){ | |
536 | const AliCDBId& anId = entry->GetId(); | |
537 | AliDebug(2,Form("Caching entry %s !", anId.GetPath().Data())); | |
538 | CacheEntry(anId.GetPath(), entry); | |
539 | } | |
540 | } | |
541 | ||
542 | return result; | |
02c4845e | 543 | } |
544 | ||
545 | //_____________________________________________________________________________ | |
b8ec52f6 | 546 | Bool_t AliCDBManager::Put(TObject* object, AliCDBId& id, AliCDBMetaData* metaData, DataType type){ |
02c4845e | 547 | // store an AliCDBEntry object into the database |
548 | ||
549 | AliCDBEntry anEntry(object, id, metaData); | |
b8ec52f6 | 550 | return Put(&anEntry, type); |
02c4845e | 551 | |
552 | } | |
553 | ||
554 | ||
555 | //_____________________________________________________________________________ | |
b8ec52f6 | 556 | Bool_t AliCDBManager::Put(AliCDBEntry* entry, DataType type){ |
02c4845e | 557 | // store an AliCDBEntry object into the database |
558 | ||
b8ec52f6 | 559 | if(type == kPrivate && !fDefaultStorage) { |
02c4845e | 560 | AliError("No storage set!"); |
561 | return kFALSE; | |
562 | } | |
563 | ||
564 | if (!entry){ | |
565 | AliError("No entry!"); | |
566 | return kFALSE; | |
567 | } | |
568 | ||
569 | if (!entry->GetId().IsValid()) { | |
570 | AliError(Form("Invalid entry ID: %s", | |
571 | entry->GetId().ToString().Data())); | |
572 | return kFALSE; | |
573 | } | |
574 | ||
575 | if (!entry->GetId().IsSpecified()) { | |
576 | AliError(Form("Unspecified entry ID: %s", | |
577 | entry->GetId().ToString().Data())); | |
578 | return kFALSE; | |
579 | } | |
580 | ||
581 | AliCDBId id = entry->GetId(); | |
024cf675 | 582 | AliCDBParam *aPar = SelectSpecificStorage(id.GetPath()); |
583 | ||
4005d0b5 | 584 | AliCDBStorage *aStorage=0; |
02c4845e | 585 | |
586 | if(aPar) { | |
587 | aStorage=GetStorage(aPar); | |
02c4845e | 588 | } else { |
b8ec52f6 | 589 | switch(type){ |
590 | case kCondition: | |
591 | aStorage = GetStorage(fCondParam); | |
592 | break; | |
593 | case kReference: | |
594 | aStorage = GetStorage(fRefParam); | |
595 | break; | |
596 | case kPrivate: | |
597 | aStorage = GetDefaultStorage(); | |
598 | break; | |
599 | } | |
02c4845e | 600 | } |
601 | ||
b8ec52f6 | 602 | AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data())); |
603 | ||
4005d0b5 | 604 | Bool_t result = aStorage->Put(entry, type); |
605 | ||
606 | if(fRun >= 0) QueryCDB(); | |
607 | ||
608 | return result; | |
02c4845e | 609 | |
610 | ||
611 | } | |
9e1ceb13 | 612 | |
4b5e0dce | 613 | //_____________________________________________________________________________ |
614 | void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry) | |
615 | { | |
616 | // cache AliCDBEntry. Cache is valid until run number is changed. | |
617 | ||
618 | AliDebug(2,Form("Filling cache with entry %s",path)); | |
619 | fEntryCache.Add(new TObjString(path), entry); | |
620 | AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries())); | |
621 | ||
622 | } | |
623 | ||
917a098b | 624 | //_____________________________________________________________________________ |
625 | void AliCDBManager::Print(Option_t* /*option*/) const | |
626 | { | |
627 | // Print list of active storages and their URIs | |
917a098b | 628 | |
b8ec52f6 | 629 | TString output=Form("Run number = %d; ",fRun); |
630 | output += "Cache is "; | |
917a098b | 631 | if(!fCache) output += "NOT "; |
b8ec52f6 | 632 | output += Form("ACTIVE; Number of active storages: %d\n",fActiveStorages.GetEntries()); |
917a098b | 633 | |
634 | if(fDefaultStorage) { | |
b8ec52f6 | 635 | output += Form("\t*** Default Storage URI: \"%s\"\n",fDefaultStorage->GetURI().Data()); |
636 | // AliInfo(output.Data()); | |
917a098b | 637 | } |
638 | if(fSpecificStorages.GetEntries()>0) { | |
917a098b | 639 | TIter iter(fSpecificStorages.GetTable()); |
62032124 | 640 | TPair *aPair=0; |
b8ec52f6 | 641 | Int_t i=1; |
917a098b | 642 | while((aPair = (TPair*) iter.Next())){ |
b8ec52f6 | 643 | output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n", |
644 | i++, ((TObjString*) aPair->Key())->GetName(), | |
917a098b | 645 | ((AliCDBParam*) aPair->Value())->GetURI().Data()); |
917a098b | 646 | } |
917a098b | 647 | } |
648 | if(fDrainStorage) { | |
b8ec52f6 | 649 | output += Form("*** Drain Storage URI: %s\n",fDrainStorage->GetURI().Data()); |
917a098b | 650 | } |
b8ec52f6 | 651 | AliInfo(output.Data()); |
917a098b | 652 | } |
653 | ||
4b5e0dce | 654 | //_____________________________________________________________________________ |
c3a7b59a | 655 | void AliCDBManager::SetRun(Int_t run) |
4b5e0dce | 656 | { |
917a098b | 657 | // Sets current run number. |
4b5e0dce | 658 | // When the run number changes the caching is cleared. |
4b5e0dce | 659 | |
660 | if (fRun == run) | |
661 | return; | |
662 | ||
663 | fRun = run; | |
664 | ClearCache(); | |
62032124 | 665 | QueryCDB(); |
4b5e0dce | 666 | } |
667 | ||
668 | //_____________________________________________________________________________ | |
669 | void AliCDBManager::ClearCache(){ | |
670 | // clear AliCDBEntry cache | |
671 | ||
672 | AliDebug(2,Form("Clearing cache!")); | |
673 | fEntryCache.DeleteAll(); | |
674 | AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries())); | |
675 | ||
676 | } | |
677 | ||
4005d0b5 | 678 | //_____________________________________________________________________________ |
679 | void AliCDBManager::UnloadFromCache(const char* path){ | |
680 | // unload cached object | |
681 | ||
682 | AliCDBPath queryPath(path); | |
683 | if(!queryPath.IsValid()) return; | |
684 | ||
685 | if(!queryPath.IsWildcard()) { // path is not wildcard, get it directly from the cache and unload it! | |
686 | if(fEntryCache.Contains(path)){ | |
687 | AliInfo(Form("Unloading object \"%s\" from cache", path)); | |
688 | TObjString pathStr(path); | |
689 | AliCDBEntry *entry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(&pathStr)); | |
690 | if(entry) delete entry; | |
691 | delete fEntryCache.Remove(&pathStr); | |
692 | } else { | |
693 | AliError(Form("Cache does not contain object \"%s\"!", path)) | |
694 | } | |
695 | AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries())); | |
696 | return; | |
697 | } | |
698 | ||
699 | // path is wildcard: loop on the cache and unload all comprised objects! | |
700 | TIter iter(fEntryCache.GetTable()); | |
701 | TPair* pair = 0; | |
702 | ||
703 | while((pair = dynamic_cast<TPair*> (iter.Next()))){ | |
704 | AliCDBPath entryPath = pair->Key()->GetName(); | |
705 | if(queryPath.Comprises(entryPath)) { | |
706 | AliInfo(Form("Unloading object \"%s\" from cache", entryPath.GetPath().Data())); | |
707 | TObjString pathStr(entryPath.GetPath().Data()); | |
708 | AliCDBEntry *entry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(&pathStr)); | |
709 | if(entry) delete entry; | |
710 | delete fEntryCache.Remove(&pathStr); | |
711 | } | |
712 | } | |
713 | AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries())); | |
714 | } | |
715 | ||
9e1ceb13 | 716 | //_____________________________________________________________________________ |
717 | void AliCDBManager::DestroyActiveStorages() { | |
718 | // delete list of active storages | |
719 | ||
720 | fActiveStorages.DeleteAll(); | |
02c4845e | 721 | fSpecificStorages.DeleteAll(); |
9e1ceb13 | 722 | } |
723 | ||
724 | //_____________________________________________________________________________ | |
725 | void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) { | |
b05400be | 726 | // destroys active storage |
727 | ||
728 | /* | |
917a098b | 729 | TIter iter(fActiveStorages.GetTable()); |
b05400be | 730 | TPair* aPair; |
731 | while ((aPair = (TPair*) iter.Next())) { | |
732 | if(storage == (AliCDBStorage*) aPair->Value()) | |
733 | delete fActiveStorages.Remove(aPair->Key()); | |
734 | storage->Delete(); storage=0x0; | |
735 | } | |
6dc56e97 | 736 | */ |
9e1ceb13 | 737 | |
738 | } | |
739 | ||
62032124 | 740 | //_____________________________________________________________________________ |
741 | void AliCDBManager::QueryCDB() { | |
742 | // query default and specific storages for files valid for fRun. Every storage loads the Ids into its list. | |
743 | ||
744 | if (fRun < 0){ | |
745 | AliError("Run number not yet set! Use AliCDBManager::SetRun."); | |
746 | return; | |
747 | } | |
6dc56e97 | 748 | if (!fDefaultStorage){ |
749 | AliError("Default storage is not set! Use AliCDBManager::SetDefaultStorage"); | |
750 | return; | |
751 | } | |
752 | if(fDefaultStorage->GetType() == "alien"){ | |
753 | fDefaultStorage->QueryCDB(fRun); | |
754 | } else { | |
755 | AliDebug(2,"Skipping query for valid files, it used only in grid..."); | |
756 | } | |
62032124 | 757 | |
758 | TIter iter(&fSpecificStorages); | |
759 | TObjString *aCalibType=0; | |
760 | AliCDBParam* aPar=0; | |
761 | while((aCalibType = dynamic_cast<TObjString*> (iter.Next()))){ | |
762 | aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType); | |
763 | if(aPar) { | |
c3a7b59a | 764 | AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName())); |
6dc56e97 | 765 | AliCDBStorage *aStorage = GetStorage(aPar); |
766 | if(aStorage->GetType() == "alien"){ | |
767 | aStorage->QueryCDB(fRun,aCalibType->GetName()); | |
768 | } else { | |
769 | AliDebug(2, | |
770 | "Skipping query for valid files, it is used only in grid..."); | |
771 | } | |
62032124 | 772 | } |
773 | } | |
62032124 | 774 | } |
775 | ||
b8ec52f6 | 776 | //______________________________________________________________________________________________ |
777 | const char* AliCDBManager::GetDataTypeName(DataType type) | |
778 | { | |
779 | // returns the name (string) of the data type | |
780 | ||
781 | switch (type){ | |
782 | case kCondition: return "Conditions"; | |
783 | case kReference: return "Reference"; | |
784 | case kPrivate: return "Private"; | |
785 | } | |
786 | return 0; | |
787 | ||
788 | } | |
62032124 | 789 | |
9e1ceb13 | 790 | /////////////////////////////////////////////////////////// |
791 | // AliCDBManager Parameter class // | |
792 | // interface to specific AliCDBParameter class // | |
793 | // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) // | |
794 | /////////////////////////////////////////////////////////// | |
795 | ||
62032124 | 796 | AliCDBParam::AliCDBParam(): |
fe12e09c | 797 | fType(), |
798 | fURI() | |
62032124 | 799 | { |
9e1ceb13 | 800 | // constructor |
801 | ||
802 | } | |
803 | ||
804 | //_____________________________________________________________________________ | |
805 | AliCDBParam::~AliCDBParam() { | |
806 | // destructor | |
807 | ||
808 | } | |
809 |