]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliCDBManager.cxx
Error messages stored in the global raw-reader error log (Cvetan, Chiara)
[u/mrichter/AliRoot.git] / STEER / AliCDBManager.cxx
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  **************************************************************************/
15 //-------------------------------------------------------------------------
16 //   Implementation of AliCDBManager and AliCDBParam classe
17 //   Author: Alberto Colla 
18 //   e-mail: Alberto.Colla@cern.ch
19 //-------------------------------------------------------------------------
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"
27 #include "AliCDBEntry.h"
28 #include "AliCDBMetaData.h"
29
30 #include <TObjString.h>
31 #include <TSystem.h>
32
33 ClassImp(AliCDBParam)
34
35 ClassImp(AliCDBManager)
36
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");
40 AliCDBManager* AliCDBManager::fgInstance = 0x0;
41
42 //_____________________________________________________________________________
43 AliCDBManager* AliCDBManager::Instance()
44 {
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());
65                 fCondParam = CreateParameter(fgkCondUri);
66                 fRefParam = CreateParameter(fgkRefUri);
67         }
68 }
69 //_____________________________________________________________________________
70 void AliCDBManager::Destroy() {
71 // delete ALCDBManager instance and active storages
72
73         if (fgInstance) {
74                 //fgInstance->Delete();
75                 delete fgInstance;
76                 fgInstance = 0x0;
77         }
78 }
79
80 //_____________________________________________________________________________
81 AliCDBManager::AliCDBManager():
82   TObject(),
83   fCondParam(0),
84   fRefParam(0),
85   fFactories(),
86   fActiveStorages(),
87   fSpecificStorages(),
88   fDefaultStorage(NULL),
89   fDrainStorage(NULL),
90   fEntryCache(),
91   fCache(kTRUE),
92   fRun(-1)
93 {
94 // default constuctor
95         fFactories.SetOwner(1);
96         fActiveStorages.SetOwner(1);
97         fSpecificStorages.SetOwner(1);
98         fEntryCache.SetOwner(1);
99 }
100
101 //_____________________________________________________________________________
102 AliCDBManager::~AliCDBManager() {
103 // destructor
104         ClearCache();
105         DestroyActiveStorages();
106         fFactories.Delete();
107         fDrainStorage = 0x0;
108         fDefaultStorage = 0x0;
109         delete fCondParam;
110         delete fRefParam;
111 }
112
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 //_____________________________________________________________________________
131 Bool_t AliCDBManager::HasStorage(const char* dbString) const {
132 // check if dbString is a URI valid for one of the registered factories 
133
134         TIter iter(&fFactories);
135
136         AliCDBStorageFactory* factory=0;
137         while ((factory = (AliCDBStorageFactory*) iter.Next())) {
138
139                 if (factory->Validate(dbString)) {
140                         return kTRUE;
141                 }
142         }
143
144         return kFALSE;
145 }
146
147 //_____________________________________________________________________________
148 AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
149 // create AliCDBParam object from URI string
150
151         TIter iter(&fFactories);
152
153         AliCDBStorageFactory* factory=0;
154         while ((factory = (AliCDBStorageFactory*) iter.Next())) {
155                 AliCDBParam* param = factory->CreateParameter(dbString);
156                 if(param) return param;
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) {
168                 AliError(Form("Failed to activate requested storage! Check URI: %s", dbString));
169                 return NULL;
170         }
171
172         AliCDBStorage* aStorage = GetStorage(param);
173
174         delete param;
175         return aStorage;
176 }
177
178 //_____________________________________________________________________________
179 AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) {
180 // get storage object from AliCDBParam object
181
182         // if the list of active storages already contains
183         // the requested storage, return it
184         AliCDBStorage* aStorage = GetActiveStorage(param);
185         if (aStorage) {
186                 return aStorage;
187         }
188
189         TIter iter(&fFactories);
190
191         AliCDBStorageFactory* factory=0;
192
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);
200                         aStorage->SetURI(param->GetURI());
201                         if(fRun >= 0) {
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                                 }
208                         }
209                         return aStorage;
210                 }
211         }
212
213         AliError(Form("Failed to activate requested storage! Check URI: %s", param->GetURI().Data()));
214
215         return NULL;
216 }
217
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
225 //_____________________________________________________________________________
226 TList* AliCDBManager::GetActiveStorages() {
227 // return list of active storages
228 // user has responsibility to delete returned object
229
230         TList* result = new TList();
231
232         TIter iter(fActiveStorages.GetTable());
233         TPair* aPair=0;
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
251
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
266         AliDebug(2, "Draining into drain storage...");
267         return fDrainStorage->Put(entry);
268 }
269
270 //_____________________________________________________________________________
271 void AliCDBManager::SetDefaultStorage(const char* dbString) {
272 // sets default storage from URI string
273
274         AliInfo(Form("Setting Default storage to: %s",dbString));
275         fDefaultStorage = GetStorage(dbString);
276 }
277
278 //_____________________________________________________________________________
279 void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
280 // set default storage from AliCDBParam object
281         
282         fDefaultStorage = GetStorage(param);
283 }
284
285 //_____________________________________________________________________________
286 void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
287 // set default storage from another active storage
288         
289         fDefaultStorage = storage;
290 }
291
292 //_____________________________________________________________________________
293 void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) {
294 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
295
296         AliCDBParam *aPar = CreateParameter(dbString);
297         if(!aPar) return;
298         SetSpecificStorage(calibType, aPar);
299         delete aPar;
300 }
301
302 //_____________________________________________________________________________
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://");
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)
310
311         if(!fDefaultStorage) {
312                 AliError("Please activate a default storage first!");
313                 return;
314         }
315
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());
323         if(fSpecificStorages.Contains(objCalibType)){
324                 AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one",
325                                         calibType));
326                 AliCDBParam *checkPar = dynamic_cast<AliCDBParam*> (fSpecificStorages.GetValue(calibType));
327                 if(checkPar) delete checkPar;
328                 delete fSpecificStorages.Remove(objCalibType);
329         }
330         GetStorage(param);
331
332         fSpecificStorages.Add(objCalibType, param->CloneParam());
333 }
334
335 //_____________________________________________________________________________
336 AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) {
337 // get storage specific for detector or calibration type 
338
339         AliCDBPath calibPath(calibType);
340         if(!calibPath.IsValid()) return NULL;
341
342         AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibPath.GetPath());
343         if(!checkPar){
344                 AliError(Form("%s storage not found!", calibType));
345                 return NULL;
346         } else {
347                 return GetStorage(checkPar);
348         }
349
350 }
351
352 //_____________________________________________________________________________
353 AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) {
354 // select storage valid for path from the list of specific storages
355
356         AliCDBPath aPath(path);
357         if(!aPath.IsValid()) return NULL;
358
359         TIter iter(&fSpecificStorages);
360         TObjString *aCalibType=0;
361         AliCDBPath tmpPath("null/null/null");
362         AliCDBParam* aPar=0;
363         while((aCalibType = (TObjString*) iter.Next())){
364                 AliCDBPath calibTypePath(aCalibType->GetName());
365                 if(calibTypePath.Comprises(aPath)) {
366                         if(calibTypePath.Comprises(tmpPath)) continue;
367                         aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
368                         tmpPath.SetPath(calibTypePath.GetPath());
369                 }
370         }
371         return aPar;
372 }
373
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
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
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         }
415         
416         // query is not specified if path contains wildcard or run range= [-1,-1]
417         if (!query.IsSpecified()) {
418                 AliError(Form("Unspecified query: %s", 
419                                 query.ToString().Data()));
420                 return NULL;
421         }
422
423         if(fCache && query.GetFirstRun() != fRun)
424                 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
425
426
427         AliCDBEntry *entry=0;
428
429         // first look into map of cached objects
430         if(fCache && query.GetFirstRun() == fRun)
431                 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
432
433         if(entry) {
434                 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
435                 return entry;
436         }
437
438         // Entry is not in cache -> retrieve it from CDB and cache it!!
439         AliCDBStorage *aStorage=0;
440         AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
441
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();
449                 AliDebug(2,"Looking into default storage");
450         }
451                         
452         entry = aStorage->Get(query);
453         if (!entry) return NULL;
454
455         if(fCache && (query.GetFirstRun() == fRun)){
456                 CacheEntry(query.GetPath(), entry);
457         }
458
459         return entry;
460                 
461 }
462
463 //_____________________________________________________________________________
464 TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber,
465         Int_t version, Int_t subVersion) {
466 // get multiple AliCDBEntry objects from the database
467
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
477         return GetAll(AliCDBId(path, runNumber, runNumber, version,     
478                         subVersion));
479 }
480
481 //_____________________________________________________________________________
482 TList* AliCDBManager::GetAll(const AliCDBPath& path,
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
492 // Warning: this method works correctly only for queries of the type "Detector/*"
493 //              and not for more specific queries e.g. "Detector/Calib/*" !
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
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
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!");
510                 return NULL;
511         }
512
513         if (query.IsAnyRange()) {
514                 AliError(Form("Unspecified run or runrange: %s",
515                                 query.ToString().Data()));
516                 return NULL;
517         }
518
519         AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
520
521         AliCDBStorage *aStorage;
522         if(aPar) {
523                 aStorage=GetStorage(aPar);
524                 AliDebug(2,Form("Looking into storage: %s", aPar->GetURI().Data()));
525
526         } else {
527                 aStorage=GetDefaultStorage();
528                 AliDebug(2,"Looking into default storage");
529         }
530
531         TList *result = 0;
532         if(aStorage) result = aStorage->GetAll(query);
533         if(!result) return 0;
534
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
572         // caching entries
573         if(fCache && (query.GetFirstRun() == fRun)){
574
575                 TIter iter(result);
576                 AliCDBEntry* entry=0;
577                 while((entry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
578                         CacheEntry(entry->GetId().GetPath(), entry);
579                 }
580         }
581
582         return result;
583 }
584
585 //_____________________________________________________________________________
586 Bool_t AliCDBManager::Put(TObject* object, AliCDBId& id,  AliCDBMetaData* metaData, DataType type){
587 // store an AliCDBEntry object into the database
588
589         AliCDBEntry anEntry(object, id, metaData);
590         return Put(&anEntry, type);
591
592 }
593
594
595 //_____________________________________________________________________________
596 Bool_t AliCDBManager::Put(AliCDBEntry* entry, DataType type){
597 // store an AliCDBEntry object into the database
598
599         if(type == kPrivate && !fDefaultStorage) {
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();
622         AliCDBParam *aPar = SelectSpecificStorage(id.GetPath());
623
624         AliCDBStorage *aStorage=0;
625         
626         if(aPar) {
627                 aStorage=GetStorage(aPar);
628         } else {
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                 }
640         }
641
642         AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data()));
643
644         Bool_t result = aStorage->Put(entry, type);
645
646         if(fRun >= 0) QueryCDB();
647
648         return result;
649
650
651 }
652
653 //_____________________________________________________________________________
654 void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry)
655 {
656 // cache AliCDBEntry. Cache is valid until run number is changed.
657
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
667         fEntryCache.Add(new TObjString(path), entry);
668         AliDebug(2,Form("Cache entries: %d", fEntryCache.GetEntries()));
669
670 }
671
672 //_____________________________________________________________________________
673 void AliCDBManager::Print(Option_t* /*option*/) const
674 {
675 // Print list of active storages and their URIs
676
677         TString output=Form("Run number = %d; ",fRun);
678         output += "Cache is ";
679         if(!fCache) output += "NOT ";
680         output += Form("ACTIVE; Number of active storages: %d\n",fActiveStorages.GetEntries());
681
682         if(fDefaultStorage) {
683                 output += Form("\t*** Default Storage URI: \"%s\"\n",fDefaultStorage->GetURI().Data());
684 //              AliInfo(output.Data());
685         }
686         if(fSpecificStorages.GetEntries()>0) {
687                 TIter iter(fSpecificStorages.GetTable());
688                 TPair *aPair=0;
689                 Int_t i=1;
690                 while((aPair = (TPair*) iter.Next())){
691                         output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n",
692                                 i++, ((TObjString*) aPair->Key())->GetName(),
693                                 ((AliCDBParam*) aPair->Value())->GetURI().Data());
694                 }
695         }
696         if(fDrainStorage) {
697                 output += Form("*** Drain Storage URI: %s\n",fDrainStorage->GetURI().Data());
698         }
699         AliInfo(output.Data());
700 }
701
702 //_____________________________________________________________________________
703 void AliCDBManager::SetRun(Int_t run)
704 {
705 // Sets current run number.
706 // When the run number changes the caching is cleared.
707   
708         if (fRun == run)
709                 return;
710   
711         fRun = run;
712         ClearCache();
713         QueryCDB();
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
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
764 //_____________________________________________________________________________
765 void AliCDBManager::DestroyActiveStorages() {
766 // delete list of active storages
767
768         fActiveStorages.DeleteAll();
769         fSpecificStorages.DeleteAll();
770 }
771
772 //_____________________________________________________________________________
773 void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
774 // destroys active storage
775
776 /*
777         TIter iter(fActiveStorages.GetTable());
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         }
784 */
785
786 }
787
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         }
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         }
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) {
812                         AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName()));
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                         }
820                 }
821         }
822 }
823
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 }
837
838 ///////////////////////////////////////////////////////////
839 // AliCDBManager Parameter class                         //
840 // interface to specific AliCDBParameter class           //
841 // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam)  //
842 ///////////////////////////////////////////////////////////
843
844 AliCDBParam::AliCDBParam():
845   fType(),
846   fURI()
847 {
848 // constructor
849
850 }
851
852 //_____________________________________________________________________________
853 AliCDBParam::~AliCDBParam() {
854 // destructor
855
856 }
857