]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/CDB/AliCDBManager.cxx
b17a6cb80a481b7d86a8b25a27d65222805e93cc
[u/mrichter/AliRoot.git] / STEER / CDB / 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 "AliCDBHandler.h"
29
30 #include <TObjString.h>
31 #include <TSAXParser.h>
32 #include <TFile.h>
33 #include <TKey.h>
34 #include <TUUID.h>
35 #include <TGrid.h>
36
37 ClassImp(AliCDBParam)
38
39 ClassImp(AliCDBManager)
40
41 //TODO OCDB and Reference folder should not be fully hardcoded but built from run number (or year/LHC period)
42 TString AliCDBManager::fgkCondUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/CDB?user=aliprod");
43 TString AliCDBManager::fgkRefUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/Reference?user=aliprod");
44 TString AliCDBManager::fgkMCIdealStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Ideal");
45 TString AliCDBManager::fgkMCFullStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Full");
46 TString AliCDBManager::fgkMCResidualStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Residual");
47 TString AliCDBManager::fgkOCDBFolderXMLfile("alien:///alice/data/OCDBFoldervsRunRange.xml");
48 AliCDBManager* AliCDBManager::fgInstance = 0x0;
49
50 //_____________________________________________________________________________
51 AliCDBManager* AliCDBManager::Instance(TMap *entryCache, Int_t run)
52 {
53 // returns AliCDBManager instance (singleton)
54
55         if (!fgInstance) {
56                 fgInstance = new AliCDBManager();
57                 if (!entryCache)
58                   fgInstance->Init();
59                 else
60                   fgInstance->InitFromCache(entryCache,run);
61         }
62
63         return fgInstance;
64 }
65
66 //_____________________________________________________________________________
67 void AliCDBManager::Init() {
68 // factory registering
69
70         RegisterFactory(new AliCDBDumpFactory());
71         RegisterFactory(new AliCDBLocalFactory()); 
72         // AliCDBGridFactory is registered only if AliEn libraries are enabled in Root
73         if(!gSystem->Exec("root-config --has-alien |grep yes 2>&1 > /dev/null")){ // returns 0 if yes
74                 AliInfo("AliEn classes enabled in Root. AliCDBGrid factory registered.");
75                 RegisterFactory(new AliCDBGridFactory());
76                 fCondParam = CreateParameter(fgkCondUri);
77                 fRefParam = CreateParameter(fgkRefUri);
78         }
79
80         InitShortLived();
81 }
82
83 //_____________________________________________________________________________
84 void AliCDBManager::InitFromCache(TMap *entryCache, Int_t run) {
85 // initialize manager from existing cache
86 // used on the slaves in case of parallel reconstruction
87   SetRun(run);
88
89   TIter iter(entryCache->GetTable());
90   TPair* pair = 0;
91
92   while((pair = dynamic_cast<TPair*> (iter.Next()))){
93     fEntryCache.Add(pair->Key(),pair->Value());
94   }
95   // fEntry is the new owner of the cache
96   fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
97   entryCache->SetOwnerKeyValue(kFALSE,kFALSE);
98   AliInfo(Form("%d cache entries have been loaded",fEntryCache.GetEntries()));
99 }
100
101 //_____________________________________________________________________________
102 void  AliCDBManager::DumpToSnapshotFile(const char* snapshotFileName){
103 // 
104 // dump the entries map and the ids list to
105 // the output file
106
107     // open the file
108     TFile *f = TFile::Open(snapshotFileName,"RECREATE");
109     if (!f || f->IsZombie()){
110         AliError(Form("Cannot open file %s",snapshotFileName));
111         return;
112     }
113
114     Printf("\ndumping entriesMap (entries'cache) with %d entries!\n", fEntryCache.GetEntries()); 
115     Printf("\ndumping entriesList with %d entries!\n", fIds->GetEntries());
116
117     f->cd();                                                                                           
118
119     f->WriteObject(&fEntryCache,"CDBentriesMap");
120     f->WriteObject(fIds,"CDBidsList");
121     f->Close();
122     delete f;
123
124     //return;
125     //exit;
126 }
127
128 //_____________________________________________________________________________
129 Bool_t AliCDBManager::InitFromSnapshot(const char* snapshotFileName){
130 // initialize manager from a CDB snapshot, that is add the entries
131 // to the entries map and the ids to the ids list taking them from
132 // the map and the list found in the input file
133
134     // open the file
135     TString snapshotFile(snapshotFileName);
136     if(snapshotFile.BeginsWith("alien://")){
137         if(!gGrid) {
138             TGrid::Connect("alien://","");
139             if(!gGrid) {
140                 AliError("Connection to alien failed!");
141                 return kFALSE;
142             }
143         }
144     }
145
146     TFile *f = TFile::Open(snapshotFileName);
147     if (!f || f->IsZombie()){
148         AliError(Form("Cannot open file %s",snapshotFileName));
149         return kFALSE;
150     }
151
152     // retrieve entries map
153     TMap *entriesMap = 0;
154     TIter next(f->GetListOfKeys());
155     TKey *key;
156     while ((key = (TKey*)next())) {
157         if (strcmp(key->GetClassName(),"TMap") != 0) continue;
158         entriesMap = (TMap*)key->ReadObj();
159         break;
160     }
161     if (!entriesMap || entriesMap->GetEntries()==0){
162         AliError("Cannot get valid map of CDB entries from snapshot file");
163         return kFALSE;
164     }
165
166     // retrieve ids list
167     TList *idsList = 0;
168     TIter nextKey(f->GetListOfKeys());
169     TKey *keyN;
170     while ((keyN = (TKey*)nextKey())) {
171         if (strcmp(keyN->GetClassName(),"TList") != 0) continue;
172         idsList = (TList*)keyN->ReadObj();
173         break;
174     }
175     if (!idsList || idsList->GetEntries()==0){
176         AliError("Cannot get valid list of CDB entries from snapshot file");
177         return kFALSE;
178     }
179
180     TIter iterObj(entriesMap->GetTable());
181     TPair* pair = 0;
182
183     while((pair = dynamic_cast<TPair*> (iterObj.Next()))){
184         fEntryCache.Add(pair->Key(),pair->Value());
185     }
186     // fEntry is the new owner of the cache
187     fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
188     entriesMap->SetOwnerKeyValue(kFALSE,kFALSE);
189     AliInfo(Form("%d cache entries have been loaded",fEntryCache.GetEntries()));
190
191     TIter iterId(idsList);       
192
193     AliCDBId* id=0;
194     while((id = dynamic_cast<AliCDBId*> (iterId.Next()))){       
195         fIds->Add(id);   
196     }    
197     fIds->SetOwner(kTRUE);
198     idsList->SetOwner(kFALSE);
199     f->Close();
200     delete f;
201     AliInfo(Form("%d cache ids loaded. Total number of ids is %d",idsList->GetEntries(),fIds->GetEntries()));
202
203     return kTRUE;
204 }
205
206 //_____________________________________________________________________________
207 void AliCDBManager::Destroy() {
208 // delete ALCDBManager instance and active storages
209
210         if (fgInstance) {
211                 //fgInstance->Delete();
212                 delete fgInstance;
213                 fgInstance = 0x0;
214         }
215 }
216
217 //_____________________________________________________________________________
218 AliCDBManager::AliCDBManager():
219   TObject(),
220   fFactories(),
221   fActiveStorages(),
222   fSpecificStorages(),
223   fEntryCache(),
224   fIds(0),
225   fStorageMap(0),
226   fShortLived(0),
227   fDefaultStorage(NULL),
228   fDrainStorage(NULL),
229   fCondParam(0),
230   fRefParam(0),
231   fRun(-1),
232   fCache(kTRUE),
233   fLock(kFALSE),
234   fRaw(kFALSE),
235   fStartRunLHCPeriod(-1),
236   fEndRunLHCPeriod(-1),
237   fLHCPeriod(""),
238   fKey(0)
239 {
240 // default constuctor
241         fFactories.SetOwner(1);
242         fActiveStorages.SetOwner(1);
243         fSpecificStorages.SetOwner(1);
244         fEntryCache.SetName("CDBEntryCache");
245         fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
246
247         fStorageMap = new TMap();
248         fStorageMap->SetOwner(1);
249         fIds = new TList();
250         fIds->SetOwner(1);
251 }
252
253 //_____________________________________________________________________________
254 AliCDBManager::~AliCDBManager() {
255 // destructor
256         ClearCache();
257         DestroyActiveStorages();
258         fFactories.Delete();
259         fDrainStorage = 0x0;
260         fDefaultStorage = 0x0;
261         delete fStorageMap; fStorageMap = 0;
262         delete fIds; fIds = 0;
263         delete fCondParam;
264         delete fRefParam;
265         delete fShortLived; fShortLived = 0x0;
266 }
267
268 //_____________________________________________________________________________
269 void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){
270 // put a storage object into the list of active storages
271
272         fActiveStorages.Add(param, storage);
273         AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries()));
274 }
275
276 //_____________________________________________________________________________
277 void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) {
278 // add a storage factory to the list of registerd factories
279  
280         if (!fFactories.Contains(factory)) {
281                 fFactories.Add(factory);
282         }
283 }
284
285 //_____________________________________________________________________________
286 Bool_t AliCDBManager::HasStorage(const char* dbString) const {
287 // check if dbString is a URI valid for one of the registered factories
288
289         TIter iter(&fFactories);
290
291         AliCDBStorageFactory* factory=0;
292         while ((factory = (AliCDBStorageFactory*) iter.Next())) {
293
294                 if (factory->Validate(dbString)) {
295                         return kTRUE;
296                 }
297         }
298
299         return kFALSE;
300 }
301
302 //_____________________________________________________________________________
303 AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
304 // create AliCDBParam object from URI string
305
306         TIter iter(&fFactories);
307
308         AliCDBStorageFactory* factory=0;
309         while ((factory = (AliCDBStorageFactory*) iter.Next())) {
310                 AliCDBParam* param = factory->CreateParameter(dbString);
311                 if(param) return param;
312         }
313
314         return NULL;
315 }
316
317 //_____________________________________________________________________________
318 AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) {
319 // get storage object from URI string
320                 
321         AliCDBParam* param = CreateParameter(dbString);
322         if (!param) {
323                 AliError(Form("Failed to activate requested storage! Check URI: %s", dbString));
324                 return NULL;
325         }
326
327         AliCDBStorage* aStorage = GetStorage(param);
328
329         delete param;
330         return aStorage;
331 }
332
333 //_____________________________________________________________________________
334 AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) {
335 // get storage object from AliCDBParam object
336         
337         // if the list of active storages already contains
338         // the requested storage, return it
339         AliCDBStorage* aStorage = GetActiveStorage(param);
340         if (aStorage) {
341                 return aStorage;
342         }
343
344         // if lock is ON, cannot activate more storages!
345         if(fLock) {
346                 if (fDefaultStorage) {
347                         AliFatal("Lock is ON, and default storage is already set: "
348                                 "cannot reset it or activate more storages!");
349                 }
350         }       
351         
352         TIter iter(&fFactories);
353
354         AliCDBStorageFactory* factory=0;
355
356         // loop on the list of registered factories
357         while ((factory = (AliCDBStorageFactory*) iter.Next())) {
358
359                 // each factory tries to create its storage from the parameter
360                 aStorage = factory->Create(param);
361                 if (aStorage) {
362                         PutActiveStorage(param->CloneParam(), aStorage);
363                         aStorage->SetURI(param->GetURI());
364                         if(fRun >= 0) {
365                                 if(aStorage->GetType() == "alien"){
366                                         aStorage->QueryCDB(fRun);
367                                 } else {
368                                         AliDebug(2,
369                                                 "Skipping query for valid files, it is used only in grid...");
370                                 }
371                         }
372                         return aStorage;
373                 }
374         }
375
376         AliError(Form("Failed to activate requested storage! Check URI: %s", param->GetURI().Data()));
377
378         return NULL;
379 }
380
381 //_____________________________________________________________________________
382 AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) {
383 // get a storage object from the list of active storages
384
385         return dynamic_cast<AliCDBStorage*> (fActiveStorages.GetValue(param));
386 }
387
388 //_____________________________________________________________________________
389 TList* AliCDBManager::GetActiveStorages() {
390 // return list of active storages
391 // user has responsibility to delete returned object
392
393         TList* result = new TList();
394
395         TIter iter(fActiveStorages.GetTable());
396         TPair* aPair=0;
397         while ((aPair = (TPair*) iter.Next())) {
398                 result->Add(aPair->Value());
399         }
400
401         return result;
402 }
403
404 //_____________________________________________________________________________
405 void AliCDBManager::SetDrain(const char* dbString) {
406 // set drain storage from URI string
407
408         fDrainStorage = GetStorage(dbString);   
409 }
410
411 //_____________________________________________________________________________
412 void AliCDBManager::SetDrain(const AliCDBParam* param) {
413 // set drain storage from AliCDBParam
414
415         fDrainStorage = GetStorage(param);
416 }
417
418 //_____________________________________________________________________________
419 void AliCDBManager::SetDrain(AliCDBStorage* storage) {
420 // set drain storage from another active storage
421         
422         fDrainStorage = storage;
423 }
424
425 //_____________________________________________________________________________
426 Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
427 // drain retrieved object to drain storage
428
429         AliDebug(2, "Draining into drain storage...");
430         return fDrainStorage->Put(entry);
431 }
432
433 //____________________________________________________________________________
434 void AliCDBManager::SetDefaultStorage(const char* dbString) {
435 // sets default storage from URI string
436         
437         // checking whether we are in the raw case
438         TString dbStringTemp(dbString);
439         if (dbStringTemp == "raw://")
440         {
441                 fRaw = kTRUE;
442                 AliInfo("Setting the run-number will set the corresponding OCDB for raw data reconstruction.");
443                 AliInfo("Connecting to the grid...");
444                 if(!gGrid) {
445                         TGrid::Connect("alien://","");
446                         if(!gGrid) {
447                                 AliError("Connection to alien failed!");
448                                 return;
449                         }
450                 }
451                 return;
452         }
453
454         AliCDBStorage* bckStorage = fDefaultStorage;
455         
456         fDefaultStorage = GetStorage(dbString);
457         
458         if(!fDefaultStorage) return;
459         
460         if(bckStorage && (fDefaultStorage != bckStorage)){
461                 AliWarning("Existing default storage replaced: clearing cache!");
462                 ClearCache();
463         }
464         
465         if (fStorageMap->Contains("default")) {
466                 delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
467         }
468         fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
469 }
470 //_____________________________________________________________________________
471 void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
472 // set default storage from AliCDBParam object
473         
474         AliCDBStorage* bckStorage = fDefaultStorage;
475
476         fDefaultStorage = GetStorage(param);
477
478         if(!fDefaultStorage) return;
479
480         if(bckStorage && (fDefaultStorage != bckStorage)){
481                 AliWarning("Existing default storage replaced: clearing cache!");
482                 ClearCache();
483         }
484
485         if (fStorageMap->Contains("default")) {
486                 delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
487         }
488         fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
489 }
490
491 //_____________________________________________________________________________
492 void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
493 // set default storage from another active storage
494         
495         // if lock is ON, cannot activate more storages!
496         if(fLock) {
497                 if (fDefaultStorage) {
498                         AliFatal("Lock is ON, and default storage is already set: "
499                                 "cannot reset it or activate more storages!");
500                 }
501         }       
502         
503         if (!storage) {
504                 UnsetDefaultStorage();
505                 return;
506         }
507         
508         AliCDBStorage* bckStorage = fDefaultStorage;
509
510         fDefaultStorage = storage;
511
512         if(bckStorage && (fDefaultStorage != bckStorage)){
513                 AliWarning("Existing default storage replaced: clearing cache!");
514                 ClearCache();
515         }
516
517         if (fStorageMap->Contains("default")) {
518                 delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
519         }
520         fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
521 }
522
523 //_____________________________________________________________________________
524 void AliCDBManager::SetDefaultStorage(const char* mcString, const char* simType) {
525 // sets default storage for MC data
526 // mcString MUST be "MC", 
527 // simType can be "Ideal","Residual","Full"
528         
529         TString strmcString(mcString);
530         TString strsimType(simType);
531         TString dbString; 
532         if (strmcString != "MC"){
533                 AliFatal("Method requires first string to be MC!");
534         }
535         else {
536                 if (strsimType == "Ideal"){
537                         dbString = fgkMCIdealStorage;
538                 }
539                 else if (strsimType == "Full"){
540                         dbString = fgkMCFullStorage;
541                 }
542                 else if (strsimType == "Residual"){
543                         dbString = fgkMCResidualStorage;
544                 }
545                 else {
546                         AliFatal("Error in setting the storage for MC data, second argument MUST be either \"Ideal\" or \"Full\" or \"Residual\".");
547                 }
548
549                 SetDefaultStorage(dbString.Data());
550                 if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",fLHCPeriod.Data()));
551         }
552 }
553 //_____________________________________________________________________________
554 void AliCDBManager::SetDefaultStorageFromRun(Int_t run) {
555 // set default storage from the run number - to be used only with raw data      
556
557         // if lock is ON, cannot activate more storages!
558         if(fLock) {
559                 if (fDefaultStorage) {
560                         AliFatal("Lock is ON, and default storage is already set: "
561                                 "cannot activate default storage from run number");
562                 }
563         }       
564
565         // retrieve XML file from alien
566         if(!gGrid) {
567             TGrid::Connect("alien://","");
568             if(!gGrid) {
569                 AliError("Connection to alien failed!");
570                 return;
571             }
572         }
573         TUUID uuid;
574         TString rndname = "/tmp/";
575         rndname += "OCDBFolderXML.";
576         rndname += uuid.AsString();
577         rndname += ".xml";
578         AliDebug(2, Form("file to be copied = %s", fgkOCDBFolderXMLfile.Data()));
579         if (!TFile::Cp(fgkOCDBFolderXMLfile.Data(), rndname.Data())) {
580                 AliFatal(Form("Cannot make a local copy of OCDBFolder xml file in %s",rndname.Data()));
581         }
582         AliCDBHandler* saxcdb = new AliCDBHandler();
583         saxcdb->SetRun(run);
584         TSAXParser *saxParser = new TSAXParser();
585         saxParser->ConnectToHandler("AliCDBHandler", saxcdb);  
586         saxParser->ParseFile(rndname.Data()); 
587         AliInfo(Form(" LHC folder = %s", saxcdb->GetOCDBFolder().Data()));
588         AliInfo(Form(" LHC period start run = %d", saxcdb->GetStartRunRange()));
589         AliInfo(Form(" LHC period end run = %d", saxcdb->GetEndRunRange()));
590         fLHCPeriod = saxcdb->GetOCDBFolder();
591         fStartRunLHCPeriod = saxcdb->GetStartRunRange();
592         fEndRunLHCPeriod = saxcdb->GetEndRunRange();
593
594         SetDefaultStorage(fLHCPeriod.Data());
595         if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",fLHCPeriod.Data()));
596
597 }
598
599 //_____________________________________________________________________________
600 void AliCDBManager::UnsetDefaultStorage() {
601 // Unset default storage
602         
603         // if lock is ON, action is forbidden!
604         if(fLock) {
605                 if (fDefaultStorage) {
606                         AliFatal("Lock is ON: cannot unset default storage!");
607                 }
608         }
609         
610         if (fDefaultStorage) {
611                 AliWarning("Clearing cache!");
612                 ClearCache();
613         }
614
615         fRun = fStartRunLHCPeriod = fEndRunLHCPeriod = -1;
616         fRaw = kFALSE;
617         
618         fDefaultStorage = 0x0;
619 }
620
621 //_____________________________________________________________________________
622 void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) {
623 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
624
625         AliCDBParam *aPar = CreateParameter(dbString);
626         if(!aPar) return;
627         SetSpecificStorage(calibType, aPar);
628         delete aPar;
629 }
630
631 //_____________________________________________________________________________
632 void AliCDBManager::SetSpecificStorage(const char* calibType, const AliCDBParam* param) {
633 // sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
634 // Default storage should be defined prior to any specific storages, e.g.:
635 // AliCDBManager::instance()->SetDefaultStorage("alien://");
636 // AliCDBManager::instance()->SetSpecificStorage("TPC/*","local://DB_TPC");
637 // AliCDBManager::instance()->SetSpecificStorage("*/Align/*","local://DB_TPCAlign");
638 // calibType must be a valid CDB path! (3 level folder structure)
639
640
641         if(!fDefaultStorage && !fRaw) {
642                 AliError("Please activate a default storage first!");
643                 return;
644         }
645
646
647         AliCDBPath aPath(calibType);
648         if(!aPath.IsValid()){
649                 AliError(Form("Not a valid path: %s", calibType));
650                 return;
651         }
652
653         TObjString *objCalibType = new TObjString(aPath.GetPath());
654         if(fSpecificStorages.Contains(objCalibType)){
655                 AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one",
656                                         calibType));
657                 AliCDBParam *checkPar = dynamic_cast<AliCDBParam*> (fSpecificStorages.GetValue(calibType));
658                 if(checkPar) delete checkPar;
659                 delete fSpecificStorages.Remove(objCalibType);
660         }
661         AliCDBStorage *aStorage = GetStorage(param);
662         if(!aStorage) return;
663
664         fSpecificStorages.Add(objCalibType, param->CloneParam());
665
666         if(fStorageMap->Contains(objCalibType)){
667                 delete fStorageMap->Remove(objCalibType);
668         }
669         fStorageMap->Add(objCalibType->Clone(), new TObjString(param->GetURI()));
670
671 }
672
673 //_____________________________________________________________________________
674 AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) {
675 // get storage specific for detector or calibration type 
676
677         AliCDBPath calibPath(calibType);
678         if(!calibPath.IsValid()) return NULL;
679
680         AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibPath.GetPath());
681         if(!checkPar){
682                 AliError(Form("%s storage not found!", calibType));
683                 return NULL;
684         } else {
685                 return GetStorage(checkPar);
686         }
687
688 }
689
690 //_____________________________________________________________________________
691 AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) {
692 // select storage valid for path from the list of specific storages
693
694         AliCDBPath aPath(path);
695         if(!aPath.IsValid()) return NULL;
696
697         TIter iter(&fSpecificStorages);
698         TObjString *aCalibType=0;
699         AliCDBPath tmpPath("null/null/null");
700         AliCDBParam* aPar=0;
701         while((aCalibType = (TObjString*) iter.Next())){
702                 AliCDBPath calibTypePath(aCalibType->GetName());
703                 if(calibTypePath.Comprises(aPath)) {
704                         if(calibTypePath.Comprises(tmpPath)) continue;
705                         aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
706                         tmpPath.SetPath(calibTypePath.GetPath());
707                 }
708         }
709         return aPar;
710 }
711
712 //_____________________________________________________________________________
713 AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber,
714         Int_t version, Int_t subVersion) {
715 // get an AliCDBEntry object from the database
716
717         if(runNumber < 0){
718                 // RunNumber is not specified. Try with fRun
719                 if (fRun < 0){
720                         AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
721                         return NULL;
722                 }
723                 runNumber = fRun;
724         }
725
726         return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
727 }
728
729 //_____________________________________________________________________________
730 AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path,
731         const AliCDBRunRange& runRange, Int_t version,
732         Int_t subVersion) {
733 // get an AliCDBEntry object from the database!
734
735         return Get(AliCDBId(path, runRange, version, subVersion));
736 }
737
738 //_____________________________________________________________________________
739 AliCDBEntry* AliCDBManager::Get(const AliCDBId& query) {
740 // get an AliCDBEntry object from the database
741         
742         // check if query's path and runRange are valid
743         // query is invalid also if version is not specified and subversion is!
744         if (!query.IsValid()) {
745                 AliError(Form("Invalid query: %s", query.ToString().Data()));
746                 return NULL;
747         }
748         
749         // query is not specified if path contains wildcard or run range= [-1,-1]
750         if (!query.IsSpecified()) {
751                 AliError(Form("Unspecified query: %s",
752                                 query.ToString().Data()));
753                 return NULL;
754         }
755
756         if(fLock && !(fRun >= query.GetFirstRun() && fRun <= query.GetLastRun())) 
757                 AliFatal("Lock is ON: cannot use different run number than the internal one!");
758         
759         if(fCache && !(fRun >= query.GetFirstRun() && fRun <= query.GetLastRun())) 
760                 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
761
762         AliCDBEntry *entry=0;
763
764         // first look into map of cached objects
765         if(fCache && query.GetFirstRun() == fRun)
766                 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
767
768         if(entry) {
769                 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
770                 return entry;
771         }
772
773         if(!fDefaultStorage) {
774                 AliError("No storage set!");
775                 return NULL;
776         }
777         // Entry is not in cache -> retrieve it from CDB and cache it!!
778         AliCDBStorage *aStorage=0;
779         AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
780 //      Bool_t usedDefStorage=kTRUE;
781
782         if(aPar) {
783                 aStorage=GetStorage(aPar);
784                 TString str = aPar->GetURI();
785                 AliDebug(2,Form("Looking into storage: %s",str.Data()));
786 //              usedDefStorage=kFALSE;
787
788         } else {
789                 aStorage=GetDefaultStorage();
790                 AliDebug(2,"Looking into default storage");
791         }
792
793         entry = aStorage->Get(query);
794
795         if(entry && fCache && (query.GetFirstRun() == fRun)){
796                 CacheEntry(query.GetPath(), entry);
797         }
798
799         if(entry && !fIds->Contains(&entry->GetId())){
800                 fIds->Add(entry->GetId().Clone());
801         }
802
803
804         return entry;
805
806 }
807
808 //_____________________________________________________________________________
809 const char* AliCDBManager::GetURI(const char* path) {
810 // return the URI of the storage where to look for path
811
812         if(!IsDefaultStorageSet()) return 0;
813         
814         AliCDBParam *aPar=SelectSpecificStorage(path);
815
816         if(aPar) {
817                 return aPar->GetURI().Data();
818
819         } else {
820                 return GetDefaultStorage()->GetURI().Data();
821         }
822         
823         return 0;
824 }
825
826 //_____________________________________________________________________________
827 AliCDBId* AliCDBManager::GetId(const AliCDBPath& path, Int_t runNumber,
828         Int_t version, Int_t subVersion) {
829 // get the AliCDBId of the valid object from the database (does not retrieve the object)
830 // User must delete returned object!
831
832         if(runNumber < 0){
833                 // RunNumber is not specified. Try with fRun
834                 if (fRun < 0){
835                         AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
836                         return NULL;
837                 }
838                 runNumber = fRun;
839         }
840
841         return GetId(AliCDBId(path, runNumber, runNumber, version, subVersion));
842 }
843
844 //_____________________________________________________________________________
845 AliCDBId* AliCDBManager::GetId(const AliCDBPath& path,
846         const AliCDBRunRange& runRange, Int_t version,
847         Int_t subVersion) {
848 // get the AliCDBId of the valid object from the database (does not retrieve the object)
849 // User must delete returned object!
850
851         return GetId(AliCDBId(path, runRange, version, subVersion));
852 }
853
854 //_____________________________________________________________________________
855 AliCDBId* AliCDBManager::GetId(const AliCDBId& query) {
856 // get the AliCDBId of the valid object from the database (does not retrieve the object)
857 // User must delete returned object!
858
859         if(!fDefaultStorage) {
860                 AliError("No storage set!");
861                 return NULL;
862         }
863
864         // check if query's path and runRange are valid
865         // query is invalid also if version is not specified and subversion is!
866         if (!query.IsValid()) {
867                 AliError(Form("Invalid query: %s", query.ToString().Data()));
868                 return NULL;
869         }
870         
871         // query is not specified if path contains wildcard or run range= [-1,-1]
872         if (!query.IsSpecified()) {
873                 AliError(Form("Unspecified query: %s",
874                                 query.ToString().Data()));
875                 return NULL;
876         }
877
878         if(fCache && query.GetFirstRun() != fRun)
879                 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
880
881         AliCDBEntry* entry = 0;
882
883         // first look into map of cached objects
884         if(fCache && query.GetFirstRun() == fRun)
885                 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
886
887         if(entry) {
888                 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
889                 return dynamic_cast<AliCDBId*> (entry->GetId().Clone());
890         }
891
892         // Entry is not in cache -> retrieve it from CDB and cache it!!
893         AliCDBStorage *aStorage=0;
894         AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
895
896         if(aPar) {
897                 aStorage=GetStorage(aPar);
898                 TString str = aPar->GetURI();
899                 AliDebug(2,Form("Looking into storage: %s",str.Data()));
900                 
901         } else {
902                 aStorage=GetDefaultStorage();
903                 AliDebug(2,"Looking into default storage");
904         }
905
906         return aStorage->GetId(query);
907
908 }
909
910 //_____________________________________________________________________________
911 TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber,
912         Int_t version, Int_t subVersion) {
913 // get multiple AliCDBEntry objects from the database
914
915         if(runNumber < 0){
916                 // RunNumber is not specified. Try with fRun
917                 if (fRun < 0){
918                         AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
919                         return NULL;
920                 }
921                 runNumber = fRun;
922         }
923
924         return GetAll(AliCDBId(path, runNumber, runNumber, version,     
925                         subVersion));
926 }
927
928 //_____________________________________________________________________________
929 TList* AliCDBManager::GetAll(const AliCDBPath& path,
930         const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
931 // get multiple AliCDBEntry objects from the database
932
933         return GetAll(AliCDBId(path, runRange, version, subVersion));
934 }
935
936 //_____________________________________________________________________________
937 TList* AliCDBManager::GetAll(const AliCDBId& query) {
938 // get multiple AliCDBEntry objects from the database
939 // Warning: this method works correctly only for queries of the type "Detector/*"
940 //              and not for more specific queries e.g. "Detector/Calib/*" !
941 // Warning #2: Entries are cached, but GetAll will keep on retrieving objects from OCDB!
942 //              To get an object from cache use Get() function
943
944         if(!fDefaultStorage) {
945                 AliError("No storage set!");
946                 return NULL;
947         }
948
949         if (!query.IsValid()) {
950                 AliError(Form("Invalid query: %s", query.ToString().Data()));
951                 return NULL;
952         }
953
954         if((fSpecificStorages.GetEntries()>0) && query.GetPath().BeginsWith('*')){
955                 // if specific storages are active a query with "*" is ambiguous
956                 AliError("Query too generic in this context!");
957                 return NULL;
958         }
959
960         if (query.IsAnyRange()) {
961                 AliError(Form("Unspecified run or runrange: %s",
962                                 query.ToString().Data()));
963                 return NULL;
964         }
965
966         if(fLock && query.GetFirstRun() != fRun)
967                 AliFatal("Lock is ON: cannot use different run number than the internal one!");
968         
969         AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
970
971         AliCDBStorage *aStorage;
972         if(aPar) {
973                 aStorage=GetStorage(aPar);
974                 AliDebug(2,Form("Looking into storage: %s", aPar->GetURI().Data()));
975
976         } else {
977                 aStorage=GetDefaultStorage();
978                 AliDebug(2,"Looking into default storage");
979         }
980
981         TList *result = 0;
982         if(aStorage) result = aStorage->GetAll(query);
983         if(!result) return 0;
984
985        // loop on result to check whether entries should be re-queried with specific storages
986         if(fSpecificStorages.GetEntries()>0 && ! (fSpecificStorages.GetEntries() == 1 && aPar)) {
987                 AliInfo("Now look into all other specific storages...");
988
989                 TIter iter(result);
990                 AliCDBEntry* chkEntry=0;
991
992                 while((chkEntry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
993                         AliCDBId& chkId = chkEntry->GetId();
994                         AliDebug(2, Form("Checking id %s ", chkId.GetPath().Data()));
995                         AliCDBParam *chkPar=SelectSpecificStorage(chkId.GetPath());
996                         if (!chkPar || aPar == chkPar) continue;
997                         AliCDBStorage *chkStorage = GetStorage(chkPar);
998                         AliDebug(2, Form("Found specific storage! %s", chkPar->GetURI().Data()));
999
1000                         AliCDBEntry *newEntry=0;
1001                         chkId.SetRunRange(query.GetFirstRun(), query.GetLastRun());
1002                         chkId.SetVersion(query.GetVersion());
1003                         chkId.SetSubVersion(query.GetSubVersion());
1004
1005                         if(chkStorage) newEntry = chkStorage->Get(chkId);
1006                         if(!newEntry) continue;
1007
1008                         // object is found in specific storage: replace entry in the result list!
1009                         chkEntry->SetOwner(1);
1010                         delete result->Remove(chkEntry);
1011                         result->AddFirst(newEntry);
1012                 }
1013
1014                 Int_t nEntries = result->GetEntries();
1015                 AliInfo("After look into other specific storages, result list is:");
1016                 for(int i=0; i<nEntries;i++){
1017                         AliCDBEntry *entry = (AliCDBEntry*) result->At(i);
1018                         AliInfo(Form("%s",entry->GetId().ToString().Data()));
1019                 }
1020         }
1021
1022         // caching entries
1023         TIter iter(result);
1024         AliCDBEntry* entry=0;
1025         while((entry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
1026
1027                 if(!fIds->Contains(&entry->GetId())){
1028                         fIds->Add(entry->GetId().Clone());
1029                 }
1030                 if(fCache && (query.GetFirstRun() == fRun)){
1031                         CacheEntry(entry->GetId().GetPath(), entry);
1032                 }
1033         }
1034
1035
1036         return result;
1037 }
1038
1039 //_____________________________________________________________________________
1040 Bool_t AliCDBManager::Put(TObject* object, const AliCDBId& id, AliCDBMetaData* metaData, const DataType type){
1041 // store an AliCDBEntry object into the database
1042
1043         if (object==0x0) {
1044                 AliError("Null Entry! No storage will be done!");
1045                 return kFALSE;
1046         } 
1047
1048         AliCDBEntry anEntry(object, id, metaData);
1049         return Put(&anEntry, type);
1050
1051 }
1052
1053
1054 //_____________________________________________________________________________
1055 Bool_t AliCDBManager::Put(AliCDBEntry* entry, DataType type){
1056 // store an AliCDBEntry object into the database
1057
1058         if(type == kPrivate && !fDefaultStorage) {
1059                 AliError("No storage set!");
1060                 return kFALSE;
1061         }
1062
1063         if (!entry){
1064                 AliError("No entry!");
1065                 return kFALSE;
1066         }
1067
1068         if (entry->GetObject()==0x0){
1069                 AliError("No valid object in CDB entry!");
1070                 return kFALSE;
1071         }
1072
1073         if (!entry->GetId().IsValid()) {
1074                 AliError(Form("Invalid entry ID: %s", 
1075                         entry->GetId().ToString().Data()));
1076                 return kFALSE;
1077         }       
1078
1079         if (!entry->GetId().IsSpecified()) {
1080                 AliError(Form("Unspecified entry ID: %s", 
1081                         entry->GetId().ToString().Data()));
1082                 return kFALSE;
1083         }
1084
1085         AliCDBId id = entry->GetId();
1086         AliCDBParam *aPar = SelectSpecificStorage(id.GetPath());
1087
1088         AliCDBStorage *aStorage=0;
1089         
1090         if(aPar) {
1091                 aStorage=GetStorage(aPar);
1092         } else {
1093                 switch(type){
1094                         case kCondition:
1095                                 aStorage = GetStorage(fCondParam);
1096                                 break;
1097                         case kReference:
1098                                 aStorage = GetStorage(fRefParam);
1099                                 break;
1100                         case kPrivate:
1101                                 aStorage = GetDefaultStorage();
1102                                 break;
1103                 }
1104         }
1105
1106         AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data()));
1107
1108         Bool_t result = aStorage->Put(entry, type);
1109
1110         if(fRun >= 0) QueryCDB();
1111
1112         return result;
1113
1114
1115 }
1116
1117 //_____________________________________________________________________________
1118 void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry)
1119 {
1120 // cache AliCDBEntry. Cache is valid until run number is changed.
1121
1122         AliCDBEntry *chkEntry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(path));
1123
1124         if(chkEntry) {
1125                 AliDebug(2, Form("Object %s already in cache !!", path));
1126                 return;
1127         } else {
1128                 AliDebug(2,Form("Caching entry %s", path));
1129         }
1130
1131         fEntryCache.Add(new TObjString(path), entry);
1132         AliDebug(2,Form("Cache entries: %d", fEntryCache.GetEntries()));
1133
1134 }
1135
1136 //_____________________________________________________________________________
1137 void AliCDBManager::Print(Option_t* /*option*/) const
1138 {
1139 // Print list of active storages and their URIs
1140
1141         TString output=Form("Run number = %d; ",fRun);
1142         output += "Cache is ";
1143         if(!fCache) output += "NOT ";
1144         output += Form("ACTIVE; Number of active storages: %d\n",fActiveStorages.GetEntries());
1145
1146         if(fDefaultStorage) {
1147                 output += Form("\t*** Default Storage URI: \"%s\"\n",fDefaultStorage->GetURI().Data());
1148 //              AliInfo(output.Data());
1149         }
1150         if(fSpecificStorages.GetEntries()>0) {
1151                 TIter iter(fSpecificStorages.GetTable());
1152                 TPair *aPair=0;
1153                 Int_t i=1;
1154                 while((aPair = (TPair*) iter.Next())){
1155                         output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n",
1156                                 i++, ((TObjString*) aPair->Key())->GetName(),
1157                                 ((AliCDBParam*) aPair->Value())->GetURI().Data());
1158                 }
1159         }
1160         if(fDrainStorage) {
1161                 output += Form("*** Drain Storage URI: %s\n",fDrainStorage->GetURI().Data());
1162         }
1163         AliInfo(output.Data());
1164 }
1165
1166 //_____________________________________________________________________________
1167 void AliCDBManager::SetRun(Int_t run)
1168 {
1169 // Sets current run number.
1170 // When the run number changes the caching is cleared.
1171         
1172         if(fRun == run)
1173                 return;
1174   
1175         if(fLock && fRun >= 0) {
1176                 AliFatal("Lock is ON, cannot reset run number!");
1177         }       
1178                 
1179         fRun = run;
1180         if(fRaw){
1181                 // here the LHCPeriod xml file is parsed; the string containing the correct period is returned; the default storage is set
1182                 if (fStartRunLHCPeriod <= run && fEndRunLHCPeriod >= run){
1183                         AliInfo("LHCPeriod alien folder for current run already in memory");
1184                 }else{
1185                         SetDefaultStorageFromRun(run);
1186                         if(fEntryCache.GetEntries()!=0) ClearCache();
1187                         return;
1188                 }
1189         }
1190         ClearCache();
1191         QueryCDB();
1192 }
1193
1194 //_____________________________________________________________________________
1195 void AliCDBManager::ClearCache(){
1196 // clear AliCDBEntry cache
1197
1198         AliDebug(2, Form("Cache entries to be deleted: %d",fEntryCache.GetEntries()));
1199         
1200         /*
1201         // To clean entries one by one
1202         TIter iter(fEntryCache.GetTable());
1203         TPair* pair=0;
1204         while((pair= dynamic_cast<TPair*> (iter.Next()))){
1205         
1206                 TObjString* key = dynamic_cast<TObjString*> (pair->Key());
1207                 AliCDBEntry* entry = dynamic_cast<AliCDBEntry*> (pair->Value());
1208                 AliDebug(2, Form("Deleting entry: %s", key->GetName()));
1209                 if (entry) delete entry;
1210                 delete fEntryCache.Remove(key);
1211         }
1212         */
1213         fEntryCache.DeleteAll();
1214         AliDebug(2, Form("After deleting - Cache entries: %d",fEntryCache.GetEntries()));
1215 }
1216
1217 //_____________________________________________________________________________
1218 void AliCDBManager::UnloadFromCache(const char* path){
1219 // unload cached object
1220
1221         if(!fActiveStorages.GetEntries()) {
1222                 AliDebug(2, Form("No active storages. Object \"%s\" is not unloaded from cache", path));
1223                 return;
1224         }
1225
1226         AliCDBPath queryPath(path);
1227         if(!queryPath.IsValid()) return;
1228
1229         if(!queryPath.IsWildcard()) { // path is not wildcard, get it directly from the cache and unload it!
1230                 if(fEntryCache.Contains(path)){
1231                         AliDebug(2, Form("Unloading object \"%s\" from cache", path));
1232                         TObjString pathStr(path);
1233                         delete fEntryCache.Remove(&pathStr);
1234                 } else {
1235                   AliErrorF("Cache does not contain object \"%s\"!", path);
1236                 }
1237                 AliDebugF(2, "Cache entries: %d",fEntryCache.GetEntries());
1238                 return;
1239         }
1240
1241         // path is wildcard: loop on the cache and unload all comprised objects!
1242         TIter iter(fEntryCache.GetTable());
1243         TPair* pair = 0;
1244
1245         while((pair = dynamic_cast<TPair*> (iter.Next()))){
1246                 AliCDBPath entryPath = pair->Key()->GetName();
1247                 if(queryPath.Comprises(entryPath)) {
1248                         AliDebug(2, Form("Unloading object \"%s\" from cache", entryPath.GetPath().Data()));
1249                         TObjString pathStr(entryPath.GetPath().Data());
1250                         delete fEntryCache.Remove(&pathStr);
1251                 }
1252         }
1253         AliDebug(2,Form("Cache entries: %d",fEntryCache.GetEntries()));
1254 }
1255
1256 //_____________________________________________________________________________
1257 void AliCDBManager::DestroyActiveStorages() {
1258 // delete list of active storages
1259
1260         fActiveStorages.DeleteAll();
1261         fSpecificStorages.DeleteAll();
1262 }
1263
1264 //_____________________________________________________________________________
1265 void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
1266 // destroys active storage
1267
1268 /*
1269         TIter iter(fActiveStorages.GetTable());
1270         TPair* aPair;
1271         while ((aPair = (TPair*) iter.Next())) {
1272                 if(storage == (AliCDBStorage*) aPair->Value())
1273                         delete fActiveStorages.Remove(aPair->Key());
1274                         storage->Delete(); storage=0x0;
1275         }
1276 */
1277
1278 }
1279
1280 //_____________________________________________________________________________
1281 void AliCDBManager::QueryCDB() {
1282 // query default and specific storages for files valid for fRun. Every storage loads the Ids into its list.
1283
1284         if (fRun < 0){
1285                 AliError("Run number not yet set! Use AliCDBManager::SetRun.");
1286         return;
1287         }
1288         if (!fDefaultStorage){
1289                 AliError("Default storage is not set! Use AliCDBManager::SetDefaultStorage");
1290         return;
1291         }
1292         if(fDefaultStorage->GetType() == "alien"){
1293                 fDefaultStorage->QueryCDB(fRun);
1294         } else {
1295                 AliDebug(2,"Skipping query for valid files, it used only in grid...");
1296         }
1297
1298         TIter iter(&fSpecificStorages);
1299         TObjString *aCalibType=0;
1300         AliCDBParam* aPar=0;
1301         while((aCalibType = dynamic_cast<TObjString*> (iter.Next()))){
1302                 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
1303                 if(aPar) {
1304                         AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName()));
1305                         AliCDBStorage *aStorage = GetStorage(aPar);
1306                         if(aStorage->GetType() == "alien"){
1307                                 aStorage->QueryCDB(fRun,aCalibType->GetName());
1308                         } else {
1309                                 AliDebug(2,
1310                                         "Skipping query for valid files, it is used only in grid...");
1311                         }
1312                 }
1313         }
1314 }
1315
1316 //______________________________________________________________________________________________
1317 const char* AliCDBManager::GetDataTypeName(DataType type)
1318 {
1319   // returns the name (string) of the data type
1320
1321       switch (type){
1322             case kCondition: return "Conditions";
1323             case kReference: return "Reference";
1324             case kPrivate: return "Private";
1325      }
1326      return 0;
1327
1328 }
1329
1330 //______________________________________________________________________________________________
1331 void AliCDBManager::InitShortLived()
1332 {
1333   // Init the list of short-lived objects
1334   // currently disabled
1335
1336         fShortLived=0x0;
1337
1338 //      fShortLived = new TList();
1339 //      fShortLived->SetOwner(1);
1340 //
1341 //      fShortLived->Add(new TObjString("EMCAL/Calib/Data"));
1342 // 
1343 //      fShortLived->Add(new TObjString("HMPID/Calib/Nmean"));
1344 //      fShortLived->Add(new TObjString("HMPID/Calib/Qthre"));
1345 // 
1346 //      fShortLived->Add(new TObjString("ITS/Calib/CalibSPD"));
1347 // 
1348 //      fShortLived->Add(new TObjString("MUON/Calib/Gains"));
1349 //      fShortLived->Add(new TObjString("MUON/Calib/HV"));
1350 //      fShortLived->Add(new TObjString("MUON/Calib/Pedestals"));
1351 // 
1352 //      fShortLived->Add(new TObjString("PHOS/Calib/CpvGainPedestals"));
1353 //      fShortLived->Add(new TObjString("PHOS/Calib/EmcGainPedestals"));
1354 // 
1355 //      fShortLived->Add(new TObjString("PMD/Calib/Data"));
1356 // 
1357 //      fShortLived->Add(new TObjString("TRD/Calib/ChamberGainFactor"));
1358 //      fShortLived->Add(new TObjString("TRD/Calib/LocalGainFactor"));
1359 //      fShortLived->Add(new TObjString("TRD/Calib/ChamberT0"));
1360 //      fShortLived->Add(new TObjString("TRD/Calib/LocalT0"));
1361 //      fShortLived->Add(new TObjString("TRD/Calib/ChamberVdrift"));
1362 //      fShortLived->Add(new TObjString("TRD/Calib/LocalVdrift"));
1363 // 
1364 //      fShortLived->Add(new TObjString("ZDC/Calib/Data"));
1365
1366 }
1367
1368 //______________________________________________________________________________________________
1369 Bool_t AliCDBManager::IsShortLived(const char* path)
1370 {
1371   // returns the name (string) of the data type
1372
1373         if(!fShortLived) return kFALSE;
1374
1375         AliCDBPath aPath(path);
1376         if(!aPath.IsValid()){
1377                 AliError(Form("Not a valid path: %s", path));
1378                 return kFALSE;
1379         }
1380
1381         return fShortLived->Contains(path);
1382
1383 }
1384
1385 //______________________________________________________________________________________________
1386 ULong_t AliCDBManager::SetLock(Bool_t lock, ULong_t key){
1387   // To lock/unlock user must provide the key. A new key is provided after
1388   // each successful lock. User should always backup the returned key and
1389   // use it on next access.
1390   if (fLock == lock) return 0;  // nothing to be done
1391   if (lock) {
1392     // User wants to lock - check his identity
1393     if (fKey) {
1394       // Lock has a user - check his key
1395       if (fKey != key) {
1396         AliFatal("Wrong key provided to lock CDB. Please remove CDB lock access from your code !");
1397         return 0;
1398       }  
1399     }  
1400     // Provide new key 
1401     fKey = gSystem->Now();
1402     fLock = kTRUE;
1403     return fKey;
1404   }
1405   // User wants to unlock - check the provided key
1406   if (key != fKey) {
1407     AliFatal("Lock is ON: wrong key provided");
1408     return 0;
1409   }  
1410   fLock = kFALSE;
1411   return key;  
1412 }
1413
1414 ///////////////////////////////////////////////////////////
1415 // AliCDBManager Parameter class                         //
1416 // interface to specific AliCDBParameter class           //
1417 // (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam)  //
1418 ///////////////////////////////////////////////////////////
1419
1420 AliCDBParam::AliCDBParam():
1421   fType(),
1422   fURI()
1423 {
1424 // constructor
1425
1426 }
1427
1428 //_____________________________________________________________________________
1429 AliCDBParam::~AliCDBParam() {
1430 // destructor
1431
1432 }
1433