]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/CDB/AliCDBManager.cxx
Add method for creating a light snapshot.
[u/mrichter/AliRoot.git] / STEER / CDB / AliCDBManager.cxx
CommitLineData
9e1ceb13 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
fdf65bb5 15//-------------------------------------------------------------------------
16// Implementation of AliCDBManager and AliCDBParam classe
5078a13f 17// Author: Alberto Colla
fdf65bb5 18// e-mail: Alberto.Colla@cern.ch
19//-------------------------------------------------------------------------
9e1ceb13 20
5078a13f 21#include <fstream>
c11cdcf2 22
9e1ceb13 23#include "AliCDBManager.h"
24#include "AliCDBStorage.h"
25#include "AliLog.h"
26#include "AliCDBDump.h"
27#include "AliCDBLocal.h"
28#include "AliCDBGrid.h"
02c4845e 29#include "AliCDBEntry.h"
7de84b33 30#include "AliCDBHandler.h"
9e1ceb13 31
02c4845e 32#include <TObjString.h>
7de84b33 33#include <TSAXParser.h>
34#include <TFile.h>
647d2bb8 35#include <TKey.h>
7de84b33 36#include <TUUID.h>
27cac7e3 37#include <TGrid.h>
a37a1dfc 38#include "TMessage.h"
39#include "TObject.h"
5078a13f 40#include "TRegexp.h"
9e1ceb13 41
42ClassImp(AliCDBParam)
43
44ClassImp(AliCDBManager)
45
b8ec52f6 46//TODO OCDB and Reference folder should not be fully hardcoded but built from run number (or year/LHC period)
47TString AliCDBManager::fgkCondUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/CDB?user=aliprod");
48TString AliCDBManager::fgkRefUri("alien://folder=/alice/cern.ch/user/a/aliprod/testCDB/Reference?user=aliprod");
7de84b33 49TString AliCDBManager::fgkMCIdealStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Ideal");
50TString AliCDBManager::fgkMCFullStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Full");
51TString AliCDBManager::fgkMCResidualStorage("alien://folder=/alice/simulation/2008/v4-15-Release/Residual");
52TString AliCDBManager::fgkOCDBFolderXMLfile("alien:///alice/data/OCDBFoldervsRunRange.xml");
9e1ceb13 53AliCDBManager* AliCDBManager::fgInstance = 0x0;
54
55//_____________________________________________________________________________
5078a13f 56AliCDBManager* AliCDBManager::Instance(TMap *entryCache, Int_t run) {
9e1ceb13 57// returns AliCDBManager instance (singleton)
58
5078a13f 59 if (!fgInstance) {
60 fgInstance = new AliCDBManager();
61 if (!entryCache)
62 fgInstance->Init();
63 else
64 fgInstance->InitFromCache(entryCache,run);
65 }
9e1ceb13 66
5078a13f 67 return fgInstance;
9e1ceb13 68}
69
70//_____________________________________________________________________________
71void AliCDBManager::Init() {
72// factory registering
73
5078a13f 74 RegisterFactory(new AliCDBDumpFactory());
75 RegisterFactory(new AliCDBLocalFactory());
76 // AliCDBGridFactory is registered only if AliEn libraries are enabled in Root
77 if(!gSystem->Exec("root-config --has-alien 2>/dev/null |grep yes 2>&1 > /dev/null")){ // returns 0 if yes
78 AliInfo("AliEn classes enabled in Root. AliCDBGrid factory registered.");
79 RegisterFactory(new AliCDBGridFactory());
80 fCondParam = CreateParameter(fgkCondUri);
81 fRefParam = CreateParameter(fgkRefUri);
82 }
4667c116 83
5078a13f 84 InitShortLived();
9e1ceb13 85}
d1982b43 86
87//_____________________________________________________________________________
88void AliCDBManager::InitFromCache(TMap *entryCache, Int_t run) {
89// initialize manager from existing cache
90// used on the slaves in case of parallel reconstruction
91 SetRun(run);
92
93 TIter iter(entryCache->GetTable());
94 TPair* pair = 0;
95
96 while((pair = dynamic_cast<TPair*> (iter.Next()))){
97 fEntryCache.Add(pair->Key(),pair->Value());
98 }
99 // fEntry is the new owner of the cache
100 fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
77d2efce 101 entryCache->SetOwnerKeyValue(kFALSE,kFALSE);
d1982b43 102 AliInfo(Form("%d cache entries have been loaded",fEntryCache.GetEntries()));
103}
104
7ec0d3df 105//_____________________________________________________________________________
18d58637 106void AliCDBManager::DumpToSnapshotFile(const char* snapshotFileName, Bool_t singleKeys) const {
5078a13f 107//
e973a743 108// If singleKeys is true, dump the entries map and the ids list to the snapshot file
109// (provided mostly for historical reasons, the file is then read with InitFromSnapshot),
110// otherwise write to file each AliCDBEntry separately (the is the preferred way, the file
111// is then read with SetSnapshotMode).
7ec0d3df 112
5078a13f 113 // open the file
114 TFile *f = TFile::Open(snapshotFileName,"RECREATE");
115 if (!f || f->IsZombie()){
116 AliError(Form("Cannot open file %s",snapshotFileName));
117 return;
118 }
7ec0d3df 119
5078a13f 120 AliInfo(Form("Dumping entriesMap (entries'cache) with %d entries!\n", fEntryCache.GetEntries()));
121 AliInfo(Form("Dumping entriesList with %d entries!\n", fIds->GetEntries()));
122
123 f->cd();
e973a743 124 if(singleKeys){
18d58637 125 f->WriteObject(&fEntryCache,"CDBentriesMap");
126 f->WriteObject(fIds,"CDBidsList");
e973a743 127 }else{
5078a13f 128 // We write the entries one by one named by their calibration path
5078a13f 129 TIter iter(fEntryCache.GetTable());
130 TPair* pair = 0;
131 while((pair = dynamic_cast<TPair*> (iter.Next()))){
132 TObjString *os = dynamic_cast<TObjString*>(pair->Key());
133 if (!os) continue;
134 TString path = os->GetString();
135 AliCDBEntry *entry = dynamic_cast<AliCDBEntry*>(pair->Value());
136 if (!entry) continue;
137 path.ReplaceAll("/","*");
138 entry->Write(path.Data());
c022b397 139 }
5078a13f 140 }
141 f->Close();
142 delete f;
7ec0d3df 143}
144
18d58637 145//_____________________________________________________________________________
146void AliCDBManager::DumpToLightSnapshotFile(const char* lightSnapshotFileName) const {
147// The light snapshot does not contain the CDB objects (AliCDBEntries) but
148// only the information identifying them, that is the map of storages and
149// the list of AliCDBIds, as in the UserInfo of AliESDs.root
150
151 // open the file
152 TFile *f = TFile::Open(lightSnapshotFileName,"RECREATE");
153 if (!f || f->IsZombie()){
154 AliError(Form("Cannot open file %s",lightSnapshotFileName));
155 return;
156 }
157
158 AliInfo(Form("Dumping map of storages with %d entries!\n", fStorageMap->GetEntries()));
159 AliInfo(Form("Dumping entriesList with %d entries!\n", fIds->GetEntries()));
160 f->WriteObject(fStorageMap,"cdbStoragesMap");
161 f->WriteObject(fIds,"CDBidsList");
162
163 f->Close();
164 delete f;
165}
166
647d2bb8 167//_____________________________________________________________________________
b0e8cda6 168Bool_t AliCDBManager::InitFromSnapshot(const char* snapshotFileName, Bool_t overwrite){
647d2bb8 169// initialize manager from a CDB snapshot, that is add the entries
170// to the entries map and the ids to the ids list taking them from
171// the map and the list found in the input file
172
5078a13f 173 // if the manager is locked it cannot initialize from a snapshot
174 if(fLock) {
175 AliError("Being locked I cannot initialize from the snapshot!");
176 return kFALSE;
177 }
178
179 // open the file
180 TString snapshotFile(snapshotFileName);
181 if(snapshotFile.BeginsWith("alien://")){
182 if(!gGrid) {
183 TGrid::Connect("alien://","");
184 if(!gGrid) {
185 AliError("Connection to alien failed!");
186 return kFALSE;
187 }
647d2bb8 188 }
5078a13f 189 }
647d2bb8 190
5078a13f 191 TFile *f = TFile::Open(snapshotFileName);
192 if (!f || f->IsZombie()){
193 AliError(Form("Cannot open file %s",snapshotFileName));
194 return kFALSE;
195 }
647d2bb8 196
5078a13f 197 // retrieve entries' map from snapshot file
198 TMap *entriesMap = 0;
199 TIter next(f->GetListOfKeys());
200 TKey *key;
201 while ((key = (TKey*)next())) {
202 if (strcmp(key->GetClassName(),"TMap") != 0) continue;
203 entriesMap = (TMap*)key->ReadObj();
204 break;
205 }
206 if (!entriesMap || entriesMap->GetEntries()==0){
207 AliError("Cannot get valid map of CDB entries from snapshot file");
208 return kFALSE;
209 }
210
211 // retrieve ids' list from snapshot file
212 TList *idsList = 0;
213 TIter nextKey(f->GetListOfKeys());
214 TKey *keyN;
215 while ((keyN = (TKey*)nextKey())) {
216 if (strcmp(keyN->GetClassName(),"TList") != 0) continue;
217 idsList = (TList*)keyN->ReadObj();
218 break;
219 }
220 if (!idsList || idsList->GetEntries()==0){
221 AliError("Cannot get valid list of CDB entries from snapshot file");
222 return kFALSE;
223 }
647d2bb8 224
5078a13f 225 // Add each (entry,id) from the snapshot to the memory: entry to the cache, id to the list of ids.
226 // If "overwrite" is false: add the entry to the cache and its id to the list of ids
227 // only if neither of them is already there.
228 // If "overwrite" is true: write the snapshot entry,id in any case. If something
229 // was already there for that calibration type, remove it and issue a warning
230 TIter iterObj(entriesMap->GetTable());
231 TPair* pair = 0;
232 Int_t nAdded=0;
233 while((pair = dynamic_cast<TPair*> (iterObj.Next()))){
234 TObjString* os = (TObjString*) pair->Key();
235 TString path = os->GetString();
236 TIter iterId(idsList);
237 AliCDBId* id=0;
238 AliCDBId* correspondingId=0;
239 while((id = dynamic_cast<AliCDBId*> (iterId.Next()))){
240 TString idpath(id->GetPath());
241 if(idpath==path){
242 correspondingId=id;
243 break;
244 }
647d2bb8 245 }
5078a13f 246 if(!correspondingId){
247 AliError(Form("id for \"%s\" not found in the snapshot (while entry was). This entry is skipped!",path.Data()));
248 break;
249 }
250 Bool_t cached = fEntryCache.Contains(path.Data());
251 Bool_t registeredId = kFALSE;
252 TIter iter(fIds);
253 AliCDBId *idT = 0;
254 while((idT = dynamic_cast<AliCDBId*> (iter.Next()))){
255 if(idT->GetPath()==path){
256 registeredId = kTRUE;
257 break;
258 }
647d2bb8 259 }
260
5078a13f 261 if(overwrite){
262 if(cached || registeredId){
263 AliWarning(Form("An entry was already cached for \"%s\". Removing it before caching from snapshot",path.Data()));
264 UnloadFromCache(path.Data());
265 }
266 fEntryCache.Add(pair->Key(),pair->Value());
267 fIds->Add(id);
268 nAdded++;
269 }else{
270 if(cached || registeredId){
271 AliWarning(Form("An entry was already cached for \"%s\". Not adding this object from snapshot",path.Data()));
272 }else{
273 fEntryCache.Add(pair->Key(),pair->Value());
274 fIds->Add(id);
275 nAdded++;
276 }
647d2bb8 277 }
5078a13f 278 }
b0e8cda6 279
5078a13f 280 // fEntry is the new owner of the cache
281 fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
282 entriesMap->SetOwnerKeyValue(kFALSE,kFALSE);
283 fIds->SetOwner(kTRUE);
284 idsList->SetOwner(kFALSE);
285 AliInfo(Form("%d new (entry,id) cached. Total number %d",nAdded,fEntryCache.GetEntries()));
b0e8cda6 286
5078a13f 287 f->Close();
288 delete f;
647d2bb8 289
5078a13f 290 return kTRUE;
647d2bb8 291}
292
9e1ceb13 293//_____________________________________________________________________________
294void AliCDBManager::Destroy() {
295// delete ALCDBManager instance and active storages
296
5078a13f 297 if (fgInstance) {
298 //fgInstance->Delete();
299 delete fgInstance;
300 fgInstance = 0x0;
301 }
9e1ceb13 302}
303
304//_____________________________________________________________________________
305AliCDBManager::AliCDBManager():
fe12e09c 306 TObject(),
307 fFactories(),
308 fActiveStorages(),
309 fSpecificStorages(),
b21e3194 310 fEntryCache(),
311 fIds(0),
312 fStorageMap(0),
313 fShortLived(0),
fe12e09c 314 fDefaultStorage(NULL),
315 fDrainStorage(NULL),
b21e3194 316 fCondParam(0),
317 fRefParam(0),
4667c116 318 fRun(-1),
1f341624 319 fCache(kTRUE),
7de84b33 320 fLock(kFALSE),
c022b397 321 fSnapshotMode(kFALSE),
322 fSnapshotFile(0),
7de84b33 323 fRaw(kFALSE),
5078a13f 324 fCvmfsOcdb(""),
7de84b33 325 fStartRunLHCPeriod(-1),
326 fEndRunLHCPeriod(-1),
a6f59240 327 fLHCPeriod(""),
328 fKey(0)
9e1ceb13 329{
5078a13f 330 // default constuctor
331 fFactories.SetOwner(1);
332 fActiveStorages.SetOwner(1);
333 fSpecificStorages.SetOwner(1);
334 fEntryCache.SetName("CDBEntryCache");
335 fEntryCache.SetOwnerKeyValue(kTRUE,kTRUE);
b21e3194 336
5078a13f 337 fStorageMap = new TMap();
338 fStorageMap->SetOwner(1);
339 fIds = new TList();
340 fIds->SetOwner(1);
9e1ceb13 341}
342
343//_____________________________________________________________________________
344AliCDBManager::~AliCDBManager() {
345// destructor
5078a13f 346 ClearCache();
347 DestroyActiveStorages();
348 fFactories.Delete();
349 fDrainStorage = 0x0;
350 fDefaultStorage = 0x0;
351 delete fStorageMap; fStorageMap = 0;
352 delete fIds; fIds = 0;
353 delete fCondParam;
354 delete fRefParam;
355 delete fShortLived; fShortLived = 0x0;
356 //fSnapshotCache = 0;
357 //fSnapshotIdsList = 0;
358 if(fSnapshotMode){
359 fSnapshotFile->Close();
360 fSnapshotFile = 0;
361 }
9e1ceb13 362}
363
9e1ceb13 364//_____________________________________________________________________________
365void AliCDBManager::PutActiveStorage(AliCDBParam* param, AliCDBStorage* storage){
366// put a storage object into the list of active storages
367
5078a13f 368 fActiveStorages.Add(param, storage);
369 AliDebug(1, Form("Active storages: %d", fActiveStorages.GetEntries()));
9e1ceb13 370}
371
372//_____________________________________________________________________________
373void AliCDBManager::RegisterFactory(AliCDBStorageFactory* factory) {
374// add a storage factory to the list of registerd factories
5078a13f 375
376 if (!fFactories.Contains(factory)) {
377 fFactories.Add(factory);
378 }
9e1ceb13 379}
380
381//_____________________________________________________________________________
fdf65bb5 382Bool_t AliCDBManager::HasStorage(const char* dbString) const {
b21e3194 383// check if dbString is a URI valid for one of the registered factories
9e1ceb13 384
5078a13f 385 TIter iter(&fFactories);
9e1ceb13 386
5078a13f 387 AliCDBStorageFactory* factory=0;
388 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
9e1ceb13 389
5078a13f 390 if (factory->Validate(dbString)) {
391 return kTRUE;
392 }
393 }
9e1ceb13 394
5078a13f 395 return kFALSE;
9e1ceb13 396}
397
398//_____________________________________________________________________________
fdf65bb5 399AliCDBParam* AliCDBManager::CreateParameter(const char* dbString) const {
9e1ceb13 400// create AliCDBParam object from URI string
401
5078a13f 402 TString uriString(dbString);
403
4dcc40d2 404 if ( !fCvmfsOcdb.IsNull() && uriString.BeginsWith("alien://")) {
5078a13f 405 AlienToCvmfsUri(uriString);
406 }
407
408 TIter iter(&fFactories);
7de84b33 409
5078a13f 410 AliCDBStorageFactory* factory=0;
411 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
412 //AliCDBParam* param = factory->CreateParameter(dbString);
413 AliCDBParam* param = factory->CreateParameter(uriString);
414 if(param) return param;
415 }
416
417 return NULL;
418}
9e1ceb13 419
5078a13f 420//_____________________________________________________________________________
421void AliCDBManager::AlienToCvmfsUri(TString& uriString) const {
422// convert alien storage uri to local:///cvmfs storage uri (called when OCDB_PATH is set)
423
5078a13f 424 TObjArray *arr = uriString.Tokenize('?');
425 TIter iter(arr);
426 TObjString *str = 0;
427 TString entryKey = "";
428 TString entryValue = "";
429 TString newUriString = "";
430 while((str = (TObjString*) iter.Next())){
431 TString entry(str->String());
432 Int_t indeq = entry.Index('=');
433 entryKey = entry(0, indeq+1);
434 entryValue = entry(indeq+1, entry.Length()-indeq);
435
436 if ( entryKey.Contains("folder", TString::kIgnoreCase) )
437 {
438
439 TRegexp re_RawFolder("^/alice/data/20[0-9]+/OCDB");
440 TRegexp re_MCFolder("^/alice/simulation/2008/v4-15-Release");
441 TString rawFolder = entryValue(re_RawFolder);
442 TString mcFolder = entryValue(re_MCFolder);
443 if ( !rawFolder.IsNull() ){
37286873 444 entryValue.Replace(0, 6, "/cvmfs/alice-ocdb.cern.ch/calibration");
7ab8651a 445 //entryValue.Replace(entryValue.Length()-4, entryValue.Length(), "");
5078a13f 446 } else if ( !mcFolder.IsNull() ){
37286873 447 entryValue.Replace(0,36,"/cvmfs/alice-ocdb.cern.ch/calibration/MC");
5078a13f 448 } else {
449 AliFatal(Form("Environment variable for cvmfs OCDB folder set for an invalid OCDB storage:\n %s", entryValue.Data()));
450 }
451 } else {
452 newUriString += entryKey;
453 }
454 newUriString += entryValue;
455 newUriString += '?';
456 }
457 newUriString.Prepend("local://");
458 newUriString.Remove(TString::kTrailing, '?');
459 uriString = newUriString;
9e1ceb13 460}
461
462//_____________________________________________________________________________
463AliCDBStorage* AliCDBManager::GetStorage(const char* dbString) {
464// get storage object from URI string
9e1ceb13 465
5078a13f 466 // Check environment variable OCDB_PATH. It is set in case the user (job) expects
467 // to find in the local /cvmfs the required OCDB tag. The OCDB_PATH variable
468 // contains the path to the directory in /cvmfs/ which is an AliRoot tag based snapshot
469 // of the AliEn file catalogue. The directory has to contain:
470 // 1) catalogue/20??.list.gz gzipped text files listing the OCDB files (seen by that AliRoot tag)
471 // 2) bin/getOCDBperRun.sh (shell+awk) script extracting from 1) the list
472 // of valid files for the given run.
473
474 AliCDBParam* param = CreateParameter(dbString);
475 if (!param) {
476 AliError(Form("Failed to activate requested storage! Check URI: %s", dbString));
477 return NULL;
478 }
479
480 AliCDBStorage* aStorage = GetStorage(param);
9e1ceb13 481
5078a13f 482 delete param;
483 return aStorage;
9e1ceb13 484}
485
486//_____________________________________________________________________________
487AliCDBStorage* AliCDBManager::GetStorage(const AliCDBParam* param) {
488// get storage object from AliCDBParam object
5078a13f 489
490 // if the list of active storages already contains
491 // the requested storage, return it
492 AliCDBStorage* aStorage = GetActiveStorage(param);
493 if (aStorage) {
494 return aStorage;
495 }
496
497 // if lock is ON, cannot activate more storages!
498 if(fLock) {
499 if (fDefaultStorage) {
500 AliFatal("Lock is ON, and default storage is already set: "
501 "cannot reset it or activate more storages!");
502 }
503 }
504
505 // loop on the list of registered factories
506 TIter iter(&fFactories);
507 AliCDBStorageFactory* factory=0;
508 while ((factory = (AliCDBStorageFactory*) iter.Next())) {
509
510 // each factory tries to create its storage from the parameter
511 aStorage = factory->Create(param);
512 if (aStorage) {
513 PutActiveStorage(param->CloneParam(), aStorage);
514 aStorage->SetURI(param->GetURI());
515 if(fRun >= 0) {
516 if( aStorage->GetType() == "alien" || aStorage->GetType() == "local" )
517 aStorage->QueryCDB(fRun);
7ab8651a 518 }
78f84046 519 return aStorage;
7ab8651a 520 }
5078a13f 521 }
5078a13f 522
7ab8651a 523 AliError(Form("Failed to activate requested storage! Check URI: %s", param->GetURI().Data()));
5078a13f 524
7ab8651a 525 return NULL;
9e1ceb13 526}
527
62032124 528//_____________________________________________________________________________
529AliCDBStorage* AliCDBManager::GetActiveStorage(const AliCDBParam* param) {
530// get a storage object from the list of active storages
531
5078a13f 532 return dynamic_cast<AliCDBStorage*> (fActiveStorages.GetValue(param));
62032124 533}
534
9e1ceb13 535//_____________________________________________________________________________
536TList* AliCDBManager::GetActiveStorages() {
537// return list of active storages
62032124 538// user has responsibility to delete returned object
9e1ceb13 539
5078a13f 540 TList* result = new TList();
9e1ceb13 541
5078a13f 542 TIter iter(fActiveStorages.GetTable());
543 TPair* aPair=0;
544 while ((aPair = (TPair*) iter.Next())) {
545 result->Add(aPair->Value());
546 }
9e1ceb13 547
5078a13f 548 return result;
9e1ceb13 549}
550
551//_____________________________________________________________________________
552void AliCDBManager::SetDrain(const char* dbString) {
553// set drain storage from URI string
554
5078a13f 555 fDrainStorage = GetStorage(dbString);
9e1ceb13 556}
557
558//_____________________________________________________________________________
559void AliCDBManager::SetDrain(const AliCDBParam* param) {
560// set drain storage from AliCDBParam
b8ec52f6 561
5078a13f 562 fDrainStorage = GetStorage(param);
9e1ceb13 563}
564
565//_____________________________________________________________________________
566void AliCDBManager::SetDrain(AliCDBStorage* storage) {
567// set drain storage from another active storage
5078a13f 568
569 fDrainStorage = storage;
9e1ceb13 570}
571
572//_____________________________________________________________________________
573Bool_t AliCDBManager::Drain(AliCDBEntry *entry) {
574// drain retrieved object to drain storage
575
5078a13f 576 AliDebug(2, "Draining into drain storage...");
577 return fDrainStorage->Put(entry);
9e1ceb13 578}
579
7de84b33 580//____________________________________________________________________________
5078a13f 581void AliCDBManager::SetDefaultStorage(const char* storageUri) {
9e1ceb13 582// sets default storage from URI string
5078a13f 583
584 // if in the cvmfs case (triggered by environment variable) check for path validity
585 // and modify Uri if it is "raw://"
586 TString cvmfsOcdb(gSystem->Getenv("OCDB_PATH"));
587 if (! cvmfsOcdb.IsNull()){
588 fCvmfsOcdb = cvmfsOcdb;
589 ValidateCvmfsCase();
590 }
591
592 // checking whether we are in the raw case
593 TString uriTemp(storageUri);
594 if (uriTemp == "raw://") {
595 fRaw = kTRUE; // read then by SetRun to check if the method has to be called again with expanded uri
596 AliInfo("Setting the run-number will set the corresponding OCDB for raw data reconstruction.");
597 return;
598 }
599
600 AliCDBStorage* bckStorage = fDefaultStorage;
601
602 fDefaultStorage = GetStorage(storageUri);
603
604 if(!fDefaultStorage) return;
605
606 if(bckStorage && (fDefaultStorage != bckStorage)){
607 AliWarning("Existing default storage replaced: clearing cache!");
608 ClearCache();
609 }
610
611 if (fStorageMap->Contains("default")) {
612 delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
613 }
614 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
9e1ceb13 615}
5078a13f 616
9e1ceb13 617//_____________________________________________________________________________
618void AliCDBManager::SetDefaultStorage(const AliCDBParam* param) {
619// set default storage from AliCDBParam object
4954c5cd 620
5078a13f 621 AliCDBStorage* bckStorage = fDefaultStorage;
4954c5cd 622
5078a13f 623 fDefaultStorage = GetStorage(param);
95c0e132 624
5078a13f 625 if(!fDefaultStorage) return;
b21e3194 626
5078a13f 627 if(bckStorage && (fDefaultStorage != bckStorage)){
628 AliWarning("Existing default storage replaced: clearing cache!");
629 ClearCache();
630 }
631
632 if (fStorageMap->Contains("default")) {
633 delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
634 }
635 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
9e1ceb13 636}
637
638//_____________________________________________________________________________
639void AliCDBManager::SetDefaultStorage(AliCDBStorage* storage) {
640// set default storage from another active storage
5078a13f 641
642 // if lock is ON, cannot activate more storages!
643 if(fLock) {
644 if (fDefaultStorage) {
645 AliFatal("Lock is ON, and default storage is already set: "
646 "cannot reset it or activate more storages!");
647 }
648 }
649
650 if (!storage) {
651 UnsetDefaultStorage();
652 return;
653 }
654
655 AliCDBStorage* bckStorage = fDefaultStorage;
656
657 fDefaultStorage = storage;
658
659 if(bckStorage && (fDefaultStorage != bckStorage)){
660 AliWarning("Existing default storage replaced: clearing cache!");
661 ClearCache();
662 }
663
664 if (fStorageMap->Contains("default")) {
665 delete fStorageMap->Remove(((TPair*)fStorageMap->FindObject("default"))->Key());
666 }
667 fStorageMap->Add(new TObjString("default"), new TObjString(fDefaultStorage->GetURI()));
9e1ceb13 668}
4667c116 669
7de84b33 670//_____________________________________________________________________________
671void AliCDBManager::SetDefaultStorage(const char* mcString, const char* simType) {
672// sets default storage for MC data
5078a13f 673// mcString MUST be "MC",
7de84b33 674// simType can be "Ideal","Residual","Full"
5078a13f 675
676 TString strmcString(mcString);
677 TString strsimType(simType);
678 TString dbString;
679 if (strmcString != "MC"){
680 AliFatal("Method requires first string to be MC!");
681 }
682 else {
683 if (strsimType == "Ideal"){
684 dbString = fgkMCIdealStorage;
685 }
686 else if (strsimType == "Full"){
687 dbString = fgkMCFullStorage;
688 }
689 else if (strsimType == "Residual"){
690 dbString = fgkMCResidualStorage;
691 }
692 else {
693 AliFatal("Error in setting the storage for MC data, second argument MUST be either \"Ideal\" or \"Full\" or \"Residual\".");
694 }
695
696 SetDefaultStorage(dbString.Data());
697 fStartRunLHCPeriod=0;
698 fEndRunLHCPeriod=AliCDBRunRange::Infinity();
699 if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",dbString.Data()));
700 }
701}
702
703//_____________________________________________________________________________
704void AliCDBManager::ValidateCvmfsCase() const {
705 if (! fCvmfsOcdb.BeginsWith("/cvmfs")) //!!!! to be commented out for testing
706 AliFatal(Form("OCDB_PATH set to an invalid path: %s", fCvmfsOcdb.Data()));
707
708 TString cvmfsUri(fCvmfsOcdb);
709 gSystem->ExpandPathName(cvmfsUri);
710 if (gSystem->AccessPathName(cvmfsUri))
711 AliFatal(Form("OCDB_PATH set to an invalid path: %s", cvmfsUri.Data()));
712
713 // check that we find the two scripts we need
714
715 AliDebug(3, "OCDB_PATH envvar is set. Changing OCDB storage from alien:// to local:///cvmfs type.");
716 cvmfsUri = cvmfsUri.Strip(TString::kTrailing, '/');
717 cvmfsUri.Append("/bin/getOCDBFilesPerRun.sh");
718 if (gSystem->AccessPathName(cvmfsUri))
719 AliFatal(Form("Cannot find valid script: %s", cvmfsUri.Data()));
7de84b33 720}
5078a13f 721
7de84b33 722//_____________________________________________________________________________
723void AliCDBManager::SetDefaultStorageFromRun(Int_t run) {
724// set default storage from the run number - to be used only with raw data
725
5078a13f 726 // if lock is ON, cannot activate more storages!
727 if(fLock) {
728 if (fDefaultStorage) {
729 AliFatal("Lock is ON, and default storage is already set: "
730 "cannot activate default storage from run number");
731 }
732 }
733
734 // fRaw and cvmfs case
735 if (! fCvmfsOcdb.IsNull()) {
736 // we don't want to connect to AliEn just to set the uri from the runnumber
737 // for that we use the script getUriFromYear.sh in the cvmfs AliRoot package
738 // check that we find the two scripts we need
739 TString getYearScript(fCvmfsOcdb);
740 getYearScript = getYearScript.Strip(TString::kTrailing, '/');
741 getYearScript.Append("/bin/getUriFromYear.sh");
742 if (gSystem->AccessPathName(getYearScript))
743 AliFatal(Form("Cannot find valid script: %s", getYearScript.Data()));
744 TString inoutFile(gSystem->WorkingDirectory());
745 inoutFile += "/uri_range_";
746 inoutFile += TString::Itoa(fRun,10);
747 TString command(getYearScript);
748 command += ' ';
749 command += TString::Itoa(fRun,10);
750 command += Form(" > %s", inoutFile.Data());
751 AliDebug(3, Form("Running command: \"%s\"",command.Data()));
752 Int_t result = gSystem->Exec(command.Data());
753 if(result != 0) {
754 AliFatal(Form("Was not able to execute \"%s\"", command.Data()));
755 }
756
757 // now read the file with the uri and first and last run
1e686a95 758 std::ifstream file(inoutFile.Data());
759 if (!file.is_open()) {
5078a13f 760 AliFatal(Form("Error opening file \"%s\"!", inoutFile.Data()));
5078a13f 761 }
762 TString lhcPeriod;
763 TObjArray* oStringsArray = 0;
1e686a95 764 while (lhcPeriod.ReadLine(file)){
5078a13f 765 oStringsArray = lhcPeriod.Tokenize(' ');
766 }
767 TObjString *oStrUri = dynamic_cast<TObjString*> (oStringsArray->At(0));
768 TObjString *oStrFirst = dynamic_cast<TObjString*> (oStringsArray->At(1));
769 TString firstRun = oStrFirst->GetString();
770 TObjString *oStrLast = dynamic_cast<TObjString*> (oStringsArray->At(2));
771 TString lastRun = oStrLast->GetString();
772
773 fLHCPeriod = oStrUri->GetString();
774 fStartRunLHCPeriod = firstRun.Atoi();
775 fEndRunLHCPeriod = lastRun.Atoi();
776
1e686a95 777 file.close();
5078a13f 778
779 } else { // if not cvmfs case, "plain" AliEn case
780 // retrieve XML file from alien
781 if(!gGrid) {
782 TGrid::Connect("alien://","");
783 if(!gGrid) {
784 AliError("Connection to alien failed!");
785 return;
786 }
787 }
788 TUUID uuid;
789 TString rndname = "/tmp/";
790 rndname += "OCDBFolderXML.";
791 rndname += uuid.AsString();
792 rndname += ".xml";
793 AliDebug(2, Form("file to be copied = %s", fgkOCDBFolderXMLfile.Data()));
794 if (!TFile::Cp(fgkOCDBFolderXMLfile.Data(), rndname.Data())) {
795 AliFatal(Form("Cannot make a local copy of OCDBFolder xml file in %s",rndname.Data()));
796 }
797 AliCDBHandler* saxcdb = new AliCDBHandler();
798 saxcdb->SetRun(run);
799 TSAXParser *saxParser = new TSAXParser();
800 saxParser->ConnectToHandler("AliCDBHandler", saxcdb);
801 saxParser->ParseFile(rndname.Data());
802 AliInfo(Form(" LHC folder = %s", saxcdb->GetOCDBFolder().Data()));
803 AliInfo(Form(" LHC period start run = %d", saxcdb->GetStartRunRange()));
804 AliInfo(Form(" LHC period end run = %d", saxcdb->GetEndRunRange()));
805 fLHCPeriod = saxcdb->GetOCDBFolder();
806 fStartRunLHCPeriod = saxcdb->GetStartRunRange();
807 fEndRunLHCPeriod = saxcdb->GetEndRunRange();
808 }
809
810 SetDefaultStorage(fLHCPeriod.Data());
811 if(!fDefaultStorage) AliFatal(Form("%s storage not there! Please check!",fLHCPeriod.Data()));
7de84b33 812
813}
814
4667c116 815//_____________________________________________________________________________
1f341624 816void AliCDBManager::UnsetDefaultStorage() {
817// Unset default storage
5078a13f 818
819 // if lock is ON, action is forbidden!
820 if(fLock) {
821 if (fDefaultStorage) {
822 AliFatal("Lock is ON: cannot unset default storage!");
823 }
824 }
825
826 if (fDefaultStorage) {
827 AliWarning("Clearing cache!");
828 ClearCache();
829 }
830
831 fRun = fStartRunLHCPeriod = fEndRunLHCPeriod = -1;
832 fRaw = kFALSE;
833
834 fDefaultStorage = 0x0;
4667c116 835}
9e1ceb13 836
02c4845e 837//_____________________________________________________________________________
024cf675 838void AliCDBManager::SetSpecificStorage(const char* calibType, const char* dbString) {
839// sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
02c4845e 840
5078a13f 841 AliCDBParam *aPar = CreateParameter(dbString);
842 if(!aPar) return;
843 SetSpecificStorage(calibType, aPar);
844 delete aPar;
02c4845e 845}
846
847//_____________________________________________________________________________
647d2bb8 848void AliCDBManager::SetSpecificStorage(const char* calibType, const AliCDBParam* param) {
024cf675 849// sets storage specific for detector or calibration type (works with AliCDBManager::Get(...))
850// Default storage should be defined prior to any specific storages, e.g.:
851// AliCDBManager::instance()->SetDefaultStorage("alien://");
c3a7b59a 852// AliCDBManager::instance()->SetSpecificStorage("TPC/*","local://DB_TPC");
853// AliCDBManager::instance()->SetSpecificStorage("*/Align/*","local://DB_TPCAlign");
854// calibType must be a valid CDB path! (3 level folder structure)
02c4845e 855
7de84b33 856
5078a13f 857 if(!fDefaultStorage && !fRaw) {
858 AliError("Please activate a default storage first!");
859 return;
860 }
4005d0b5 861
5078a13f 862 AliCDBPath aPath(calibType);
863 if(!aPath.IsValid()){
864 AliError(Form("Not a valid path: %s", calibType));
865 return;
866 }
62032124 867
5078a13f 868 TObjString *objCalibType = new TObjString(aPath.GetPath());
869 if(fSpecificStorages.Contains(objCalibType)){
870 AliWarning(Form("Storage \"%s\" already activated! It will be replaced by the new one",
871 calibType));
872 AliCDBParam *checkPar = dynamic_cast<AliCDBParam*> (fSpecificStorages.GetValue(calibType));
873 if(checkPar) delete checkPar;
874 delete fSpecificStorages.Remove(objCalibType);
875 }
876 AliCDBStorage *aStorage = GetStorage(param);
877 if(!aStorage) return;
96b7636d 878
5078a13f 879 fSpecificStorages.Add(objCalibType, param->CloneParam());
b21e3194 880
5078a13f 881 if(fStorageMap->Contains(objCalibType)){
882 delete fStorageMap->Remove(objCalibType);
883 }
884 fStorageMap->Add(objCalibType->Clone(), new TObjString(param->GetURI()));
b21e3194 885
02c4845e 886}
887
888//_____________________________________________________________________________
024cf675 889AliCDBStorage* AliCDBManager::GetSpecificStorage(const char* calibType) {
5078a13f 890// get storage specific for detector or calibration type
4b5e0dce 891
5078a13f 892 AliCDBPath calibPath(calibType);
893 if(!calibPath.IsValid()) return NULL;
96b7636d 894
5078a13f 895 AliCDBParam *checkPar = (AliCDBParam*) fSpecificStorages.GetValue(calibPath.GetPath());
896 if(!checkPar){
897 AliError(Form("%s storage not found!", calibType));
898 return NULL;
899 } else {
900 return GetStorage(checkPar);
901 }
96b7636d 902
02c4845e 903}
904
024cf675 905//_____________________________________________________________________________
906AliCDBParam* AliCDBManager::SelectSpecificStorage(const TString& path) {
82096dfc 907// select storage valid for path from the list of specific storages
024cf675 908
5078a13f 909 AliCDBPath aPath(path);
910 if(!aPath.IsValid()) return NULL;
911
912 TIter iter(&fSpecificStorages);
913 TObjString *aCalibType=0;
914 AliCDBPath tmpPath("null/null/null");
915 AliCDBParam* aPar=0;
916 while((aCalibType = (TObjString*) iter.Next())){
917 AliCDBPath calibTypePath(aCalibType->GetName());
918 if(calibTypePath.Comprises(aPath)) {
919 if(calibTypePath.Comprises(tmpPath)) continue;
920 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
921 tmpPath.SetPath(calibTypePath.GetPath());
922 }
923 }
924 return aPar;
024cf675 925}
926
02c4845e 927//_____________________________________________________________________________
4667c116 928AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path, Int_t runNumber,
5078a13f 929 Int_t version, Int_t subVersion) {
930 // get an AliCDBEntry object from the database
931
932 if(runNumber < 0){
933 // RunNumber is not specified. Try with fRun
934 if (fRun < 0){
935 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
936 return NULL;
937 }
938 runNumber = fRun;
939 }
024cf675 940
5078a13f 941 return Get(AliCDBId(path, runNumber, runNumber, version, subVersion));
02c4845e 942}
943
944//_____________________________________________________________________________
4667c116 945AliCDBEntry* AliCDBManager::Get(const AliCDBPath& path,
5078a13f 946 const AliCDBRunRange& runRange, Int_t version,
947 Int_t subVersion) {
948 // get an AliCDBEntry object from the database!
02c4845e 949
5078a13f 950 return Get(AliCDBId(path, runRange, version, subVersion));
02c4845e 951}
952
953//_____________________________________________________________________________
e973a743 954AliCDBEntry* AliCDBManager::Get(const AliCDBId& query, Bool_t forceCaching) {
02c4845e 955// get an AliCDBEntry object from the database
5078a13f 956
957 // check if query's path and runRange are valid
958 // query is invalid also if version is not specified and subversion is!
959 if (!query.IsValid()) {
960 AliError(Form("Invalid query: %s", query.ToString().Data()));
961 return NULL;
962 }
963
964 // query is not specified if path contains wildcard or run range= [-1,-1]
965 if (!query.IsSpecified()) {
966 AliError(Form("Unspecified query: %s",
967 query.ToString().Data()));
968 return NULL;
969 }
970
971 if(fLock && !(fRun >= query.GetFirstRun() && fRun <= query.GetLastRun()))
972 AliFatal("Lock is ON: cannot use different run number than the internal one!");
973
974 if(fCache && !(fRun >= query.GetFirstRun() && fRun <= query.GetLastRun()))
975 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
976
977 AliCDBEntry *entry=0;
978
979 // first look into map of cached objects
980 if(fCache && query.GetFirstRun() == fRun)
981 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
982 if(entry) {
983 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
984 return entry;
985 }
986
987 // if snapshot flag is set, try getting from the snapshot
988 // but in the case a specific storage is specified for this path
989 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
990 if(!aPar){
991 if(fSnapshotMode && query.GetFirstRun() == fRun)
992 {
993 entry = GetEntryFromSnapshot(query.GetPath());
994 if(entry) {
995 AliInfo(Form("Object \"%s\" retrieved from the snapshot.",query.GetPath().Data()));
996 if(query.GetFirstRun() == fRun) // no need to check fCache, fSnapshotMode not possible otherwise
997 CacheEntry(query.GetPath(), entry);
998
999 if(!fIds->Contains(&entry->GetId()))
1000 fIds->Add(entry->GetId().Clone());
1001
1002 return entry;
1003 }
1004 }
1005 }
1006
1007 // Entry is not in cache (and, in case we are in snapshot mode, not in the snapshot either)
1008 // => retrieve it from the storage and cache it!!
1009 if(!fDefaultStorage) {
1010 AliError("No storage set!");
1011 return NULL;
1012 }
1013
1014 AliCDBStorage *aStorage=0;
1015 if(aPar) {
1016 aStorage=GetStorage(aPar);
1017 TString str = aPar->GetURI();
1018 AliDebug(2,Form("Looking into storage: %s",str.Data()));
1019 } else {
1020 aStorage=GetDefaultStorage();
1021 AliDebug(2,"Looking into default storage");
1022 }
1023
1024 entry = aStorage->Get(query);
1025
1026 if(entry && fCache && (query.GetFirstRun()==fRun || forceCaching)){
1027 CacheEntry(query.GetPath(), entry);
1028 }
1029
1030 if(entry && !fIds->Contains(&entry->GetId())){
1031 fIds->Add(entry->GetId().Clone());
1032 }
e973a743 1033
5078a13f 1034 return entry;
4667c116 1035}
1036
c022b397 1037//_____________________________________________________________________________
1038AliCDBEntry* AliCDBManager::GetEntryFromSnapshot(const char* path) {
5078a13f 1039// get the entry from the open snapshot file
c022b397 1040
5078a13f 1041 TString sPath(path);
1042 sPath.ReplaceAll("/","*");
1043 if(!fSnapshotFile){
1044 AliError("No snapshot file is open!");
1045 return 0;
1046 }
1047 AliCDBEntry *entry = dynamic_cast<AliCDBEntry*>(fSnapshotFile->Get(sPath.Data()));
1048 if(!entry){
1049 AliDebug(2,Form("Cannot get a CDB entry for \"%s\" from snapshot file",path));
1050 return 0;
1051 }
c022b397 1052
5078a13f 1053 return entry;
c022b397 1054}
1055
1056//_____________________________________________________________________________
1057Bool_t AliCDBManager::SetSnapshotMode(const char* snapshotFileName) {
1058// set the manager in snapshot mode
c022b397 1059
5078a13f 1060 if(!fCache){
1061 AliError("Cannot set the CDB manage in snapshot mode if the cache is not active!");
1062 return kFALSE;
1063 }
c022b397 1064
5078a13f 1065 //open snapshot file
1066 TString snapshotFile(snapshotFileName);
1067 if(snapshotFile.BeginsWith("alien://")){
1068 if(!gGrid) {
1069 TGrid::Connect("alien://","");
1070 if(!gGrid) {
1071 AliError("Connection to alien failed!");
1072 return kFALSE;
1073 }
c022b397 1074 }
5078a13f 1075 }
c022b397 1076
5078a13f 1077 fSnapshotFile = TFile::Open(snapshotFileName);
1078 if (!fSnapshotFile || fSnapshotFile->IsZombie()){
1079 AliError(Form("Cannot open file %s",snapshotFileName));
1080 return kFALSE;
1081 }
1082
1083 AliInfo("The CDB manager is set in snapshot mode!");
1084 fSnapshotMode = kTRUE;
1085 return kTRUE;
c022b397 1086
1087}
1088
0f40a831 1089//_____________________________________________________________________________
1090const char* AliCDBManager::GetURI(const char* path) {
1091// return the URI of the storage where to look for path
1092
5078a13f 1093 if(!IsDefaultStorageSet()) return 0;
1094
1095 AliCDBParam *aPar=SelectSpecificStorage(path);
0f40a831 1096
5078a13f 1097 if(aPar) {
1098 return aPar->GetURI().Data();
0f40a831 1099
5078a13f 1100 } else {
1101 return GetDefaultStorage()->GetURI().Data();
1102 }
1103
1104 return 0;
0f40a831 1105}
1106
b7df0cc5 1107//_____________________________________________________________________________
1108Int_t AliCDBManager::GetStartRunLHCPeriod(){
5078a13f 1109// get the first run of validity
1110// for the current period
1111// if set
1112 if(fStartRunLHCPeriod==-1)
1113 AliWarning("Run-range not yet set for the current LHC period.");
1114 return fStartRunLHCPeriod;
b7df0cc5 1115}
1116
1117//_____________________________________________________________________________
1118Int_t AliCDBManager::GetEndRunLHCPeriod(){
5078a13f 1119// get the last run of validity
1120// for the current period
1121// if set
1122 if(fEndRunLHCPeriod==-1)
1123 AliWarning("Run-range not yet set for the current LHC period.");
1124 return fEndRunLHCPeriod;
b7df0cc5 1125}
1126
1127//_____________________________________________________________________________
1128TString AliCDBManager::GetLHCPeriod(){
5078a13f 1129// get the current LHC period string
1130//
1131 if(fLHCPeriod.IsWhitespace() || fLHCPeriod.IsNull())
1132 AliWarning("LHC period (OCDB folder) not yet set");
1133 return fLHCPeriod;
b7df0cc5 1134}
1135
4667c116 1136//_____________________________________________________________________________
1137AliCDBId* AliCDBManager::GetId(const AliCDBPath& path, Int_t runNumber,
5078a13f 1138 Int_t version, Int_t subVersion) {
1139 // get the AliCDBId of the valid object from the database (does not retrieve the object)
1140 // User must delete returned object!
1141
1142 if(runNumber < 0){
1143 // RunNumber is not specified. Try with fRun
1144 if (fRun < 0){
1145 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
1146 return NULL;
1147 }
1148 runNumber = fRun;
1149 }
4667c116 1150
5078a13f 1151 return GetId(AliCDBId(path, runNumber, runNumber, version, subVersion));
4667c116 1152}
1153
1154//_____________________________________________________________________________
1155AliCDBId* AliCDBManager::GetId(const AliCDBPath& path,
5078a13f 1156 const AliCDBRunRange& runRange, Int_t version,
1157 Int_t subVersion) {
1158 // get the AliCDBId of the valid object from the database (does not retrieve the object)
1159 // User must delete returned object!
4667c116 1160
5078a13f 1161 return GetId(AliCDBId(path, runRange, version, subVersion));
4667c116 1162}
1163
1164//_____________________________________________________________________________
1165AliCDBId* AliCDBManager::GetId(const AliCDBId& query) {
1166// get the AliCDBId of the valid object from the database (does not retrieve the object)
1167// User must delete returned object!
1168
5078a13f 1169 if(!fDefaultStorage) {
1170 AliError("No storage set!");
1171 return NULL;
1172 }
1173
1174 // check if query's path and runRange are valid
1175 // query is invalid also if version is not specified and subversion is!
1176 if (!query.IsValid()) {
1177 AliError(Form("Invalid query: %s", query.ToString().Data()));
1178 return NULL;
1179 }
1180
1181 // query is not specified if path contains wildcard or run range= [-1,-1]
1182 if (!query.IsSpecified()) {
1183 AliError(Form("Unspecified query: %s",
1184 query.ToString().Data()));
1185 return NULL;
1186 }
1187
1188 if(fCache && query.GetFirstRun() != fRun)
1189 AliWarning("Run number explicitly set in query: CDB cache temporarily disabled!");
1190
1191 AliCDBEntry* entry = 0;
1192
1193 // first look into map of cached objects
1194 if(fCache && query.GetFirstRun() == fRun)
1195 entry = (AliCDBEntry*) fEntryCache.GetValue(query.GetPath());
1196
1197 if(entry) {
1198 AliDebug(2, Form("Object %s retrieved from cache !!",query.GetPath().Data()));
1199 return dynamic_cast<AliCDBId*> (entry->GetId().Clone());
1200 }
1201
1202 // Entry is not in cache -> retrieve it from CDB and cache it!!
1203 AliCDBStorage *aStorage=0;
1204 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
1205
1206 if(aPar) {
1207 aStorage=GetStorage(aPar);
1208 TString str = aPar->GetURI();
1209 AliDebug(2,Form("Looking into storage: %s",str.Data()));
1210
1211 } else {
1212 aStorage=GetDefaultStorage();
1213 AliDebug(2,"Looking into default storage");
1214 }
1215
1216 return aStorage->GetId(query);
4667c116 1217
02c4845e 1218}
1219
1220//_____________________________________________________________________________
62032124 1221TList* AliCDBManager::GetAll(const AliCDBPath& path, Int_t runNumber,
5078a13f 1222 Int_t version, Int_t subVersion) {
1223 // get multiple AliCDBEntry objects from the database
1224
1225 if(runNumber < 0){
1226 // RunNumber is not specified. Try with fRun
1227 if (fRun < 0){
1228 AliError("Run number neither specified in query nor set in AliCDBManager! Use AliCDBManager::SetRun.");
1229 return NULL;
1230 }
1231 runNumber = fRun;
1232 }
afd8dbf4 1233
5078a13f 1234 return GetAll(AliCDBId(path, runNumber, runNumber, version,
1235 subVersion));
02c4845e 1236}
1237
1238//_____________________________________________________________________________
8e245d15 1239TList* AliCDBManager::GetAll(const AliCDBPath& path,
5078a13f 1240 const AliCDBRunRange& runRange, Int_t version, Int_t subVersion) {
1241 // get multiple AliCDBEntry objects from the database
02c4845e 1242
5078a13f 1243 return GetAll(AliCDBId(path, runRange, version, subVersion));
02c4845e 1244}
1245
1246//_____________________________________________________________________________
1247TList* AliCDBManager::GetAll(const AliCDBId& query) {
1248// get multiple AliCDBEntry objects from the database
024cf675 1249// Warning: this method works correctly only for queries of the type "Detector/*"
1250// and not for more specific queries e.g. "Detector/Calib/*" !
8e245d15 1251// Warning #2: Entries are cached, but GetAll will keep on retrieving objects from OCDB!
1252// To get an object from cache use Get() function
02c4845e 1253
5078a13f 1254 if(!fDefaultStorage) {
1255 AliError("No storage set!");
1256 return NULL;
1257 }
1258
1259 if (!query.IsValid()) {
1260 AliError(Form("Invalid query: %s", query.ToString().Data()));
1261 return NULL;
1262 }
1263
1264 if((fSpecificStorages.GetEntries()>0) && query.GetPath().BeginsWith('*')){
1265 // if specific storages are active a query with "*" is ambiguous
1266 AliError("Query too generic in this context!");
1267 return NULL;
1268 }
1269
1270 if (query.IsAnyRange()) {
1271 AliError(Form("Unspecified run or runrange: %s",
1272 query.ToString().Data()));
1273 return NULL;
1274 }
1275
1276 if(fLock && query.GetFirstRun() != fRun)
1277 AliFatal("Lock is ON: cannot use different run number than the internal one!");
1278
1279 AliCDBParam *aPar=SelectSpecificStorage(query.GetPath());
1280
1281 AliCDBStorage *aStorage;
1282 if(aPar) {
1283 aStorage=GetStorage(aPar);
1284 AliDebug(2,Form("Looking into storage: %s", aPar->GetURI().Data()));
1285
1286 } else {
1287 aStorage=GetDefaultStorage();
1288 AliDebug(2,Form("Looking into default storage: %s", aStorage->GetURI().Data()));
1289 }
1290
1291 TList *result = 0;
1292 if(aStorage) result = aStorage->GetAll(query);
1293 if(!result) return 0;
1294
1295 // loop on result to check whether entries should be re-queried with specific storages
1296 if(fSpecificStorages.GetEntries()>0 && ! (fSpecificStorages.GetEntries() == 1 && aPar)) {
1297 AliInfo("Now look into all other specific storages...");
1298
1299 TIter iter(result);
1300 AliCDBEntry* chkEntry=0;
1301
1302 while((chkEntry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
1303 AliCDBId& chkId = chkEntry->GetId();
1304 AliDebug(2, Form("Checking id %s ", chkId.GetPath().Data()));
1305 AliCDBParam *chkPar=SelectSpecificStorage(chkId.GetPath());
1306 if (!chkPar || aPar == chkPar) continue;
1307 AliCDBStorage *chkStorage = GetStorage(chkPar);
1308 AliDebug(2, Form("Found specific storage! %s", chkPar->GetURI().Data()));
1309
1310 AliCDBEntry *newEntry=0;
1311 chkId.SetRunRange(query.GetFirstRun(), query.GetLastRun());
1312 chkId.SetVersion(query.GetVersion());
1313 chkId.SetSubVersion(query.GetSubVersion());
1314
1315 if(chkStorage) newEntry = chkStorage->Get(chkId);
1316 if(!newEntry) continue;
1317
1318 // object is found in specific storage: replace entry in the result list!
1319 chkEntry->SetOwner(1);
1320 delete result->Remove(chkEntry);
1321 result->AddFirst(newEntry);
1322 }
1323
1324 Int_t nEntries = result->GetEntries();
1325 AliInfo("After look into other specific storages, result list is:");
1326 for(int i=0; i<nEntries;i++){
1327 AliCDBEntry *entry = (AliCDBEntry*) result->At(i);
1328 AliInfo(Form("%s",entry->GetId().ToString().Data()));
1329 }
1330 }
1331
1332 // caching entries
1333 TIter iter(result);
1334 AliCDBEntry* entry=0;
1335 while((entry = dynamic_cast<AliCDBEntry*> (iter.Next()))){
1336
1337 if(!fIds->Contains(&entry->GetId())){
1338 fIds->Add(entry->GetId().Clone());
1339 }
1340 if(fCache && (query.GetFirstRun() == fRun)){
1341 CacheEntry(entry->GetId().GetPath(), entry);
1342 }
1343 }
1344
1345
1346 return result;
02c4845e 1347}
1348
1349//_____________________________________________________________________________
b1bfa962 1350Bool_t AliCDBManager::Put(TObject* object, const AliCDBId& id, AliCDBMetaData* metaData, const char* mirrors, DataType type){
02c4845e 1351// store an AliCDBEntry object into the database
1352
5078a13f 1353 if (object==0x0) {
1354 AliError("Null Entry! No storage will be done!");
1355 return kFALSE;
1356 }
968cfa08 1357
5078a13f 1358 AliCDBEntry anEntry(object, id, metaData);
1359 return Put(&anEntry, mirrors, type);
02c4845e 1360
1361}
1362
1363
1364//_____________________________________________________________________________
06eeadea 1365Bool_t AliCDBManager::Put(AliCDBEntry* entry, const char* mirrors, DataType type){
02c4845e 1366// store an AliCDBEntry object into the database
1367
5078a13f 1368 if(type == kPrivate && !fDefaultStorage) {
1369 AliError("No storage set!");
1370 return kFALSE;
1371 }
1372
1373 if (!entry){
1374 AliError("No entry!");
1375 return kFALSE;
1376 }
1377
1378 if (entry->GetObject()==0x0){
1379 AliError("No valid object in CDB entry!");
1380 return kFALSE;
1381 }
1382
1383 if (!entry->GetId().IsValid()) {
1384 AliError(Form("Invalid entry ID: %s",
1385 entry->GetId().ToString().Data()));
1386 return kFALSE;
1387 }
1388
1389 if (!entry->GetId().IsSpecified()) {
1390 AliError(Form("Unspecified entry ID: %s",
1391 entry->GetId().ToString().Data()));
1392 return kFALSE;
1393 }
1394
1395 AliCDBId id = entry->GetId();
1396 AliCDBParam *aPar = SelectSpecificStorage(id.GetPath());
1397
1398 AliCDBStorage *aStorage=0;
1399
1400 if(aPar) {
1401 aStorage=GetStorage(aPar);
1402 } else {
1403 switch(type){
1404 case kCondition:
1405 aStorage = GetStorage(fCondParam);
1406 break;
1407 case kReference:
1408 aStorage = GetStorage(fRefParam);
1409 break;
1410 case kPrivate:
1411 aStorage = GetDefaultStorage();
1412 break;
1413 }
1414 }
1415
1416 AliDebug(2,Form("Storing object into storage: %s", aStorage->GetURI().Data()));
1417
1418 TString strMirrors(mirrors);
1419 Bool_t result = kFALSE;
1420 if(!strMirrors.IsNull() && !strMirrors.IsWhitespace())
1421 result = aStorage->Put(entry, mirrors, type);
1422 else
1423 result = aStorage->Put(entry, "", type);
1424
1425 if(fRun >= 0) QueryCDB();
1426
1427 return result;
02c4845e 1428
1429
1430}
9e1ceb13 1431
c5941d67 1432//_____________________________________________________________________________
5078a13f 1433void AliCDBManager::SetMirrorSEs(const char* mirrors) {
c5941d67 1434// set mirror Storage Elements for the default storage, if it is of type "alien"
5078a13f 1435 if(fDefaultStorage->GetType() != "alien"){
1436 AliInfo("The default storage is not of type \"alien\". Settings for Storage Elements are not taken into account!");
1437 return;
1438 }
1439 fDefaultStorage->SetMirrorSEs(mirrors);
c5941d67 1440}
1441
1442//_____________________________________________________________________________
1443const char* AliCDBManager::GetMirrorSEs() const {
1444// get mirror Storage Elements for the default storage, if it is of type "alien"
5078a13f 1445 if(fDefaultStorage->GetType() != "alien"){
1446 AliInfo("The default storage is not of type \"alien\". Settings for Storage Elements are not taken into account!");
1447 return "";
1448 }
1449 return fDefaultStorage->GetMirrorSEs();
c5941d67 1450}
1451
4b5e0dce 1452//_____________________________________________________________________________
5078a13f 1453void AliCDBManager::CacheEntry(const char* path, AliCDBEntry* entry) {
4b5e0dce 1454// cache AliCDBEntry. Cache is valid until run number is changed.
1455
5078a13f 1456 AliCDBEntry *chkEntry = dynamic_cast<AliCDBEntry*> (fEntryCache.GetValue(path));
96b7636d 1457
5078a13f 1458 if(chkEntry) {
1459 AliDebug(2, Form("Object %s already in cache !!", path));
1460 return;
1461 } else {
1462 AliDebug(2,Form("Caching entry %s", path));
1463 }
96b7636d 1464
5078a13f 1465 fEntryCache.Add(new TObjString(path), entry);
1466 AliDebug(2,Form("Cache entries: %d", fEntryCache.GetEntries()));
4b5e0dce 1467
1468}
1469
917a098b 1470//_____________________________________________________________________________
5078a13f 1471void AliCDBManager::Print(Option_t* /*option*/) const {
917a098b 1472// Print list of active storages and their URIs
917a098b 1473
5078a13f 1474 TString output=Form("Run number = %d; ",fRun);
1475 output += "Cache is ";
1476 if(!fCache) output += "NOT ";
1477 output += Form("ACTIVE; Number of active storages: %d\n",fActiveStorages.GetEntries());
1478
1479 if(fDefaultStorage) {
1480 output += Form("\t*** Default Storage URI: \"%s\"\n",fDefaultStorage->GetURI().Data());
1481 // AliInfo(output.Data());
1482 }
1483 if(fSpecificStorages.GetEntries()>0) {
1484 TIter iter(fSpecificStorages.GetTable());
1485 TPair *aPair=0;
1486 Int_t i=1;
1487 while((aPair = (TPair*) iter.Next())){
1488 output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n",
1489 i++, ((TObjString*) aPair->Key())->GetName(),
1490 ((AliCDBParam*) aPair->Value())->GetURI().Data());
1491 }
1492 }
1493 if(fDrainStorage) {
1494 output += Form("*** Drain Storage URI: %s\n",fDrainStorage->GetURI().Data());
1495 }
1496 AliInfo(output.Data());
917a098b 1497}
1498
4b5e0dce 1499//_____________________________________________________________________________
5078a13f 1500void AliCDBManager::SetRun(Int_t run) {
917a098b 1501// Sets current run number.
4b5e0dce 1502// When the run number changes the caching is cleared.
5078a13f 1503
1504 if(fRun == run)
1505 return;
1506
1507 if(fLock && fRun >= 0) {
1508 AliFatal("Lock is ON, cannot reset run number!");
1509 }
1510
1511 fRun = run;
1512
1513 if (fRaw) {
1514 // here the LHCPeriod xml file is parsed; the string containing the correct period is returned; the default storage is set
1515 if (fStartRunLHCPeriod <= run && fEndRunLHCPeriod >= run){
1516 AliInfo("LHCPeriod alien folder for current run already in memory");
1517 }else{
1518 SetDefaultStorageFromRun(run);
1519 if(fEntryCache.GetEntries()!=0) ClearCache();
1520 return;
1521 }
1522 }
1523 ClearCache();
1524 QueryCDB();
4b5e0dce 1525}
1526
1527//_____________________________________________________________________________
1528void AliCDBManager::ClearCache(){
1529// clear AliCDBEntry cache
1530
5078a13f 1531 AliDebug(2, Form("Cache entries to be deleted: %d",fEntryCache.GetEntries()));
1532
1533 /*
1534 // To clean entries one by one
1535 TIter iter(fEntryCache.GetTable());
1536 TPair* pair=0;
1537 while((pair= dynamic_cast<TPair*> (iter.Next()))){
1538
1539 TObjString* key = dynamic_cast<TObjString*> (pair->Key());
1540 AliCDBEntry* entry = dynamic_cast<AliCDBEntry*> (pair->Value());
1541 AliDebug(2, Form("Deleting entry: %s", key->GetName()));
1542 if (entry) delete entry;
1543 delete fEntryCache.Remove(key);
1544 }
1545 */
1546 fEntryCache.DeleteAll();
1547 AliDebug(2, Form("After deleting - Cache entries: %d",fEntryCache.GetEntries()));
4b5e0dce 1548}
1549
4005d0b5 1550//_____________________________________________________________________________
1551void AliCDBManager::UnloadFromCache(const char* path){
1552// unload cached object
b0e8cda6 1553// that is remove the entry from the cache and the id from the list of ids
1554//
5078a13f 1555 if(!fActiveStorages.GetEntries()) {
1556 AliDebug(2, Form("No active storages. Object \"%s\" is not unloaded from cache", path));
1557 return;
1558 }
1559
1560 AliCDBPath queryPath(path);
1561 if(!queryPath.IsValid()) return;
1562
1563 if(!queryPath.IsWildcard()) { // path is not wildcard, get it directly from the cache and unload it!
1564 if(fEntryCache.Contains(path)){
1565 AliDebug(2, Form("Unloading object \"%s\" from cache and from list of ids", path));
1566 TObjString pathStr(path);
1567 delete fEntryCache.Remove(&pathStr);
1568 // we do not remove from the list of Id's (it's not very coherent but we leave the
1569 // id for the benefit of the userinfo)
1570 /*
1571 TIter iter(fIds);
1572 AliCDBId *id = 0;
1573 while((id = dynamic_cast<AliCDBId*> (iter.Next()))){
1574 if(queryPath.Comprises(id->GetPath()))
1575 delete fIds->Remove(id);
1576 }*/
1577 } else {
1578 AliWarning(Form("Cache does not contain object \"%s\"!", path));
1579 }
1580 AliDebug(2, Form("Cache entries: %d",fEntryCache.GetEntries()));
1581 return;
1582 }
1583
1584 // path is wildcard: loop on the cache and unload all comprised objects!
1585 TIter iter(fEntryCache.GetTable());
1586 TPair* pair = 0;
1587 Int_t removed=0;
1588
1589 while((pair = dynamic_cast<TPair*> (iter.Next()))){
1590 AliCDBPath entryPath = pair->Key()->GetName();
1591 if(queryPath.Comprises(entryPath)) {
1592 AliDebug(2, Form("Unloading object \"%s\" from cache and from list of ids", entryPath.GetPath().Data()));
1593 TObjString pathStr(entryPath.GetPath());
1594 delete fEntryCache.Remove(&pathStr);
1595 removed++;
1596
1597 // we do not remove from the list of Id's (it's not very coherent but we leave the
1598 // id for the benefit of the userinfo)
1599 /*
1600 TIter iterids(fIds);
1601 AliCDBId *anId = 0;
1602 while((anId = dynamic_cast<AliCDBId*> (iterids.Next()))){
1603 AliCDBPath aPath = anId->GetPath();
1604 TString aPathStr = aPath.GetPath();
1605 if(queryPath.Comprises(aPath)) {
1606 delete fIds->Remove(anId);
1607 }
1608 }*/
1609 }
1610 }
1611 AliDebug(2,Form("Cache entries and ids removed: %d Remaining: %d",removed,fEntryCache.GetEntries()));
4005d0b5 1612}
1613
9e1ceb13 1614//_____________________________________________________________________________
1615void AliCDBManager::DestroyActiveStorages() {
1616// delete list of active storages
1617
5078a13f 1618 fActiveStorages.DeleteAll();
1619 fSpecificStorages.DeleteAll();
9e1ceb13 1620}
1621
1622//_____________________________________________________________________________
1623void AliCDBManager::DestroyActiveStorage(AliCDBStorage* /*storage*/) {
b05400be 1624// destroys active storage
1625
5078a13f 1626 /*
1627 TIter iter(fActiveStorages.GetTable());
1628 TPair* aPair;
1629 while ((aPair = (TPair*) iter.Next())) {
1630 if(storage == (AliCDBStorage*) aPair->Value())
1631 delete fActiveStorages.Remove(aPair->Key());
1632 storage->Delete(); storage=0x0;
1633 }
1634 */
9e1ceb13 1635
1636}
1637
62032124 1638//_____________________________________________________________________________
1639void AliCDBManager::QueryCDB() {
1640// query default and specific storages for files valid for fRun. Every storage loads the Ids into its list.
1641
5078a13f 1642 if (fRun < 0){
1643 AliError("Run number not yet set! Use AliCDBManager::SetRun.");
1644 return;
1645 }
1646 if (!fDefaultStorage){
1647 AliError("Default storage is not set! Use AliCDBManager::SetDefaultStorage");
1648 return;
1649 }
1650 if(fDefaultStorage->GetType() == "alien" || fDefaultStorage->GetType() == "local"){
1651 fDefaultStorage->QueryCDB(fRun);
1652 //} else {
1653 // AliDebug(2,"Skipping query for valid files, it used only in grid...");
1654 }
1655
1656 TIter iter(&fSpecificStorages);
1657 TObjString *aCalibType=0;
1658 AliCDBParam* aPar=0;
1659 while((aCalibType = dynamic_cast<TObjString*> (iter.Next()))){
1660 aPar = (AliCDBParam*) fSpecificStorages.GetValue(aCalibType);
1661 if(aPar) {
1662 AliDebug(2,Form("Querying specific storage %s",aCalibType->GetName()));
1663 AliCDBStorage *aStorage = GetStorage(aPar);
7ab8651a 1664 if(aStorage->GetType() == "alien" || aStorage->GetType() == "local"){
003e9909 1665 aStorage->QueryCDB(fRun, aCalibType->GetName());
5078a13f 1666 } else {
1667 AliDebug(2,
1668 "Skipping query for valid files, it is used only in grid...");
1669 }
1670 }
1671 }
62032124 1672}
1673
b8ec52f6 1674//______________________________________________________________________________________________
5078a13f 1675const char* AliCDBManager::GetDataTypeName(DataType type) {
1676// returns the name (string) of the data type
b8ec52f6 1677
5078a13f 1678 switch (type){
1679 case kCondition: return "Conditions";
1680 case kReference: return "Reference";
1681 case kPrivate: return "Private";
1682 }
1683 return 0;
b8ec52f6 1684
1685}
62032124 1686
a37a1dfc 1687//______________________________________________________________________________________________
5078a13f 1688Bool_t AliCDBManager::DiffObjects(const char *cdbFile1, const char *cdbFile2) const {
1689// Compare byte-by-byte the objects contained in the CDB entry in two different files,
1690// whose name is passed as input
1691// Return value:
1692// kTRUE - in case the content of the OCDB object (persistent part) is exactly the same
1693// kFALSE - otherwise
1694
1695 TString f1Str(cdbFile1);
1696 TString f2Str(cdbFile2);
1697 if (!gGrid && ( f1Str.BeginsWith("alien://") || f2Str.BeginsWith("alien://") ))
1698 TGrid::Connect("alien://");
1699
1700 TFile * f1 = TFile::Open(cdbFile1);
1701 if (!f1){
1702 Printf("Cannot open file \"%s\"",cdbFile1);
1703 return kFALSE;
1704 }
1705 TFile * f2 = TFile::Open(cdbFile2);
1706 if (!f2){
1707 Printf("Cannot open file \"%s\"",cdbFile2);
1708 return kFALSE;
1709 }
a37a1dfc 1710
5078a13f 1711 AliCDBEntry * entry1 = (AliCDBEntry*)f1->Get("AliCDBEntry");
1712 if (!entry1){
1713 Printf("Cannot get CDB entry from file \"%s\"",cdbFile1);
1714 return kFALSE;
1715 }
1716 AliCDBEntry * entry2 = (AliCDBEntry*)f2->Get("AliCDBEntry");
1717 if (!entry2){
1718 Printf("Cannot get CDB entry from file \"%s\"",cdbFile2);
1719 return kFALSE;
1720 }
a37a1dfc 1721
5078a13f 1722 // stream the two objects in the buffer of two TMessages
1723 TObject* object1 = entry1->GetObject();
1724 TObject* object2 = entry2->GetObject();
1725 TMessage * file1 = new TMessage(TBuffer::kWrite);
1726 file1->WriteObject(object1);
1727 Int_t size1 = file1->Length();
1728 TMessage * file2 = new TMessage(TBuffer::kWrite);
1729 file2->WriteObject(object2);
1730 Int_t size2 = file2->Length();
1731 if (size1!=size2){
1732 Printf("Problem 2: OCDB entry of different size (%d,%d)",size1,size2);
1733 return kFALSE;
1734 }
1735
1736 // if the two buffers have the same size, check that they are the same byte-by-byte
1737 Int_t countDiff=0;
1738 char* buf1 = file1->Buffer();
1739 char* buf2 = file2->Buffer();
1740 //for (Int_t i=0; i<size1; i++) if (file1->Buffer()[i]!=file2->Buffer()[i]) countDiff++;
1741 for(Int_t i=0; i<size1; i++)
1742 if (buf1[i]!=buf2[i]) countDiff++;
1743
1744 if (countDiff>0){
1745 Printf("The CDB objects differ by %d bytes.", countDiff);
1746 return kFALSE;
1747 }
a37a1dfc 1748
5078a13f 1749 Printf("The CDB objects are the same in the two files.");
1750 return kTRUE;
a37a1dfc 1751}
1752
4667c116 1753//______________________________________________________________________________________________
5078a13f 1754void AliCDBManager::InitShortLived() {
1755// Init the list of short-lived objects
1756// currently disabled
1757
1758 fShortLived=0x0;
1759
1760 // fShortLived = new TList();
1761 // fShortLived->SetOwner(1);
1762 //
1763 // fShortLived->Add(new TObjString("EMCAL/Calib/Data"));
1764 //
1765 // fShortLived->Add(new TObjString("HMPID/Calib/Nmean"));
1766 // fShortLived->Add(new TObjString("HMPID/Calib/Qthre"));
1767 //
1768 // fShortLived->Add(new TObjString("ITS/Calib/CalibSPD"));
1769 //
1770 // fShortLived->Add(new TObjString("MUON/Calib/Gains"));
1771 // fShortLived->Add(new TObjString("MUON/Calib/HV"));
1772 // fShortLived->Add(new TObjString("MUON/Calib/Pedestals"));
1773 //
1774 // fShortLived->Add(new TObjString("PHOS/Calib/CpvGainPedestals"));
1775 // fShortLived->Add(new TObjString("PHOS/Calib/EmcGainPedestals"));
1776 //
1777 // fShortLived->Add(new TObjString("PMD/Calib/Data"));
1778 //
1779 // fShortLived->Add(new TObjString("TRD/Calib/ChamberGainFactor"));
1780 // fShortLived->Add(new TObjString("TRD/Calib/LocalGainFactor"));
1781 // fShortLived->Add(new TObjString("TRD/Calib/ChamberT0"));
1782 // fShortLived->Add(new TObjString("TRD/Calib/LocalT0"));
1783 // fShortLived->Add(new TObjString("TRD/Calib/ChamberVdrift"));
1784 // fShortLived->Add(new TObjString("TRD/Calib/LocalVdrift"));
1785 //
1786 // fShortLived->Add(new TObjString("ZDC/Calib/Data"));
4667c116 1787
1788}
1789
1790//______________________________________________________________________________________________
5078a13f 1791Bool_t AliCDBManager::IsShortLived(const char* path) {
1792// returns the name (string) of the data type
4667c116 1793
5078a13f 1794 if(!fShortLived) return kFALSE;
4667c116 1795
5078a13f 1796 AliCDBPath aPath(path);
1797 if(!aPath.IsValid()){
1798 AliError(Form("Not a valid path: %s", path));
1799 return kFALSE;
1800 }
4667c116 1801
5078a13f 1802 return fShortLived->Contains(path);
4667c116 1803
1804}
1805
1f341624 1806//______________________________________________________________________________________________
096d8e90 1807ULong64_t AliCDBManager::SetLock(Bool_t lock, ULong64_t key){
5078a13f 1808// To lock/unlock user must provide the key. A new key is provided after
1809// each successful lock. User should always backup the returned key and
1810// use it on next access.
a6f59240 1811 if (fLock == lock) return 0; // nothing to be done
1812 if (lock) {
1813 // User wants to lock - check his identity
1814 if (fKey) {
1815 // Lock has a user - check his key
1816 if (fKey != key) {
1817 AliFatal("Wrong key provided to lock CDB. Please remove CDB lock access from your code !");
1818 return 0;
5078a13f 1819 }
1820 }
1821 // Provide new key
a6f59240 1822 fKey = gSystem->Now();
1823 fLock = kTRUE;
1824 return fKey;
1825 }
1826 // User wants to unlock - check the provided key
1827 if (key != fKey) {
1828 AliFatal("Lock is ON: wrong key provided");
1829 return 0;
5078a13f 1830 }
a6f59240 1831 fLock = kFALSE;
5078a13f 1832 return key;
1f341624 1833}
1834
9e1ceb13 1835///////////////////////////////////////////////////////////
1836// AliCDBManager Parameter class //
1837// interface to specific AliCDBParameter class //
1838// (AliCDBGridParam, AliCDBLocalParam, AliCDBDumpParam) //
1839///////////////////////////////////////////////////////////
1840
62032124 1841AliCDBParam::AliCDBParam():
fe12e09c 1842 fType(),
1843 fURI()
62032124 1844{
5078a13f 1845 // constructor
9e1ceb13 1846
1847}
1848
1849//_____________________________________________________________________________
1850AliCDBParam::~AliCDBParam() {
5078a13f 1851 // destructor
9e1ceb13 1852
1853}
1854